-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbasic.tsx
63 lines (57 loc) · 1.99 KB
/
basic.tsx
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
import React, { version } from 'react';
import classNames from 'classnames';
import Portal from '../../src';
import './basic.less';
export default () => {
const [show, setShow] = React.useState(true);
const [customizeContainer, setCustomizeContainer] = React.useState(false);
const [lock, setLock] = React.useState(true);
const divRef = React.useRef<HTMLDivElement>(null);
React.useEffect(
() => () => {
console.log('Demo unmount!!');
},
[],
)
// const getContainer = customizeContainer ? () => divRef.current : undefined;
const getContainer = () => {
const el = document.createElement('div');
document.body.appendChild(el);
return el
}
const contentCls = customizeContainer ? '' : 'abs';
return (
<React.StrictMode>
<div style={{ height: '200vh' }}>
<div style={{ border: '2px solid red' }}>
Real Version: {version}
<button onClick={() => setShow(!show)}>
show: {show.toString()}
</button>
<button onClick={() => setCustomizeContainer(!customizeContainer)}>
customize container: {customizeContainer.toString()}
</button>
<button onClick={() => setLock(!lock)}>
lock scroll: {lock.toString()}
</button>
<div
id="customize"
ref={divRef}
style={{ border: '1px solid green', minHeight: 10 }}
/>
</div>
<Portal open={show} getContainer={getContainer} autoLock={lock}>
<p className={classNames(contentCls, 'root')}>Hello Root</p>
<Portal open={show} getContainer={getContainer} autoLock={lock}>
<p className={classNames(contentCls, 'parent')}>Hello Parent</p>
<Portal open={show} getContainer={getContainer} autoLock={lock}>
<p className={classNames(contentCls, 'children')}>
Hello Children
</p>
</Portal>
</Portal>
</Portal>
</div>
</React.StrictMode>
);
};