Controls and surfaces
switch
An on/off switch.
When to use it
A setting that takes effect as soon as it is flipped. For a choice that is submitted with a form use checkbox; for a pressed/unpressed toolbar button use toggle.
See it working
The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Records page.
Compare table
| Plan | Starter | Team | Studio |
|---|---|---|---|
| Basics | |||
| Price a monthBilled yearly | €12Best | €29 | €59 |
| Projects | 3 | 20 | No limitBest |
| Export | Yes | Yes | Yes |
| Support | |||
| Help by email | Within 2 days | Within 2 days | Within 2 days |
| Team | |||
| Members | 1 | 10 | 50 |
Fact rows
- DietVegetarian
- Home airport (editing is controlled)Lisbon
Editing the airport: no
Consent sheet
Decision: nothing yet
Consent panel
Share your trip with the guide?
The guide sees it until the day after the trip.
- Your first nameRequired
- So that the route can be adapted.
Switched on: none. Decision: nothing yet
Language switcher
Chosen: en
Price breakdown and countdown
- 2 × day ticket€46.00 each
- €92.00
- Service fee
- €6.00
- Early booking
- -€10.00
- Audio guide
- Included
- TotalTaxes included
- €88.00
The price is held for no time yet. Ended 0 times.
Undo line
- Market walk
- Lunch
- Pottery class
Timeline
- Done:
Order placed
- Done:
Packed
Two parcels. - Now:
On its way
With the carrier since this morning. - Upcoming:
Delivered
Expected on 15 March.
Add it
npx shadcn@latest add @rivier-ui/switchThe registry is named once in components.json: see Installation.
Example
Import it from @/components/ui/switch.
<Label><Switch defaultChecked /> Weekly summary</Label>
<Switch aria-label="Dark mode" checked={dark} onCheckedChange={setDark} />What it needs
A client component: it uses state, effects or browser behaviour. Packages: radix-ui.
It imports
It is used by
Source
The whole file. Once copied it is yours: the registry item holds the same text.
"use client";
/**
* @name switch
* @category ui
* @description An on/off switch.
* @when A setting that takes effect as soon as it is flipped. For a choice that is submitted with a form use checkbox; for a pressed/unpressed toolbar button use toggle.
* @example
* <Label><Switch defaultChecked /> Weekly summary</Label>
* <Switch aria-label="Dark mode" checked={dark} onCheckedChange={setDark} />
*/
import { Switch as SwitchPrimitive } from "radix-ui";
import type { ComponentProps } from "react";
import { cn } from "@/lib/cn";
/** The track is 44 by 24px; an invisible margin makes the touch target 40px tall. */
export function Switch({ className, ...props }: ComponentProps<typeof SwitchPrimitive.Root>) {
return (
<SwitchPrimitive.Root
data-slot="switch"
className={cn(
"peer relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border border-transparent bg-input transition-[background-color,border-color,opacity] duration-instant ease-out after:absolute after:-inset-x-px after:-inset-y-2 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive data-[state=checked]:bg-primary motion-reduce:transition-none",
className,
)}
{...props}
>
<SwitchPrimitive.Thumb
data-slot="switch-thumb"
className="pointer-events-none block size-5 translate-x-px rounded-full bg-background transition-transform duration-base ease-out data-[state=checked]:translate-x-[calc(100%+1px)] data-[state=checked]:bg-primary-foreground motion-reduce:transition-none rtl:-translate-x-px rtl:data-[state=checked]:-translate-x-[calc(100%+1px)]"
/>
</SwitchPrimitive.Root>
);
}