Skip to content

Checkbox

Overview

The Checkbox component provides an input for boolean data selection. It's designed with customizable aesthetics and behavior, allowing it to seamlessly fit into various application designs.

Storybook

Props

PropTypeDefaultDescription
modelValueBoolean, ArrayfalseThe value bound to the checkbox. Can be a boolean or an array of values.
labelString''Label displayed alongside the checkbox.
inputClassString''Class to be applied to the checkbox input element.
colorString'primary'Color of the checkbox.
sizeString''Size of the checkbox.
valueString, Number, BooleanfalseValue associated with the checkbox.
nameString''Name attribute for the checkbox.
idString''ID attribute for the checkbox. If not provided, the name prop will be used as the ID.
wrapperClassString''Class to be applied to the component wrapper.
disabledBooleanfalseIf true, the checkbox will be disabled.
errorClassString''Class to be applied to the error message display.
labelClassString''Class to be applied to the label.
hideErrorBooleanfalseIf true, hides the error message even if there's an error.
hintString''Hint or help text displayed below the checkbox.
errorBooleanfalseIndicates if the checkbox has an error.
errorMessageString''Error message displayed when there's a validation error related to the checkbox.

Events

EventPayload TypeDescription
update:modelValueCheckboxValueEmits the current value of the checkbox.

Slots

SlotPropsDescription
default{}Default slot, useful if you want to insert content inside the checkbox's wrapper but outside the checkbox itself.
hint{}Custom hint content. If not provided, the hint prop will be used.
error{}Custom error content. If not provided, the errorMessage prop will be used.

Usage

To use the Checkbox component:

  1. Import the component.
  2. Bind the necessary props.
  3. Optionally, use the slots for custom content.
vue
<script setup lang="ts">
import {ref} from 'vue';
import {Checkbox} from '@morpheme/forms';

const acceptTerms = ref(false);
</script>

<template>
  <Checkbox
    v-model="acceptTerms"
    label="I accept the terms and conditions"
    hint="Make sure to read the terms before proceeding."
  />
</template>
<script setup lang="ts">
import {ref} from 'vue';
import {Checkbox} from '@morpheme/forms';

const acceptTerms = ref(false);
</script>

<template>
  <Checkbox
    v-model="acceptTerms"
    label="I accept the terms and conditions"
    hint="Make sure to read the terms before proceeding."
  />
</template>

This will render a checkbox with a label "I accept the terms and conditions" and a hint message. The checkbox state will be bound to the acceptTerms ref. If the checkbox is checked, acceptTerms will be true, otherwise it will be false.