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.

WebBêtaMédias

Web uniquement — React, depuis @krizaka/ui/video-trimmer. Bêta : son API peut encore changer à une version mineure.

Quand l’utiliser

  • 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).

Quand ne pas l’utiliser

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

Installation

Installer

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

Styles

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

Importer

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

Exemples

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.

PropTypeDéfautDescription
durationrequisnumber—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).

Accessibilité

  • 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.

Clavier

TouchesAction
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.

Bonnes pratiques

  • 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).

Générée depuis le code de @krizaka/ui 2.4.0 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page