Appearance
Checkbox
A checkbox in its simplest form provides a toggle between 2 values.
Checkbox Basic Usage
Bind v-model to a Boolean typed variable.
<template>
<div class="flex justify-between items-end">
<HcCheckbox
v-model="checked"
label="Checkbox"
/>
</div>
</template>
<script lang="ts" setup>
import { HcCheckbox } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const checked = ref(false);
</script>
Checkbox States
Checkbox can have different states such as disabled, readonly and indeterminate.
<template>
<div class="flex flex-col">
<HcCheckbox
v-model="value1"
label="Disabled checked"
disabled
/>
<HcCheckbox
v-model="value2"
label="Disabled unchecked"
disabled
class="mt-4"
/>
<HcCheckbox
v-model="value3"
label="Readonly checked"
readonly
class="mt-4"
/>
<HcCheckbox
v-model="value4"
label="Readonly unchecked"
readonly
class="mt-4"
/>
<HcCheckbox
v-model="value5"
label="Indeterminate"
indeterminate
class="mt-4"
/>
</div>
</template>
<script lang="ts" setup>
import { HcCheckbox } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref(true);
const value2 = ref(false);
const value3 = ref(true);
const value4 = ref(true);
const value5 = ref(true);
</script>
Error Usage
Add Boolean prop error or prop errorMsg for show error state
<template>
<div class="flex flex-col">
<HcCheckbox
v-model="value1"
label="Checkbox 1"
error
/>
<HcCheckbox
v-model="value2"
label="Checkbox 2"
:error-msg="!value2 ? 'This field is required' : ''"
class="mt-4"
/>
</div>
</template>
<script lang="ts" setup>
import { HcCheckbox } from '@deeepvision/hope-component-kit';
import { ref } from 'vue';
const value1 = ref(false);
const value2 = ref(false);
</script>
Props
| Property | Type | Values | Description | Default |
|---|---|---|---|---|
| modelValue | Boolean | Boolean | binding value | false |
| label | String | String | label text | |
| disabled | Boolean | Boolean | whether component is disabled | false |
| error | Boolean | Boolean | determine if the component has error and change its style to that state. | false |
| errorMsg | String | String | error message | |
| indeterminate | Boolean | Boolean | same as indeterminate in native checkbox | false |
| readonly | Boolean | Boolean | whether component is read only | false |
| id | String | String | native 'id' attribute | |
| name | String | String | native 'name' attribute |
Slots
| Property | Type | Values | Description | Default |
|---|---|---|---|---|
| left-slot | - | customize left content | ||
| default | - | customize label content |
Events
| Property | Type | Values | Description | Default |
|---|---|---|---|---|
| update:model-value | Function | value - boolean | triggers when the binding value changes | |
| change | Function | value - boolean | triggers when the binding value changes | |
| blur | Function | evt - FocusEvent | triggers when checkbox blurs |