Form Switch

GitHub

Switch connected to Form context with server validation errors.

Installation

bash
pnpm dlx shadcn@latest add @cs/form-switch

Usage

tsx
import { FormSwitch } from "@/components/cs/form-switch"
tsx
<FormSwitch name="enabled" />

API Reference

FormSwitch

Switch connected to Form context that displays server validation errors.

Props

NameTypeDefaultDescription
classNamestring | (((state: SwitchRootState) => string | undefined) & string) | undefined-CSS class applied to the element, or a function that returns a class based on the component's state. Classes for the switch control.
color"default" | "green" | "red" | "dark" | "yellow" | "orange" | null | undefined-Controls the checked switch color.
descriptionstring | undefined-Helper text displayed below the label.
errorstring | null | undefined-Validation error message.
labelstring | undefined-Switch label.
name *string-Form field name used for submission and validation errors.
orientation"vertical" | "horizontal" | "responsive" | null | undefined-Layout of the switch control and its text.
size"default" | "sm" | undefined--
switchClassNamestring | undefined-Additional class name for the field wrapper.