Checkbox
Checkbox (체크박스)
여러 개 중 여러 개를 고르는 다중 선택 컴포넌트예요. 단독으로도 쓰고, CheckboxGroup으로 묶어서 그룹 선택·전체 선택·최대 개수 제한까지 구현할 수 있어요.
출처: 문서
본문
소개 (Intro)
다중 선택 버튼으로 선택에 사용해요.
설치 (Install)
import { createApp } from 'vue'
import { Checkbox, CheckboxGroup } from '@nutui/nutui'
const app = createApp()
app.use(Checkbox)
app.use(CheckboxGroup)
데모 (Demos)
아래 항목들은 원문 문서의 대화형 데모로 제공돼요.
- 기본 사용법 (Basic Usage) —
demo: checkbox basic - 반쯤 선택 (Indeterminate) —
demo: checkbox indeterminate - 비활성화 (Disabled) —
demo: checkbox disabled - 커스텀 크기 (Custom Size) —
demo: checkbox size - 커스텀 아이콘 (Custom Icon) —
demo: checkbox icon - change 이벤트 (Change Event) —
demo: checkbox event - CheckboxGroup —
demo: checkbox group - CheckboxGroup 비활성화 (Disabled CheckboxGroup) —
demo: checkbox group-disabled - CheckboxGroup 메서드 (CheckboxGroup Methods) —
demo: checkbox methods - CheckboxGroup 최대 선택 개수 제한 (Limit the maximum number of options) —
demo: checkbox max - 전체 선택 / 반쯤 / 취소 (Select all / half / cancel) —
demo: checkbox methods - 버튼 모양 (Button Shape) —
demo: checkbox shape
커스텀 아이콘 (Custom Icon)
슬롯으로 아이콘을 커스터마이즈할 수 있어요. 이때 icon과 checkedIcon 두 슬롯을 같이 설정하는 걸 추천해요.
change 이벤트 (Change Event)
값이 바뀌면 change 이벤트가 발생해요.
API
Checkbox Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| v-model | If selected | boolean | false |
| disabled | Disable selection | boolean | false |
| text-position | The position of the text, optional value:left,right |
string | right |
| icon-size | Icon Size | string | number | 18 |
| label | Text content of the check box | string | - |
| indeterminate | Whether half selection status is currently supported. It is generally used in select all operation | boolean | false |
| shape | Shape, optional values:button、round |
String | round |
Checkbox Slots
| Name | Description |
|---|---|
| icon | Icon when not selected |
| checkedIcon | Icon when selected |
| indeterminate | Icon when half selected |
CheckboxGroup Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| v-model | Identifier of the currently selected item, corresponding to label |
Array | - |
| disabled | Whether to disable the selection, which will be used for all check boxes under it | boolean | false |
| max | Limit the number of choices. It cannot be used with select all / cancel / invert selection. `0 'means there is no limit | number | 0 |
Checkbox Events
| Event | Description | Arguments |
|---|---|---|
| change | Triggered when the value changes | (state, label),state represents the current state,label indicates the currently selected value |
CheckboxGroup Events
| Event | Description | Arguments |
|---|---|---|
| change | Triggered when the value changes | label,label returns an array representing the collection of currently selected items |
CheckboxGroup Methods
| methodName | Description | Arguments |
|---|---|---|
| toggleAll | Select all / cancel | true,to select all,false,cancel the selection |
| toggleReverse | Reverse selection | - |
Theming
CSS Variables
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
| Name | Default Value |
|---|---|
| --nut-checkbox-label-color | #1d1e1e |
| --nut-checkbox-label-disable-color | #999 |
| --nut-checkbox-icon-disable-color | #d6d6d6 |
| --nut-checkbox-label-margin-left | 15px |
| --nut-checkbox-label-font-size | 14px |
| --nut-checkbox-icon-font-size | 18px |
| --nut-checkbox-icon-disable-color2 | var(--nut-help-color) |
| --nut-checkbox-button-padding | 5px 18px |
| --nut-checkbox-button-font-size | 12px |
| --nut-checkbox-button-border-radius | 15px |
| --nut-checkbox-button-border-color | #f6f7f9 |
| --nut-checkbox-button-background | #f6f7f9 |
| --nut-checkbox-button-font-color-active | var(--nut-primary-color) |
| --nut-checkbox-button-border-color-active | var(--nut-primary-color) |
| --nut-checkbox-button-background-active | var(--nut-primary-color) |
| --nut-checkbox-display | inline-flex |
| --nut-checkbox-margin-right | 20px |
더 알아보기 (Learn more)
- 원문 문서: Checkbox — NutUI v4 영문 문서
- NutUI 저장소: jd-opensource/nutui