Tracks

Slant / Editor

Tracks of clips under a ruler, with a playhead you can scrub or step with the keys.

Demo

Usage

@tuttn/slant
import { Tracks, type TracksTrack } from '@tuttn/slant'

const tracks: TracksTrack[] = [
  { id: 'screen', label: 'Screen', tone: 'accent', icon: <MonitorIcon />, clips: [
    { id: 'intro', start: 0, end: 7, label: 'Intro' },
    { id: 'tour', start: 7, end: 31, label: 'Dashboard tour' },
  ] },
  { id: 'voice', label: 'Voice', tone: 'warning', clips: [
    { id: 'vo-3', start: 2, end: 22, label: 'VO take 3' },
  ] },
]

// Uncontrolled: the playhead starts at defaultValue (0), nothing selected.
<Tracks tracks={tracks} duration={60} defaultSelectedClip="tour" />

// Controlled: you hold the time (to play it) and the selection.
const [time, setTime] = useState(0)
const [clip, setClip] = useState<string | null>(null)
<Tracks tracks={tracks} duration={60} value={time} onValueChange={setTime}
  selectedClip={clip} onSelectedClipChange={setClip} label="Walkthrough edit" />

// Frames instead of seconds: format writes every time the timeline shows or reads.
<Tracks tracks={shots} duration={240} ticks={24} step={1} largeStep={24}
  format={frame => `${Math.floor(frame / 24)}s ${frame % 24}f`} />

Props

PropTypeDefaultDescription
tracksreadonly TracksTrack[]—The tracks, top to bottom, each with its clips.
durationnumber—How long the timeline is, in the clips' unit (seconds by default). The playhead runs from 0 to here.
valuenumber—Where the playhead is, when controlled.
defaultValuenumber0Where an uncontrolled playhead starts.
onValueChange(time: number) => void—Called with the new time when the keys, a press on the ruler or a scrub move the playhead.
selectedClipstring | null—The selected clip's id, or null for none, when controlled.
defaultSelectedClipstring | nullnullThe clip an uncontrolled timeline starts with selected.
onSelectedClipChange(id: string | null) => void—Called with a clip's id when a click, Enter or Space selects another clip.
stepnumber1How far an arrow key moves the playhead.
largeStepnumberduration / 10How far Shift with an arrow, PageUp and PageDown move the playhead.
format(time: number) => stringm:ssWrites a time for the ruler, the readout, each clip's name and the playhead's value text.
ticksnumberthe first of 1, 2, 5, 10, 15, 30, 60, 120, 300… that gives at most 10 marks, and no more than fit about 48px apartThe time between the ruler's labelled marks.
labelstringmessages.tracks ("Tracks")The timeline's accessible name.
playheadLabelstringmessages.playhead ("Playhead")The playhead slider's accessible name.
variant'framed' | 'plain''framed'`framed` sits in a hairline border with a radius; `plain` fills a Workbench region.
…restHTMLAttributes<HTMLDivElement>—className, style, other attributes and the ref go on the root, the group named by label.

A track is { id, label, clips, tone?, icon? } and a clip { id, start, end, label, text?, tone?, disabled? }, in seconds unless your format reads another unit. Each clip sits at start / duration and spans (end − start) / duration of its lane, as percentages on logical properties, so the server's HTML is already laid out and the whole timeline mirrors under right-to-left text. A clip takes its own tone, else its track's.

Keyboard

The playhead is a slider on the ruler. Right and Up step it on by step, Left and Down step it back (Left and Right swap under RTL), Shift with an arrow and PageUp or PageDown move by largeStep, Home and End jump to the ends, and it never leaves 0 to duration. The clips share one tab stop: the selected clip, else the first enabled one. The arrows walk them in order, track by track and by start time, Home and End jump to the first and last, and Enter, Space or a click selects one; selecting it again keeps it.

Pointer

Pressing anywhere on the ruler moves the playhead there, focuses it, and scrubs while you drag (the pointer is captured, so the drag can leave the ruler).

Screen readers

The timeline is a group named by label, and each track a group named by its label. The playhead reads its time as “0:12 of 1:00” (messages.timeOf), and each clip its name and span, “Intro, 0:00 to 0:07” (messages.clipSpan), with aria-pressed on the selected one. The ruler's marks, the readout and the playhead's line are hidden, since the slider already says where it is.

Reduced motion

Nothing in Tracks animates its position: the playhead and its line are placed where the value says, so a playing timeline moves as fast as you update value. The demo plays frame by frame, and under reduced motion in whole-second jumps.