Skip to content

← All components

Actions and forms

Switch

Immediate boolean setting with switch semantics.

Live example

Usage

Each example includes the complete adapter-specific parameter reference. Copy it as a starting point, then remove options your use case does not need.

React

tsx
import { Switch } from "@cofob/design-system-react";

/**
 * Complete Switch parameter reference.
 * @param checked/defaultChecked
 *   type: boolean; controlled or initial state
 *   default: —
 *   example: true
 * @param label
 *   type: string | renderable content
 *   default: —
 *   example: "Accessible label"
 * @param description
 *   type: string | renderable content
 *   default: —
 *   example: "Supporting context for this control."
 * @param size
 *   type: "sm" | "md" | "lg" (plus heading sizes)
 *   default: "md"
 *   example: "md"
 * @param children
 *   type: ReactNode | Svelte Snippet | child HTML
 *   default: —
 *   example: children / snippet / child HTML
 * @param input attributes
 *   type: native element attributes
 *   default: —
 *   example: class / style / aria-* / data-*
 */
export function SwitchExample() {
  return (
    <Switch label="Dark mode" />
  );
}

Svelte

svelte
<script lang="ts">
  import { Switch } from "@cofob/design-system-svelte";

  // Complete Switch parameter reference.
  // checked/defaultChecked
  //   type: boolean; controlled or initial state
  //   default: —
  //   example: true
  // label
  //   type: string | renderable content
  //   default: —
  //   example: "Accessible label"
  // description
  //   type: string | renderable content
  //   default: —
  //   example: "Supporting context for this control."
  // size
  //   type: "sm" | "md" | "lg" (plus heading sizes)
  //   default: "md"
  //   example: "md"
  // children
  //   type: ReactNode | Svelte Snippet | child HTML
  //   default: —
  //   example: children / snippet / child HTML
  // onCheckedChange
  //   type: (checked: boolean) => void (Svelte)
  //   default: —
  //   example: {handleCheckedChange}
  // input attributes
  //   type: native element attributes
  //   default: —
  //   example: class / style / aria-* / data-*
</script>

<Switch label="Dark mode" bind:checked />

HTML

html
<!--
  Complete Switch parameter reference.
  checked/defaultChecked
    type: boolean; controlled or initial state
    default: —
    example: true
  label
    type: string | renderable content
    default: —
    example: "Accessible label"
  description
    type: string | renderable content
    default: —
    example: "Supporting context for this control."
  size
    type: "sm" | "md" | "lg" (plus heading sizes)
    default: "md"
    example: "md"
  children
    type: ReactNode | Svelte Snippet | child HTML
    default: —
    example: children / snippet / child HTML
  input attributes
    type: native element attributes
    default: —
    example: class / style / aria-* / data-*
-->
<button class="cf-switch" role="switch" aria-checked="false">Dark mode</button>

<script type="module">
  import { initDesignSystem } from "@cofob/design-system-css";

  const designSystem = initDesignSystem(document);
  window.addEventListener("pagehide", () => designSystem.destroy(), { once: true });
</script>

Parameters

Adapter differences are explicit. Native element attributes are forwarded in React and Svelte and can be written directly in HTML.

ParameterTypeDefaultAdaptersExampleDescription
checked/defaultCheckedboolean; controlled or initial stateReact · Svelte · HTMLtrueUse checked/bind:checked for controlled state or defaultChecked for initial state.
labelstring | renderable contentReact · Svelte · HTML"Accessible label"Visible or accessible name, depending on the component.
descriptionstring | renderable contentReact · Svelte · HTML"Supporting context for this control."Supporting explanatory content.
size"sm" | "md" | "lg" (plus heading sizes)"md"React · Svelte · HTML"md"Applies a design-system size token.
childrenReactNode | Svelte Snippet | child HTMLReact · Svelte · HTMLchildren / snippet / child HTMLIdiomatic adapter composition content.
onCheckedChange(checked: boolean) => void (Svelte)Svelte{handleCheckedChange}Svelte callback fired after switch state changes.
input attributesnative element attributesReact · Svelte · HTMLclass / style / aria-* / data-*Forwards native class/style, accessibility, event, and data attributes to the root element.