-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FEAT] Switch 컴포넌트, 스토리북 제작 #20
Changes from all commits
c9a7253
155cbd5
3514e6a
98938b6
0960cfb
4f49357
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 |
---|---|---|
|
@@ -41,3 +41,4 @@ yarn-error.log* | |
next-env.d.ts | ||
|
||
*storybook.log | ||
storybook-static |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { COLORS } from '@/shared/lib/colors'; | ||
|
||
import { Switch } from '.'; | ||
|
||
const meta = { | ||
title: 'components/common/Switch', | ||
component: Switch, | ||
tags: ['autodocs'], | ||
} satisfies Meta<typeof Switch>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Switch>; | ||
|
||
export const Basic: Story = { | ||
args: { | ||
color: 'primary', | ||
}, | ||
argTypes: { | ||
color: { | ||
control: { type: 'select' }, | ||
table: { | ||
type: { summary: 'SwitchColor' }, | ||
defaultValue: { summary: 'primary' }, | ||
}, | ||
options: Object.keys(COLORS), | ||
}, | ||
}, | ||
render: (args) => <Switch {...args} />, | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||||
import * as SwitchPrimitives from '@radix-ui/react-switch'; | ||||||||||
|
||||||||||
import { COLORS, SwitchColor } from '@/shared/lib/colors'; | ||||||||||
|
||||||||||
type Props = React.ComponentProps<typeof SwitchPrimitives.Root> & { | ||||||||||
/** | ||||||||||
* color of the switch. | ||||||||||
* @default 'primary' | ||||||||||
*/ | ||||||||||
color?: SwitchColor; | ||||||||||
}; | ||||||||||
|
||||||||||
export function Switch({ color = 'primary', ...props }: Props) { | ||||||||||
return ( | ||||||||||
<SwitchPrimitives.Root | ||||||||||
{...props} | ||||||||||
className="group flex h-3.5 w-7 items-center rounded-full shadow-lg data-[state=checked]:bg-[var(--switch-color)] data-[state=unchecked]:bg-gray-500" | ||||||||||
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 접근성 개선이 필요합니다. Switch 컴포넌트의 접근성을 높이기 위해 ARIA 레이블과 역할을 명시적으로 설정하는 것이 좋습니다. 다음과 같이 수정하는 것을 제안드립니다: className="group flex h-3.5 w-7 items-center rounded-full shadow-lg data-[state=checked]:bg-[var(--switch-color)] data-[state=unchecked]:bg-gray-500"
+aria-label="Toggle switch"
+role="switch" 📝 Committable suggestion
Suggested change
|
||||||||||
style={color && ({ '--switch-color': COLORS[color] } as React.CSSProperties)} | ||||||||||
> | ||||||||||
<SwitchPrimitives.Thumb className="h-5 w-5 -translate-x-1.5 rounded-full bg-white shadow-inner drop-shadow-md duration-100 group-data-[state=checked]:translate-x-3.5" /> | ||||||||||
</SwitchPrimitives.Root> | ||||||||||
); | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Switch } from './Switch'; |
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.
피그마 상에는 다른 색상은 사용되고 있지 않은 것으로 확인했는데, 다른 색상의 사용 활용에 대해 전달받으신 부분이 있는지 궁금합니다 !
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.
PR에도 남긴 부분인데, 디자인팀과는 primary 단일 색상으로 의견을 맞췄어요.
하지만 다른 색상을 적용해야하는 경우가 존재할 수 있다고 판단했고, 이 경우에 대응이 쉽도록
color 속성 + defualt
처리했어요 :)