Krizaka
Documentation

Video trimmer

The trim timeline of a video editor: two edge handles over a filmstrip frame the part kept, the outside dimmed, a playhead to scrub — every part stylable, the keyboard included.

WebBetaMedia

Web only — React, from @krizaka/ui/video-trimmer. Beta: its API may still change in a minor version.

When to use

  • To keep a part of a clip before publishing it: a story, a highlight, a reply.
  • To choose a segment of any timeline (a sound with a waveform as children, a recording).

When not to use

  • For one value or a range of numbers without a media: a slider.Use instead: Slider
  • To play a video: the video player.Use instead: Video player

Installation

Install

npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Import

import { VideoTrimmer } from "@krizaka/ui/video-trimmer";

Examples

Filmstrip

A 42-second clip, 12 seconds kept, frames in the track.

0:08.00:12.0 kept0:20.0

With the playhead

time and onSeek: the playhead stays within the part kept.

0:03.00:21.0 kept0:24.0

Custom parts

classNames and renderHandle: thin handles over a waveform band.

0:42.0Extract: 0:54.01:36.0

Props

Keeps a part of a clip between two handles over its filmstrip, with a playhead to scrub — the keyboard included.

PropTypeDefaultDescription
durationrequirednumber—The length of the clip, in seconds.
childrenReactNode—Track content instead of the filmstrip (a waveform, a coloured band).
classNamesPartial<Record<"root" | "base" | "header" | "track" | "range" | "frame" | "kept" | "strip" | "shade" | "grip" | "handle" | "playhead", string>>{}Classes per part: root, header, kept, track, strip, frame, shade, range, handle, grip, playhead.
defaultValuereadonly [number, number]—The part kept at first, uncontrolled. Default: the whole clip.
disabledboolean—Not available (a render is running).
formatTime((seconds: number) => string)(seconds: number) => `${formatClock(seconds)}.${Math.floor((Math.max(0, seconds) % 1) * 10)}`A time as read and shown. Default m:ss with tenths.
framesreadonly string[]—Pictures of the clip, in order: the filmstrip.
labelsPartial<VideoTrimmerLabels>—The words, passed translated; English by default.
largeStepnumber1Shift + arrow, Page Up / Page Down, in seconds. Default 1.
minLengthnumber0.5The shortest part that can be kept, in seconds. Default 0.5.
onSeek((time: number) => void)—Called when the playhead is moved (a drag on the track, the arrows on the playhead).
onValueChange((value: [number, number]) => void)—Called on every move of a handle.
onValueCommit((value: [number, number]) => void)—Called once a drag or a key press ends: render a preview, save.
renderHandle((edge: "start" | "end") => ReactNode)—The content of a handle (default: two grip lines).
showHeaderbooleantrueShows the times and the length kept above the track. Default true.
stepnumber0.1One arrow press, in seconds. Default 0.1.
timenumber—The time played, in seconds: shows the playhead.
valuereadonly [number, number]—The part kept, [start, end] in seconds (controlled).

Accessibility

  • Each handle is a slider named by a prop (“Start”, “End”), its bounds set by the other handle and minLength.
  • The values are read as times (aria-valuetext, formatTime), not as seconds.
  • The playhead is a slider too when onSeek is given; read-only otherwise.

Keyboard

KeysAction
Arrow keysMove the focused handle (or the playhead) by step; with Shift by largeStep.
Page Up / Page DownMove by largeStep.
Home / EndTo the start or the end, as far as the other handle allows.

Best practices

  • Render the preview on onValueCommit (the end of a drag), not on every move.
  • Set minLength to the shortest clip the product accepts, and largeStep to a second.
  • Make the filmstrip from a few frames of the clip (8 to 12), the same width each.
  • Restyle any part with classNames and the handles with renderHandle; the alignment stays (each handle on its value by its outer edge).

Generated from the code of @krizaka/ui 2.4.0: its meta.ts, its examples and its types.Edit this documentation on GitHub

On this page