@rc-component/trigger 1.5.9 → 1.6.0
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/hooks/useAction.d.ts +1 -1
- package/es/hooks/useAction.js +19 -4
- package/es/index.js +41 -31
- package/lib/hooks/useAction.d.ts +1 -1
- package/lib/hooks/useAction.js +20 -4
- package/lib/index.js +41 -31
- package/package.json +1 -1
package/es/hooks/useAction.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ActionType } from '../interface';
|
|
2
2
|
declare type ActionTypes = ActionType | ActionType[];
|
|
3
|
-
export default function useAction(action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
|
|
3
|
+
export default function useAction(mobile: boolean, action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
|
|
4
4
|
export {};
|
package/es/hooks/useAction.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
function toArray(val) {
|
|
2
3
|
return val ? Array.isArray(val) ? val : [val] : [];
|
|
3
4
|
}
|
|
4
|
-
export default function useAction(action, showAction, hideAction) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export default function useAction(mobile, action, showAction, hideAction) {
|
|
6
|
+
return React.useMemo(function () {
|
|
7
|
+
var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
|
|
8
|
+
var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
|
|
9
|
+
var showActionSet = new Set(mergedShowAction);
|
|
10
|
+
var hideActionSet = new Set(mergedHideAction);
|
|
11
|
+
if (mobile) {
|
|
12
|
+
if (showActionSet.has('hover')) {
|
|
13
|
+
showActionSet.delete('hover');
|
|
14
|
+
showActionSet.add('click');
|
|
15
|
+
}
|
|
16
|
+
if (hideActionSet.has('hover')) {
|
|
17
|
+
hideActionSet.delete('hover');
|
|
18
|
+
hideActionSet.add('click');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return [showActionSet, hideActionSet];
|
|
22
|
+
}, [mobile, action, showAction, hideAction]);
|
|
8
23
|
}
|
package/es/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { isDOM } from "rc-util/es/Dom/findDOMNode";
|
|
|
9
9
|
import useEvent from "rc-util/es/hooks/useEvent";
|
|
10
10
|
import useId from "rc-util/es/hooks/useId";
|
|
11
11
|
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
|
12
|
+
import isMobile from "rc-util/es/isMobile";
|
|
12
13
|
import * as React from 'react';
|
|
13
14
|
import TriggerContext from "./context";
|
|
14
15
|
import useAction from "./hooks/useAction";
|
|
@@ -68,6 +69,15 @@ export function generateTrigger() {
|
|
|
68
69
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
69
70
|
var mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
|
|
70
71
|
|
|
72
|
+
// =========================== Mobile ===========================
|
|
73
|
+
var _React$useState = React.useState(false),
|
|
74
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
75
|
+
mobile = _React$useState2[0],
|
|
76
|
+
setMobile = _React$useState2[1];
|
|
77
|
+
useLayoutEffect(function () {
|
|
78
|
+
setMobile(isMobile());
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
71
81
|
// ========================== Context ===========================
|
|
72
82
|
var subPopupElements = React.useRef({});
|
|
73
83
|
var parentContext = React.useContext(TriggerContext);
|
|
@@ -82,10 +92,10 @@ export function generateTrigger() {
|
|
|
82
92
|
|
|
83
93
|
// =========================== Popup ============================
|
|
84
94
|
var id = useId();
|
|
85
|
-
var _React$
|
|
86
|
-
_React$
|
|
87
|
-
popupEle = _React$
|
|
88
|
-
setPopupEle = _React$
|
|
95
|
+
var _React$useState3 = React.useState(null),
|
|
96
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
97
|
+
popupEle = _React$useState4[0],
|
|
98
|
+
setPopupEle = _React$useState4[1];
|
|
89
99
|
var setPopupRef = useEvent(function (node) {
|
|
90
100
|
if (isDOM(node) && popupEle !== node) {
|
|
91
101
|
setPopupEle(node);
|
|
@@ -95,10 +105,10 @@ export function generateTrigger() {
|
|
|
95
105
|
|
|
96
106
|
// =========================== Target ===========================
|
|
97
107
|
// Use state to control here since `useRef` update not trigger render
|
|
98
|
-
var _React$
|
|
99
|
-
_React$
|
|
100
|
-
targetEle = _React$
|
|
101
|
-
setTargetEle = _React$
|
|
108
|
+
var _React$useState5 = React.useState(null),
|
|
109
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
110
|
+
targetEle = _React$useState6[0],
|
|
111
|
+
setTargetEle = _React$useState6[1];
|
|
102
112
|
var setTargetRef = useEvent(function (node) {
|
|
103
113
|
if (isDOM(node) && targetEle !== node) {
|
|
104
114
|
setTargetEle(node);
|
|
@@ -121,10 +131,10 @@ export function generateTrigger() {
|
|
|
121
131
|
var mergeMaskMotion = getMotion(prefixCls, maskMotion, maskAnimation, maskTransitionName);
|
|
122
132
|
|
|
123
133
|
// ============================ Open ============================
|
|
124
|
-
var _React$
|
|
125
|
-
_React$
|
|
126
|
-
internalOpen = _React$
|
|
127
|
-
setInternalOpen = _React$
|
|
134
|
+
var _React$useState7 = React.useState(defaultPopupVisible || false),
|
|
135
|
+
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
136
|
+
internalOpen = _React$useState8[0],
|
|
137
|
+
setInternalOpen = _React$useState8[1];
|
|
128
138
|
|
|
129
139
|
// Render still use props as first priority
|
|
130
140
|
var mergedOpen = popupVisible !== null && popupVisible !== void 0 ? popupVisible : internalOpen;
|
|
@@ -168,10 +178,10 @@ export function generateTrigger() {
|
|
|
168
178
|
}, []);
|
|
169
179
|
|
|
170
180
|
// ========================== Motion ============================
|
|
171
|
-
var _React$
|
|
172
|
-
_React$
|
|
173
|
-
inMotion = _React$
|
|
174
|
-
setInMotion = _React$
|
|
181
|
+
var _React$useState9 = React.useState(false),
|
|
182
|
+
_React$useState10 = _slicedToArray(_React$useState9, 2),
|
|
183
|
+
inMotion = _React$useState10[0],
|
|
184
|
+
setInMotion = _React$useState10[1];
|
|
175
185
|
var mountRef = React.useRef(true);
|
|
176
186
|
useLayoutEffect(function () {
|
|
177
187
|
if (!mountRef.current || mergedOpen) {
|
|
@@ -179,16 +189,16 @@ export function generateTrigger() {
|
|
|
179
189
|
}
|
|
180
190
|
mountRef.current = true;
|
|
181
191
|
}, [mergedOpen]);
|
|
182
|
-
var _React$
|
|
183
|
-
_React$
|
|
184
|
-
motionPrepareResolve = _React$
|
|
185
|
-
setMotionPrepareResolve = _React$
|
|
192
|
+
var _React$useState11 = React.useState(null),
|
|
193
|
+
_React$useState12 = _slicedToArray(_React$useState11, 2),
|
|
194
|
+
motionPrepareResolve = _React$useState12[0],
|
|
195
|
+
setMotionPrepareResolve = _React$useState12[1];
|
|
186
196
|
|
|
187
197
|
// =========================== Align ============================
|
|
188
|
-
var _React$
|
|
189
|
-
_React$
|
|
190
|
-
mousePos = _React$
|
|
191
|
-
setMousePos = _React$
|
|
198
|
+
var _React$useState13 = React.useState([0, 0]),
|
|
199
|
+
_React$useState14 = _slicedToArray(_React$useState13, 2),
|
|
200
|
+
mousePos = _React$useState14[0],
|
|
201
|
+
setMousePos = _React$useState14[1];
|
|
192
202
|
var setMousePosByEvent = function setMousePosByEvent(event) {
|
|
193
203
|
setMousePos([event.clientX, event.clientY]);
|
|
194
204
|
};
|
|
@@ -253,14 +263,14 @@ export function generateTrigger() {
|
|
|
253
263
|
}, [motionPrepareResolve]);
|
|
254
264
|
|
|
255
265
|
// ========================== Stretch ===========================
|
|
256
|
-
var _React$useState13 = React.useState(0),
|
|
257
|
-
_React$useState14 = _slicedToArray(_React$useState13, 2),
|
|
258
|
-
targetWidth = _React$useState14[0],
|
|
259
|
-
setTargetWidth = _React$useState14[1];
|
|
260
266
|
var _React$useState15 = React.useState(0),
|
|
261
267
|
_React$useState16 = _slicedToArray(_React$useState15, 2),
|
|
262
|
-
|
|
263
|
-
|
|
268
|
+
targetWidth = _React$useState16[0],
|
|
269
|
+
setTargetWidth = _React$useState16[1];
|
|
270
|
+
var _React$useState17 = React.useState(0),
|
|
271
|
+
_React$useState18 = _slicedToArray(_React$useState17, 2),
|
|
272
|
+
targetHeight = _React$useState18[0],
|
|
273
|
+
setTargetHeight = _React$useState18[1];
|
|
264
274
|
var onTargetResize = function onTargetResize(_, ele) {
|
|
265
275
|
triggerAlign();
|
|
266
276
|
if (stretch) {
|
|
@@ -271,7 +281,7 @@ export function generateTrigger() {
|
|
|
271
281
|
};
|
|
272
282
|
|
|
273
283
|
// =========================== Action ===========================
|
|
274
|
-
var _useAction = useAction(action, showAction, hideAction),
|
|
284
|
+
var _useAction = useAction(mobile, action, showAction, hideAction),
|
|
275
285
|
_useAction2 = _slicedToArray(_useAction, 2),
|
|
276
286
|
showActions = _useAction2[0],
|
|
277
287
|
hideActions = _useAction2[1];
|
package/lib/hooks/useAction.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ActionType } from '../interface';
|
|
2
2
|
declare type ActionTypes = ActionType | ActionType[];
|
|
3
|
-
export default function useAction(action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
|
|
3
|
+
export default function useAction(mobile: boolean, action: ActionTypes, showAction?: ActionTypes, hideAction?: ActionTypes): [showAction: Set<ActionType>, hideAction: Set<ActionType>];
|
|
4
4
|
export {};
|
package/lib/hooks/useAction.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.default = useAction;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
7
9
|
function toArray(val) {
|
|
8
10
|
return val ? Array.isArray(val) ? val : [val] : [];
|
|
9
11
|
}
|
|
10
|
-
function useAction(action, showAction, hideAction) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
function useAction(mobile, action, showAction, hideAction) {
|
|
13
|
+
return React.useMemo(function () {
|
|
14
|
+
var mergedShowAction = toArray(showAction !== null && showAction !== void 0 ? showAction : action);
|
|
15
|
+
var mergedHideAction = toArray(hideAction !== null && hideAction !== void 0 ? hideAction : action);
|
|
16
|
+
var showActionSet = new Set(mergedShowAction);
|
|
17
|
+
var hideActionSet = new Set(mergedHideAction);
|
|
18
|
+
if (mobile) {
|
|
19
|
+
if (showActionSet.has('hover')) {
|
|
20
|
+
showActionSet.delete('hover');
|
|
21
|
+
showActionSet.add('click');
|
|
22
|
+
}
|
|
23
|
+
if (hideActionSet.has('hover')) {
|
|
24
|
+
hideActionSet.delete('hover');
|
|
25
|
+
hideActionSet.add('click');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [showActionSet, hideActionSet];
|
|
29
|
+
}, [mobile, action, showAction, hideAction]);
|
|
14
30
|
}
|
package/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var _findDOMNode = require("rc-util/lib/Dom/findDOMNode");
|
|
|
17
17
|
var _useEvent = _interopRequireDefault(require("rc-util/lib/hooks/useEvent"));
|
|
18
18
|
var _useId = _interopRequireDefault(require("rc-util/lib/hooks/useId"));
|
|
19
19
|
var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
|
|
20
|
+
var _isMobile = _interopRequireDefault(require("rc-util/lib/isMobile"));
|
|
20
21
|
var React = _interopRequireWildcard(require("react"));
|
|
21
22
|
var _context = _interopRequireDefault(require("./context"));
|
|
22
23
|
var _useAction3 = _interopRequireDefault(require("./hooks/useAction"));
|
|
@@ -77,6 +78,15 @@ function generateTrigger() {
|
|
|
77
78
|
restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
78
79
|
var mergedAutoDestroy = autoDestroy || destroyPopupOnHide || false;
|
|
79
80
|
|
|
81
|
+
// =========================== Mobile ===========================
|
|
82
|
+
var _React$useState = React.useState(false),
|
|
83
|
+
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
84
|
+
mobile = _React$useState2[0],
|
|
85
|
+
setMobile = _React$useState2[1];
|
|
86
|
+
(0, _useLayoutEffect.default)(function () {
|
|
87
|
+
setMobile((0, _isMobile.default)());
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
80
90
|
// ========================== Context ===========================
|
|
81
91
|
var subPopupElements = React.useRef({});
|
|
82
92
|
var parentContext = React.useContext(_context.default);
|
|
@@ -91,10 +101,10 @@ function generateTrigger() {
|
|
|
91
101
|
|
|
92
102
|
// =========================== Popup ============================
|
|
93
103
|
var id = (0, _useId.default)();
|
|
94
|
-
var _React$
|
|
95
|
-
_React$
|
|
96
|
-
popupEle = _React$
|
|
97
|
-
setPopupEle = _React$
|
|
104
|
+
var _React$useState3 = React.useState(null),
|
|
105
|
+
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
|
|
106
|
+
popupEle = _React$useState4[0],
|
|
107
|
+
setPopupEle = _React$useState4[1];
|
|
98
108
|
var setPopupRef = (0, _useEvent.default)(function (node) {
|
|
99
109
|
if ((0, _findDOMNode.isDOM)(node) && popupEle !== node) {
|
|
100
110
|
setPopupEle(node);
|
|
@@ -104,10 +114,10 @@ function generateTrigger() {
|
|
|
104
114
|
|
|
105
115
|
// =========================== Target ===========================
|
|
106
116
|
// Use state to control here since `useRef` update not trigger render
|
|
107
|
-
var _React$
|
|
108
|
-
_React$
|
|
109
|
-
targetEle = _React$
|
|
110
|
-
setTargetEle = _React$
|
|
117
|
+
var _React$useState5 = React.useState(null),
|
|
118
|
+
_React$useState6 = (0, _slicedToArray2.default)(_React$useState5, 2),
|
|
119
|
+
targetEle = _React$useState6[0],
|
|
120
|
+
setTargetEle = _React$useState6[1];
|
|
111
121
|
var setTargetRef = (0, _useEvent.default)(function (node) {
|
|
112
122
|
if ((0, _findDOMNode.isDOM)(node) && targetEle !== node) {
|
|
113
123
|
setTargetEle(node);
|
|
@@ -130,10 +140,10 @@ function generateTrigger() {
|
|
|
130
140
|
var mergeMaskMotion = (0, _util.getMotion)(prefixCls, maskMotion, maskAnimation, maskTransitionName);
|
|
131
141
|
|
|
132
142
|
// ============================ Open ============================
|
|
133
|
-
var _React$
|
|
134
|
-
_React$
|
|
135
|
-
internalOpen = _React$
|
|
136
|
-
setInternalOpen = _React$
|
|
143
|
+
var _React$useState7 = React.useState(defaultPopupVisible || false),
|
|
144
|
+
_React$useState8 = (0, _slicedToArray2.default)(_React$useState7, 2),
|
|
145
|
+
internalOpen = _React$useState8[0],
|
|
146
|
+
setInternalOpen = _React$useState8[1];
|
|
137
147
|
|
|
138
148
|
// Render still use props as first priority
|
|
139
149
|
var mergedOpen = popupVisible !== null && popupVisible !== void 0 ? popupVisible : internalOpen;
|
|
@@ -177,10 +187,10 @@ function generateTrigger() {
|
|
|
177
187
|
}, []);
|
|
178
188
|
|
|
179
189
|
// ========================== Motion ============================
|
|
180
|
-
var _React$
|
|
181
|
-
_React$
|
|
182
|
-
inMotion = _React$
|
|
183
|
-
setInMotion = _React$
|
|
190
|
+
var _React$useState9 = React.useState(false),
|
|
191
|
+
_React$useState10 = (0, _slicedToArray2.default)(_React$useState9, 2),
|
|
192
|
+
inMotion = _React$useState10[0],
|
|
193
|
+
setInMotion = _React$useState10[1];
|
|
184
194
|
var mountRef = React.useRef(true);
|
|
185
195
|
(0, _useLayoutEffect.default)(function () {
|
|
186
196
|
if (!mountRef.current || mergedOpen) {
|
|
@@ -188,16 +198,16 @@ function generateTrigger() {
|
|
|
188
198
|
}
|
|
189
199
|
mountRef.current = true;
|
|
190
200
|
}, [mergedOpen]);
|
|
191
|
-
var _React$
|
|
192
|
-
_React$
|
|
193
|
-
motionPrepareResolve = _React$
|
|
194
|
-
setMotionPrepareResolve = _React$
|
|
201
|
+
var _React$useState11 = React.useState(null),
|
|
202
|
+
_React$useState12 = (0, _slicedToArray2.default)(_React$useState11, 2),
|
|
203
|
+
motionPrepareResolve = _React$useState12[0],
|
|
204
|
+
setMotionPrepareResolve = _React$useState12[1];
|
|
195
205
|
|
|
196
206
|
// =========================== Align ============================
|
|
197
|
-
var _React$
|
|
198
|
-
_React$
|
|
199
|
-
mousePos = _React$
|
|
200
|
-
setMousePos = _React$
|
|
207
|
+
var _React$useState13 = React.useState([0, 0]),
|
|
208
|
+
_React$useState14 = (0, _slicedToArray2.default)(_React$useState13, 2),
|
|
209
|
+
mousePos = _React$useState14[0],
|
|
210
|
+
setMousePos = _React$useState14[1];
|
|
201
211
|
var setMousePosByEvent = function setMousePosByEvent(event) {
|
|
202
212
|
setMousePos([event.clientX, event.clientY]);
|
|
203
213
|
};
|
|
@@ -262,14 +272,14 @@ function generateTrigger() {
|
|
|
262
272
|
}, [motionPrepareResolve]);
|
|
263
273
|
|
|
264
274
|
// ========================== Stretch ===========================
|
|
265
|
-
var _React$useState13 = React.useState(0),
|
|
266
|
-
_React$useState14 = (0, _slicedToArray2.default)(_React$useState13, 2),
|
|
267
|
-
targetWidth = _React$useState14[0],
|
|
268
|
-
setTargetWidth = _React$useState14[1];
|
|
269
275
|
var _React$useState15 = React.useState(0),
|
|
270
276
|
_React$useState16 = (0, _slicedToArray2.default)(_React$useState15, 2),
|
|
271
|
-
|
|
272
|
-
|
|
277
|
+
targetWidth = _React$useState16[0],
|
|
278
|
+
setTargetWidth = _React$useState16[1];
|
|
279
|
+
var _React$useState17 = React.useState(0),
|
|
280
|
+
_React$useState18 = (0, _slicedToArray2.default)(_React$useState17, 2),
|
|
281
|
+
targetHeight = _React$useState18[0],
|
|
282
|
+
setTargetHeight = _React$useState18[1];
|
|
273
283
|
var onTargetResize = function onTargetResize(_, ele) {
|
|
274
284
|
triggerAlign();
|
|
275
285
|
if (stretch) {
|
|
@@ -280,7 +290,7 @@ function generateTrigger() {
|
|
|
280
290
|
};
|
|
281
291
|
|
|
282
292
|
// =========================== Action ===========================
|
|
283
|
-
var _useAction = (0, _useAction3.default)(action, showAction, hideAction),
|
|
293
|
+
var _useAction = (0, _useAction3.default)(mobile, action, showAction, hideAction),
|
|
284
294
|
_useAction2 = (0, _slicedToArray2.default)(_useAction, 2),
|
|
285
295
|
showActions = _useAction2[0],
|
|
286
296
|
hideActions = _useAction2[1];
|