Pan Control
Left and right balance with a fill from the centre and a centre detent.
Pan L30
L R
Installation
$ pnpm dlx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/pan-control.json$ npx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/pan-control.json$ yarn dlx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/pan-control.json$ bunx --bun shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/pan-control.jsonUsage
<script lang="ts">
import { PanControl } from "#lib/components/ui/pan-control/index.js";
let pan = $state(0);
</script>
<PanControl bind:value={pan} />The value runs from −1 (left) to 1 (right). Dragging near the centre snaps to it, and double-clicking returns to it. formatPan turns a value into "L30", "C" or "R30", and parsePan reads that text back.
For a rotary pan, use a Knob with min={-1}, max={1}, origin={0}, format={formatPan}, and parse={parsePan}:
C Pan
Accessibility
The thumb is a slider named "Pan", with aria-valuetext such as "30% left" or "Center". The knob example uses describePan for the same text on its dial, while formatPan keeps the visible value short. Both support arrow keys, Page Up, Page Down, Home and End.
API reference
| Prop | Type | Default |
|---|---|---|
value −1 to 1. Bindable. | number | 0 |
onValueChange | (value) => void | — |
onValueCommit | (value) => void | — |
step | number | 0.05 |
largeStep | number | 0.25 |
detent Snap to the centre while dragging near it. | boolean | true |
format | (value: number) => string | formatPan |
size | "sm" | "default" | "lg" | "default" |
disabled | boolean | false |