@rc-component/trigger 1.11.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/index.css +5 -5
- package/assets/index.less +5 -5
- package/es/Popup/Arrow.d.ts +3 -2
- package/es/Popup/Arrow.js +10 -8
- package/es/Popup/index.d.ts +3 -2
- package/es/Popup/index.js +6 -1
- package/es/index.js +5 -3
- package/es/interface.d.ts +2 -1
- package/es/util.d.ts +23 -1
- package/es/util.js +70 -14
- package/lib/Popup/Arrow.d.ts +3 -2
- package/lib/Popup/Arrow.js +11 -9
- package/lib/Popup/index.d.ts +3 -2
- package/lib/Popup/index.js +6 -1
- package/lib/index.js +5 -3
- package/lib/interface.d.ts +2 -1
- package/lib/util.d.ts +23 -1
- package/lib/util.js +70 -14
- package/package.json +1 -1
package/assets/index.css
CHANGED
|
@@ -31,34 +31,34 @@
|
|
|
31
31
|
animation-play-state: running;
|
|
32
32
|
}
|
|
33
33
|
.rc-trigger-popup-arrow {
|
|
34
|
+
z-index: 1;
|
|
34
35
|
width: 0px;
|
|
35
36
|
height: 0px;
|
|
36
37
|
background: #000;
|
|
37
38
|
border-radius: 100vw;
|
|
38
39
|
box-shadow: 0 0 0 3px black;
|
|
39
|
-
z-index: 1;
|
|
40
40
|
}
|
|
41
41
|
@keyframes rcTriggerZoomIn {
|
|
42
42
|
0% {
|
|
43
43
|
transform: scale(0, 0);
|
|
44
|
-
transform-origin: 50% 50
|
|
44
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
45
45
|
opacity: 0;
|
|
46
46
|
}
|
|
47
47
|
100% {
|
|
48
48
|
transform: scale(1, 1);
|
|
49
|
-
transform-origin: 50% 50
|
|
49
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
50
50
|
opacity: 1;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
@keyframes rcTriggerZoomOut {
|
|
54
54
|
0% {
|
|
55
55
|
transform: scale(1, 1);
|
|
56
|
-
transform-origin: 50% 50
|
|
56
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
57
57
|
opacity: 1;
|
|
58
58
|
}
|
|
59
59
|
100% {
|
|
60
60
|
transform: scale(0, 0);
|
|
61
|
-
transform-origin: 50% 50
|
|
61
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
62
62
|
opacity: 0;
|
|
63
63
|
}
|
|
64
64
|
}
|
package/assets/index.less
CHANGED
|
@@ -41,35 +41,35 @@
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
&-arrow {
|
|
44
|
+
z-index: 1;
|
|
44
45
|
width: 0px;
|
|
45
46
|
height: 0px;
|
|
46
47
|
background: #000;
|
|
47
48
|
border-radius: 100vw;
|
|
48
49
|
box-shadow: 0 0 0 3px black;
|
|
49
|
-
z-index: 1;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
@keyframes rcTriggerZoomIn {
|
|
53
53
|
0% {
|
|
54
54
|
transform: scale(0, 0);
|
|
55
|
-
transform-origin: 50% 50
|
|
55
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
56
56
|
opacity: 0;
|
|
57
57
|
}
|
|
58
58
|
100% {
|
|
59
59
|
transform: scale(1, 1);
|
|
60
|
-
transform-origin: 50% 50
|
|
60
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
61
61
|
opacity: 1;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
@keyframes rcTriggerZoomOut {
|
|
65
65
|
0% {
|
|
66
66
|
transform: scale(1, 1);
|
|
67
|
-
transform-origin: 50% 50
|
|
67
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
68
68
|
opacity: 1;
|
|
69
69
|
}
|
|
70
70
|
100% {
|
|
71
71
|
transform: scale(0, 0);
|
|
72
|
-
transform-origin: 50% 50
|
|
72
|
+
transform-origin: var(--arrow-x, 50%) var(--arrow-y, 50%);
|
|
73
73
|
opacity: 0;
|
|
74
74
|
}
|
|
75
75
|
}
|
package/es/Popup/Arrow.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { AlignType,
|
|
2
|
+
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
|
|
3
3
|
export interface ArrowProps {
|
|
4
4
|
prefixCls: string;
|
|
5
5
|
align: AlignType;
|
|
6
|
-
arrow:
|
|
6
|
+
arrow: ArrowTypeOuter;
|
|
7
|
+
arrowPos: ArrowPos;
|
|
7
8
|
}
|
|
8
9
|
export default function Arrow(props: ArrowProps): React.JSX.Element;
|
package/es/Popup/Arrow.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import classNames from 'classnames';
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
export default function Arrow(props) {
|
|
4
4
|
var prefixCls = props.prefixCls,
|
|
5
5
|
align = props.align,
|
|
6
|
-
arrow = props.arrow
|
|
6
|
+
arrow = props.arrow,
|
|
7
|
+
arrowPos = props.arrowPos;
|
|
7
8
|
var _ref = arrow || {},
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
className = _ref.className,
|
|
10
|
+
content = _ref.content;
|
|
11
|
+
var _arrowPos$x = arrowPos.x,
|
|
12
|
+
x = _arrowPos$x === void 0 ? 0 : _arrowPos$x,
|
|
13
|
+
_arrowPos$y = arrowPos.y,
|
|
14
|
+
y = _arrowPos$y === void 0 ? 0 : _arrowPos$y;
|
|
13
15
|
var arrowRef = React.useRef();
|
|
14
16
|
|
|
15
17
|
// Skip if no align
|
|
@@ -51,5 +53,5 @@ export default function Arrow(props) {
|
|
|
51
53
|
ref: arrowRef,
|
|
52
54
|
className: classNames("".concat(prefixCls, "-arrow"), className),
|
|
53
55
|
style: alignStyle
|
|
54
|
-
});
|
|
56
|
+
}, content);
|
|
55
57
|
}
|
package/es/Popup/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CSSMotionProps } from 'rc-motion';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import type { TriggerProps } from '../';
|
|
4
|
-
import type { AlignType,
|
|
4
|
+
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
|
|
5
5
|
export interface PopupProps {
|
|
6
6
|
prefixCls: string;
|
|
7
7
|
className?: string;
|
|
@@ -14,7 +14,8 @@ export interface PopupProps {
|
|
|
14
14
|
mask?: boolean;
|
|
15
15
|
onVisibleChanged: (visible: boolean) => void;
|
|
16
16
|
align?: AlignType;
|
|
17
|
-
arrow?:
|
|
17
|
+
arrow?: ArrowTypeOuter;
|
|
18
|
+
arrowPos: ArrowPos;
|
|
18
19
|
open: boolean;
|
|
19
20
|
/** Tell Portal that should keep in screen. e.g. should wait all motion end */
|
|
20
21
|
keepDom: boolean;
|
package/es/Popup/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
22
22
|
onClick = props.onClick,
|
|
23
23
|
mask = props.mask,
|
|
24
24
|
arrow = props.arrow,
|
|
25
|
+
arrowPos = props.arrowPos,
|
|
25
26
|
align = props.align,
|
|
26
27
|
motion = props.motion,
|
|
27
28
|
maskMotion = props.maskMotion,
|
|
@@ -129,7 +130,10 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
129
130
|
return /*#__PURE__*/React.createElement("div", {
|
|
130
131
|
ref: composeRef(resizeObserverRef, ref, motionRef),
|
|
131
132
|
className: cls,
|
|
132
|
-
style: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
133
|
+
style: _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
134
|
+
'--arrow-x': "".concat(arrowPos.x || 0, "px"),
|
|
135
|
+
'--arrow-y': "".concat(arrowPos.y || 0, "px")
|
|
136
|
+
}, offsetStyle), miscStyle), motionStyle), {}, {
|
|
133
137
|
boxSizing: 'border-box',
|
|
134
138
|
zIndex: zIndex
|
|
135
139
|
}, style),
|
|
@@ -139,6 +143,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
139
143
|
}, arrow && /*#__PURE__*/React.createElement(Arrow, {
|
|
140
144
|
prefixCls: prefixCls,
|
|
141
145
|
arrow: arrow,
|
|
146
|
+
arrowPos: arrowPos,
|
|
142
147
|
align: align
|
|
143
148
|
}), /*#__PURE__*/React.createElement(PopupContent, {
|
|
144
149
|
cache: !open
|
package/es/index.js
CHANGED
|
@@ -448,10 +448,11 @@ export function generateTrigger() {
|
|
|
448
448
|
|
|
449
449
|
// Child Node
|
|
450
450
|
var triggerNode = /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread({}, mergedChildrenProps), passedProps));
|
|
451
|
-
var
|
|
451
|
+
var arrowPos = {
|
|
452
452
|
x: arrowX,
|
|
453
453
|
y: arrowY
|
|
454
|
-
}
|
|
454
|
+
};
|
|
455
|
+
var innerArrow = arrow ? _objectSpread({}, arrow !== true ? arrow : {}) : null;
|
|
455
456
|
|
|
456
457
|
// Render
|
|
457
458
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ResizeObserver, {
|
|
@@ -497,7 +498,8 @@ export function generateTrigger() {
|
|
|
497
498
|
// Arrow
|
|
498
499
|
,
|
|
499
500
|
align: alignInfo,
|
|
500
|
-
arrow: innerArrow
|
|
501
|
+
arrow: innerArrow,
|
|
502
|
+
arrowPos: arrowPos
|
|
501
503
|
// Align
|
|
502
504
|
,
|
|
503
505
|
ready: ready,
|
package/es/interface.d.ts
CHANGED
package/es/util.d.ts
CHANGED
|
@@ -10,13 +10,35 @@ export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
|
|
|
10
10
|
* @param areaOnly Only return the parent which will cut visible area
|
|
11
11
|
*/
|
|
12
12
|
export declare function collectScroller(ele: HTMLElement): HTMLElement[];
|
|
13
|
-
export declare function toNum(num: number): number;
|
|
13
|
+
export declare function toNum(num: number, defaultValue?: number): number;
|
|
14
14
|
export interface VisibleArea {
|
|
15
15
|
left: number;
|
|
16
16
|
top: number;
|
|
17
17
|
right: number;
|
|
18
18
|
bottom: number;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* **************************************
|
|
24
|
+
* * Border *
|
|
25
|
+
* * ************************** *
|
|
26
|
+
* * * * * *
|
|
27
|
+
* * B * * S * B *
|
|
28
|
+
* * o * * c * o *
|
|
29
|
+
* * r * Content * r * r *
|
|
30
|
+
* * d * * o * d *
|
|
31
|
+
* * e * * l * e *
|
|
32
|
+
* * r ******************** l * r *
|
|
33
|
+
* * * Scroll * *
|
|
34
|
+
* * ************************** *
|
|
35
|
+
* * Border *
|
|
36
|
+
* **************************************
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Get visible area of element
|
|
41
|
+
*/
|
|
20
42
|
export declare function getVisibleArea(initArea: VisibleArea, scrollerList?: HTMLElement[]): {
|
|
21
43
|
left: number;
|
|
22
44
|
top: number;
|
package/es/util.js
CHANGED
|
@@ -50,12 +50,15 @@ export function getWin(ele) {
|
|
|
50
50
|
export function collectScroller(ele) {
|
|
51
51
|
var scrollerList = [];
|
|
52
52
|
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
53
|
-
var scrollStyle = ['hidden', 'scroll', 'auto'];
|
|
53
|
+
var scrollStyle = ['hidden', 'scroll', 'clip', 'auto'];
|
|
54
54
|
while (current) {
|
|
55
55
|
var _getWin$getComputedSt = getWin(current).getComputedStyle(current),
|
|
56
56
|
overflowX = _getWin$getComputedSt.overflowX,
|
|
57
|
-
overflowY = _getWin$getComputedSt.overflowY
|
|
58
|
-
|
|
57
|
+
overflowY = _getWin$getComputedSt.overflowY,
|
|
58
|
+
overflow = _getWin$getComputedSt.overflow;
|
|
59
|
+
if ([overflowX, overflowY, overflow].some(function (o) {
|
|
60
|
+
return scrollStyle.includes(o);
|
|
61
|
+
})) {
|
|
59
62
|
scrollerList.push(current);
|
|
60
63
|
}
|
|
61
64
|
current = current.parentElement;
|
|
@@ -63,8 +66,34 @@ export function collectScroller(ele) {
|
|
|
63
66
|
return scrollerList;
|
|
64
67
|
}
|
|
65
68
|
export function toNum(num) {
|
|
66
|
-
|
|
69
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
70
|
+
return Number.isNaN(num) ? defaultValue : num;
|
|
67
71
|
}
|
|
72
|
+
function getPxValue(val) {
|
|
73
|
+
return toNum(parseFloat(val), 0);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
*
|
|
78
|
+
* **************************************
|
|
79
|
+
* * Border *
|
|
80
|
+
* * ************************** *
|
|
81
|
+
* * * * * *
|
|
82
|
+
* * B * * S * B *
|
|
83
|
+
* * o * * c * o *
|
|
84
|
+
* * r * Content * r * r *
|
|
85
|
+
* * d * * o * d *
|
|
86
|
+
* * e * * l * e *
|
|
87
|
+
* * r ******************** l * r *
|
|
88
|
+
* * * Scroll * *
|
|
89
|
+
* * ************************** *
|
|
90
|
+
* * Border *
|
|
91
|
+
* **************************************
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* Get visible area of element
|
|
96
|
+
*/
|
|
68
97
|
export function getVisibleArea(initArea, scrollerList) {
|
|
69
98
|
var visibleArea = _objectSpread({}, initArea);
|
|
70
99
|
(scrollerList || []).forEach(function (ele) {
|
|
@@ -74,23 +103,50 @@ export function getVisibleArea(initArea, scrollerList) {
|
|
|
74
103
|
|
|
75
104
|
// Skip if static position which will not affect visible area
|
|
76
105
|
var _getWin$getComputedSt2 = getWin(ele).getComputedStyle(ele),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
106
|
+
overflow = _getWin$getComputedSt2.overflow,
|
|
107
|
+
overflowClipMargin = _getWin$getComputedSt2.overflowClipMargin,
|
|
108
|
+
borderTopWidth = _getWin$getComputedSt2.borderTopWidth,
|
|
109
|
+
borderBottomWidth = _getWin$getComputedSt2.borderBottomWidth,
|
|
110
|
+
borderLeftWidth = _getWin$getComputedSt2.borderLeftWidth,
|
|
111
|
+
borderRightWidth = _getWin$getComputedSt2.borderRightWidth;
|
|
81
112
|
var eleRect = ele.getBoundingClientRect();
|
|
82
113
|
var eleOutHeight = ele.offsetHeight,
|
|
83
114
|
eleInnerHeight = ele.clientHeight,
|
|
84
115
|
eleOutWidth = ele.offsetWidth,
|
|
85
116
|
eleInnerWidth = ele.clientWidth;
|
|
117
|
+
var borderTopNum = getPxValue(borderTopWidth);
|
|
118
|
+
var borderBottomNum = getPxValue(borderBottomWidth);
|
|
119
|
+
var borderLeftNum = getPxValue(borderLeftWidth);
|
|
120
|
+
var borderRightNum = getPxValue(borderRightWidth);
|
|
86
121
|
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
87
122
|
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var
|
|
91
|
-
var
|
|
92
|
-
|
|
93
|
-
|
|
123
|
+
|
|
124
|
+
// Original visible area
|
|
125
|
+
var eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
|
|
126
|
+
var eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
|
|
127
|
+
|
|
128
|
+
// Cut border size
|
|
129
|
+
var scaledBorderTopWidth = borderTopNum * scaleY;
|
|
130
|
+
var scaledBorderBottomWidth = borderBottomNum * scaleY;
|
|
131
|
+
var scaledBorderLeftWidth = borderLeftNum * scaleX;
|
|
132
|
+
var scaledBorderRightWidth = borderRightNum * scaleX;
|
|
133
|
+
|
|
134
|
+
// Clip margin
|
|
135
|
+
var clipMarginWidth = 0;
|
|
136
|
+
var clipMarginHeight = 0;
|
|
137
|
+
if (overflow === 'clip') {
|
|
138
|
+
var clipNum = getPxValue(overflowClipMargin);
|
|
139
|
+
clipMarginWidth = clipNum * scaleX;
|
|
140
|
+
clipMarginHeight = clipNum * scaleY;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Region
|
|
144
|
+
var eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
|
|
145
|
+
var eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
|
|
146
|
+
var eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
|
|
147
|
+
var eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
|
|
148
|
+
visibleArea.left = Math.max(visibleArea.left, eleLeft);
|
|
149
|
+
visibleArea.top = Math.max(visibleArea.top, eleTop);
|
|
94
150
|
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
95
151
|
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
96
152
|
});
|
package/lib/Popup/Arrow.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { AlignType,
|
|
2
|
+
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
|
|
3
3
|
export interface ArrowProps {
|
|
4
4
|
prefixCls: string;
|
|
5
5
|
align: AlignType;
|
|
6
|
-
arrow:
|
|
6
|
+
arrow: ArrowTypeOuter;
|
|
7
|
+
arrowPos: ArrowPos;
|
|
7
8
|
}
|
|
8
9
|
export default function Arrow(props: ArrowProps): React.JSX.Element;
|
package/lib/Popup/Arrow.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = Arrow;
|
|
9
|
-
var React = _interopRequireWildcard(require("react"));
|
|
10
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
function Arrow(props) {
|
|
12
12
|
var prefixCls = props.prefixCls,
|
|
13
13
|
align = props.align,
|
|
14
|
-
arrow = props.arrow
|
|
14
|
+
arrow = props.arrow,
|
|
15
|
+
arrowPos = props.arrowPos;
|
|
15
16
|
var _ref = arrow || {},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
className = _ref.className,
|
|
18
|
+
content = _ref.content;
|
|
19
|
+
var _arrowPos$x = arrowPos.x,
|
|
20
|
+
x = _arrowPos$x === void 0 ? 0 : _arrowPos$x,
|
|
21
|
+
_arrowPos$y = arrowPos.y,
|
|
22
|
+
y = _arrowPos$y === void 0 ? 0 : _arrowPos$y;
|
|
21
23
|
var arrowRef = React.useRef();
|
|
22
24
|
|
|
23
25
|
// Skip if no align
|
|
@@ -59,5 +61,5 @@ function Arrow(props) {
|
|
|
59
61
|
ref: arrowRef,
|
|
60
62
|
className: (0, _classnames.default)("".concat(prefixCls, "-arrow"), className),
|
|
61
63
|
style: alignStyle
|
|
62
|
-
});
|
|
64
|
+
}, content);
|
|
63
65
|
}
|
package/lib/Popup/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CSSMotionProps } from 'rc-motion';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import type { TriggerProps } from '../';
|
|
4
|
-
import type { AlignType,
|
|
4
|
+
import type { AlignType, ArrowPos, ArrowTypeOuter } from '../interface';
|
|
5
5
|
export interface PopupProps {
|
|
6
6
|
prefixCls: string;
|
|
7
7
|
className?: string;
|
|
@@ -14,7 +14,8 @@ export interface PopupProps {
|
|
|
14
14
|
mask?: boolean;
|
|
15
15
|
onVisibleChanged: (visible: boolean) => void;
|
|
16
16
|
align?: AlignType;
|
|
17
|
-
arrow?:
|
|
17
|
+
arrow?: ArrowTypeOuter;
|
|
18
|
+
arrowPos: ArrowPos;
|
|
18
19
|
open: boolean;
|
|
19
20
|
/** Tell Portal that should keep in screen. e.g. should wait all motion end */
|
|
20
21
|
keepDom: boolean;
|
package/lib/Popup/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
30
30
|
onClick = props.onClick,
|
|
31
31
|
mask = props.mask,
|
|
32
32
|
arrow = props.arrow,
|
|
33
|
+
arrowPos = props.arrowPos,
|
|
33
34
|
align = props.align,
|
|
34
35
|
motion = props.motion,
|
|
35
36
|
maskMotion = props.maskMotion,
|
|
@@ -137,7 +138,10 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
137
138
|
return /*#__PURE__*/React.createElement("div", {
|
|
138
139
|
ref: (0, _ref2.composeRef)(resizeObserverRef, ref, motionRef),
|
|
139
140
|
className: cls,
|
|
140
|
-
style: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
141
|
+
style: (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
142
|
+
'--arrow-x': "".concat(arrowPos.x || 0, "px"),
|
|
143
|
+
'--arrow-y': "".concat(arrowPos.y || 0, "px")
|
|
144
|
+
}, offsetStyle), miscStyle), motionStyle), {}, {
|
|
141
145
|
boxSizing: 'border-box',
|
|
142
146
|
zIndex: zIndex
|
|
143
147
|
}, style),
|
|
@@ -147,6 +151,7 @@ var Popup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
147
151
|
}, arrow && /*#__PURE__*/React.createElement(_Arrow.default, {
|
|
148
152
|
prefixCls: prefixCls,
|
|
149
153
|
arrow: arrow,
|
|
154
|
+
arrowPos: arrowPos,
|
|
150
155
|
align: align
|
|
151
156
|
}), /*#__PURE__*/React.createElement(_PopupContent.default, {
|
|
152
157
|
cache: !open
|
package/lib/index.js
CHANGED
|
@@ -457,10 +457,11 @@ function generateTrigger() {
|
|
|
457
457
|
|
|
458
458
|
// Child Node
|
|
459
459
|
var triggerNode = /*#__PURE__*/React.cloneElement(child, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, mergedChildrenProps), passedProps));
|
|
460
|
-
var
|
|
460
|
+
var arrowPos = {
|
|
461
461
|
x: arrowX,
|
|
462
462
|
y: arrowY
|
|
463
|
-
}
|
|
463
|
+
};
|
|
464
|
+
var innerArrow = arrow ? (0, _objectSpread2.default)({}, arrow !== true ? arrow : {}) : null;
|
|
464
465
|
|
|
465
466
|
// Render
|
|
466
467
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_rcResizeObserver.default, {
|
|
@@ -506,7 +507,8 @@ function generateTrigger() {
|
|
|
506
507
|
// Arrow
|
|
507
508
|
,
|
|
508
509
|
align: alignInfo,
|
|
509
|
-
arrow: innerArrow
|
|
510
|
+
arrow: innerArrow,
|
|
511
|
+
arrowPos: arrowPos
|
|
510
512
|
// Align
|
|
511
513
|
,
|
|
512
514
|
ready: ready,
|
package/lib/interface.d.ts
CHANGED
package/lib/util.d.ts
CHANGED
|
@@ -10,13 +10,35 @@ export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
|
|
|
10
10
|
* @param areaOnly Only return the parent which will cut visible area
|
|
11
11
|
*/
|
|
12
12
|
export declare function collectScroller(ele: HTMLElement): HTMLElement[];
|
|
13
|
-
export declare function toNum(num: number): number;
|
|
13
|
+
export declare function toNum(num: number, defaultValue?: number): number;
|
|
14
14
|
export interface VisibleArea {
|
|
15
15
|
left: number;
|
|
16
16
|
top: number;
|
|
17
17
|
right: number;
|
|
18
18
|
bottom: number;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* **************************************
|
|
24
|
+
* * Border *
|
|
25
|
+
* * ************************** *
|
|
26
|
+
* * * * * *
|
|
27
|
+
* * B * * S * B *
|
|
28
|
+
* * o * * c * o *
|
|
29
|
+
* * r * Content * r * r *
|
|
30
|
+
* * d * * o * d *
|
|
31
|
+
* * e * * l * e *
|
|
32
|
+
* * r ******************** l * r *
|
|
33
|
+
* * * Scroll * *
|
|
34
|
+
* * ************************** *
|
|
35
|
+
* * Border *
|
|
36
|
+
* **************************************
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Get visible area of element
|
|
41
|
+
*/
|
|
20
42
|
export declare function getVisibleArea(initArea: VisibleArea, scrollerList?: HTMLElement[]): {
|
|
21
43
|
left: number;
|
|
22
44
|
top: number;
|
package/lib/util.js
CHANGED
|
@@ -62,12 +62,15 @@ function getWin(ele) {
|
|
|
62
62
|
function collectScroller(ele) {
|
|
63
63
|
var scrollerList = [];
|
|
64
64
|
var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
|
|
65
|
-
var scrollStyle = ['hidden', 'scroll', 'auto'];
|
|
65
|
+
var scrollStyle = ['hidden', 'scroll', 'clip', 'auto'];
|
|
66
66
|
while (current) {
|
|
67
67
|
var _getWin$getComputedSt = getWin(current).getComputedStyle(current),
|
|
68
68
|
overflowX = _getWin$getComputedSt.overflowX,
|
|
69
|
-
overflowY = _getWin$getComputedSt.overflowY
|
|
70
|
-
|
|
69
|
+
overflowY = _getWin$getComputedSt.overflowY,
|
|
70
|
+
overflow = _getWin$getComputedSt.overflow;
|
|
71
|
+
if ([overflowX, overflowY, overflow].some(function (o) {
|
|
72
|
+
return scrollStyle.includes(o);
|
|
73
|
+
})) {
|
|
71
74
|
scrollerList.push(current);
|
|
72
75
|
}
|
|
73
76
|
current = current.parentElement;
|
|
@@ -75,8 +78,34 @@ function collectScroller(ele) {
|
|
|
75
78
|
return scrollerList;
|
|
76
79
|
}
|
|
77
80
|
function toNum(num) {
|
|
78
|
-
|
|
81
|
+
var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
82
|
+
return Number.isNaN(num) ? defaultValue : num;
|
|
79
83
|
}
|
|
84
|
+
function getPxValue(val) {
|
|
85
|
+
return toNum(parseFloat(val), 0);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
*
|
|
90
|
+
* **************************************
|
|
91
|
+
* * Border *
|
|
92
|
+
* * ************************** *
|
|
93
|
+
* * * * * *
|
|
94
|
+
* * B * * S * B *
|
|
95
|
+
* * o * * c * o *
|
|
96
|
+
* * r * Content * r * r *
|
|
97
|
+
* * d * * o * d *
|
|
98
|
+
* * e * * l * e *
|
|
99
|
+
* * r ******************** l * r *
|
|
100
|
+
* * * Scroll * *
|
|
101
|
+
* * ************************** *
|
|
102
|
+
* * Border *
|
|
103
|
+
* **************************************
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
/**
|
|
107
|
+
* Get visible area of element
|
|
108
|
+
*/
|
|
80
109
|
function getVisibleArea(initArea, scrollerList) {
|
|
81
110
|
var visibleArea = (0, _objectSpread2.default)({}, initArea);
|
|
82
111
|
(scrollerList || []).forEach(function (ele) {
|
|
@@ -86,23 +115,50 @@ function getVisibleArea(initArea, scrollerList) {
|
|
|
86
115
|
|
|
87
116
|
// Skip if static position which will not affect visible area
|
|
88
117
|
var _getWin$getComputedSt2 = getWin(ele).getComputedStyle(ele),
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
overflow = _getWin$getComputedSt2.overflow,
|
|
119
|
+
overflowClipMargin = _getWin$getComputedSt2.overflowClipMargin,
|
|
120
|
+
borderTopWidth = _getWin$getComputedSt2.borderTopWidth,
|
|
121
|
+
borderBottomWidth = _getWin$getComputedSt2.borderBottomWidth,
|
|
122
|
+
borderLeftWidth = _getWin$getComputedSt2.borderLeftWidth,
|
|
123
|
+
borderRightWidth = _getWin$getComputedSt2.borderRightWidth;
|
|
93
124
|
var eleRect = ele.getBoundingClientRect();
|
|
94
125
|
var eleOutHeight = ele.offsetHeight,
|
|
95
126
|
eleInnerHeight = ele.clientHeight,
|
|
96
127
|
eleOutWidth = ele.offsetWidth,
|
|
97
128
|
eleInnerWidth = ele.clientWidth;
|
|
129
|
+
var borderTopNum = getPxValue(borderTopWidth);
|
|
130
|
+
var borderBottomNum = getPxValue(borderBottomWidth);
|
|
131
|
+
var borderLeftNum = getPxValue(borderLeftWidth);
|
|
132
|
+
var borderRightNum = getPxValue(borderRightWidth);
|
|
98
133
|
var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
|
|
99
134
|
var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
135
|
+
|
|
136
|
+
// Original visible area
|
|
137
|
+
var eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
|
|
138
|
+
var eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
|
|
139
|
+
|
|
140
|
+
// Cut border size
|
|
141
|
+
var scaledBorderTopWidth = borderTopNum * scaleY;
|
|
142
|
+
var scaledBorderBottomWidth = borderBottomNum * scaleY;
|
|
143
|
+
var scaledBorderLeftWidth = borderLeftNum * scaleX;
|
|
144
|
+
var scaledBorderRightWidth = borderRightNum * scaleX;
|
|
145
|
+
|
|
146
|
+
// Clip margin
|
|
147
|
+
var clipMarginWidth = 0;
|
|
148
|
+
var clipMarginHeight = 0;
|
|
149
|
+
if (overflow === 'clip') {
|
|
150
|
+
var clipNum = getPxValue(overflowClipMargin);
|
|
151
|
+
clipMarginWidth = clipNum * scaleX;
|
|
152
|
+
clipMarginHeight = clipNum * scaleY;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Region
|
|
156
|
+
var eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
|
|
157
|
+
var eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
|
|
158
|
+
var eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
|
|
159
|
+
var eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
|
|
160
|
+
visibleArea.left = Math.max(visibleArea.left, eleLeft);
|
|
161
|
+
visibleArea.top = Math.max(visibleArea.top, eleTop);
|
|
106
162
|
visibleArea.right = Math.min(visibleArea.right, eleRight);
|
|
107
163
|
visibleArea.bottom = Math.min(visibleArea.bottom, eleBottom);
|
|
108
164
|
});
|