Components
Switch

Switch

The Switch component provides you with toggle switches.

Import

import { Switch } from '@nostromo/ui-core'
// or
import { Switch } from '@nostromo/ui-core/switch'

Usage

import { Switch, Label } from '@nostromo/ui-core'
 
export default function Example() {
  const [enabled, setEnabled] = React.useState(false)
  
  return (
    <div className="flex items-center space-x-2">
      <Switch 
        id="notifications"
        checked={enabled}
        onCheckedChange={setEnabled}
      />
      <Label htmlFor="notifications">Enable notifications</Label>
    </div>
  )
}

Live Examples

Live Example
☀️
Copy
Storybook →
View Code
import { Switch } from '@nostromo/ui-core' export default function SwitchExample() { return ( <div className="space-y-4"> <div className="flex items-center space-x-2"> <Switch id="notifications" /> <label htmlFor="notifications">Notifications</label> </div> ...

With Label

Live Example
☀️
Copy
Storybook →
View Code
import { Switch, Label } from '@nostromo/ui-core' export default function SwitchWithLabel() { return ( <div className="space-y-4"> <div className="flex items-center space-x-2"> <Switch id="option1" /> <Label htmlFor="option1">Option 1</Label> </div> <div className="flex items-center space-x-2">...

Props

PropTypeDefaultRequiredDescription
checkedbooleanfalseNoWhether the switch is on (controlled)
defaultCheckedbooleanfalseNoDefault checked state (uncontrolled)
onCheckedChange(checked: boolean) => voidundefinedNoCallback when checked state changes
disabledbooleanfalseNoWhether the switch is disabled
requiredbooleanfalseNoWhether the switch is required
errorbooleanfalseNoWhether the switch is in an error state
labelstringundefinedNoLabel text (alternative to Label component)
helperTextstringundefinedNoHelper text displayed below switch
idstringundefinedNoSwitch ID (auto-generated if not provided)
namestringundefinedNoName for form submission
valuestringundefinedNoValue for form submission
classNamestringundefinedNoAdditional CSS classes
asChildbooleanfalseNoRender as child element

Standard HTML Props

The Switch component extends standard HTML button attributes, including:

  • aria-* attributes for accessibility
  • data-* attributes for custom data