Checkbox
확인란을 통해 사용자는 세트에서 하나 이상의 항목을 선택할 수 있습니다. 옵션을 켜거나 끄는 데 사용할 수 있습니다.
사용 시기
- 여러 옵션에서 여러 값을 선택하는 데 사용됩니다.
- 하나의 확인란만 사용하는 경우 스위치를 사용하여 두 상태 사이를 전환하는 것과 같습니다. 차이점은 스위치가 상태 변경을 직접 트리거하지만 확인란은 상태가 변경된 것으로 표시할 뿐이며 이를 제출해야 한다는 것입니다.
사용 예시
확인란의 기본 사용법.
astro
---
import Checkbox from '@/components/data-entry/Checkbox.astro';
---
<Checkbox id="terms" label="Accept terms and conditions" />
<Checkbox id="newsletter" label="Subscribe to newsletter" checked /> 비활성화됨
비활성화된 확인란.
astro
---
import Checkbox from '@/components/data-entry/Checkbox.astro';
---
<Checkbox id="chk-disabled" label="Disabled unchecked" disabled />
<Checkbox id="chk-disabled-checked" label="Disabled checked" checked disabled /> 상태
확인란에는 오류 상태 및 비활성화 상태가 있을 수 있습니다.
astro
---
import Checkbox from '@/components/data-entry/Checkbox.astro';
---
<Checkbox
id="required-chk"
label="Required field"
error="You must check this box"
/> 슬롯을 사용한 사용자 정의 라벨 및 오류
슬롯을 사용하여 링크와 같은 HTML 요소로 라벨 및 오류 메시지를 사용자 정의할 수 있습니다.
astro
---
import Checkbox from '@/components/data-entry/Checkbox.astro';
---
<Checkbox id="chk-slot-label">
I accept the <a href="#" class="text-blue-500 hover:underline">Terms of Service</a>
</Checkbox>
<Checkbox id="chk-slot-error" error>
<span slot="error" class="text-red-500 text-xs mt-1 block">Custom error with <strong>HTML</strong> support</span>
Default slot is the label
</Checkbox> | 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| id | Unique identifier for the input element. An auto-generated string is used if not provided. | string | auto-generated |
| label | The label text to display next to the checkbox. | string | |
| variant | Controls the visual variant of the checkbox. When the 'error' prop/slot is used, this defaults to 'error'. | 'default' | 'error' | 'default' |
| checked | Determines if the checkbox is checked by default. | boolean | false |
| class | Additional CSS classes to apply to the root element. | string | '' |
| error | Indicates an error state or displays an error message | string | boolean | |
| success | Indicates a success state or displays a success message | string | boolean | |
| disabled | Disables the component | boolean | false |