Scrub Bar

PreviousNext

A component for scrubbing through a timeline, typically used for audio or video playback.

Installation

pnpm dlx @elevenlabs/cli@latest components add scrub-bar

Usage

import * as React from "react"
 
import {
  ScrubBarContainer,
  ScrubBarProgress,
  ScrubBarThumb,
  ScrubBarTimeLabel,
  ScrubBarTrack,
} from "@/components/ui/scrub-bar"
 
export function ScrubBarExample() {
  const [value, setValue] = React.useState(30)
  const duration = 100
 
  return (
    <ScrubBarContainer duration={duration} value={value} onScrub={setValue}>
      <ScrubBarTimeLabel time={value} />
      <ScrubBarTrack className="mx-2">
        <ScrubBarProgress />
        <ScrubBarThumb />
      </ScrubBarTrack>
      <ScrubBarTimeLabel time={duration} />
    </ScrubBarContainer>
  )
}

API Reference

ScrubBarContainer

The main container for the scrub bar components. It provides the context for its children.

PropTypeDescription
durationnumberRequired. The total duration of the timeline.
valuenumberRequired. The current value of the timeline.
onScrub(time: number) => voidOptional. Callback when the user scrubs the timeline.
onScrubStart() => voidOptional. Callback when the user starts scrubbing.
onScrubEnd() => voidOptional. Callback when the user ends scrubbing.

ScrubBarTrack

The track for the scrub bar. It handles the pointer events for scrubbing.

This component accepts standard HTMLDivElement attributes.

ScrubBarProgress

Displays the progress on the scrub bar track.

This component is a wrapper around the Progress component and accepts its props, except for value.

ScrubBarThumb

The handle for scrubbing.

This component accepts standard HTMLDivElement attributes.

ScrubBarTimeLabel

A label to display time.

PropTypeDescription
timenumberRequired. The time to display, in seconds.
format(time: number) => stringOptional. A function to format the time into a string. Defaults to m:ss.