Switch

A toggle control for binary on/off states.

Installation

Install the component package, shared coss-svelte theme, and Bits UI peer.

npm install coss-svelte @coss-svelte/theme bits-ui

Usage

Import the Svelte component exports directly from the package.

import { Switch, SwitchThumb } from "coss-svelte";

Anatomy

  • Switch
  • SwitchThumb

API Reference

Switch

A toggle control for binary on/off states.

PropTypeDefaultDescription
idstringuseId()ID forwarded to the form control.
bind:checkedbooleanfalseChecked state for the control. Bind with `bind:checked` when supported.
labelstring""Accessible label or fallback visible label for the control.
children : Snippet<[SwitchRootSnippetProps]>bind:ref : HTMLElement | null

Inherits from Bits UI Switch.Root.

SwitchThumb

Renders the draggable or moving indicator.

children : Snippet<[SwitchRootSnippetProps]>bind:ref : HTMLElement | null

Inherits from Bits UI Switch.Thumb.

Implementation Details

Status
Stable
Foundation
bits
Category
Toggle & Choice
Particles
6