# Motorized fader

A console fader with a motor: when someone else sets it, the cap travels there on its own and says who moved it. Grab it and it's yours. For settings an agent, a teammate or an automation can change too.

- Category: Instruments
- Part of: Mixer strip (https://bevel-ui.vercel.app/components/mixer-strip.md)
- Docs: https://bevel-ui.vercel.app/components/mixer-strip/motorized-fader
- Import from: `@/components/ui/motorized-fader`

## Install

```bash
npx shadcn@latest add @bevel/motorized-fader
```

npm dependencies (installed by the CLI): `cn`.

## Anatomy

```tsx
<MotorizedFader
  aria-label="Temperature"
  value={value}
  changedBy={changedBy}
  onValueChange={(v) => { setValue(v); setChangedBy("You") }}
/>
<MotorizedFaderReadout value={format(value)} changedBy={changedBy} />
```

## Parts

| Part | Renders | Description |
| --- | --- | --- |
| `MotorizedFader` | div (slider) | value, onValueChange, min, max, step, changedBy, you, format, disabled. Arrow keys, Page Up and Down, Home and End, or drag. Reads as “0.70, set by Agent”. With reduced motion it jumps instead of travelling. |
| `MotorizedFaderReadout` | p | A scribble strip: the value and who set it, lit when it wasn't you. Works on its own. |

## Example: Temperature the agent tunes

The agent adjusts its own temperature; grab the fader to take over, then hand it back.

```tsx
"use client"

import * as React from "react"
import { MotorizedFader, MotorizedFaderReadout } from "@/components/ui/motorized-fader"

const format = (v: number) => (v / 100).toFixed(2)

/**
 * The agent tunes its own temperature as it works, and the fader follows.
 * Grab it and the setting is yours until you hand it back.
 */
export function MotorizedFaderTemperature() {
  const [value, setValue] = React.useState(70)
  const [changedBy, setChangedBy] = React.useState("Agent")

  React.useEffect(() => {
    if (changedBy !== "Agent") return
    const timer = setInterval(() => setValue(10 + Math.round(Math.random() * 18) * 5), 2200)
    return () => clearInterval(timer)
  }, [changedBy])

  return (
    <div className="flex flex-col items-center gap-3">
      <MotorizedFader
        aria-label="Temperature"
        value={value}
        changedBy={changedBy}
        format={format}
        onValueChange={(v) => {
          setValue(v)
          setChangedBy("You")
        }}
      />
      <MotorizedFaderReadout value={format(value)} changedBy={changedBy} />
      <button
        type="button"
        disabled={changedBy === "Agent"}
        onClick={() => setChangedBy("Agent")}
        className="h-9 rounded-md border px-3 text-sm font-medium hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none disabled:opacity-50"
      >
        Hand back to the agent
      </button>
    </div>
  )
}
```
