Checkbox
A checkbox component for selecting a boolean value.
Example
Section titled “Example”<script> import { Checkbox } from '@soleil-se/config-svelte';</script>
<Checkbox name="enable" label="Enable option" />| Prop | Type | Description |
|---|---|---|
labelrequired | string | Snippet | Field label, a string or Svelte snippet. |
value$bindable | boolean | Whether the checkbox is selected. Default:false |
description | string | Snippet | Description shown below the field, a string or Svelte snippet. |
name | string | Configuration key and HTML name attribute. |
checked | boolean | Whether the checkbox is initially checked. Default:false |
disabled | boolean | Disables the checkbox. Default:false |
show | boolean | Shows or hides the checkbox without destroying it. Default:true |
class | string | CSS class added to the form-group wrapper. Default:'' |
children | Snippet | Content rendered after the checkbox and validation message. |
onInput | function | Called on the native input event with the updated value. |
onChange | function | Called on the native change event with the updated value. |
validate | function | Custom validator. |
Validation
Section titled “Validation”Checkbox does not run required or native browser validation by default. Provide validate to apply custom validation. It receives a boolean value in its context and returns { success: boolean, message?: string }.
<script> import { Checkbox } from '@soleil-se/config-svelte';
function validateTerms({ value }) { return value ? { success: true } : { success: false, message: 'Du måste godkänna villkoren.' }; }</script>
<Checkbox name="accepted" label="Jag godkänner villkoren" validate={validateTerms} />Validation errors are displayed below the checkbox and prevent saving.
See validation for validation timing.
Snippets
Section titled “Snippets”label and description accept text or Svelte snippets.
Default child content is rendered after the checkbox and validation message.
<script> import { Checkbox } from '@soleil-se/config-svelte';</script>
<Checkbox name="checkbox"> {#snippet label()} Aktivera <strong>alternativet</strong> {/snippet} {#snippet description()} Använd <strong>alternativet</strong> i appen. {/snippet} <p>Ytterligare information.</p></Checkbox>