Checkbox
테마가 적용된 체크박스 요소예요. 표준 체크박스를 확장해서 상태 표시와 크기, 변형 등을 지원해요.
출처: 문서
본문
Checkbox는 테마가 적용된 표준 체크박스 요소의 확장판이에요.
사용법 (Usage)
import { Checkbox } from '@primereact/ui/checkbox';
<Checkbox.Root>
<Checkbox.Box>
<Checkbox.Indicator />
</Checkbox.Box>
</Checkbox.Root>
예제 (Examples)
기본 (Basic)
라벨과 함께 불리언 값을 토글해요.
인디케이터 (Indicator)
Checkbox.Indicator를 사용해 Checkbox.Box 안에 시각적 상태를 렌더링해요.
Checkbox.Indicator는 체크박스 상태에 따라 렌더링할 수 있도록 match prop도 받아요.
<Checkbox.Root indeterminate>
<Checkbox.Box>
<Checkbox.Indicator match="checked">
<Check />
</Checkbox.Indicator>
<Checkbox.Indicator match="unchecked">
<Times />
</Checkbox.Indicator>
<Checkbox.Indicator match="indeterminate">
<Minus />
</Checkbox.Indicator>
</Checkbox.Box>
</Checkbox.Root>
사용 가능한 match 값은 checked, unchecked, indeterminate, always예요. 기본값은 always라서, match prop이 없으면 인디케이터가 어떤 상태에서든 마운트된 채 유지돼요.
match="always"(기본값)를 쓰면 인디케이터가 항상 렌더링돼요. 그래서 상태별로 인디케이터를 바꾸는 대신, className 안의 data-checked, data-unchecked, data-indeterminate 상태 속성으로 직접 표시 여부를 제어하면 돼요:
<Checkbox.Root>
<Checkbox.Box>
<Checkbox.Indicator match="always" className="hidden data-checked:block">
<Check />
</Checkbox.Indicator>
</Checkbox.Box>
</Checkbox.Root>
불확정 (Indeterminate)
indeterminate 속성을 사용해 불확정 상태를 표시해요.
크기 (Sizes)
size 속성으로 체크박스의 크기를 바꿔요.
채우기 (Filled)
variant="filled" 속성을 지정하면 기본 outlined 스타일보다 시각적 강조가 더 강한 모습으로 표시돼요.
비활성 (Disabled)
disabled 속성으로 체크박스를 비활성화해요.
유효하지 않음 (Invalid)
invalid 속성을 지정하면 빨간 테두리로 표시돼요.
관련 자료 (Related)
하위 컴포넌트 (Sub-Components)
CheckboxRoot, CheckboxBox, CheckboxIndicator, CheckboxGroup 컴포넌트 문서는 Primitive API에서 확인할 수 있어요.
훅 (Hooks)
useCheckbox와 useCheckboxGroup 훅 문서는 Headless API에서 확인할 수 있어요.
접근성 (Accessibility)
WAI-ARIA 준수 상세와 키보드 지원은 Checkbox Primitive에서 확인할 수 있어요.
테마 (Theming)
CSS 클래스 (CSS Classes)
styled 모드에서 사용하는 클래스 이름 목록이에요.
| ClassName | Description |
|---|---|
| p-checkbox | Class name of the root element |
| p-checkbox-box | Class name of the box element |
| p-checkbox-input | Class name of the input element |
| p-checkbox-indicator | Class name of the indicator element |
디자인 토큰 (Design Tokens)
디자인 토큰 목록이에요.
| Token | CSS Variable | Description |
|---|---|---|
| checkbox.border.radius | --p-checkbox-border-radius | Border radius of root |
| checkbox.width | --p-checkbox-width | Width of root |
| checkbox.height | --p-checkbox-height | Height of root |
| checkbox.background | --p-checkbox-background | Background of root |
| checkbox.checked.background | --p-checkbox-checked-background | Checked background of root |
| checkbox.checked.hover.background | --p-checkbox-checked-hover-background | Checked hover background of root |
| checkbox.disabled.background | --p-checkbox-disabled-background | Disabled background of root |
| checkbox.filled.background | --p-checkbox-filled-background | Filled background of root |
| checkbox.border.color | --p-checkbox-border-color | Border color of root |
| checkbox.hover.border.color | --p-checkbox-hover-border-color | Hover border color of root |
| checkbox.focus.border.color | --p-checkbox-focus-border-color | Focus border color of root |
| checkbox.checked.border.color | --p-checkbox-checked-border-color | Checked border color of root |
| checkbox.checked.hover.border.color | --p-checkbox-checked-hover-border-color | Checked hover border color of root |
| checkbox.checked.focus.border.color | --p-checkbox-checked-focus-border-color | Checked focus border color of root |
| checkbox.checked.disabled.border.color | --p-checkbox-checked-disabled-border-color | Checked disabled border color of root |
| checkbox.invalid.border.color | --p-checkbox-invalid-border-color | Invalid border color of root |
| checkbox.shadow | --p-checkbox-shadow | Shadow of root |
| checkbox.focus.ring.width | --p-checkbox-focus-ring-width | Focus ring width of root |
| checkbox.focus.ring.style | --p-checkbox-focus-ring-style | Focus ring style of root |
| checkbox.focus.ring.color | --p-checkbox-focus-ring-color | Focus ring color of root |
| checkbox.focus.ring.offset | --p-checkbox-focus-ring-offset | Focus ring offset of root |
| checkbox.focus.ring.shadow | --p-checkbox-focus-ring-shadow | Focus ring shadow of root |
| checkbox.transition.duration | --p-checkbox-transition-duration | Transition duration of root |
| checkbox.sm.width | --p-checkbox-sm-width | Sm width of root |
| checkbox.sm.height | --p-checkbox-sm-height | Sm height of root |
| checkbox.lg.width | --p-checkbox-lg-width | Lg width of root |
| checkbox.lg.height | --p-checkbox-lg-height | Lg height of root |
| checkbox.icon.size | --p-checkbox-icon-size | Size of icon |
| checkbox.icon.color | --p-checkbox-icon-color | Color of icon |
| checkbox.icon.checked.color | --p-checkbox-icon-checked-color | Checked color of icon |
| checkbox.icon.checked.hover.color | --p-checkbox-icon-checked-hover-color | Checked hover color of icon |
| checkbox.icon.disabled.color | --p-checkbox-icon-disabled-color | Disabled color of icon |
| checkbox.icon.sm.size | --p-checkbox-icon-sm-size | Sm size of icon |
| checkbox.icon.lg.size | --p-checkbox-icon-lg-size | Lg size of icon |