Fidely UI v1 beta is now available!. 🚀

Switch

A control element that allows for a binary selection.

Usage

import { Switch } from '@fidely-ui/react'
<Switch.Root>
  <Switch.HiddenInput />
  <Switch.Control>
    <Switch.Thumb />
  </Switch.Control>
  <Switch.Label />
</Switch.Root>

Examples

Sizes

Pass the size prop to the Switch.Root component to change the size of the switch component.

Colors

Pass the colorPalette prop to the Switch.Root component to change the color of the component.

green

orange

Controlled

Use the checked and onCheckedChange props to control the state of the switch.

Props

Root

PropTypeDefaultDescription
checkedboolean—Controls the checked state of the switch (for controlled usage).
defaultCheckedbooleanfalseSets the initial checked state (for uncontrolled usage).
onCheckedChange(checked: boolean) => void—Callback fired when the switch state changes.
requiredbooleanfalseMarks the switch as required in a form.
disabledbooleanfalseDisables interaction with the switch.
namestring—The name of the switch input for form submission.
valuestring"on"The value of the switch input when checked.
size"sm" | "md" | "lg""md"Controls the size of the switch.
colorPalette"red" | "blue" | "green" | "purple" | "orange" | "gray""blue"Sets the color palette of the switch.
childrenReactNode—The content of the switch, typically including control, thumb, and label.
asReact.ElementType—The content of the switch, typically including control, thumb, and label.

Control

PropTypeDefaultDescription
childrenReactNode—Contains the visual parts of the switch (usually the Thumb).

Thumb

PropTypeDefaultDescription
childrenReactNode—Optional custom thumb content.

Label

PropTypeDefaultDescription
childrenReactNode—The label text displayed beside the switch.

HiddenInput

PropTypeDefaultDescription
namestring—The name of the hidden input field.
valuestring"on"The value of the hidden input when the switch is checked.

On this page