StoryViewer
A full-screen story player.
View code
<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.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
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.
StoryViewerStoryViewer.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.
| Prop | Type | Required | Description |
|---|---|---|---|
label | string | Yes | The viewer's accessible name, such as "Stories". |
closeHref | string | Yes | Where 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 | |
children | RemixNode | Yes | StoryViewer.Group elements, one per person, in viewing order. |
Also accepts everything in TagProps<"section">.
StoryViewer.Group
| Prop | Type | Required | Description |
|---|---|---|---|
label | string | Yes | The group's accessible name, such as "Mara Quint's story". |
header | RemixNode | No | What sits under the progress bars: the person, how long ago, a menu. |
durations | number[] | Yes | Each segment's length in seconds, in order, which times its progress bar. |
current | number | Yes | The segment the group shows first. |
active | boolean | No | Whether the viewer opens on this group; exactly one group in a viewer sets it. |
previousHref | string | Yes | The address of the segment before the current one, or the close address before the first. |
nextHref | string | Yes | The address of the segment after the current one, or the close address after the last. |
labels | { previous: string; next: string } | Yes | The tap zones' names. |
footer | RemixNode | No | What sits at the foot of the card, such as a reply field. |
children | RemixNode | Yes | StoryViewer.Segment elements in order. |
Also accepts everything in Omit<TagProps<"article">, "children">.
StoryViewer.Segment
| Prop | Type | Required | Description |
|---|---|---|---|
href | string | Yes | The segment's own address, which the address bar follows. |
current | boolean | Yes | Whether this is the group's current segment. |
Also accepts everything in TagProps<"div">.