Unlock faster development with Fidely UI Pro components Coming soon

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
checkedbooleanControls the checked state of the switch (for controlled usage).
defaultCheckedbooleanfalseSets the initial checked state (for uncontrolled usage).
onCheckedChange(checked: boolean) => voidCallback fired when the switch state changes.
requiredbooleanfalseMarks the switch as required in a form.
disabledbooleanfalseDisables interaction with the switch.
namestringThe 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.
childrenReactNodeThe content of the switch, typically including control, thumb, and label.
asReact.ElementTypeThe content of the switch, typically including control, thumb, and label.

Control

PropTypeDefaultDescription
childrenReactNodeContains the visual parts of the switch (usually the Thumb).

Thumb

PropTypeDefaultDescription
childrenReactNodeOptional custom thumb content.

Label

PropTypeDefaultDescription
childrenReactNodeThe label text displayed beside the switch.

HiddenInput

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

On this page