Skip to content

Commit cb31b5c

Browse files
committed
feat: storybook stories
1 parent f1cfa0f commit cb31b5c

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

src/components/SmartVideoPlayer/SmartVideoPlayer.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,39 @@
22
title: SmartVideoPlayer
33
---
44

5+
import { Meta, Canvas, Story, ArgTypes, Controls } from '@storybook/addon-docs/blocks'
6+
import * as SmartVideoPlayerStories from './SmartVideoPlayer.stories'
7+
8+
<Meta of={SmartVideoPlayerStories} />
9+
510
# SmartVideoPlayer
611

712
统一的播放器封装(HTML5 / YouTube / Embed),内置设置面板、字幕/倍速、HLS(原生优先 + hls.js 动态加载)等能力。
813

914
- “界面语言”只影响 SmartVideoPlayer 自身(不影响全站 i18n)
1015
- 语言通过 `localStorage: svpUiLanguage` 持久化(刷新后仍生效)
1116

17+
## 组件预览
18+
19+
<Canvas>
20+
<Story of={SmartVideoPlayerStories.Html5Mp4} />
21+
</Canvas>
22+
23+
<Canvas>
24+
<Story of={SmartVideoPlayerStories.YouTube} />
25+
</Canvas>
26+
27+
## Props(可调参数)
28+
29+
<ArgTypes />
30+
31+
<Controls />
32+
33+
## 说明
34+
35+
- “界面语言”只影响 SmartVideoPlayer 自身(不影响全站 i18n)
36+
- 语言通过 localStorage 的 svpUiLanguage 持久化(刷新后仍生效)
37+
1238
## 基本使用
1339

1440
### HTML5(MP4)

src/components/SmartVideoPlayer/SmartVideoPlayer.stories.tsx

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,94 @@ const meta = {
2626
},
2727
argTypes: {
2828
provider: {
29+
description: '播放提供方:HTML5 / YouTube / Embed。不同 provider 会使用不同的输入参数。',
2930
control: { type: 'select' },
3031
options: ['html5', 'youtube', 'embed'],
32+
table: { type: { summary: '"html5" | "youtube" | "embed"' } },
33+
},
34+
35+
title: {
36+
description: '标题(用于可访问性/Embed iframe title/文案展示)。',
37+
control: { type: 'text' },
38+
table: { type: { summary: 'string' } },
39+
},
40+
41+
src: {
42+
description: 'HTML5 视频地址(MP4 / HLS m3u8)。仅 provider=html5 时生效。',
43+
control: { type: 'text' },
44+
table: { type: { summary: 'string' } },
45+
},
46+
47+
youtubeId: {
48+
description: 'YouTube 视频 ID。仅 provider=youtube 时生效。',
49+
control: { type: 'text' },
50+
table: { type: { summary: 'string' } },
51+
},
52+
53+
embedUrl: {
54+
description: 'Embed iframe URL。仅 provider=embed 时生效。',
55+
control: { type: 'text' },
56+
table: { type: { summary: 'string' } },
57+
},
58+
59+
getEmbedUrl: {
60+
description: '动态生成 embed URL:getEmbedUrl(config) => string。优先级高于 embedUrl/youtubeId。',
61+
control: false,
62+
table: { type: { summary: '(config) => string' } },
63+
},
64+
65+
externalUrl: {
66+
description: '点击“新窗口打开”时使用的外部 URL(优先级高于 sourceUrl/自动推导)。',
67+
control: { type: 'text' },
68+
table: { type: { summary: 'string' } },
69+
},
70+
71+
sourceUrl: {
72+
description: '源地址/落地页 URL(用于“新窗口打开”的兜底)。',
73+
control: { type: 'text' },
74+
table: { type: { summary: 'string' } },
75+
},
76+
77+
trackSrc: {
78+
description: '字幕 VTT 地址(可选)。未传时会尝试从 mp4 src 推导同名 .vtt。',
79+
control: { type: 'text' },
80+
table: { type: { summary: 'string' } },
81+
},
82+
83+
trackLang: {
84+
description: '字幕语言(用于 track srcLang/label)。',
85+
control: { type: 'text' },
86+
table: { type: { summary: 'string' }, defaultValue: { summary: '"en"' } },
87+
},
88+
89+
initialConfig: {
90+
description: '初始配置(非受控)。包含:lazyPlay/miniPlayer/autoPlay/autoMute/playbackRate/ytControls。',
91+
control: { type: 'object' },
92+
table: { type: { summary: 'Partial<Config>' } },
93+
},
94+
95+
config: {
96+
description: '受控配置(传入即受控)。',
97+
control: { type: 'object' },
98+
table: { type: { summary: 'Config' } },
99+
},
100+
101+
onConfigChange: {
102+
description: '受控模式下配置变化回调。',
103+
control: false,
104+
table: { type: { summary: '(nextConfig) => void' } },
105+
},
106+
107+
onError: {
108+
description: '播放错误回调(含 provider/src/youtubeId/embedUrl 等上下文)。',
109+
control: false,
110+
table: { type: { summary: '(err) => void' } },
111+
},
112+
113+
onEvent: {
114+
description: '可观测事件回调(例如 play/pause/seek/hlsError/embedTimeout 等)。',
115+
control: false,
116+
table: { type: { summary: '(name, detail) => void' } },
31117
},
32118
},
33119
render: (args) => {

0 commit comments

Comments
 (0)