Checkbox component allows users to select multiple options.
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}
19Checkbox props extends the input HTML attributes (except type and onChange).
| Prop | description | Type | Default |
|---|---|---|---|
| children | The label content of the checkbox |
| |
| checked | Whether the checkbox is checked (controlled) |
|
|
| defaultChecked | Whether the checkbox is checked by default (uncontrolled) |
|
|
| disabled | Whether the checkbox is disabled |
|
|
| onChange | Callback when the checked state changes |
|
|
| colors | Custom color variables for the checkbox |
|
|