Skip to content

Commit e976903

Browse files
committed
docs: add debug demo
1 parent 8abc4f9 commit e976903

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

docs/demos/portal.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Portal
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../examples/portal.tsx"></code>

docs/examples/portal.tsx

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/* eslint no-console:0 */
2+
3+
import Trigger from 'rc-trigger';
4+
import React from 'react';
5+
import { createPortal } from 'react-dom';
6+
import '../../assets/index.less';
7+
8+
const builtinPlacements = {
9+
left: {
10+
points: ['cr', 'cl'],
11+
},
12+
right: {
13+
points: ['cl', 'cr'],
14+
},
15+
top: {
16+
points: ['bc', 'tc'],
17+
},
18+
bottom: {
19+
points: ['tc', 'bc'],
20+
},
21+
topLeft: {
22+
points: ['bl', 'tl'],
23+
},
24+
topRight: {
25+
points: ['br', 'tr'],
26+
},
27+
bottomRight: {
28+
points: ['tr', 'br'],
29+
},
30+
bottomLeft: {
31+
points: ['tl', 'bl'],
32+
},
33+
};
34+
35+
const popupBorderStyle = {
36+
border: '1px solid red',
37+
padding: 10,
38+
background: 'rgba(255, 0, 0, 0.1)',
39+
};
40+
41+
const PortalPopup = () =>
42+
createPortal(
43+
<div
44+
style={popupBorderStyle}
45+
onMouseDown={(e) => {
46+
console.log('Portal Down', e);
47+
}}
48+
>
49+
i am a portal element
50+
</div>,
51+
document.body,
52+
);
53+
54+
const Test = () => {
55+
const buttonRef = React.useRef<HTMLButtonElement>(null);
56+
React.useEffect(() => {
57+
const button = buttonRef.current;
58+
if (button) {
59+
button.addEventListener('mousedown', (e) => {
60+
console.log('button natives down');
61+
e.stopPropagation();
62+
e.preventDefault();
63+
});
64+
}
65+
}, []);
66+
67+
return (
68+
<div
69+
style={{
70+
padding: 100,
71+
display: 'flex',
72+
flexDirection: 'column',
73+
alignItems: 'flex-start',
74+
gap: 100,
75+
}}
76+
>
77+
<Trigger
78+
popupPlacement="right"
79+
action={['click']}
80+
builtinPlacements={builtinPlacements}
81+
popup={
82+
<div style={popupBorderStyle}>
83+
i am a click popup
84+
<PortalPopup />
85+
</div>
86+
}
87+
>
88+
<button>Click Me</button>
89+
</Trigger>
90+
91+
<button
92+
onMouseDown={(e) => {
93+
console.log('button down');
94+
e.stopPropagation();
95+
e.preventDefault();
96+
}}
97+
>
98+
Stop Pop & Prevent Default
99+
</button>
100+
<button ref={buttonRef}>Native Stop Pop & Prevent Default</button>
101+
</div>
102+
);
103+
};
104+
105+
export default Test;

0 commit comments

Comments
 (0)