GooseUI

Components

Story Player

New

A vertical card that plays photo and video slides one after another, like stories in a social app. Tap the left third to go back, the rest to go forward, press and hold to pause. The segment fill is a CSS animation, so there is no timer ticking on every frame, and a small client script only handles taps, keys, visibility and video.

Browser Support

Baseline Widely available
2 features
Details
inert

Slides that are not on screen are inert, so Tab and screen readers skip them. Without support they stay hidden with visibility, so only focus order is affected.

Your browser:
Intersection observer

Autoplay runs only while the player is visible. Without support the player plays as soon as it is mounted.

Your browser:

Preview

First light

First light

Clouds fill the valley before sunrise

The long way down

The long way down

A glacier valley, five hours in

Sun over the hills

Eleven seconds of a real video

Above the snow line

Above the snow line

The air gets thin and quiet

Last stop: the lake

Last stop: the lake

Worth every step

Mei Tanaka2h

Installation

npx shadcn@latest add @gooseui/story-player
pnpm dlx shadcn@latest add @gooseui/story-player
yarn dlx shadcn@latest add @gooseui/story-player
bunx --bun shadcn@latest add @gooseui/story-player

Usage

import { StoryPlayer } from "@/components/ui/story-player"

const slides = [
  { src: "/stories/dawn.webp", title: "First light", alt: "Clouds in a valley" },
  { src: "/stories/hills.mp4", title: "Sun over the hills" },
  { src: "/stories/lake.webp", duration: 7000 },
]

export default function Example() {
  return (
    <StoryPlayer
      slides={slides}
      author="Mei Tanaka"
      avatar="/avatars/mei.webp"
      meta="2h"
      className="max-w-[340px]"
    />
  )
}

Examples

Video slide and per-slide duration

The type is detected from the extension (or set type). A video is muted and its slide lasts as long as the file; a photo takes duration, and a slide can override it with its own duration.

Sun over the hills

A video slide takes its length from the file

Above the snow line

Above the snow line

A photo slide lasts 3 seconds here

Mei Tanaka2h
const slides = [
  { src: "/stories/hills.mp4", poster: "/stories/hills.webp" }, // length of the file
  { src: "/stories/peaks.webp", duration: 3000 },
]

<StoryPlayer slides={slides} author="Mei Tanaka" />

Transitions

transition accepts "fade" (default), "slide" and "blur". Three players side by side, each with 3-second slides.

Fade

First light

First light

Clouds fill the valley before sunrise

The long way down

The long way down

A glacier valley, five hours in

Above the snow line

Above the snow line

The air gets thin and quiet

Last stop: the lake

Last stop: the lake

Worth every step

Mei Tanaka

Slide

First light

First light

Clouds fill the valley before sunrise

The long way down

The long way down

A glacier valley, five hours in

Above the snow line

Above the snow line

The air gets thin and quiet

Last stop: the lake

Last stop: the lake

Worth every step

Mei Tanaka

Blur

First light

First light

Clouds fill the valley before sunrise

The long way down

The long way down

A glacier valley, five hours in

Above the snow line

Above the snow line

The air gets thin and quiet

Last stop: the lake

Last stop: the lake

Worth every step

Mei Tanaka
<StoryPlayer slides={slides} author="Mei" transition="slide" duration={3000} className="w-44" />
{/* "fade" | "slide" | "blur" */}

Manual control with a ref

With autoplay={false} the player waits. A ref exposes next, prev, goTo, play and pause, and onChange and onEnd report progress. Here loop is off, so the last slide fires onEnd.

First light

First light

Clouds fill the valley before sunrise

The long way down

The long way down

A glacier valley, five hours in

Sun over the hills

Eleven seconds of a real video

Above the snow line

Above the snow line

The air gets thin and quiet

Last stop: the lake

Last stop: the lake

Worth every step

Mei Tanaka2h

Slide 1 / 5

const ref = React.useRef<StoryPlayerHandle>(null)

<StoryPlayer
  ref={ref}
  slides={slides}
  author="Mei Tanaka"
  autoplay={false}
  loop={false}
  onChange={(index) => console.log(index)}
  onEnd={() => console.log("done")}
/>
<Button onClick={() => ref.current?.play()}>Play</Button>
<Button onClick={() => ref.current?.goTo(2)}>Go to 3</Button>

Props

PropTypeDefaultDescription
slidesStoryPlayerSlide[]-Slides to play (required)
authorstring-Name in the header (required)
avatarstring-Avatar URL. Without it the initials of the author are shown
metastring-Small text next to the name, e.g. "2h"
durationnumber5000Default time per photo slide in milliseconds
autoplaybooleantruePlay while the player is on screen. Off under reduced motion until play() or the button
loopbooleantrueStart over after the last slide. When off, onEnd is called and the player stops
transition"fade" | "slide" | "blur""fade"How slides change
kenBurnsbooleantrueSlow zoom and drift of photos (CSS)
labelsPartial<StoryPlayerLabels>-Texts, all optional, English by default
onChange(index: number) => void-Called with the new index when the slide changes
onEnd() => void-Called after the last slide when loop is off
refRef<StoryPlayerHandle>-Handle with next, prev, goTo, play and pause
classNamestring-Extra classes. The width follows the container up to max-w-[340px]; override it here. The height comes from aspect-9/16

Slide fields

PropTypeDefaultDescription
srcstring-Image or video URL (required)
type"image" | "video"by extensionmp4, webm, mov, m4v and ogv count as video
titlestring-Caption at the bottom
subtitlestring-Smaller line under the title
durationnumberduration prop or video lengthMilliseconds for this slide
altstringtitleAlt text of an image, accessible name of a video
posterstring-Poster of a video slide

Labels

story, roleDescription, previous, next, pause, play and slide. The slide template replaces {current} and {total}.

Accessibility

  • The player is a group with aria-roledescription="story" and the name "Story: author". Each slide is a group named "Slide N of M"; slides that are not current are inert.
  • Tap zones are real buttons with labels, so Tab and Enter work. With focus on the player, the arrow keys go back and forward and Space pauses or resumes.
  • A visible pause button is always in the header and changes its label to Play.
  • A polite live region announces Slide N of M only after manual navigation (tap, keys, ref), so autoplay does not talk over a screen reader.
  • Images take alt from alt or the title; a video takes it as its accessible name. Avatars are decorative.

Reduced motion and pausing

  • With prefers-reduced-motion: reduce the Ken Burns drift is removed and slides switch without a transition.
  • Autoplay is off by default under reduced motion: the player starts on the first slide with the active segment shown filled, and navigation is manual. play(), Space or the pause button start it on purpose.
  • Autoplay also waits until the player is at least a quarter visible and pauses when the tab is hidden.
  • Holding a press on a tap zone for about 200 ms pauses the timer and the video; releasing resumes and is not counted as a tap.

Notes

  • The progress is the source of truth: a video that stalls shows as buffering and pauses the fill, but a video may drift by a fraction of a second from the segment.
  • Callbacks are plain functions, so pass them from a client component.
  • Photos load lazily and the next slide is preloaded. Use 720x1280 images for a 340 px card.