CheckboxToggle
Toggle switch with sliding pill animation. Semantically a switch (role=“switch”) with optional label and press animation on the thumb.
import { CheckboxToggle } from "phoundry-ui";Basic toggle
Loading interactive example…
View source
<script lang="ts"> import { CheckboxToggle } from "phoundry-ui";
let basic = $state(false);</script>
<div class="flex items-center gap-3"> <CheckboxToggle checked={basic} onchange={() => (basic = !basic)} /> <span class="text-xs text-txt-tertiary">{basic ? "On" : "Off"}</span></div>With label
Loading interactive example…
View source
<script lang="ts"> import { CheckboxToggle } from "phoundry-ui";
let withLabel = $state(true);
let withDesc = $state(false);</script>
<div class="flex flex-col gap-3"> <CheckboxToggle checked={withLabel} onchange={() => (withLabel = !withLabel)} label="Auto-save enabled" /> <CheckboxToggle checked={withDesc} onchange={() => (withDesc = !withDesc)} label="Enable notifications" description="Receive push notifications for important events" /></div>Sizes
Loading interactive example…
View source
<script lang="ts"> import { CheckboxToggle } from "phoundry-ui";
let sizeSm = $state(true);
let sizeMd = $state(false);</script>
<div class="flex flex-col gap-3"> <CheckboxToggle checked={sizeSm} onchange={() => (sizeSm = !sizeSm)} size="sm" label="Small (default)" /> <CheckboxToggle checked={sizeMd} onchange={() => (sizeMd = !sizeMd)} size="md" label="Medium" /></div>Snippet label
Loading interactive example…
View source
<script lang="ts"> import { CheckboxToggle } from "phoundry-ui";
let richLabelToggle = $state(true);</script>
{#snippet promo()} Accept <span class="font-medium text-accent-secondary">beta features</span>{/snippet}
<CheckboxToggle checked={richLabelToggle} onchange={() => (richLabelToggle = !richLabelToggle)} label={promo} description="Pass a snippet when the label needs inline formatting."/>Disabled
Loading interactive example…
View source
<script lang="ts"> import { CheckboxToggle } from "phoundry-ui";
let disabled = $state(false);</script>
<div class="flex flex-col gap-3"> <CheckboxToggle checked={true} disabled label="Disabled (on)" /> <CheckboxToggle checked={disabled} disabled label="Disabled (off)" /></div>API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
checkedrequired | boolean | — | Whether the toggle is on |
onchange | () => void | — | Called when the toggle is flipped |
disabled | boolean | false | Prevents interaction |
size | "xs" | "sm" | "md" | 'sm' | Size of the toggle track and thumb |
label | string | Snippet<[]> | — | Inline label rendered next to the toggle |
description | string | — | Helper text below the label |
class | ClassValue | — | Additional CSS classes |
style | string | — | Inline styles on the component styling target described below. |
id | string | — | Element id (auto-generated if omitted) |
name | string | — | Form field name - renders a hidden input |
elementbindable | HTMLButtonElement | — | Bindable reference to the switch button. |
Other native attributes: Forwarded to the <button> (e.g. aria-describedby).
Usage tips
- Use for boolean settings that take effect immediately (e.g. dark mode, notifications).
- Prefer
CheckboxoverCheckboxTogglewhen the value is part of a form that requires explicit submission. - The thumb has a press animation - users get tactile feedback on click.
- Pass a
nameprop for native form submission via hidden input.
Styling
.ph-toggle is the stable root identification hook. Styling is component-local vanilla CSS; data-size always identifies the selected size. The root is the label wrapper when labelled and the switch button otherwise. class and style apply to that root; native attributes, attachments, and bind:element still target the button. Sizes remain xs, sm, and md. --ph-toggle-thumb-shadow controls the thumb shadow. Press and slide transitions respect reduced-motion preferences. Internal part selectors and --_ph-* properties are implementation details. Filled indicators use the active Theme’s --text-on-accent foreground.