# Checkbox — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/checkbox

Category: Input controls

creates a checkbox, toggle, or dark theme switch with optional label, error states, and custom on/off values

Public component import: `Checkbox`

Public manager import: `create_checkbox_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Checkbox, create_checkbox_manager } from "sveltekit-ui"

  const manager = create_checkbox_manager({
    label: "Email me product updates",
    name: "product_updates",
    val: false,
  })
</script>

<Checkbox {manager} />
<p>Updates {manager.val ? "enabled" : "disabled"}</p>
```

## Configuration

### `type`

- type: string
- default: checkbox
- description: the display variant: 'checkbox', 'toggle', or 'dark_theme'

### `val`

- type: any
- default: null
- description: the current value of the checkbox, which can match on_val or off_val

### `on_val`

- type: any
- default: true
- description: the value considered 'checked'

### `off_val`

- type: any
- default: false
- description: the value considered 'unchecked'

### `label`

- type: string
- default: null
- description: label text displayed beside the checkbox

### `name`

- type: string
- default: checkbox
- description: the input name attribute

### `color`

- type: string
- default: var(--primary-t)
- description: the base color for the checked state or toggle

### `is_required`

- type: boolean
- default: false
- description: marks the input as required

### `is_read_only`

- type: boolean
- default: false
- description: makes the checkbox read-only if true

### `is_disabled`

- type: boolean
- default: false
- description: disables the checkbox if true

### `is_loading`

- type: boolean
- default: false
- description: displays a loading spinner if true

### `size`

- type: number
- default: 2.4
- description: base size in rem for the checkbox or toggle

### `ml`

- type: number
- default: 0
- description: margin-left in rem

### `mr`

- type: number
- default: 0
- description: margin-right in rem

### `mt`

- type: number
- default: 0
- description: margin-top in rem

### `mb`

- type: number
- default: 0
- description: margin-bottom in rem

### `error_message`

- type: string
- default: null
- description: an error message displayed next to the checkbox

### `on_change`

- type: function
- default: null
- description: callback fired when the checkbox toggles, receiving new value

### `on_hover_change`

- type: function
- default: null
- description: callback fired on pointerenter/leave, receiving true or false

## Methods

### `set_val()`

- description: sets the checkbox value to on_val or off_val; updates internal bool state
- parameters:
  - val_input: any
- returns: void

### `set_val_from_bool()`

- description: sets checkbox to on/off based on a boolean, optionally triggering on_change
- parameters:
  - val_bool_input: boolean
  - is_trigger_on_change: boolean
- returns: void

### `handle_on_hover_change()`

- description: internal event that calls on_hover_change(true/false)
- parameters:
  - input: boolean
- returns: void

## Returned state

### `id`

- type: string
- description: unique id generated for the checkbox input

### `type`

- type: string
- description: the display variant (checkbox, toggle, or dark_theme)

### `val_initial`

- type: any
- description: the initial value set from config

### `val`

- type: any
- description: the current on/off value (on_val or off_val)

### `val_bool`

- type: boolean
- description: true if current value matches on_val, false otherwise

### `off_val`

- type: any
- description: the value for unchecked state

### `on_val`

- type: any
- description: the value for checked state

### `name`

- type: string
- description: the input name attribute

### `label`

- type: string
- description: label text displayed beside the checkbox

### `color`

- type: string
- description: the base color for the checked state or toggle

### `is_required`

- type: boolean
- description: true if the field is required

### `is_read_only`

- type: boolean
- description: true if the checkbox is read-only

### `is_disabled`

- type: boolean
- description: true if the checkbox is disabled

### `is_loading`

- type: boolean
- description: true if a loading spinner is shown

### `error_message`

- type: string
- description: any error text displayed beside the label

### `size`

- type: number
- description: base size in rem of the checkbox or toggle

### `ml`

- type: number
- description: margin-left in rem

### `mr`

- type: number
- description: margin-right in rem

### `mt`

- type: number
- description: margin-top in rem

### `mb`

- type: number
- description: margin-bottom in rem

### `check_icon_manager`

- type: object
- description: icon manager used for the check mark

### `moon_icon_manager`

- type: object
- description: icon manager used for the moon icon in dark_theme mode

### `sun_icon_manager`

- type: object
- description: icon manager used for the sun icon in dark_theme mode
