Repository navigation
Expand file tree
/
Copy pathdraggable.tsx
More file actions
46 lines (44 loc) · 1.6 KB
/
Copy pathdraggable.tsx
File metadata and controls
46 lines (44 loc) · 1.6 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
import React, { useState } from 'react';
import { Button, Space, Tooltip } from 'antd';
import { Modal, TinyTag } from 'dt-react-component';
export default function Basic() {
const [visible, setVisible] = useState(false);
const [position, setPosition] = useState({ x: 120, y: 120 });
return (
<>
<Modal
title={
<Space>
Draggable Modal
<Tooltip title="通过阻止 mousedown 事件冒泡,可以让 title 中的元素不触发拖拽">
<TinyTag
onMouseDown={(e) => e.stopPropagation()}
value="Cancel"
style={{ color: '#1D78FF' }}
/>
</Tooltip>
</Space>
}
draggable={{
bounds: 'body',
}}
position={position}
onPositionChange={({ x, y }) => setPosition({ x, y })}
open={visible}
onCancel={() => setVisible(false)}
onOk={() => setVisible(false)}
>
<ul>
{Array.from({ length: 300 }).map((_, i) => (
<li key={i} style={{ height: 30 }}>
{i}
</li>
))}
</ul>
</Modal>
<Button type="primary" onClick={() => setVisible(true)}>
Draggable Modal
</Button>
</>
);
}