# Toggle

A latching key that stays lit while pressed. Set cipher to decode its label when switched on.

[View Toggle on CyberSpec](https://www.cyberspec.dev/components/sidebar/toggle)

## Component

Toggle belongs to the Actions group in the CyberSpec catalog. It uses @ui-sdk/react/toggle.

## Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/toggle.json
```

## Example

```tsx
"use client"

import { BellOff, Flashlight, Radar } from "lucide-react"
import { Toggle } from "@/components/ui/toggle"

export default function ToggleDemo() {
  return (
    <>
      <Toggle icon={<BellOff aria-hidden />} defaultPressed>
        Silent mode
      </Toggle>
      <Toggle icon={<Flashlight aria-hidden />} aria-label="Torch" />
      <Toggle icon={<Radar aria-hidden />} aria-label="Proximity ping" defaultPressed />
      <Toggle size="sm" cipher>Autopilot</Toggle>
      <Toggle disabled defaultPressed>
        Uplink
      </Toggle>
    </>
  )
}
```

## Install this example

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/toggle-demo.json
```

## Resources

- [Interactive Toggle preview](https://www.cyberspec.dev/preview/toggle)
- [Component catalog](https://www.cyberspec.dev/components.md)
- [Toggle source code](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/ui/toggle.tsx)
- [Shadcn registry item](https://www.cyberspec.dev/r/toggle.json)
