# Switch

> A sliding on/off control that takes effect immediately, built on a native checkbox input.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Forms
- Tags: switch, toggle, form, settings
- Types: `SwitchProps`, `SwitchSize`
- Docs: https://fancy-ui.rama.app/docs/components/switch
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/switch

## Import

```tsx
import { Switch } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `checked` | `boolean` | `false` | Whether the switch is on; bindable |
| `onCheckedChange` | `(checked: boolean) => void` | — | Called with the new value whenever the switch is activated |
| `disabled` | `boolean` | `false` | Blocks interaction; excluded from form submission |
| `required` | `boolean` | `false` | Native required |
| `id` | `string` | — | Element id |
| `name` | `string` | — | Native name, read on form submission |
| `value` | `string` | — | Form value submitted while on |
| `label` | `string` | — | Accessible name, rendered as aria-label; skip it when children already supplies the visible label text |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Track/knob size |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes, merged onto the wrapping label |
| `ref` | `HTMLInputElement \| null` | `null` | Bindable element reference to the native input |
| `sound` | `boolean` | `false` | Plays toggle-on or toggle-off on each change, once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `children` | Visible label text, rendered beside the track |

## Example

```tsx
import { useState } from "react";
import { Switch } from "fancy-ui-react";

export function SwitchExample() {
	const [notifications, setNotifications] = useState(false);

	return (
		<Switch
			sound
			checked={notifications}
			onCheckedChange={setNotifications}
			label="Notifications"
		/>
	);
}
```
