# Gauge and dial

A needle on a brass-bezelled scale. Gauge reads a value; Dial sets one, turned by drag or keyboard.

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

## Install

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

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

## Anatomy

```tsx
<Gauge value={12} max={30} marks={<DialMark value={5} />}>
  <GaugeLabel />
  <GaugeValue />
</Gauge>

<Dial label="Keep above" value={30} onValueChange={setValue} />
```

## Parts

| Part | Renders | Description |
| --- | --- | --- |
| `Gauge` | Meter | Read-only. value, min, max, ticks, marks. Announced as a meter; pass getAriaValueText to describe marks. |
| `GaugeLabel / GaugeValue` | Meter parts | The name and the formatted value. |
| `Dial` | div (slider) | Adjustable. value, defaultValue, onValueChange, min, max, step, label, and Amount formatting for the readout. Arrows, Page Up/Down, Home, End. |
| `DialMark` | span | A painted mark on the scale: red, amber or green. Decorative. |

## Example: Runway

Days of credit left, with the auto top-up level marked.

```tsx
"use client"

import {
  DialMark,
  Gauge,
  GaugeLabel,
  GaugeValue,
} from "@/components/ui/dial"

/** Days of credit left, with the auto top-up level marked in amber. */
export function DialRunway() {
  return (
    <div className="flex flex-col items-center gap-2">
      <Gauge
        value={12}
        max={30}
        ticks={30}
        getAriaValueText={(_, value) =>
          `${value} days left; auto top-up at 5 days`
        }
        marks={<DialMark value={5} tone="amber" />}
      >
        <GaugeLabel>Runway</GaugeLabel>
        <GaugeValue>{(_, value) => `${value} days`}</GaugeValue>
      </Gauge>
      <p className="text-xs text-muted-foreground">
        Amber mark: auto top-up at 5 days
      </p>
    </div>
  )
}
```

## Example: Auto top-up

Set like a thermostat: the level to keep above, and how much to add.

```tsx
"use client"

import * as React from "react"
import { Dial, DialMark } from "@/components/ui/dial"

/** Auto top-up, set like a thermostat: the level to keep above, and how much to add. */
export function DialAutoTopUp() {
  const [threshold, setThreshold] = React.useState(30)
  const [amount, setAmount] = React.useState(10)
  return (
    <div className="flex flex-col items-center gap-6">
      <div className="flex flex-wrap justify-center gap-8">
        <Dial
          label="Keep balance above"
          value={threshold}
          onValueChange={setThreshold}
          max={100}
          step={5}
          currency="USD"
          format={{ maximumFractionDigits: 0 }}
          marks={<DialMark value={threshold} tone="amber" />}
          className="w-40"
        />
        <Dial
          label="Top up by"
          value={amount}
          onValueChange={setAmount}
          min={5}
          max={200}
          step={5}
          currency="USD"
          format={{ maximumFractionDigits: 0 }}
          className="w-40"
        />
      </div>
      <p className="max-w-xs text-center text-sm text-muted-foreground">
        When the balance drops below ${threshold}, we add ${amount}.
      </p>
    </div>
  )
}
```
