Checkbox
Checkbox 컴포넌트는 사용자가 여러 옵션을 선택할 수 있게 합니다.
예제
Default Basic checkbox with a label. Users can click to toggle the checked state.
1import { Checkbox } from '@devup-ui/components'
2
3export default function Default() {
4 return <Checkbox>Agree to terms and conditions</Checkbox>
5}
61import { Checkbox } from '@devup-ui/components'
2
3export default function Default() {
4 return <Checkbox>Agree to terms and conditions</Checkbox>
5}
6Checked
Use defaultChecked prop to set the initial checked state for uncontrolled usage, or use checked prop for controlled state management.
1import { Checkbox } from '@devup-ui/components'
2
3export default function Checked() {
4 return <Checkbox defaultChecked>Checked by default</Checkbox>
5}
61import { Checkbox } from '@devup-ui/components'
2
3export default function Checked() {
4 return <Checkbox defaultChecked>Checked by default</Checkbox>
5}
6Disabled
Use disabled prop to prevent user interaction. The checkbox will have a muted appearance and cannot be toggled.
1import { Checkbox } from '@devup-ui/components'
2import { VStack } from '@devup-ui/react'
3
4export default function Disabled() {
5 return (
6 <VStack gap="8px">
7 <Checkbox disabled>Disabled unchecked</Checkbox>
8 <Checkbox defaultChecked disabled>
9 Disabled checked
10 </Checkbox>
11 </VStack>
12 )
13}
141import { Checkbox } from '@devup-ui/components'
2import { VStack } from '@devup-ui/react'
3
4export default function Disabled() {
5 return (
6 <VStack gap="8px">
7 <Checkbox disabled>Disabled unchecked</Checkbox>
8 <Checkbox defaultChecked disabled>
9 Disabled checked
10 </Checkbox>
11 </VStack>
12 )
13}
14Colors
Pass in an object containing color tokens into colors prop. You can customize the checkbox appearance using primary, border, text, inputBg, and checkIcon color values.
1import { Checkbox } from '@devup-ui/components'
2import { Flex } from '@devup-ui/react'
3
4export default function Colors() {
5 return (
6 <Flex flexWrap="wrap" gap="16px">
7 <Checkbox colors={{ primary: '#10B981' }} defaultChecked>
8 Green
9 </Checkbox>
10 <Checkbox colors={{ primary: 'orange' }} defaultChecked>
11 Orange
12 </Checkbox>
13 <Checkbox colors={{ primary: 'steelblue' }} defaultChecked>
14 Steel Blue
15 </Checkbox>
16 </Flex>
17 )
18}
191import { Checkbox } from '@devup-ui/components'
2import { Flex } from '@devup-ui/react'
3
4export default function Colors() {
5 return (
6 <Flex flexWrap="wrap" gap="16px">
7 <Checkbox colors={{ primary: '#10B981' }} defaultChecked>
8 Green
9 </Checkbox>
10 <Checkbox colors={{ primary: 'orange' }} defaultChecked>
11 Orange
12 </Checkbox>
13 <Checkbox colors={{ primary: 'steelblue' }} defaultChecked>
14 Steel Blue
15 </Checkbox>
16 </Flex>
17 )
18}
19API
Checkbox props는 input HTML 속성(type, onChange 제외)을 확장합니다.
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| children | 체크박스의 레이블 내용 |
| |
| checked | 체크박스의 선택 여부(제어) |
|
|
| defaultChecked | 체크박스의 기본 선택 여부(비제어) |
|
|
| disabled | 체크박스의 비활성화 여부 |
|
|
| onChange | 선택 상태가 바뀔 때 호출되는 콜백 |
|
|
| colors | 체크박스의 사용자 정의 색상 변수 |
|
|