@rc-component/trigger 3.6.0 → 3.6.2
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 +12 -3
- package/es/context.d.ts +1 -0
- package/es/index.js +6 -3
- package/lib/UniqueProvider/index.js +12 -3
- package/lib/context.d.ts +1 -0
- package/lib/index.js +6 -3
- 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
|
}) => {
|
|
@@ -62,6 +63,14 @@ const UniqueProvider = ({
|
|
|
62
63
|
// onPopupAlign
|
|
63
64
|
false // isMobile
|
|
64
65
|
);
|
|
66
|
+
const alignedClassName = React.useMemo(() => {
|
|
67
|
+
if (!options) {
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
const baseClassName = getAlignPopupClassName(options.builtinPlacements || {}, options.prefixCls || '', alignInfo, false // alignPoint is false for UniqueProvider
|
|
71
|
+
);
|
|
72
|
+
return classNames(baseClassName, options.getPopupClassNameFromAlign?.(alignInfo));
|
|
73
|
+
}, [alignInfo, options?.getPopupClassNameFromAlign, options?.builtinPlacements, options?.prefixCls]);
|
|
65
74
|
const contextValue = React.useMemo(() => ({
|
|
66
75
|
show,
|
|
67
76
|
hide
|
|
@@ -97,7 +106,7 @@ const UniqueProvider = ({
|
|
|
97
106
|
prefixCls: prefixCls,
|
|
98
107
|
key: popupId
|
|
99
108
|
}, options.popup),
|
|
100
|
-
className: classNames(options.popupClassName, `${prefixCls}-unique-controlled`),
|
|
109
|
+
className: classNames(options.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
|
101
110
|
style: options.popupStyle,
|
|
102
111
|
target: options.target,
|
|
103
112
|
open: open,
|
|
@@ -125,8 +134,8 @@ const UniqueProvider = ({
|
|
|
125
134
|
mask: options.mask,
|
|
126
135
|
arrow: options.arrow,
|
|
127
136
|
motion: options.popupMotion,
|
|
128
|
-
maskMotion: options.maskMotion
|
|
129
|
-
getPopupContainer
|
|
137
|
+
maskMotion: options.maskMotion
|
|
138
|
+
// getPopupContainer={options.getPopupContainer}
|
|
130
139
|
}, /*#__PURE__*/React.createElement(FloatBg, {
|
|
131
140
|
prefixCls: prefixCls,
|
|
132
141
|
isMobile: false,
|
package/es/context.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ 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
31
|
show: (options: UniqueShowOptions) => void;
|
package/es/index.js
CHANGED
|
@@ -172,13 +172,15 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
172
172
|
maskMotion,
|
|
173
173
|
arrow: innerArrow,
|
|
174
174
|
getPopupContainer,
|
|
175
|
+
getPopupClassNameFromAlign,
|
|
175
176
|
id
|
|
176
177
|
}));
|
|
177
178
|
|
|
178
179
|
// Handle controlled state changes for UniqueProvider
|
|
179
180
|
// Only sync to UniqueProvider when it's controlled mode
|
|
181
|
+
// If there is a parentContext, don't call uniqueContext methods
|
|
180
182
|
useLayoutEffect(() => {
|
|
181
|
-
if (uniqueContext && unique && targetEle && !openUncontrolled) {
|
|
183
|
+
if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
|
|
182
184
|
if (mergedOpen) {
|
|
183
185
|
Promise.resolve().then(() => {
|
|
184
186
|
uniqueContext.show(getUniqueOptions(0));
|
|
@@ -187,7 +189,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
187
189
|
uniqueContext.hide(0);
|
|
188
190
|
}
|
|
189
191
|
}
|
|
190
|
-
}, [mergedOpen]);
|
|
192
|
+
}, [mergedOpen, targetEle]);
|
|
191
193
|
const openRef = React.useRef(mergedOpen);
|
|
192
194
|
openRef.current = mergedOpen;
|
|
193
195
|
const lastTriggerRef = React.useRef([]);
|
|
@@ -218,7 +220,8 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
// If UniqueContext exists and not controlled, pass delay to Provider instead of handling it internally
|
|
221
|
-
|
|
223
|
+
// If there is a parentContext, don't call uniqueContext methods
|
|
224
|
+
if (uniqueContext && unique && openUncontrolled && !parentContext) {
|
|
222
225
|
if (nextOpen) {
|
|
223
226
|
uniqueContext.show(getUniqueOptions(delay));
|
|
224
227
|
} else {
|
|
@@ -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; }
|
|
@@ -71,6 +72,14 @@ const UniqueProvider = ({
|
|
|
71
72
|
// onPopupAlign
|
|
72
73
|
false // isMobile
|
|
73
74
|
);
|
|
75
|
+
const alignedClassName = React.useMemo(() => {
|
|
76
|
+
if (!options) {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
const baseClassName = (0, _util2.getAlignPopupClassName)(options.builtinPlacements || {}, options.prefixCls || '', alignInfo, false // alignPoint is false for UniqueProvider
|
|
80
|
+
);
|
|
81
|
+
return (0, _classnames.default)(baseClassName, options.getPopupClassNameFromAlign?.(alignInfo));
|
|
82
|
+
}, [alignInfo, options?.getPopupClassNameFromAlign, options?.builtinPlacements, options?.prefixCls]);
|
|
74
83
|
const contextValue = React.useMemo(() => ({
|
|
75
84
|
show,
|
|
76
85
|
hide
|
|
@@ -106,7 +115,7 @@ const UniqueProvider = ({
|
|
|
106
115
|
prefixCls: prefixCls,
|
|
107
116
|
key: popupId
|
|
108
117
|
}, options.popup),
|
|
109
|
-
className: (0, _classnames.default)(options.popupClassName, `${prefixCls}-unique-controlled`),
|
|
118
|
+
className: (0, _classnames.default)(options.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`),
|
|
110
119
|
style: options.popupStyle,
|
|
111
120
|
target: options.target,
|
|
112
121
|
open: open,
|
|
@@ -134,8 +143,8 @@ const UniqueProvider = ({
|
|
|
134
143
|
mask: options.mask,
|
|
135
144
|
arrow: options.arrow,
|
|
136
145
|
motion: options.popupMotion,
|
|
137
|
-
maskMotion: options.maskMotion
|
|
138
|
-
getPopupContainer
|
|
146
|
+
maskMotion: options.maskMotion
|
|
147
|
+
// getPopupContainer={options.getPopupContainer}
|
|
139
148
|
}, /*#__PURE__*/React.createElement(_FloatBg.default, {
|
|
140
149
|
prefixCls: prefixCls,
|
|
141
150
|
isMobile: false,
|
package/lib/context.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ 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
31
|
show: (options: UniqueShowOptions) => void;
|
package/lib/index.js
CHANGED
|
@@ -187,13 +187,15 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
187
187
|
maskMotion,
|
|
188
188
|
arrow: innerArrow,
|
|
189
189
|
getPopupContainer,
|
|
190
|
+
getPopupClassNameFromAlign,
|
|
190
191
|
id
|
|
191
192
|
}));
|
|
192
193
|
|
|
193
194
|
// Handle controlled state changes for UniqueProvider
|
|
194
195
|
// Only sync to UniqueProvider when it's controlled mode
|
|
196
|
+
// If there is a parentContext, don't call uniqueContext methods
|
|
195
197
|
(0, _useLayoutEffect.default)(() => {
|
|
196
|
-
if (uniqueContext && unique && targetEle && !openUncontrolled) {
|
|
198
|
+
if (uniqueContext && unique && targetEle && !openUncontrolled && !parentContext) {
|
|
197
199
|
if (mergedOpen) {
|
|
198
200
|
Promise.resolve().then(() => {
|
|
199
201
|
uniqueContext.show(getUniqueOptions(0));
|
|
@@ -202,7 +204,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
202
204
|
uniqueContext.hide(0);
|
|
203
205
|
}
|
|
204
206
|
}
|
|
205
|
-
}, [mergedOpen]);
|
|
207
|
+
}, [mergedOpen, targetEle]);
|
|
206
208
|
const openRef = React.useRef(mergedOpen);
|
|
207
209
|
openRef.current = mergedOpen;
|
|
208
210
|
const lastTriggerRef = React.useRef([]);
|
|
@@ -233,7 +235,8 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
233
235
|
}
|
|
234
236
|
|
|
235
237
|
// If UniqueContext exists and not controlled, pass delay to Provider instead of handling it internally
|
|
236
|
-
|
|
238
|
+
// If there is a parentContext, don't call uniqueContext methods
|
|
239
|
+
if (uniqueContext && unique && openUncontrolled && !parentContext) {
|
|
237
240
|
if (nextOpen) {
|
|
238
241
|
uniqueContext.show(getUniqueOptions(delay));
|
|
239
242
|
} else {
|