# Breaker

A circuit breaker: on, off, or tripped until someone resets it. For spending caps, kill switches and feature flags.

- Category: Instruments
- Docs: https://bevel-ui.vercel.app/components/breaker
- Import from: `@/components/ui/breaker`

## Install

```bash
npx shadcn@latest add @bevel/breaker
```

npm dependencies (installed by the CLI): `@base-ui/react`, `cn`.

## Anatomy

```tsx
<BreakerPanel>
  <BreakerPanelTitle />
  <BreakerRow>
    <Breaker label="Workspace" description="$500 a month" tripped />
  </BreakerRow>
</BreakerPanel>
```

## Parts

| Part | Renders | Description |
| --- | --- | --- |
| `BreakerPanel` | div (group) | The panel. Give it an aria-label. |
| `Breaker` | Switch | checked, defaultChecked, onCheckedChange, disabled, plus tripped: the lever drops to the middle and a red flag shows. Switching a tripped breaker resets it; clear tripped in onCheckedChange. |

## Example: Spending caps

The per-person cap has tripped; switch it to reset. Overage is locked to owners.

```tsx
"use client"

import * as React from "react"
import { Breaker, BreakerPanel, BreakerPanelTitle, BreakerRow } from "@/components/ui/breaker"

/** Spending caps as breakers. A cap that's hit trips; switching it resets it. */
export function BreakerCaps() {
  const [workspace, setWorkspace] = React.useState(true)
  const [perPerson, setPerPerson] = React.useState({ on: true, tripped: true })
  const [perCase, setPerCase] = React.useState(false)

  return (
    <BreakerPanel aria-label="Spending caps">
      <BreakerPanelTitle>Spending caps</BreakerPanelTitle>
      <BreakerRow>
        <Breaker label="Workspace" description="$500 a month" checked={workspace} onCheckedChange={setWorkspace} />
        <Breaker
          label="Per person"
          description="$50 a month"
          checked={perPerson.on}
          tripped={perPerson.tripped}
          onCheckedChange={(on) => setPerPerson({ on, tripped: false })}
        />
        <Breaker label="Per case" description="$200" checked={perCase} onCheckedChange={setPerCase} />
        <Breaker label="Overage" description="Owners only" defaultChecked disabled />
      </BreakerRow>
    </BreakerPanel>
  )
}
```
