This repository was archived by the owner on Nov 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathfollow.tsx
More file actions
93 lines (87 loc) · 2.15 KB
/
Copy pathfollow.tsx
File metadata and controls
93 lines (87 loc) · 2.15 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
90
91
92
93
import React from 'react';
import Align from '../src';
const Demo = () => {
const [width, setWidth] = React.useState(100);
const [height, setHeight] = React.useState(100);
const [left, setLeft] = React.useState('100%');
const [top, setTop] = React.useState('100%');
const [visible, setVisible] = React.useState(true);
const [svg, setSvg] = React.useState(false);
const sharedStyle: React.CSSProperties = {
width,
height,
position: 'absolute',
left,
top,
display: visible ? 'flex' : 'none',
};
return (
<div>
<button
type="button"
onClick={() => {
setLeft(`${Math.random() * 100}%`);
setTop(`${Math.random() * 100}%`);
setWidth(50 + Math.random() * 50);
setHeight(50 + Math.random() * 50);
}}
>
Random Size and Position
</button>
<button
type="button"
onClick={() => {
setVisible(!visible);
}}
>
Trigger Visible
</button>
<button
type="button"
onClick={() => {
setSvg(!svg);
}}
>
Follow SVG ({String(svg)})
</button>
<div
style={{
border: '1px solid red',
width: '90vw',
height: '50vh',
position: 'relative',
}}
>
{svg ? (
<svg id="content" width={width} height={height} style={sharedStyle}>
<rect x="0" y="0" width={width} height={height} />
</svg>
) : (
<div
style={{
border: '1px solid green',
boxSizing: 'border-box',
alignItems: 'center',
justifyContent: 'center',
...sharedStyle,
}}
id="content"
>
Content
</div>
)}
<Align target={() => document.getElementById('content')} align={{ points: ['tc', 'bc'] }}>
<div
style={{
border: '1px solid blue',
position: 'absolute',
}}
>
Popup
</div>
</Align>
</div>
</div>
);
};
export default Demo;