A step grid for a drum pattern or any row of on and off steps, with a velocity bar under each. The registry component is written on the sequencer primitive, which installs with it.
Installation
The primitives are built on the UI SDK kernel, in beta. Nothing of ours comes from npm: the primitive and its adapter are files you copy into your project and own, and the only packages are the kernel's. The commands name its version, @ui-sdk/*@0.1.0-beta.14.
The styled component, with sizes and themed steps, is one command:
The styled component, with size variants and theme styles:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/sequencer
Or the primitive alone, to style yourself:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/sequencer-react
It writes the primitive, its adapter and primitive.ts into components/audio-ui/ and installs the kernel's packages and what each file imports. The optional styles are one more command:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/primitives-css
Usage
Copy to Clipboardimport { Sequencer } from "@/components/audio-ui/sequencer"; <Sequencer aria-label="Drum pattern" onValueChange={setPattern} rowLabels={["Kick", "Snare", "Hihat"]} source={step} value={pattern} />;
value is a row per sound, each a list of steps: boolean[][]. velocities is how loud each step plays, from 0 to 1, in the same shape; a step it does not list plays at full. Add showVelocity for a bar under each row to draw them. source is the step being played, a live { getSnapshot, subscribe } such as one made with createSource: a clock ticking every step never re-renders React.
The primitive alone, part by part:
A Root groups the rows. A Row is one sound, a Cell one of its steps, a <button> pressed when the step is on, and a Velocity a bar under a step. You write a Row for each row and a Cell for each step, with their row and step: the Root's content can read the state, { rows, steps }, so the grid follows the pattern. That is a function in React, the default slot in Vue and a snippet in Svelte.
Copy to Clipboardimport { Sequencer } from "@/components/audio-ui/sequencer/react"; const KIT = ["Kick", "Snare", "Hat"]; export function Beat({ pattern, onChange }: { pattern: boolean[][]; onChange: (pattern: boolean[][]) => void }) { return ( <Sequencer.Root onValueChange={onChange} value={pattern}> {({ rows, steps }) => Array.from({ length: rows }, (_, row) => ( <Sequencer.Row aria-label={KIT[row]} className="flex gap-1" index={row} key={row}> {Array.from({ length: steps }, (_, step) => ( <Sequencer.Cell aria-label={`${KIT[row]}, step ${step + 1}`} className="size-8 rounded bg-muted data-on:bg-primary data-current:ring-2" key={step} row={row} step={step} /> ))} </Sequencer.Row> )) } </Sequencer.Root> ); }
In the web adapter the sequencer makes the rows, the cells and the velocity bars itself, one for each step of its pattern. Add the velocity-bars attribute to get the bars.
Velocity bars. Write a Velocity for each step, in the Row, under the cells. Its height is the --sequencer-velocity CSS variable, from 0 to 1, which you read in your styles. It holds a native <input type="range"> that carries its name and takes the keys.
The step being played
Give the Root a source, a live value of the step being played, in the shape of an external store: getSnapshot() returns the step and subscribe(listener) is called on each tick. The step's cells get data-current straight in the DOM, so a clock ticking every step renders nothing. Any object with those two methods works, with nothing to install, and useTransportClock from the registry gives you one on the audio clock.
In the web adapter, source is a property, not an attribute.
Interaction
Gestures · 7
Ctrl or Cmd, Home and End go to the corners.The steps share one tab stop, and each is a toggle button (aria-pressed) named after its row and step.
API reference
Registry component
Sequencer takes the Root props, plus:
Props · 7
sm draws short steps and a thin bar under them, so many rows fit.velocities.Options
Set on the Root, as props (an attribute in kebab case in the web adapter, the grids as JSON).
| Option | Type | Default | |
|---|---|---|---|
value, defaultValue | boolean[][] | The pattern: a row for each sound, each a list of steps. Controlled, or the starting one. | |
velocities, defaultVelocities | number[][] | How loud each step plays, from 0 to 1, a row for each sound like the pattern. A step it does not list plays at full. | |
source | { getSnapshot, subscribe } | The step being played, followed with no render. | |
disabled | boolean | false | Takes no gesture. |
onValueChange | (pattern, details) => void | A step is flipped. details.cancel() keeps the pattern as it was. | |
onValueCommitted | (pattern, details) => void | A press, a paint or a key that changed the pattern ends. | |
onVelocityChange | (velocities, details) => void | A velocity is drawn or nudged. | |
onVelocityCommitted | (velocities, details) => void | A drag, a key or a reset that changed a velocity ends. |
What a change reports
- Pattern:
reasonis"press","paint"or"keyboard". - Velocities:
reasonis"drag","keyboard","input-change"or"reset". - Both carry a
source("mouse","touch","pen","keyboard") and theevent. - In the web adapter, the pattern is the
inputandchangeevents, and the velocities thevelocitychangeandvelocitycommitevents, withdetail: { value, reason, source }.
States to style from
data-onandaria-pressedon a cell while its step is on,data-currentwhile it is the step being played,data-rowanddata-stepfor its place.data-paintingon the Root and the cells while a pointer paints.data-disabledon every part.
Parts
Parts · 4
cell: key, row: number, step: number.index: key.cell: key, row: number, step: number.Events
Events · 4
@value-change. Web: the input event.@value-committed. Web: the change event.@velocity-change. Web: the velocitychange event.@velocity-committed. Web: the velocitycommit event.