@rc-component/trigger 3.6.1 → 3.6.3
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/es/UniqueProvider/index.js +21 -2
- package/es/context.d.ts +2 -1
- package/es/index.js +6 -4
- package/lib/UniqueProvider/index.js +21 -2
- package/lib/context.d.ts +2 -1
- package/lib/index.js +6 -4
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ import { isDOM } from "@rc-component/util/es/Dom/findDOMNode";
|
|
|
10
10
|
import FloatBg from "./FloatBg";
|
|
11
11
|
import classNames from 'classnames';
|
|
12
12
|
import MotionContent from "./MotionContent";
|
|
13
|
+
import { getAlignPopupClassName } from "../util";
|
|
13
14
|
const UniqueProvider = ({
|
|
14
15
|
children
|
|
15
16
|
}) => {
|
|
@@ -30,8 +31,13 @@ const UniqueProvider = ({
|
|
|
30
31
|
|
|
31
32
|
// ========================== Register ==========================
|
|
32
33
|
const [popupId, setPopupId] = React.useState(0);
|
|
34
|
+
|
|
35
|
+
// Store the isOpen function from the latest show call
|
|
36
|
+
const isOpenRef = React.useRef(null);
|
|
33
37
|
const delayInvoke = useDelay();
|
|
34
|
-
const show = useEvent(showOptions => {
|
|
38
|
+
const show = useEvent((showOptions, isOpen) => {
|
|
39
|
+
// Store the isOpen function for later use in hide
|
|
40
|
+
isOpenRef.current = isOpen;
|
|
35
41
|
delayInvoke(() => {
|
|
36
42
|
if (showOptions.id !== options?.id) {
|
|
37
43
|
setPopupId(i => i + 1);
|
|
@@ -41,6 +47,11 @@ const UniqueProvider = ({
|
|
|
41
47
|
});
|
|
42
48
|
const hide = delay => {
|
|
43
49
|
delayInvoke(() => {
|
|
50
|
+
// Check if we should still hide by calling the isOpen function
|
|
51
|
+
// If isOpen returns true, it means another trigger wants to keep it open
|
|
52
|
+
if (isOpenRef.current?.()) {
|
|
53
|
+
return; // Don't hide if something else wants it open
|
|
54
|
+
}
|
|
44
55
|
trigger(false);
|
|
45
56
|
// Don't clear target, currentNode, options immediately, wait until animation completes
|
|
46
57
|
}, delay);
|
|
@@ -62,6 +73,14 @@ const UniqueProvider = ({
|
|
|
62
73
|
// onPopupAlign
|
|
63
74
|
false // isMobile
|
|
64
75
|
);
|
|
76
|
+
const alignedClassName = React.useMemo(() => {
|
|
77
|
+
if (!options) {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
const baseClassName = getAlignPopupClassName(options.builtinPlacements || {}, options.prefixCls || '', alignInfo, false // alignPoint is false for UniqueProvider
|
|
81
|
+
);
|
|
82
|
+
return classNames(baseClassName, options.getPopupClassNameFromAlign?.(alignInfo));
|
|
83
|
+
}, [alignInfo, options?.getPopupClassNameFromAlign, options?.builtinPlacements, options?.prefixCls]);
|
|
65
84
|
const contextValue = React.useMemo(() => ({
|
|
66
85
|
show,
|
|
67
86
|
hide
|
|
@@ -97,7 +116,7 @@ const UniqueProvider = ({
|
|
|
97
116
|
prefixCls: prefixCls,
|
|
98
117
|
key: popupId
|
|
99
118
|
}, options.popup),
|
|
100
|
-
className: classNames(options.popupClassName, `${prefixCls}-unique-controlled`),
|
|
119
|
+
className: classNames(options.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
|
101
120
|
style: options.popupStyle,
|
|
102
121
|
target: options.target,
|
|
103
122
|
open: open,
|
package/es/context.d.ts
CHANGED
|
@@ -25,9 +25,10 @@ export interface UniqueShowOptions {
|
|
|
25
25
|
maskMotion?: CSSMotionProps;
|
|
26
26
|
arrow?: ArrowTypeOuter;
|
|
27
27
|
getPopupContainer?: TriggerProps['getPopupContainer'];
|
|
28
|
+
getPopupClassNameFromAlign?: (align: AlignType) => string;
|
|
28
29
|
}
|
|
29
30
|
export interface UniqueContextProps {
|
|
30
|
-
show: (options: UniqueShowOptions) => void;
|
|
31
|
+
show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
|
|
31
32
|
hide: (delay: number) => void;
|
|
32
33
|
}
|
|
33
34
|
export declare const UniqueContext: React.Context<UniqueContextProps>;
|
package/es/index.js
CHANGED
|
@@ -150,6 +150,9 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
150
150
|
setInternalOpen(nextOpen);
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
|
+
|
|
154
|
+
// Support ref
|
|
155
|
+
const isOpen = useEvent(() => mergedOpen);
|
|
153
156
|
useLayoutEffect(() => {
|
|
154
157
|
setInternalOpen(popupVisible || false);
|
|
155
158
|
}, [popupVisible]);
|
|
@@ -172,6 +175,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
172
175
|
maskMotion,
|
|
173
176
|
arrow: innerArrow,
|
|
174
177
|
getPopupContainer,
|
|
178
|
+
getPopupClassNameFromAlign,
|
|
175
179
|
id
|
|
176
180
|
}));
|
|
177
181
|
|
|
@@ -181,9 +185,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
181
185
|
useLayoutEffect(() => {
|
|
182
186
|
if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
|
|
183
187
|
if (mergedOpen) {
|
|
184
|
-
|
|
185
|
-
uniqueContext.show(getUniqueOptions(0));
|
|
186
|
-
});
|
|
188
|
+
uniqueContext.show(getUniqueOptions(0), isOpen);
|
|
187
189
|
} else {
|
|
188
190
|
uniqueContext.hide(0);
|
|
189
191
|
}
|
|
@@ -222,7 +224,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
222
224
|
// If there is a parentContext, don't call uniqueContext methods
|
|
223
225
|
if (uniqueContext && unique && openUncontrolled && !parentContext) {
|
|
224
226
|
if (nextOpen) {
|
|
225
|
-
uniqueContext.show(getUniqueOptions(delay));
|
|
227
|
+
uniqueContext.show(getUniqueOptions(delay), isOpen);
|
|
226
228
|
} else {
|
|
227
229
|
uniqueContext.hide(delay);
|
|
228
230
|
}
|
|
@@ -16,6 +16,7 @@ var _findDOMNode = require("@rc-component/util/lib/Dom/findDOMNode");
|
|
|
16
16
|
var _FloatBg = _interopRequireDefault(require("./FloatBg"));
|
|
17
17
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
18
18
|
var _MotionContent = _interopRequireDefault(require("./MotionContent"));
|
|
19
|
+
var _util2 = require("../util");
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
22
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -39,8 +40,13 @@ const UniqueProvider = ({
|
|
|
39
40
|
|
|
40
41
|
// ========================== Register ==========================
|
|
41
42
|
const [popupId, setPopupId] = React.useState(0);
|
|
43
|
+
|
|
44
|
+
// Store the isOpen function from the latest show call
|
|
45
|
+
const isOpenRef = React.useRef(null);
|
|
42
46
|
const delayInvoke = (0, _useDelay.default)();
|
|
43
|
-
const show = (0, _util.useEvent)(showOptions => {
|
|
47
|
+
const show = (0, _util.useEvent)((showOptions, isOpen) => {
|
|
48
|
+
// Store the isOpen function for later use in hide
|
|
49
|
+
isOpenRef.current = isOpen;
|
|
44
50
|
delayInvoke(() => {
|
|
45
51
|
if (showOptions.id !== options?.id) {
|
|
46
52
|
setPopupId(i => i + 1);
|
|
@@ -50,6 +56,11 @@ const UniqueProvider = ({
|
|
|
50
56
|
});
|
|
51
57
|
const hide = delay => {
|
|
52
58
|
delayInvoke(() => {
|
|
59
|
+
// Check if we should still hide by calling the isOpen function
|
|
60
|
+
// If isOpen returns true, it means another trigger wants to keep it open
|
|
61
|
+
if (isOpenRef.current?.()) {
|
|
62
|
+
return; // Don't hide if something else wants it open
|
|
63
|
+
}
|
|
53
64
|
trigger(false);
|
|
54
65
|
// Don't clear target, currentNode, options immediately, wait until animation completes
|
|
55
66
|
}, delay);
|
|
@@ -71,6 +82,14 @@ const UniqueProvider = ({
|
|
|
71
82
|
// onPopupAlign
|
|
72
83
|
false // isMobile
|
|
73
84
|
);
|
|
85
|
+
const alignedClassName = React.useMemo(() => {
|
|
86
|
+
if (!options) {
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
89
|
+
const baseClassName = (0, _util2.getAlignPopupClassName)(options.builtinPlacements || {}, options.prefixCls || '', alignInfo, false // alignPoint is false for UniqueProvider
|
|
90
|
+
);
|
|
91
|
+
return (0, _classnames.default)(baseClassName, options.getPopupClassNameFromAlign?.(alignInfo));
|
|
92
|
+
}, [alignInfo, options?.getPopupClassNameFromAlign, options?.builtinPlacements, options?.prefixCls]);
|
|
74
93
|
const contextValue = React.useMemo(() => ({
|
|
75
94
|
show,
|
|
76
95
|
hide
|
|
@@ -106,7 +125,7 @@ const UniqueProvider = ({
|
|
|
106
125
|
prefixCls: prefixCls,
|
|
107
126
|
key: popupId
|
|
108
127
|
}, options.popup),
|
|
109
|
-
className: (0, _classnames.default)(options.popupClassName, `${prefixCls}-unique-controlled`),
|
|
128
|
+
className: (0, _classnames.default)(options.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
|
110
129
|
style: options.popupStyle,
|
|
111
130
|
target: options.target,
|
|
112
131
|
open: open,
|
package/lib/context.d.ts
CHANGED
|
@@ -25,9 +25,10 @@ export interface UniqueShowOptions {
|
|
|
25
25
|
maskMotion?: CSSMotionProps;
|
|
26
26
|
arrow?: ArrowTypeOuter;
|
|
27
27
|
getPopupContainer?: TriggerProps['getPopupContainer'];
|
|
28
|
+
getPopupClassNameFromAlign?: (align: AlignType) => string;
|
|
28
29
|
}
|
|
29
30
|
export interface UniqueContextProps {
|
|
30
|
-
show: (options: UniqueShowOptions) => void;
|
|
31
|
+
show: (options: UniqueShowOptions, isOpen: () => boolean) => void;
|
|
31
32
|
hide: (delay: number) => void;
|
|
32
33
|
}
|
|
33
34
|
export declare const UniqueContext: React.Context<UniqueContextProps>;
|
package/lib/index.js
CHANGED
|
@@ -165,6 +165,9 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
165
165
|
setInternalOpen(nextOpen);
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
|
+
|
|
169
|
+
// Support ref
|
|
170
|
+
const isOpen = (0, _useEvent.default)(() => mergedOpen);
|
|
168
171
|
(0, _useLayoutEffect.default)(() => {
|
|
169
172
|
setInternalOpen(popupVisible || false);
|
|
170
173
|
}, [popupVisible]);
|
|
@@ -187,6 +190,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
187
190
|
maskMotion,
|
|
188
191
|
arrow: innerArrow,
|
|
189
192
|
getPopupContainer,
|
|
193
|
+
getPopupClassNameFromAlign,
|
|
190
194
|
id
|
|
191
195
|
}));
|
|
192
196
|
|
|
@@ -196,9 +200,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
196
200
|
(0, _useLayoutEffect.default)(() => {
|
|
197
201
|
if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
|
|
198
202
|
if (mergedOpen) {
|
|
199
|
-
|
|
200
|
-
uniqueContext.show(getUniqueOptions(0));
|
|
201
|
-
});
|
|
203
|
+
uniqueContext.show(getUniqueOptions(0), isOpen);
|
|
202
204
|
} else {
|
|
203
205
|
uniqueContext.hide(0);
|
|
204
206
|
}
|
|
@@ -237,7 +239,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
237
239
|
// If there is a parentContext, don't call uniqueContext methods
|
|
238
240
|
if (uniqueContext && unique && openUncontrolled && !parentContext) {
|
|
239
241
|
if (nextOpen) {
|
|
240
|
-
uniqueContext.show(getUniqueOptions(delay));
|
|
242
|
+
uniqueContext.show(getUniqueOptions(delay), isOpen);
|
|
241
243
|
} else {
|
|
242
244
|
uniqueContext.hide(delay);
|
|
243
245
|
}
|