-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: 체크박스 구현
- Loading branch information
Showing
5 changed files
with
157 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import './App.css' | ||
import { Test } from "ui"; | ||
import { Test } from 'ui'; | ||
import './App.css'; | ||
|
||
function App() { | ||
return ( | ||
<> | ||
<Test text="Test Component" size="big" color="blue" /> | ||
</> | ||
) | ||
); | ||
} | ||
|
||
export default App | ||
export default App; |
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,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<typeof CheckBox>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Basic: Story = { | ||
render: function Render() { | ||
const [checked, onChange] = useState<boolean>(false); | ||
|
||
return <CheckBox checked={checked} size="small" onChange={(e) => onChange(e.target.checked)} />; | ||
}, | ||
|
||
name: '체크박스 기본', | ||
}; | ||
|
||
export const LargeLabel: StoryObj = { | ||
render: function Render() { | ||
const [checked, onChange] = useState<boolean>(false); | ||
|
||
return ( | ||
<CheckBox | ||
checked={checked} | ||
size="large" | ||
label="Label" | ||
onChange={(e) => onChange(e.target.checked)} | ||
/> | ||
); | ||
}, | ||
|
||
name: '체크박스 설명 있는 큰 사이즈', | ||
}; | ||
|
||
export const SmallLabel: StoryObj = { | ||
render: function Render() { | ||
const [checked, onChange] = useState<boolean>(false); | ||
|
||
return ( | ||
<CheckBox | ||
checked={checked} | ||
size="small" | ||
label="Label" | ||
onChange={(e) => onChange(e.target.checked)} | ||
/> | ||
); | ||
}, | ||
|
||
name: '체크박스 설명 있는 작은 사이즈', | ||
}; |
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
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,33 @@ | ||
import { InputHTMLAttributes, forwardRef } from 'react'; | ||
import { | ||
checkBox, | ||
checkBoxChecked, | ||
checkBoxInput, | ||
checkBoxLabel, | ||
checkBoxWrapper, | ||
} from './style.css'; | ||
|
||
interface CheckBoxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'> { | ||
label?: string; | ||
size?: 'small' | 'large'; | ||
checked?: boolean; | ||
} | ||
|
||
const CheckBox = forwardRef<HTMLInputElement, CheckBoxProps>( | ||
({ checked = false, label, size = 'small', ...props }, ref) => { | ||
return ( | ||
<label className={checkBoxWrapper}> | ||
<input ref={ref} type="checkbox" {...props} className={checkBoxInput} /> | ||
<div className={`${checkBox[size]} ${checkBoxChecked[`${checked}`]}`}> | ||
{checked && ( | ||
// TODO: 체크 아이콘 삽입 | ||
<></> | ||
)} | ||
</div> | ||
<p className={checkBoxLabel[size]}>{label && label}</p> | ||
</label> | ||
); | ||
} | ||
); | ||
|
||
export default CheckBox; |
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,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', | ||
}, | ||
}); |