Skip to content

Commit 277d110

Browse files
authored
[Stream] Video chapters collapsed (#24445)
* [Stream] Chapters in collapsible details * [Stream] Add optional expandChapters prop
1 parent f938fdb commit 277d110

File tree

5 files changed

+67
-48
lines changed

5 files changed

+67
-48
lines changed

src/components/Stream.astro

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { z } from "astro:schema";
33
import { Badge } from "@astrojs/starlight/components";
44
import parse from "parse-duration";
5+
import Details from "./Details.astro";
56
67
type Props = z.input<typeof props>;
78
@@ -12,12 +13,12 @@ const props = z
1213
thumbnail: z.string().optional(),
1314
chapters: z.record(z.string(), z.string()).optional(),
1415
showMoreVideos: z.boolean().default(false),
16+
expandChapters: z.boolean().default(false),
1517
})
1618
.strict();
1719
18-
const { id, title, thumbnail, chapters, showMoreVideos } = props.parse(
19-
Astro.props,
20-
);
20+
const { id, title, thumbnail, chapters, showMoreVideos, expandChapters } =
21+
props.parse(Astro.props);
2122
2223
const BASE_URL = `https://customer-1mwganm1ma0xgnmj.cloudflarestream.com/`;
2324
@@ -53,42 +54,43 @@ if (thumbnail) {
5354

5455
{
5556
chapters && (
56-
<p>
57-
<strong>Chapters</strong>
58-
<ul class="flex list-none gap-4 overflow-x-scroll pb-4 pl-0">
59-
{Object.entries(chapters).map(([chapter, time]) => {
60-
const totalSeconds = parse(time, "s");
61-
62-
const thumbnail = new URL(thumbnailUrl);
63-
thumbnail.searchParams.set("fit", "crop");
64-
thumbnail.searchParams.set("time", `${totalSeconds}s`);
65-
66-
return (
67-
<li class="mt-0!">
68-
<button
69-
class="flex h-full w-36 cursor-pointer flex-col rounded-sm border border-gray-200 bg-transparent p-4 dark:border-gray-700"
70-
data-chapter={chapter}
71-
data-time={totalSeconds}
72-
>
73-
<img
74-
src={thumbnail.toString()}
75-
alt={chapter}
76-
width="120"
77-
height="64"
78-
class="border-accent bg-accent/10 rounded-sm border"
79-
/>
80-
<div class="flex h-full flex-col items-center justify-between">
81-
<strong class="line-clamp-2 text-xs" title={chapter}>
82-
{chapter}
83-
</strong>
84-
<Badge text={time} variant="tip" class="w-fit" />
85-
</div>
86-
</button>
87-
</li>
88-
);
89-
})}
90-
</ul>
91-
</p>
57+
<Details header="Chapters" open={expandChapters}>
58+
<p>
59+
<ul class="flex list-none gap-4 overflow-x-scroll pb-4 pl-0">
60+
{Object.entries(chapters).map(([chapter, time]) => {
61+
const totalSeconds = parse(time, "s");
62+
63+
const thumbnail = new URL(thumbnailUrl);
64+
thumbnail.searchParams.set("fit", "crop");
65+
thumbnail.searchParams.set("time", `${totalSeconds}s`);
66+
67+
return (
68+
<li class="mt-0!">
69+
<button
70+
class="flex h-full w-36 cursor-pointer flex-col rounded-sm border border-gray-200 bg-transparent p-4 dark:border-gray-700"
71+
data-chapter={chapter}
72+
data-time={totalSeconds}
73+
>
74+
<img
75+
src={thumbnail.toString()}
76+
alt={chapter}
77+
width="120"
78+
height="64"
79+
class="border-accent bg-accent/10 rounded-sm border"
80+
/>
81+
<div class="flex h-full flex-col items-center justify-between">
82+
<strong class="line-clamp-2 text-xs" title={chapter}>
83+
{chapter}
84+
</strong>
85+
<Badge text={time} variant="tip" class="w-fit" />
86+
</div>
87+
</button>
88+
</li>
89+
);
90+
})}
91+
</ul>
92+
</p>
93+
</Details>
9294
)
9395
}
9496

src/content/docs/cache/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Cache content across Cloudflare's global server network.
2020

2121
Cache stores copies of frequently accessed content (such as images, videos, or webpages) in geographically distributed data centers that are located closer to end users than origin servers, reducing server load and improving website performance.
2222

23-
<Stream id="90d8a506e1e3935cff71223f9d785aa6" title="How Cloudflare protects and accelerates your website or app" thumbnail="https://pub-d9bf66e086fb4b639107aa52105b49dd.r2.dev/How%20Cloudflare%20%20protects%20and%20accelerates%20your%20website%20and%20app.png" />
23+
<Stream id="90d8a506e1e3935cff71223f9d785aa6" title="How Cloudflare protects and accelerates your website or app" thumbnail="https://pub-d9bf66e086fb4b639107aa52105b49dd.r2.dev/How%20Cloudflare%20%20protects%20and%20accelerates%20your%20website%20and%20app.png"/>
2424

2525
## Features
2626

src/content/docs/learning-paths/r2-intro/series/r2-4.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Render, Tabs, TabItem, Stream, Card } from "~/components";
1515
<TabItem label="Watch this episode" icon="seti:video">
1616

1717
In this video, you will learn how to use Cloudflare R2's data migration tools to transfer data from other cloud providers such as Amazon S3 and Google Cloud Storage to R2. The video will demonstrate the step-by-step process of setting up and executing a data migration.
18-
18+
1919
<Card>
2020
<Stream
2121
id="2bb9f663c21bab9e8996cb2bc93d7218"

src/content/docs/style-guide/components/details.mdx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,31 @@ styleGuide:
44
component: Details
55
---
66

7+
import { Type, MetaInfo } from "~/components";
8+
79
When you want to provide additional information in context, but you do not want it to clutter up the more important content, use `<Details>` to add a collapsible container.
810

911
```mdx live
10-
import { Details } from "~/components"
12+
import { Details } from "~/components";
1113

12-
<Details header="Open me!">
13-
Hello, world!
14-
</Details>
14+
<Details header="Open me!">Hello, world!</Details>
1515
```
1616

1717
You can specify the default configuration of each instance of the `<Details>` component (that is, whether it is open or closed by default).
1818

1919
```mdx live
20-
import { Details } from "~/components"
20+
import { Details } from "~/components";
2121

22-
<Details header="Close me!" open = {true}>
23-
Long piece of code example.
22+
<Details header="Close me!" open={true}>
23+
Long piece of code example.
2424
</Details>
2525
```
26+
27+
## Properties
28+
29+
- `header` <Type text="string" /> <MetaInfo text="required" />
30+
- `id` <Type text="string" /> <MetaInfo text="optional" />
31+
32+
Adds a specific `id` to the HTML element
33+
34+
- `open` <Type text="boolean" /> <MetaInfo text="optional" />

src/content/docs/style-guide/components/stream.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ Either a timestamp (i.e `2.5s` or `1m35s`) or a URL to an image.
7272

7373
Optional chapters displayed as cards below the video.
7474

75+
### `expandChapters`
76+
77+
**type:** `boolean`
78+
79+
**default:** `false`
80+
81+
If `chapters` is present, is passed through to the `open` property of the [Details component](/style-guide/components/details/).
82+
7583
### `showMoreVideos`
7684

7785
**type:** `boolean`

0 commit comments

Comments
 (0)