-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Skeleton 컴포넌트 생성 (#90) #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { createVar, style } from "@vanilla-extract/css"; | ||
|
|
||
| import { colors } from "@/styles"; | ||
|
|
||
| export const widthVar = createVar(); | ||
| export const heightVar = createVar(); | ||
| export const radiusVar = createVar(); | ||
|
|
||
| export const wrapper = style({ | ||
| width: widthVar, | ||
| height: heightVar, | ||
| borderRadius: radiusVar, | ||
| backgroundColor: colors.coolNeutral[98], | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import type { Meta, StoryObj } from "@storybook/nextjs"; | ||
|
|
||
| import { Skeleton } from "./Skeleton"; | ||
|
|
||
| const meta: Meta<typeof Skeleton> = { | ||
| title: "Components/Skeleton", | ||
| component: Skeleton, | ||
| tags: ["autodocs"], | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| "Skeleton 컴포넌트는 로딩 상태를 시각적으로 표시하기 위한 사각형 스켈레톤 UI입니다. width, height, radius를 지정할 수 있습니다.", | ||
| }, | ||
| }, | ||
| }, | ||
| argTypes: { | ||
| width: { | ||
| control: "number", | ||
| description: "스켈레톤의 너비 (px)", | ||
| }, | ||
| height: { | ||
| control: "number", | ||
| description: "스켈레톤의 높이 (px)", | ||
| }, | ||
| radius: { | ||
| control: "text", | ||
| description: "스켈레톤의 border-radius (px 또는 string)", | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof Skeleton>; | ||
|
|
||
| export const Default: Story = { | ||
| render: args => <Skeleton {...args} />, | ||
| args: { | ||
| width: 120, | ||
| height: 24, | ||
| radius: 8, | ||
| }, | ||
| }; | ||
|
|
||
| export const CustomRadius: Story = { | ||
| render: args => <Skeleton {...args} />, | ||
| args: { | ||
| width: 120, | ||
| height: 24, | ||
| radius: "50%", | ||
| }, | ||
| }; | ||
|
|
||
| export const VariousSizes: Story = { | ||
| render: () => ( | ||
| <div style={{ display: "flex", gap: 16, alignItems: "center" }}> | ||
| <Skeleton width={40} height={40} radius={20} /> | ||
| <Skeleton width={80} height={16} radius={4} /> | ||
| <Skeleton width={120} height={24} radius={8} /> | ||
| <Skeleton width={200} height={32} radius={16} /> | ||
| </div> | ||
| ), | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { assignInlineVars } from "@vanilla-extract/dynamic"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { coerceCssRemValue } from "@/lib/utils/coerceCssRemValue"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as styles from "./Skeleton.css"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type SkeletonProps = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** 스켈레톤 너비 */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** 스켈레톤 높이 */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| height: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** border-radius(px 또는 string) */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| radius?: number | string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Skeleton 컴포넌트 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @example | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * ```tsx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * <Skeleton width={120} height={24} radius={8} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * ``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const Skeleton = ({ width, height, radius }: SkeletonProps) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const style = assignInlineVars({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [styles.widthVar]: coerceCssRemValue(width), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [styles.heightVar]: coerceCssRemValue(height), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [styles.radiusVar]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof radius === "number" ? coerceCssRemValue(radius) : radius, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <div className={styles.wrapper} style={style} />; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const Skeleton = ({ width, height, radius }: SkeletonProps) => { | |
| const style = assignInlineVars({ | |
| [styles.widthVar]: coerceCssRemValue(width), | |
| [styles.heightVar]: coerceCssRemValue(height), | |
| [styles.radiusVar]: | |
| typeof radius === "number" ? coerceCssRemValue(radius) : radius, | |
| }); | |
| return <div className={styles.wrapper} style={style} />; | |
| }; | |
| export const Skeleton = ({ width, height, radius }: SkeletonProps) => { | |
| const style = assignInlineVars({ | |
| [styles.widthVar]: coerceCssRemValue(width), | |
| [styles.heightVar]: coerceCssRemValue(height), | |
| [styles.radiusVar]: | |
| typeof radius === "number" ? coerceCssRemValue(radius) : radius, | |
| }); | |
| return ( | |
| <div | |
| className={styles.wrapper} | |
| style={style} | |
| role="status" | |
| aria-busy="true" | |
| /> | |
| ); | |
| }; |
🤖 Prompt for AI Agents
In src/components/ui/Skeleton/Skeleton.tsx around lines 25 to 34, the Skeleton
component lacks screen reader accessibility attributes. Add either
aria-busy="true" or role="status" to the div to indicate loading state to
assistive technologies. Optionally, include visually hidden text inside the div
to provide additional context for screen readers.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { Skeleton, type SkeletonProps } from "./Skeleton"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Border-radius 미전달 시 유효하지 않은 CSS가 렌더될 가능성
borderRadius: var(--radiusVar)형태이므로,radiusprop이 넘어오지 않을 때 해당 CSS 변수 자체가 정의되지 않습니다. 이 경우border-radius: var(--radius)가 브라우저에서 invalid value 로 판단되어 전체 규칙이 무시될 수 있습니다.다음과 같이 기본값을 주입해 두면 안전합니다.
📝 Committable suggestion
🤖 Prompt for AI Agents