-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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], | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ), | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { assignInlineVars } from "@vanilla-extract/dynamic"; | ||
| import { type HTMLAttributes } from "react"; | ||
|
|
||
| import { coerceCssRemValue } from "@/lib/utils/coerceCssRemValue"; | ||
|
|
||
| import * as styles from "./Skeleton.css"; | ||
|
|
||
| export type SkeletonProps = { | ||
| /** 스켈레톤 너비 */ | ||
| width: number; | ||
|
|
||
| /** 스켈레톤 높이 */ | ||
| height: number; | ||
|
|
||
| /** border-radius(px, rem, %, 토큰 모두 가능) */ | ||
| radius?: number | string; | ||
| } & HTMLAttributes<HTMLDivElement>; | ||
|
|
||
| /** | ||
| * Skeleton 컴포넌트 | ||
| * @example | ||
| * ```tsx | ||
| * <Skeleton width={120} height={24} radius={8} /> | ||
| * ``` | ||
| */ | ||
| export const Skeleton = ({ | ||
| width, | ||
| height, | ||
| radius, | ||
| style: customStyle, | ||
| ...rest | ||
| }: SkeletonProps) => { | ||
| const style = { | ||
| ...assignInlineVars({ | ||
| [styles.widthVar]: coerceCssRemValue(width), | ||
| [styles.heightVar]: coerceCssRemValue(height), | ||
| [styles.radiusVar]: radius ? coerceCssRemValue(radius) : undefined, | ||
| }), | ||
| ...customStyle, | ||
| }; | ||
|
|
||
| return <div className={styles.wrapper} style={style} {...rest} />; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { Skeleton, type SkeletonProps } from "./Skeleton"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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