-
Notifications
You must be signed in to change notification settings - Fork 1
Feat(design-system): 뱃지 컴포넌트 #30
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 all commits
9afe16c
8d30dc9
8a1f4a5
19307b2
be6051f
4dcb82f
0a0a6d5
9a565f4
fe509d6
c82a479
c198917
6ff7e2c
75082e1
a0b21d8
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,54 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react-vite'; | ||
| import { within, userEvent } from '@storybook/test'; | ||
| import Badge, { type BadgeProps } from './Badge'; | ||
|
|
||
| const meta: Meta<typeof Badge> = { | ||
| title: 'Components/Badge', | ||
| component: Badge, | ||
| tags: ['autodocs'], | ||
| args: { | ||
| text: '알림', | ||
| countNum: 3, | ||
| }, | ||
| argTypes: { | ||
| text: { control: 'text', description: '뱃지 라벨 텍스트' }, | ||
| countNum: { | ||
| control: { type: 'number', min: 0 }, | ||
| description: '카운트 숫자(옵션)', | ||
| }, | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| '클릭 시 내부 state(isClick)가 true로 바뀌며 스타일이 활성화됩니다. 토글 방식은 아닙니다.', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof Badge>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const NoCount: Story = { | ||
| args: { text: '카운트 없음', countNum: undefined }, | ||
| }; | ||
|
|
||
| export const LargeCount: Story = { | ||
| args: { text: '메시지', countNum: 12000 }, | ||
| }; | ||
|
|
||
| export const Clicked: Story = { | ||
| args: { text: '클릭해줘', countNum: 5 }, | ||
| play: async ({ canvasElement, args }) => { | ||
| const canvas = within(canvasElement); | ||
| await userEvent.click(await canvas.findByText(String(args.text))); | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { story: '로드 직후 자동 클릭으로 활성 상태 미리보기.' }, | ||
| }, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import { cva } from 'class-variance-authority'; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||
| export interface BadgeProps { | ||||||||||||||||||||||||||||||||||||||||||||||
| text: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| countNum?: number; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| const BadgeTxtStyleVariants = cva('sub3-b', { | ||||||||||||||||||||||||||||||||||||||||||||||
| variants: { | ||||||||||||||||||||||||||||||||||||||||||||||
| click: { | ||||||||||||||||||||||||||||||||||||||||||||||
| true: 'text-font-black-1', | ||||||||||||||||||||||||||||||||||||||||||||||
| false: 'text-font-ltgray-4', | ||||||||||||||||||||||||||||||||||||||||||||||
| } as const, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| defaultVariants: { | ||||||||||||||||||||||||||||||||||||||||||||||
| click: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| const BadgeStyleVariants = cva( | ||||||||||||||||||||||||||||||||||||||||||||||
| 'text-white-bg sub5-sb rounded-[0.4rem] px-[0.8rem] py-[0.4rem]', | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오타 추정: Tailwind/DS 네이밍 관례상 다음 패치를 제안합니다: -const BadgeStyleVariants = cva(
- 'text-white-bg sub5-sb rounded-[0.4rem] px-[0.8rem] py-[0.4rem]',
+const BadgeStyleVariants = cva(
+ 'text-white sub5-sb rounded-[0.4rem] px-[0.8rem] py-[0.4rem]',📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| variants: { | ||||||||||||||||||||||||||||||||||||||||||||||
| click: { | ||||||||||||||||||||||||||||||||||||||||||||||
| true: 'bg-main500', | ||||||||||||||||||||||||||||||||||||||||||||||
| false: 'bg-gray300', | ||||||||||||||||||||||||||||||||||||||||||||||
| } as const, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| defaultVariants: { | ||||||||||||||||||||||||||||||||||||||||||||||
| click: false, | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| const Badge = ({ text, countNum }: BadgeProps) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| const [isClick, setIsClick] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||||||||||||||
| className="flex cursor-pointer items-center justify-center gap-[0.8rem]" | ||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => setIsClick(true)} | ||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||
| <span className={BadgeTxtStyleVariants({ click: isClick })}>{text}</span> | ||||||||||||||||||||||||||||||||||||||||||||||
| <span className={BadgeStyleVariants({ click: isClick })}>{countNum}</span> | ||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 클릭 가능한 요소의 접근성/키보드 조작 개선 ( 현재 다음 패치를 제안합니다: - return (
- <div
- className="flex cursor-pointer items-center justify-center gap-[0.8rem]"
- onClick={() => setIsClick(true)}
- >
+ return (
+ <button
+ type="button"
+ className="inline-flex items-center gap-[0.8rem] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-main500"
+ aria-pressed={isClick}
+ onClick={() => setIsClick((prev) => !prev)}
+ >
@@
- </div>
+ </button>📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export default Badge; | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ export default defineConfig({ | |
| resolve: { | ||
| alias: { | ||
| '@': path.resolve(__dirname, 'src'), | ||
| '@utils': path.resolve(__dirname, './src/utils'), | ||
| '@lib': path.resolve(__dirname, '/src/lib'), | ||
| }, | ||
|
Comment on lines
27
to
29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain중대: @lib 별칭이 절대경로(
아래 패치 적용을 권장합니다. resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
- '@lib': path.resolve(__dirname, '/src/lib'),
+ '@lib': path.resolve(__dirname, 'src/lib'),
},
},적용 후 다음 스크립트로 최소한의 정적 확인을 할 수 있습니다. 🏁 Script executed: #!/bin/bash
# @lib 사용처 나열 및 실존 파일 확인
rg -nP --type=ts --type=tsx "\@lib/" packages/design-system | sed -n '1,100p'
test -d packages/design-system/src/lib && echo "src/lib 디렉터리 존재" || echo "src/lib 없음"Length of output: 187 중대한 경로 해석 오류:
아래와 같이 패치 적용을 권장합니다: resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
- '@lib': path.resolve(__dirname, '/src/lib'),
+ '@lib': path.resolve(__dirname, 'src/lib'),
},
},적용 후 🤖 Prompt for AI Agents |
||
| }, | ||
| build: { | ||
|
|
||
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.
boolean값이니isClick으로 바꾸는 것은 어떨까요?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.
오 boolean은 최대한 가독성 위해서 is~으로 맞춰서 작업해두겠습니다