Files
shadcn-ui/apps/www/content/docs/components/switch.mdx
shadcn 4ccff13f9c feat: react-hook-form (#377)
* feat(form): add form component

* feat(www): update site styles

* feat: add form examples

* docs(www): add docs for forms

* docs(www): hide tabs for docs demo
2023-05-19 22:56:49 +04:00

67 lines
1.4 KiB
Plaintext

---
title: Switch
description: A control that allows the user to toggle between checked and not checked.
component: true
radix:
link: https://www.radix-ui.com/docs/primitives/components/switch
api: https://www.radix-ui.com/docs/primitives/components/switch#api-reference
---
<ComponentExample src="/components/examples/switch/demo.tsx">
<SwitchDemo />
</ComponentExample>
## Installation
```bash
npx shadcn-ui add switch
```
<Accordion type="single" collapsible>
<AccordionItem value="manual-installation">
<AccordionTrigger>Manual Installation</AccordionTrigger>
<AccordionContent>
1. Install the `@radix-ui/react-switch` component from radix-ui:
```bash
npm install @radix-ui/react-switch
```
2. Copy and paste the following code into your project.
<ComponentSource src="/components/ui/switch.tsx" />
<Callout>
This is the `<Switch />` primitive. You can place it in a file at
`components/ui/switch.tsx`.
</Callout>
</AccordionContent>
</AccordionItem>
</Accordion>
## Usage
```tsx
import { Switch } from "@/components/ui/switch"
```
```tsx
<Switch />
```
## React Hook Form
<Alert className="mt-4">
<AlertDescription>
**Note**: Learn more about using React Hook Form on the
[docs](/docs/forms/react-hook-form) page.
</AlertDescription>
</Alert>
<ComponentExample src="/components/examples/switch/react-hook-form.tsx">
<SwitchReactHookForm />
</ComponentExample>