@rc-component/trigger 3.6.16 → 3.7.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/es/index.d.ts +3 -1
- package/es/index.js +12 -18
- package/lib/index.d.ts +3 -1
- package/lib/index.js +12 -18
- package/package.json +1 -1
package/es/index.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export interface TriggerRef {
|
|
|
12
12
|
forceAlign: VoidFunction;
|
|
13
13
|
}
|
|
14
14
|
export interface TriggerProps {
|
|
15
|
-
children: React.ReactElement<any
|
|
15
|
+
children: React.ReactElement<any> | ((info: {
|
|
16
|
+
open: boolean;
|
|
17
|
+
}) => React.ReactElement<any>);
|
|
16
18
|
action?: ActionType | ActionType[];
|
|
17
19
|
showAction?: ActionType[];
|
|
18
20
|
hideAction?: ActionType[];
|
package/es/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import useWatch from "./hooks/useWatch";
|
|
|
16
16
|
import useWinClick from "./hooks/useWinClick";
|
|
17
17
|
import { getAlignPopupClassName } from "./util";
|
|
18
18
|
import UniqueProvider from "./UniqueProvider";
|
|
19
|
+
import { useControlledState } from '@rc-component/util';
|
|
19
20
|
export { UniqueProvider };
|
|
20
21
|
|
|
21
22
|
// Removed Props List
|
|
@@ -125,10 +126,6 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
125
126
|
externalForwardRef.current = node;
|
|
126
127
|
}
|
|
127
128
|
});
|
|
128
|
-
|
|
129
|
-
// ========================== Children ==========================
|
|
130
|
-
const child = React.Children.only(children);
|
|
131
|
-
const originChildProps = child?.props || {};
|
|
132
129
|
const cloneProps = {};
|
|
133
130
|
const inPopupOrChild = useEvent(ele => {
|
|
134
131
|
const childDOM = targetEle;
|
|
@@ -142,23 +139,20 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
142
139
|
} : null;
|
|
143
140
|
|
|
144
141
|
// ============================ Open ============================
|
|
145
|
-
const [internalOpen, setInternalOpen] =
|
|
142
|
+
const [internalOpen, setInternalOpen] = useControlledState(defaultPopupVisible || false, popupVisible);
|
|
143
|
+
const mergedOpen = internalOpen || false;
|
|
146
144
|
|
|
147
|
-
//
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
145
|
+
// ========================== Children ==========================
|
|
146
|
+
const child = React.useMemo(() => {
|
|
147
|
+
const nextChild = typeof children === 'function' ? children({
|
|
148
|
+
open: mergedOpen
|
|
149
|
+
}) : children;
|
|
150
|
+
return React.Children.only(nextChild);
|
|
151
|
+
}, [children, mergedOpen]);
|
|
152
|
+
const originChildProps = child?.props || {};
|
|
156
153
|
|
|
157
154
|
// Support ref
|
|
158
155
|
const isOpen = useEvent(() => mergedOpen);
|
|
159
|
-
useLayoutEffect(() => {
|
|
160
|
-
setInternalOpen(popupVisible || false);
|
|
161
|
-
}, [popupVisible]);
|
|
162
156
|
|
|
163
157
|
// Extract common options for UniqueProvider
|
|
164
158
|
const getUniqueOptions = useEvent((delay = 0) => ({
|
|
@@ -201,7 +195,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
201
195
|
const lastTriggerRef = React.useRef([]);
|
|
202
196
|
lastTriggerRef.current = [];
|
|
203
197
|
const internalTriggerOpen = useEvent(nextOpen => {
|
|
204
|
-
|
|
198
|
+
setInternalOpen(nextOpen);
|
|
205
199
|
|
|
206
200
|
// Enter or Pointer will both trigger open state change
|
|
207
201
|
// We only need take one to avoid duplicated change event trigger
|
package/lib/index.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export interface TriggerRef {
|
|
|
12
12
|
forceAlign: VoidFunction;
|
|
13
13
|
}
|
|
14
14
|
export interface TriggerProps {
|
|
15
|
-
children: React.ReactElement<any
|
|
15
|
+
children: React.ReactElement<any> | ((info: {
|
|
16
|
+
open: boolean;
|
|
17
|
+
}) => React.ReactElement<any>);
|
|
16
18
|
action?: ActionType | ActionType[];
|
|
17
19
|
showAction?: ActionType[];
|
|
18
20
|
hideAction?: ActionType[];
|
package/lib/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var _useWatch = _interopRequireDefault(require("./hooks/useWatch"));
|
|
|
29
29
|
var _useWinClick = _interopRequireDefault(require("./hooks/useWinClick"));
|
|
30
30
|
var _util = require("./util");
|
|
31
31
|
var _UniqueProvider = _interopRequireDefault(require("./UniqueProvider"));
|
|
32
|
+
var _util2 = require("@rc-component/util");
|
|
32
33
|
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); }
|
|
33
34
|
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; }
|
|
34
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -139,10 +140,6 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
139
140
|
externalForwardRef.current = node;
|
|
140
141
|
}
|
|
141
142
|
});
|
|
142
|
-
|
|
143
|
-
// ========================== Children ==========================
|
|
144
|
-
const child = React.Children.only(children);
|
|
145
|
-
const originChildProps = child?.props || {};
|
|
146
143
|
const cloneProps = {};
|
|
147
144
|
const inPopupOrChild = (0, _useEvent.default)(ele => {
|
|
148
145
|
const childDOM = targetEle;
|
|
@@ -156,23 +153,20 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
156
153
|
} : null;
|
|
157
154
|
|
|
158
155
|
// ============================ Open ============================
|
|
159
|
-
const [internalOpen, setInternalOpen] =
|
|
156
|
+
const [internalOpen, setInternalOpen] = (0, _util2.useControlledState)(defaultPopupVisible || false, popupVisible);
|
|
157
|
+
const mergedOpen = internalOpen || false;
|
|
160
158
|
|
|
161
|
-
//
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
159
|
+
// ========================== Children ==========================
|
|
160
|
+
const child = React.useMemo(() => {
|
|
161
|
+
const nextChild = typeof children === 'function' ? children({
|
|
162
|
+
open: mergedOpen
|
|
163
|
+
}) : children;
|
|
164
|
+
return React.Children.only(nextChild);
|
|
165
|
+
}, [children, mergedOpen]);
|
|
166
|
+
const originChildProps = child?.props || {};
|
|
170
167
|
|
|
171
168
|
// Support ref
|
|
172
169
|
const isOpen = (0, _useEvent.default)(() => mergedOpen);
|
|
173
|
-
(0, _useLayoutEffect.default)(() => {
|
|
174
|
-
setInternalOpen(popupVisible || false);
|
|
175
|
-
}, [popupVisible]);
|
|
176
170
|
|
|
177
171
|
// Extract common options for UniqueProvider
|
|
178
172
|
const getUniqueOptions = (0, _useEvent.default)((delay = 0) => ({
|
|
@@ -215,7 +209,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
215
209
|
const lastTriggerRef = React.useRef([]);
|
|
216
210
|
lastTriggerRef.current = [];
|
|
217
211
|
const internalTriggerOpen = (0, _useEvent.default)(nextOpen => {
|
|
218
|
-
|
|
212
|
+
setInternalOpen(nextOpen);
|
|
219
213
|
|
|
220
214
|
// Enter or Pointer will both trigger open state change
|
|
221
215
|
// We only need take one to avoid duplicated change event trigger
|