coss.com Svelte

Toggle

A two-state button that can be toggled on or off.

API Reference
Loading p-toggle-1 preview…

Installation

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/toggle.json

Usage

<script lang="ts">
  import { Toggle } from "$lib/components/ui/toggle/index.js";
</script>

<Toggle>Toggle</Toggle>

API Reference

Toggle

Styled wrapper for the Shards toggle with variant and size options.

PropTypeDefaultDescription
variant"default" \| "outline""default"Controls the toggle styling
size"default" \| "sm" \| "lg""default"Controls the toggle size
pressedbooleanfalseCurrent pressed state; supports bind:pressed
onPressedChange(pressed: boolean) => voidRuns when the pressed state changes
disabledbooleanfalsePrevents focus and activation
valuestringautoIdentifies the toggle inside a Toggle Group
askeyof HTMLElementTagNameMap"button"HTML element to render

See the Shards Toggle API for state and keyboard props.

Examples

Outline

Loading p-toggle-2 preview…

With Icon

Loading p-toggle-3 preview…

Small Size

Loading p-toggle-4 preview…

Large Size

Loading p-toggle-5 preview…

Disabled

Loading p-toggle-6 preview…

Icon Group

Loading p-toggle-7 preview…