Skip to content

Commit e82f7e0

Browse files
committed
feat: interactive book
1 parent a0017e9 commit e82f7e0

4 files changed

Lines changed: 690 additions & 22 deletions

File tree

src/components/stateless/InteractiveBook/InteractiveBook.mdx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import * as InteractiveBookStories from './InteractiveBook.stories'
1616
- 🎨 3D 翻页动画效果
1717
- ⌨️ 完整的键盘导航支持(箭头键、Escape、Home、End)
1818
- 📖 双面内容显示(正面内容 + 背面内容)
19-
- 🎯 空状态处理
19+
- � 页角海浪卷起翻页提示
20+
- 🖱️ 拖拽翻页 & 点击翻页
21+
- �🎯 空状态处理
2022
- 🔄 页面变化回调
2123
- 📱 响应式设计
2224

@@ -26,6 +28,22 @@ import * as InteractiveBookStories from './InteractiveBook.stories'
2628
<Story of={InteractiveBookStories.Default} />
2729
</Canvas>
2830

31+
## 页角翻页提示
32+
33+
鼠标悬停在页面的右下角或左下角时,页角会出现海浪卷起的动画效果,提示用户可以点击翻页。
34+
35+
<Canvas>
36+
<Story of={InteractiveBookStories.CornerCurlHint} />
37+
</Canvas>
38+
39+
## 少量页面
40+
41+
当翻到最后一页(结束页)时,拖动手势自动禁用,鼠标恢复为普通箭头光标。
42+
43+
<Canvas>
44+
<Story of={InteractiveBookStories.FewPages} />
45+
</Canvas>
46+
2947
## Props(可调参数)
3048

3149
<ArgTypes />
@@ -106,6 +124,20 @@ interface BookPage {
106124
- `Home`:回到封面
107125
- `End`:跳到最后一页
108126

127+
## 交互方式
128+
129+
组件支持多种翻页交互方式:
130+
131+
| 交互方式 | 说明 |
132+
|---------|------|
133+
| 拖拽翻页 | 在页面上按住并左右拖拽,超过阈值后松手翻页 |
134+
| 页角点击 | 鼠标悬停在页面右下角/左下角,出现卷起效果后点击翻页 |
135+
| 导航栏按钮 | 底部导航栏的前后翻页按钮 |
136+
| 键盘快捷键 | 方向键、Home、End、Escape |
137+
| 封面点击/拖拽 | 点击或向左拖拽封面打开书籍 |
138+
139+
> **注意**:最后一页(结束页)禁用拖拽,鼠标光标恢复为普通箭头。
140+
109141
## 高级用法
110142

111143
### 自定义样式

src/components/stateless/InteractiveBook/InteractiveBook.stories.tsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ const meta: Meta<typeof InteractiveBook> = {
229229
bookAuthor: { control: 'text' },
230230
width: { control: 'number' },
231231
height: { control: 'number' },
232+
enableKeyboard: { control: 'boolean' },
232233
},
233234
parameters: {
234235
layout: 'centered',
@@ -251,5 +252,77 @@ export const Default: Story = {
251252
pages: bookPages,
252253
width: 350,
253254
height: 500,
255+
enableKeyboard: true,
256+
},
257+
}
258+
259+
/**
260+
* 页角翻页提示:鼠标悬停在页面右下角/左下角时,
261+
* 页角会出现海浪卷起的动画效果,提示用户可以点击翻页。
262+
*/
263+
export const CornerCurlHint: Story = {
264+
name: '页角翻页提示',
265+
render: (args: InteractiveBookProps) => (
266+
<div className="flex h-[800px] w-full flex-col items-center justify-center gap-4 bg-neutral-100 p-10">
267+
<p style={{ color: '#6b7280', fontSize: '0.875rem', textAlign: 'center', maxWidth: 400 }}>
268+
打开书籍后,将鼠标悬停在页面的右下角或左下角,页角会出现海浪卷起的动画效果。点击页角即可翻页。
269+
</p>
270+
<InteractiveBook {...args} />
271+
</div>
272+
),
273+
args: {
274+
coverImage: AiCover,
275+
bookTitle: 'AI Agent 完全指南',
276+
bookAuthor: 'AI 专家',
277+
pages: bookPages,
278+
width: 350,
279+
height: 500,
280+
enableKeyboard: true,
281+
},
282+
}
283+
284+
/**
285+
* 少量页面示例:展示两页内容时的翻页交互,
286+
* 最后一页(结束页)不再显示拖动手势。
287+
*/
288+
export const FewPages: Story = {
289+
name: '少量页面',
290+
render: (args: InteractiveBookProps) => (
291+
<div className="flex h-[800px] w-full items-center justify-center bg-neutral-100 p-10">
292+
<InteractiveBook {...args} />
293+
</div>
294+
),
295+
args: {
296+
coverImage: AiCover,
297+
bookTitle: '简短手册',
298+
bookAuthor: '作者',
299+
pages: [
300+
{
301+
pageNumber: 1,
302+
title: '唯一的章节',
303+
content: (
304+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
305+
<p>"这本书只有一页正文,翻到最后一页时不再显示拖动手势。"</p>
306+
<p>"将鼠标移到右下角,可以看到页角卷起效果。"</p>
307+
</div>
308+
),
309+
backContent: (
310+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
311+
<p style={{ fontStyle: 'italic', color: '#9ca3af' }}>背面内容</p>
312+
</div>
313+
),
314+
},
315+
{
316+
pageNumber: 2,
317+
title: '结束',
318+
content: (
319+
<div style={{ display: 'flex', flexDirection: 'column', gap: '16px' }}>
320+
<p>"最后一页,拖动手势已禁用,鼠标恢复为普通箭头。"</p>
321+
</div>
322+
),
323+
},
324+
],
325+
width: 350,
326+
height: 500,
254327
},
255328
}

0 commit comments

Comments
 (0)