Switch component is a toggle switch used for on/off, active/inactive, or enabled/disabled states. It provides an intuitive interface for toggling between two distinct states with clear visual feedback.tsx
import { Switch } from "@arkyn/components";
name property.tsx
<Switch name="basic-switch" />
sm, md, and lg, with lg being the default.tsx
<Switch name="switch-sm" label="Small size" size="sm" /><Switch name="switch-md" label="Medium size" size="md" /><Switch name="switch-lg" label="Large size" size="lg" />
tsx
<Switch name="terms" label="I accept the terms and conditions" />
tsx
<Switch name="option1" label="Option 1" orientation="horizontal" /><Switch name="option2" label="Option 2" orientation="horizontal" />
tsx
<Switch name="option1" label="Option 1" /><Switch name="option2" label="Option 2" />
tsx
<Switch name="option1" label="Option 1" orientation="vertical" /><Switch name="option2" label="Option 2" orientation="vertical" />
tsx
<Switch name="remember-me" label="Remember me" defaultChecked={true} />
tsx
<Switchname="disabled-unchecked"label="Disabled option (unchecked)"disabled/><Switchname="disabled-checked"label="Disabled option (checked)"disableddefaultChecked/>
value and unCheckedValue.tsx
<Switchname="theme-switch"label="Application theme"value="dark"unCheckedValue="light"defaultChecked={false}/><Switchname="subscription-switch"label="Premium subscription"value="subscribed"unCheckedValue="unsubscribed"size="md"/>
onCheck callback is called whenever the switch state changes, receiving the current value.tsx
const [themeMode, setThemeMode] = useState("light");const handleThemeChange = (value) => {console.log("Theme changed to:", value);setThemeMode(value);// Apply theme globallydocument.documentElement.setAttribute("data-theme", value);};<Switchname="app-theme"label="Dark theme"value="dark"unCheckedValue="light"onCheck={handleThemeChange}/>;
name - string (required)
Field name for form manipulation and identificationlabel - string
Label text to be displayed next to the switchsize - "sm" | "md" | "lg" (default: "lg")
Switch size variantdefaultChecked - boolean (default: false)
Default checked state for uncontrolled usechecked - boolean
Controlled state of the switch (used with onCheck)value - string (default: "checked")
Value to be used when the switch is enabledunCheckedValue - string (default: "")
Value to be used when the switch is disabledonCheck - (value: string) => void
Callback function called when state changes, receives current valueorientation - "vertical" | "horizontal" | "horizontalReverse" (default: "vertical")
Switch and label orientationdisabled - boolean (default: false)
Whether the switch is disabledclassName - string
Additional CSS classes for stylingid - string
Optional unique identifier for the switch<button> properties are also supported, except children, onChange, defaultValue, onCheck and value which are controlled by the component."checked" if not specified"" (empty string) if not specifiedonCheck callback always receives the current value (value or unCheckedValue)