-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathscrollIntoView.tsx
More file actions
89 lines (86 loc) · 2.98 KB
/
Copy pathscrollIntoView.tsx
File metadata and controls
89 lines (86 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, { useRef, useState } from 'react';
import Tour from '../../src/index';
import './basic.less';
const App = () => {
const createBtnRef = useRef<HTMLButtonElement>(null);
const updateBtnRef = useRef<HTMLButtonElement>(null);
const deleteBtnRef = useRef<HTMLButtonElement>(null);
const [open, setOpen] = useState(false);
const [curScrollIntoViewOptions, setCurScrollIntoViewOptions] = useState<ScrollIntoViewOptions>({
block: 'start'
});
return (
<div style={{ margin: 20 }}>
<h2>{JSON.stringify(curScrollIntoViewOptions)}</h2>
<button onClick={() => setCurScrollIntoViewOptions({block: 'start'})}>block start</button>
<button onClick={() => setCurScrollIntoViewOptions({block: 'center'})}>block center</button>
<button onClick={() => setCurScrollIntoViewOptions({block: 'nearest'})}>block nearest</button>
<button onClick={() => setCurScrollIntoViewOptions({block: 'end'})}>block end</button>
<button onClick={() => setCurScrollIntoViewOptions({inline: 'start'})}>inline start</button>
<button onClick={() => setCurScrollIntoViewOptions({inline: 'center'})}>inline center</button>
<button onClick={() => setCurScrollIntoViewOptions({inline: 'nearest'})}>inline nearest</button>
<button onClick={() => setCurScrollIntoViewOptions({inline: 'end'})}>inline end</button>
<div>
<button
className="ant-target"
ref={createBtnRef}
style={{ marginLeft: 100 }}
onClick={() => {
setOpen(true);
}}
>
Create
</button>
<div style={{ height: 1500 }} />
<button className="ant-target" ref={updateBtnRef}>
Update
</button>
<button className="ant-target" ref={deleteBtnRef}>
Delete
</button>
</div>
<div style={{ height: 200 }} />
<Tour
open={open}
animated={true}
onClose={() => setOpen(false)}
onFinish={() => setOpen(false)}
scrollIntoViewOptions={curScrollIntoViewOptions}
steps={[
{
title: '创建',
description: '创建一条数据',
target: () => createBtnRef.current,
mask: true,
},
{
title: '更新',
description: (
<div>
<span>更新一条数据</span>
<button>帮助文档</button>
</div>
),
target: () => updateBtnRef.current,
scrollIntoViewOptions: {
block: 'start', behavior:'smooth'
}
},
{
title: '删除',
description: (
<div>
<span>危险操作:删除一条数据</span>
<button>帮助文档</button>
</div>
),
target: () => deleteBtnRef.current,
mask: true,
style: { color: 'red' },
},
]}
/>
</div>
);
};
export default App;