From 3d83b0c83d934a78c80b7ff698113308c529ac8f Mon Sep 17 00:00:00 2001 From: Seojisoo20191941 Date: Thu, 7 Dec 2023 05:26:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B2=B4=ED=81=AC=EB=B0=95=EC=8A=A4=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/docs/src/App.tsx | 8 +-- apps/docs/src/stories/CheckBox.stories.tsx | 59 ++++++++++++++++++++++ apps/web/app/page.tsx | 4 +- packages/ui/CheckBox/index.tsx | 33 ++++++++++++ packages/ui/CheckBox/style.css.ts | 59 ++++++++++++++++++++++ 5 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 apps/docs/src/stories/CheckBox.stories.tsx create mode 100644 packages/ui/CheckBox/index.tsx create mode 100644 packages/ui/CheckBox/style.css.ts diff --git a/apps/docs/src/App.tsx b/apps/docs/src/App.tsx index 394b833..1970856 100644 --- a/apps/docs/src/App.tsx +++ b/apps/docs/src/App.tsx @@ -1,12 +1,12 @@ -import './App.css' -import { Test } from "ui"; +import { Test } from 'ui'; +import './App.css'; function App() { return ( <> - ) + ); } -export default App +export default App; diff --git a/apps/docs/src/stories/CheckBox.stories.tsx b/apps/docs/src/stories/CheckBox.stories.tsx new file mode 100644 index 0000000..0a07af1 --- /dev/null +++ b/apps/docs/src/stories/CheckBox.stories.tsx @@ -0,0 +1,59 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import { useState } from 'react'; +import CheckBox from 'ui/CheckBox'; + +const meta = { + title: 'Example/CheckBox', + component: CheckBox, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], +} as Meta; + +export default meta; +type Story = StoryObj; + +export const Basic: Story = { + render: function Render() { + const [checked, onChange] = useState(false); + + return onChange(e.target.checked)} />; + }, + + name: '체크박스 기본', +}; + +export const LargeLabel: StoryObj = { + render: function Render() { + const [checked, onChange] = useState(false); + + return ( + onChange(e.target.checked)} + /> + ); + }, + + name: '체크박스 설명 있는 큰 사이즈', +}; + +export const SmallLabel: StoryObj = { + render: function Render() { + const [checked, onChange] = useState(false); + + return ( + onChange(e.target.checked)} + /> + ); + }, + + name: '체크박스 설명 있는 작은 사이즈', +}; diff --git a/apps/web/app/page.tsx b/apps/web/app/page.tsx index bd75328..539da62 100644 --- a/apps/web/app/page.tsx +++ b/apps/web/app/page.tsx @@ -1,5 +1,5 @@ -import { Test } from "ui"; -import styles from "./page.module.css"; +import { Test } from 'ui'; +import styles from './page.module.css'; export default function Page(): JSX.Element { return ( diff --git a/packages/ui/CheckBox/index.tsx b/packages/ui/CheckBox/index.tsx new file mode 100644 index 0000000..3022c1f --- /dev/null +++ b/packages/ui/CheckBox/index.tsx @@ -0,0 +1,33 @@ +import { InputHTMLAttributes, forwardRef } from 'react'; +import { + checkBox, + checkBoxChecked, + checkBoxInput, + checkBoxLabel, + checkBoxWrapper, +} from './style.css'; + +interface CheckBoxProps extends Omit, 'size'> { + label?: string; + size?: 'small' | 'large'; + checked?: boolean; +} + +const CheckBox = forwardRef( + ({ checked = false, label, size = 'small', ...props }, ref) => { + return ( + + ); + } +); + +export default CheckBox; diff --git a/packages/ui/CheckBox/style.css.ts b/packages/ui/CheckBox/style.css.ts new file mode 100644 index 0000000..bd98e5b --- /dev/null +++ b/packages/ui/CheckBox/style.css.ts @@ -0,0 +1,59 @@ +import { style, styleVariants } from '@vanilla-extract/css'; +import theme from '../theme.css'; + +export const checkBoxWrapper = style({ + display: 'flex', + alignItems: 'center', + cursor: 'pointer', +}); + +export const checkBoxInput = style({ + position: 'absolute', + width: '1px', + height: '1px', + overflow: 'hidden', + whiteSpace: 'nowrap', + clip: 'rect(0 0 0 0)', + clipPath: 'inset(50%)', +}); + +const checkBoxBase = style({ + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + transition: '0.2s background-color', + borderRadius: '5px', +}); + +export const checkBox = styleVariants({ + small: [checkBoxBase, { width: '18px', height: '18px' }], + large: [checkBoxBase, { width: '24px', height: '24px' }], +}); + +export const checkBoxChecked = styleVariants({ + true: [checkBoxBase, { backgroundColor: `${theme.colors.blue400}` }], + false: [checkBoxBase, { backgroundColor: `${theme.colors.gray500}` }], +}); + +export const checkBoxLabel = styleVariants({ + small: { + marginLeft: '8px', + // MEMO: 객체 형태로 css 받도록 수정되면 수정하기 + fontFamily: 'SUIT', + fontSize: '14px', + fontStyle: 'normal', + fontWeight: '400', + lineHeight: '22px', + letterSpacing: '-0.21px', + }, + large: { + marginLeft: '10px', + // MEMO: 객체 형태로 css 받도록 수정되면 수정하기 + fontFamily: 'SUIT', + fontSize: '16px', + fontStyle: 'normal', + fontWeight: '400', + lineHeight: '26px', + letterSpacing: '-0.24px', + }, +});