-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(Checkbox): 체크박스 공통 컴포넌트 구현 * test(Checkbox): 체크박스 스토리북 작성 * refactor: id값은 필수입력으로 수정 * refactor: autodocs 제거 * style: css 코드 정렬 * refactor: import React 제거
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
frontend/src/components/_common/Checkbox/Checkbox.stories.tsx
This file contains 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,42 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { useArgs } from 'storybook/internal/preview-api'; | ||
|
||
import Checkbox from '.'; | ||
|
||
const meta = { | ||
title: 'Common/Checkbox', | ||
component: Checkbox, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
decorators: [ | ||
(Story, context) => { | ||
const [{ isChecked }, setArgState] = useArgs(); | ||
|
||
const onToggleIsChecked = () => { | ||
setArgState({ isChecked: !isChecked }); | ||
}; | ||
|
||
return ( | ||
<Story | ||
args={{ | ||
...context.args, | ||
onChange: onToggleIsChecked, | ||
}} | ||
/> | ||
); | ||
}, | ||
], | ||
} satisfies Meta<typeof Checkbox>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
id: 'checkbox', | ||
isChecked: false, | ||
labelText: '체크박스입니다.', | ||
}, | ||
}; |
This file contains 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,7 @@ | ||
import { css } from '@emotion/react'; | ||
|
||
export const s_container = css` | ||
display: flex; | ||
gap: 0.2rem; | ||
align-items: center; | ||
`; |
This file contains 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,18 @@ | ||
import type { InputHTMLAttributes } from 'react'; | ||
|
||
import { s_container } from './Checkbox.styles'; | ||
|
||
interface CheckboxProps extends InputHTMLAttributes<HTMLInputElement> { | ||
isChecked: boolean; | ||
labelText: string; | ||
id: string; | ||
} | ||
|
||
export default function Checkbox({ isChecked, id, labelText, ...props }: CheckboxProps) { | ||
return ( | ||
<div css={s_container}> | ||
<input id={id} checked={isChecked} type="checkbox" {...props} /> | ||
<label htmlFor={id}>{labelText}</label> | ||
</div> | ||
); | ||
} |