ReScript Shadcn
Get started
  • Installation
Components
  • Accordion
  • Alert
  • AlertDialog
  • AspectRatio
  • Attachment
  • Avatar
  • Badge
  • Breadcrumb
  • Bubble
  • Button
  • ButtonGroup
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Collapsible
  • Combobox
  • Command
  • ContextMenu
  • DataTable
  • DatePicker
  • Dialog
  • Direction
  • Drawer
  • DropdownMenu
  • Empty
  • Field
  • HoverCard
  • Input
  • InputGroup
  • InputOtp
  • Item
  • Kbd
  • Label
  • Marker
  • Menubar
  • Message
  • MessageScroller
  • NativeSelect
  • NavigationMenu
  • Pagination
  • Popover
  • Progress
  • RadioGroup
  • Resizable
  • ScrollArea
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Skeleton
  • Slider
  • Sonner
  • Spinner
  • Switch
  • Table
  • Tabs
  • Textarea
  • Toast
  • Toggle
  • ToggleGroup
  • Tooltip
  • Typography

Switch

A control that allows the user to toggle between checked and not checked.

Installation#

npx shadcn@latest add @rescript-shadcn/Switch

Usage#

<Switch />

Examples#

Description#

Focus is shared across devices, and turns off when you leave the app.

Choice Card#

Card-style selection where FieldLabel wraps the entire Field for a clickable card pattern.

Disabled#

Add the disabled prop to the Switch component to disable the switch. Add the data-disabled prop to the Field component for styling.

Invalid#

Add the aria-invalid prop to the Switch component to indicate an invalid state. Add the data-invalid prop to the Field component for styling.

You must accept the terms and conditions to continue.

Size#

Use the size prop to change the size of the switch.

API Reference#

See the Base UI Switch documentation.

@react.component
let make = () =>
  <div className="flex items-center space-x-2">
@react.component
let make = () =>
  <Field orientation=Horizontal className="max-w-sm">
@react.component
let make = () =>
  <Field.Group className="w-full max-w-sm">
@react.component
let make = () =>
  <Field orientation=Horizontal dataDisabled={true} className="w-fit">
@react.component
let make = () =>
  <Field orientation=Horizontal className="max-w-sm" dataInvalid={true}>
@react.component
let make = () =>
  <Field.Group className="w-full max-w-[10rem]">