# Clip timeline

Trim a field recording from either end and see the length of the selected clip.

[View Clip timeline on CyberSpec](https://www.cyberspec.dev/sink/clip-timeline)

## Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/clip-timeline.json
```

## Usage

```tsx
import { Cyber } from "@/components/ui/cyber"
import Recipe from "@/components/recipes/clip-timeline"

export default function App() {
  return (
    <Cyber>
      <Recipe />
    </Cyber>
  )
}
```

## Source

```tsx
"use client"

import "./recipe-layout.css"
import { useState } from "react"
import { Readout } from "@/components/ui/readout"
import { Slider } from "@/components/ui/slider"

const duration = 60
const samples = Array.from({ length: duration }, (_, i) => 12 + 88 * Math.abs(Math.sin(i * 0.43) * Math.cos(i * 0.19)))

export default function ClipTimeline() {
  const [range, setRange] = useState([8, 42])
  const [start, end] = range

  return (
    <div className="sink-stack">
      <div className="sink-between"><strong>Night train.wav</strong><span className="sink-label">1:00</span></div>
      <div aria-hidden="true" style={{ display: "flex", alignItems: "center", gap: 1, height: 64, paddingBlock: 6, backgroundColor: "var(--cy-panel)", borderBlock: "1px solid var(--cy-line-deco)" }}>
        {samples.map((height, i) => <span key={i} style={{ flex: "1 1 0", height: `${height}%`, backgroundColor: i >= start && i < end ? "var(--cy-signal)" : "var(--cy-line-ctl)" }} />)}
      </div>
      <Slider label="Trim points" thumbLabels={["Clip start", "Clip end"]} value={range} onValueChange={setRange} min={0} max={duration} ticks={12} format={(value) => `${value}s`} />
      <Readout label="Selected duration" value={end - start} unit="s" size="sm" />
    </div>
  )
}
```

## Components in this recipe

- [Slider](https://www.cyberspec.dev/components/sidebar/slider.md) — A ticked track with a cut thumb and a value readout, single or range.
- [Readout](https://www.cyberspec.dev/components/sidebar/readout.md) — A large numeral with a unit and a label that counts to its new value when it changes.

## Resources

- [All kitchen sink recipes](https://www.cyberspec.dev/sink.md)
- [Recipe source on GitHub](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/clip-timeline.tsx)
- [Recipe layout stylesheet](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/recipes/recipe-layout.css)
- [Shadcn registry item](https://www.cyberspec.dev/r/clip-timeline.json)
