# Checkbox

> A tri-look checkbox — unchecked, checked, indeterminate and disabled — built on a native checkbox input.

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

## Import

```tsx
import { Checkbox } 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 box is checked; bindable |
| `indeterminate` | `boolean` | `false` | Mixed/dash visual state; bindable |
| `onCheckedChange` | `(checked: boolean) => void` | — | Called with the new checked value whenever the box is activated |
| `disabled` | `boolean` | `false` | Blocks interaction; excluded from form submission |
| `required` | `boolean` | `false` | Native required |
| `invalid` | `boolean` | `false` | Drives the error border and aria-invalid |
| `id` | `string` | — | Element id |
| `name` | `string` | — | Native name, read on form submission |
| `value` | `string` | — | Form value submitted while checked |
| `label` | `string` | — | Accessible name, rendered as aria-label; skip it when children already supplies the visible label text |
| `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 box |

## Example

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

export function CheckboxExample() {
	const [agreed, setAgreed] = useState(false);

	return (
		<Checkbox sound checked={agreed} onCheckedChange={setAgreed}>
			I agree to the terms and conditions
		</Checkbox>
	);
}
```
