Twigs Logo

Switch

A toggle control that allows users to switch between two states. Perfect for enabling/disabling features, toggling settings, and binary choices with smooth animations and full keyboard accessibility.

Import

import { Switch } from "@sparrowengg/twigs-react";

Usage

const SwitchExample = () => {
  const [enabled, setEnabled] = useState(false);

  return (
    <Flex css={{ alignItems: "center", gap: "$4" }}>
      <Switch 
        checked={enabled} 
        onChange={setEnabled}
        size="md"
      />
      <Text>Enable notifications</Text>
    </Flex>
  );
};

Props

Switch

PropTypeDefault
checked?
boolean
-
defaultChecked?
boolean
-
onChange?
(checked: boolean) => void
-
disabled?
boolean
false
required?
boolean
false
size?
'sm' | 'md'
'sm'
css?
object
-

Data Attributes

These props are used for the conditional rendering of the components

Applicable - Switch, SwitchThumb
PropTypeDefault
[data-state]?
'checked' | 'unchecked'
-
[data-disabled]?
boolean
-