Updated
Podcast Chapters
NewCustomize
Color
Trail
Start at742s
Bars96
Width460px
Installation
npx shadcn@latest add https://uibrik.com/r/podcast-chapters.jsonInstall the packages
npm install @tabler/icons-react motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/podcast-chapters/podcast-chapters.tsx"use client"; // An episode player where the waveform is split into chapters. The played // part fills in behind the playhead, the current chapter's title sits under it // and the transcript line being spoken fades in word by word. Hovering the // waveform previews the time and chapter under the pointer; clicking seeks. // The chapter list below jumps too, and the playing chapter fills as it goes. // Playback is simulated unless a `src` is passed, in which case an <audio> // element drives everything. import { IconBookmark, IconBookmarkFilled, IconChevronDown, IconPlayerPauseFilled, IconPlayerPlayFilled, IconRewindBackward15, IconRewindForward15 } from "@tabler/icons-react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { Fragment, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type PointerEvent, type ReactNode } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; export type PodcastChapter = { title: string; start: number }; export type TranscriptLine = { time: number; speaker?: string; text: string }; export type PodcastChaptersProps = { title?: string; show?: string; /** Episode length in seconds. Read from the audio when `src` is set. */
Adds the files to
components/uibrik/podcast-chapters and installs @tabler/icons-react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/podcast-chapters.Usage
import { PodcastChapters } from "@/components/uibrik/podcast-chapters/podcast-chapters";const chapters = [ { title: "Cold open", start: 0 }, { title: "Why most apps feel loud", start: 184 }, // …4 more];const transcript = [ { time: 0, speaker: "Ana", text: "Welcome back. Today is all about software that gets out of the way." }, { time: 702, speaker: "Ana", text: "So let's talk about motion. When does an animation actually help?" }, // …14 more];<PodcastChapters title="Designing calm software" show="Field Notes · Ep. 142" color="#e5484d" trailColors={["#ff4d6d", "#ffb547"]} autoPlay defaultTime={742} defaultTranscriptOpen={false} bars={96} width={460} chapters={chapters} transcript={transcript} duration={2910} defaultBookmarks={[412, 1588]} speeds={[1, 1.5, 2]} onTimeChange={(seconds) => {}} // src="…" // bookmarks={[0]} // onBookmarksChange={(seconds) => {}}/>Where to use Podcast Chapters
Podcast and audio apps
Chapters on the waveform and a live transcript line make a long episode easy to skim.
Pairs with Music Player
Course and lecture players
Learners jump to the section they need, and the transcript shows what they are hearing.
Pairs with Voice Note
Show pages on marketing sites
An episode with chapters and quotes reads well before anyone presses play.
Props
PodcastChapters- title
- Type string
- "Designing calm software"
- Episode title.
- show
- Type string
- "Field Notes · Ep. 142"
- Show name and episode number.
- color
- Type string
- "#e5484d"
- Colour of the played waveform and the current chapter.
- trailColors
- Type string[]
- ["#ff4d6d","#ffb547"]
- The two colours of the trail that leads the transcript in, front first.
- autoPlay
- Type boolean
- true
- Start simulated playback on mount.
- defaultTime
- Type number
- 742
- Where playback starts.
- defaultTranscriptOpen
- Type boolean
- false
- Show the full transcript on mount.
- bars
- Type number
- 96
- Number of waveform bars.
- width
- Type number
- 460
- Width of the card; never wider than its container.
- chapters
- Type { title: string; start: number }[]
- –
- Chapter titles and start times in seconds.
- transcript
- Type { time: number; speaker?: string; text: string }[]
- –
- Lines with the second they start; the current one shows under the waveform.
- duration
- Type number
- 2910
- Episode length in seconds; read from the audio when src is set.
- src
- Type string
- –
- Audio file. Without it, playback is simulated.
- bookmarks / onBookmarksChange
- Type number[] / (seconds: number[]) => void
- –
- Saved moments in seconds, controlled; shown as pins on the waveform.
- defaultBookmarks
- Type number[]
- –
- Bookmarks on mount when uncontrolled.
- speeds
- Type number[]
- [1, 1.5, 2]
- Speeds the speed button cycles through.
- onTimeChange
- Type (seconds: number) => void
- –
- Called about once a second while playing, and on every seek.
- className
- Type string
- –
- Classes for the wrapper.