> ## Documentation Index
> Fetch the complete documentation index at: https://araf.badr.co.id/llms.txt
> Use this file to discover all available pages before exploring further.

# Switch

> A toggle control for binary on/off settings that take immediate effect — supports labels, descriptions, and disabled state.

## Overview

<div style={{display:"flex",gap:"32px",flexWrap:"wrap",padding:"28px 24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb",alignItems:"flex-start"}}>
  <div style={{display:"flex",flexDirection:"column",gap:"8px",alignItems:"center"}}>
    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#D0D5DD",padding:"2px",display:"flex",alignItems:"center"}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.2)",transition:"all 0.2s"}} />
    </div>

    <span style={{fontSize:"11px",color:"#71717a",fontFamily:"Inter,sans-serif"}}>Off</span>
  </div>

  <div style={{display:"flex",flexDirection:"column",gap:"8px",alignItems:"center"}}>
    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#0479CE",padding:"2px",display:"flex",alignItems:"center",justifyContent:"flex-end"}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}} />
    </div>

    <span style={{fontSize:"11px",color:"#71717a",fontFamily:"Inter,sans-serif"}}>On</span>
  </div>

  <div style={{display:"flex",flexDirection:"column",gap:"8px",alignItems:"center"}}>
    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#E5E7EB",padding:"2px",display:"flex",alignItems:"center",cursor:"not-allowed",opacity:0.6}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.1)"}} />
    </div>

    <span style={{fontSize:"11px",color:"#71717a",fontFamily:"Inter,sans-serif"}}>Disabled off</span>
  </div>

  <div style={{display:"flex",flexDirection:"column",gap:"8px",alignItems:"center"}}>
    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#93C5FD",padding:"2px",display:"flex",alignItems:"center",justifyContent:"flex-end",cursor:"not-allowed",opacity:0.6}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.1)"}} />
    </div>

    <span style={{fontSize:"11px",color:"#71717a",fontFamily:"Inter,sans-serif"}}>Disabled on</span>
  </div>
</div>

**Switch** is used for settings that take immediate effect when toggled — no form submission needed. Unlike Checkbox, a Switch implies an instant action rather than a selection to be submitted.

***

## Installation

<CodeGroup>
  ```bash npm theme={null}
  npm install @araf-ds/core
  ```

  ```bash yarn theme={null}
  yarn add @araf-ds/core
  ```

  ```bash pnpm theme={null}
  pnpm add @araf-ds/core
  ```
</CodeGroup>

***

## Usage

```tsx theme={null}
import { Switch } from "@araf-ds/core"

export default function Example() {
  return (
    <Switch label="Enable dark mode" />
  )
}
```

***

## Variants

### Basic

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb"}}>
  <div style={{display:"flex",alignItems:"center",gap:"12px"}}>
    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#D0D5DD",padding:"2px",display:"flex",alignItems:"center",flexShrink:0}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}} />
    </div>

    <span style={{fontSize:"14px",fontWeight:500,color:"#344054",fontFamily:"Inter,sans-serif"}}>Enable dark mode</span>
  </div>
</div>

```tsx theme={null}
<Switch label="Enable dark mode" />
```

### On by Default

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb"}}>
  <div style={{display:"flex",alignItems:"center",gap:"12px"}}>
    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#0479CE",padding:"2px",display:"flex",alignItems:"center",justifyContent:"flex-end",flexShrink:0}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}} />
    </div>

    <span style={{fontSize:"14px",fontWeight:500,color:"#344054",fontFamily:"Inter,sans-serif"}}>Email notifications</span>
  </div>
</div>

```tsx theme={null}
<Switch label="Email notifications" defaultChecked />
```

### With Description

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb"}}>
  <div style={{display:"flex",alignItems:"flex-start",gap:"12px"}}>
    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#0479CE",padding:"2px",display:"flex",alignItems:"center",justifyContent:"flex-end",flexShrink:0,marginTop:"2px"}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}} />
    </div>

    <div>
      <div style={{fontSize:"14px",fontWeight:500,color:"#344054",fontFamily:"Inter,sans-serif"}}>Auto-save</div>
      <div style={{fontSize:"13px",color:"#667085",fontFamily:"Inter,sans-serif",marginTop:"2px"}}>Automatically save your work every 5 minutes.</div>
    </div>
  </div>
</div>

```tsx theme={null}
<Switch
  label="Auto-save"
  description="Automatically save your work every 5 minutes."
  defaultChecked
/>
```

