component

Checkbox

Checkbox component to allow the user to select one or more options in the form of a square box available in multiple sizes and colors

Set Up #

To use the Checkbox component, import it in the script tag:

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

Usage #

The Checkbox component allows users to select one or more options in the form of a square box. It is available in multiple styles, sizes, colors, and variants.

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

<Checkbox />

Variant #

The variant prop lets you customize the color theme of the Checkbox:

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

<Checkbox checked variant="primary" />
<Checkbox checked variant="secondary" />
<Checkbox checked variant="success" />
<Checkbox checked variant="warning" />
<Checkbox checked variant="danger" />

Size #

Use the size prop to adjust the size of the Checkbox:

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

<div class="flex flex-row gap-2">
	<Checkbox size="sm" />
	<Checkbox size="md" />
	<Checkbox size="lg" />
</div>

Disabled #

The disabled prop disables the Checkbox:

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

<Checkbox checked disabled />

Default Checked #

Set the initial check state using the checked prop:

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

<Checkbox checked />

Indeterminate #

Use the indeterminate prop to set the Checkbox to an indeterminate state:

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

<Checkbox indeterminate />

Animation #

Control the Checkbox animation using the animation prop:

Example.svelte
<script>
	import { Checkbox } from '@sans-ui/core';
</script>

<Checkbox animation={false} />

Accessibility #

  • Built with native HTML input elements.
  • Full support for browser features like form autofill.
  • Keyboard event support for "Tab" and "Space" keys.
  • Labeling support for assistive technology.
  • Indeterminate state support.

API #

Checkbox provides APIs(Properties) that is necessary for you to configure a Checkbox compponent.

Checkbox Props #

Name Type Default Value
variant 'primary' | 'secondary' | 'success' | 'warning' | 'danger' 'primary'
size 'sm' | 'md' | 'lg' md
label string ""
value string undefined
disabled boolean false
defaultChecked boolean false
indeterminate boolean false
animation boolean true

Checkbox Handlers #

Name Type Description
on:change ChangeEventHandler The change event is fired for , , and elements when a change to the element value is committed by the user.

Checkbox Slots #

Name Description
base This slot is applied to the div element(wrapper) for icon slot.
icon This slot is applied to the svg element(check icon).