Switch

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

@react.component
let make = () =>
  <div className="flex items-center space-x-2">

Installation

npx shadcn@latest add @rescript-shadcn/Switch

Usage

<Switch />

Examples

Description

@react.component
let make = () =>
  <Field orientation=BaseUi.Types.Orientation.Horizontal className="max-w-sm">

Choice Card

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

@react.component
let make = () =>
  <Field.Group className="w-full max-w-sm">

Disabled

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

@react.component
let make = () =>
  <Field orientation=BaseUi.Types.Orientation.Horizontal dataDisabled={true} className="w-fit">

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.

@react.component
let make = () =>
  <Field orientation=BaseUi.Types.Orientation.Horizontal className="max-w-sm" dataInvalid={true}>

Size

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

@react.component
let make = () =>
  <Field.Group className="w-full max-w-[10rem]">

API Reference

See the Base UI Switch documentation.