### Label on Left

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb"}}>
  <div style={{display:"flex",alignItems:"center",gap:"12px",justifyContent:"space-between",maxWidth:"240px"}}>
    <span style={{fontSize:"14px",fontWeight:500,color:"#344054",fontFamily:"Inter,sans-serif"}}>Show sidebar</span>

    <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#D0D5DD",padding:"2px",display:"flex",alignItems:"center",flexShrink:0}}>
      <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}} />
    </div>
  </div>
</div>

```tsx theme={null}
<Switch label="Show sidebar" labelPosition="left" />
```

### Disabled

<div style={{padding:"24px",background:"#f9fafb",borderRadius:"12px",border:"1px solid #e5e7eb"}}>
  <div style={{display:"flex",flexDirection:"column",gap:"12px"}}>
    <div style={{display:"flex",alignItems:"center",gap:"12px",opacity:0.5,cursor:"not-allowed"}}>
      <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#E5E7EB",padding:"2px",display:"flex",alignItems:"center",flexShrink:0}}>
        <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.1)"}} />
      </div>

      <span style={{fontSize:"14px",fontWeight:500,color:"#344054",fontFamily:"Inter,sans-serif"}}>Beta features</span>
    </div>

    <div style={{display:"flex",alignItems:"center",gap:"12px",opacity:0.5,cursor:"not-allowed"}}>
      <div style={{width:"44px",height:"24px",borderRadius:"12px",background:"#93C5FD",padding:"2px",display:"flex",alignItems:"center",justifyContent:"flex-end",flexShrink:0}}>
        <div style={{width:"20px",height:"20px",borderRadius:"50%",background:"#fff",boxShadow:"0 1px 3px rgba(0,0,0,0.1)"}} />
      </div>

      <span style={{fontSize:"14px",fontWeight:500,color:"#344054",fontFamily:"Inter,sans-serif"}}>Always-on feature</span>
    </div>
  </div>
</div>

```tsx theme={null}
<Switch label="Beta features" disabled />
<Switch label="Always-on feature" disabled defaultChecked />
```

### Controlled

```tsx theme={null}
const [enabled, setEnabled] = useState(false);

<Switch
  checked={enabled}
  onCheckedChange={setEnabled}
  label="Maintenance mode"
/>
```

***

## API Reference

<ParamField path="checked" type="boolean">
  Controlled checked state.
</ParamField>

<ParamField path="defaultChecked" type="boolean" default="false">
  Uncontrolled initial state.
</ParamField>

<ParamField path="onCheckedChange" type="(checked: boolean) => void">
  Callback fired when the switch state changes.
</ParamField>

<ParamField path="label" type="string">
  Label text displayed next to the switch.
</ParamField>

<ParamField path="description" type="string">
  Supporting description shown below the label.
</ParamField>

<ParamField path="labelPosition" type="string" default="right">
  Position of the label relative to the switch. Values: `left` · `right`
</ParamField>

<ParamField path="disabled" type="boolean" default="false">
  Disables the switch and applies the disabled visual style.
</ParamField>

<ParamField path="className" type="string">
  Additional Tailwind classes for custom overrides.
</ParamField>

***

## Accessibility

* Switch uses `role="switch"` with `aria-checked` for proper screen reader announcement
* Label is associated via `htmlFor` / `id` — clicking the label also toggles the switch
* `description` is linked via `aria-describedby`
* `disabled` uses the native `disabled` attribute, removing the element from tab order
* Space bar toggles the switch when focused — follows ARIA switch pattern
* Focus ring meets WCAG 2.1 AA contrast requirements

***

## Do's & Don'ts

<CardGroup cols={2}>
  <Card title="Do" icon="check" iconType="solid" color="#16A34A">
    * Use Switch for settings that take immediate effect (dark mode, notifications)
    * Always provide a descriptive label — never a switch alone
    * Use `description` to clarify the impact of toggling
    * Place switches in settings panels or preference pages
  </Card>

  <Card title="Don't" icon="xmark" iconType="solid" color="#DC2626">
    * Don't use Switch inside a form that requires submission — use Checkbox instead
    * Don't use Switch for multi-select scenarios — use Checkbox Group
    * Don't use ambiguous labels like "On/Off" — describe what is being toggled
    * Don't disable without explaining why in nearby helper text
  </Card>
</CardGroup>
