SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

StoryViewer

A full-screen story player.

mara.quint

teo.lind

View code
tsx
<StoryViewer label="Stories" closeHref="/" labels={{ close: "Close", pause: "Pause" }}>
	{people.map((person, index) => (
		<StoryViewer.Group
			label={`${person.name}'s story`}
			durations={person.segments.map(() => 5)}
			current={0}
			active={index === 0}
			previousHref={person.previousHref}
			nextHref={person.segments[1]?.href ?? person.nextHref}
			labels={{ previous: "Previous", next: "Next" }}
			header={<p>{person.handle}</p>}
		>
			{person.segments.map((segment, position) => (
				<StoryViewer.Segment href={segment.href} current={position === 0}>
					<img src={segment.photo} alt={segment.alt} />
				</StoryViewer.Segment>
			))}
		</StoryViewer.Group>
	))}
</StoryViewer>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
import { StoryViewer } from "@sdxc/ui/video";

Renders the viewer: a full-screen dark stage with the close and pause buttons, and the track of groups; the group marked active is the one the track starts at. A page shows it inside a box by setting --ui-story-viewer-position: absolute and --ui-story-viewer-height.

Composition

The parts the component publishes, each a static property of the host.

  • StoryViewer
  • StoryViewer.GroupOne person's stories: a screen-wide snap point holding a card that fills a phone and stands 9:16 with a margin on a wider screen, with the bars, the header, the segments, the two tap zones and an optional footer.
  • StoryViewer.SegmentOne segment: a full-card layer, shown only while it is its group's current one.

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeRequiredDescription
labelstringYesThe viewer's accessible name, such as "Stories".
closeHrefstringYesWhere closing leaves to: the page the viewer opened from.
labels{ close: string; /** The pause button's name; it is pressed while the story is paused. */ pause: string; }Yes
childrenRemixNodeYesStoryViewer.Group elements, one per person, in viewing order.

Also accepts everything in TagProps<"section">.

StoryViewer.Group

PropTypeRequiredDescription
labelstringYesThe group's accessible name, such as "Mara Quint's story".
headerRemixNodeNoWhat sits under the progress bars: the person, how long ago, a menu.
durationsnumber[]YesEach segment's length in seconds, in order, which times its progress bar.
currentnumberYesThe segment the group shows first.
activebooleanNoWhether the viewer opens on this group; exactly one group in a viewer sets it.
previousHrefstringYesThe address of the segment before the current one, or the close address before the first.
nextHrefstringYesThe address of the segment after the current one, or the close address after the last.
labels{ previous: string; next: string }YesThe tap zones' names.
footerRemixNodeNoWhat sits at the foot of the card, such as a reply field.
childrenRemixNodeYesStoryViewer.Segment elements in order.

Also accepts everything in Omit<TagProps<"article">, "children">.

StoryViewer.Segment

PropTypeRequiredDescription
hrefstringYesThe segment's own address, which the address bar follows.
currentbooleanYesWhether this is the group's current segment.

Also accepts everything in TagProps<"div">.

@sdxc/ui

Can’t find it? Contact us