@lumx/react 3.0.3 → 3.0.4-alpha.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/_internal/ClickAwayProvider.js +37 -232
- package/_internal/ClickAwayProvider.js.map +1 -1
- package/index.d.ts +10 -2
- package/index.js +4031 -4319
- package/index.js.map +1 -1
- package/package.json +28 -34
- package/src/components/alert-dialog/__snapshots__/AlertDialog.test.tsx.snap +23 -23
- package/src/components/autocomplete/Autocomplete.tsx +8 -0
- package/src/components/autocomplete/__snapshots__/Autocomplete.test.tsx.snap +4 -4
- package/src/components/autocomplete/__snapshots__/AutocompleteMultiple.test.tsx.snap +1 -1
- package/src/components/avatar/__snapshots__/Avatar.test.tsx.snap +6 -6
- package/src/components/button/__snapshots__/ButtonRoot.test.tsx.snap +1 -1
- package/src/components/button/index.ts +1 -0
- package/src/components/date-picker/__snapshots__/DatePicker.test.tsx.snap +2 -2
- package/src/components/date-picker/__snapshots__/DatePickerField.test.tsx.snap +2 -2
- package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +22 -22
- package/src/components/dropdown/Dropdown.tsx +2 -0
- package/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +2 -2
- package/src/components/flag/__snapshots__/Flag.test.tsx.snap +1 -1
- package/src/components/flex-box/__snapshots__/FlexBox.test.tsx.snap +31 -31
- package/src/components/heading/Heading.test.tsx +32 -27
- package/src/components/icon/__snapshots__/Icon.test.tsx.snap +2 -2
- package/src/components/image-block/__snapshots__/ImageBlock.test.tsx.snap +1 -1
- package/src/components/index.ts +5 -0
- package/src/components/inline-list/InlineList.tsx +3 -1
- package/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +7 -7
- package/src/components/list/__snapshots__/List.test.tsx.snap +13 -13
- package/src/components/notification/__snapshots__/Notification.test.tsx.snap +1 -1
- package/src/components/popover/__snapshots__/Popover.test.tsx.snap +52 -52
- package/src/components/post-block/__snapshots__/PostBlock.test.tsx.snap +4 -4
- package/src/components/progress-tracker/__snapshots__/ProgressTracker.test.tsx.snap +2 -2
- package/src/components/select/__snapshots__/Select.test.tsx.snap +2 -2
- package/src/components/select/__snapshots__/SelectMultiple.test.tsx.snap +6 -6
- package/src/components/skeleton/__snapshots__/SkeletonCircle.test.tsx.snap +1 -1
- package/src/components/skeleton/__snapshots__/SkeletonRectangle.test.tsx.snap +1 -1
- package/src/components/skeleton/__snapshots__/SkeletonTypography.test.tsx.snap +15 -15
- package/src/components/slider/__snapshots__/Slider.test.tsx.snap +4 -4
- package/src/components/slideshow/__snapshots__/Slideshow.test.tsx.snap +10 -10
- package/src/components/table/__snapshots__/Table.test.tsx.snap +1 -1
- package/src/components/text/Text.test.tsx +67 -35
- package/src/components/text/Text.tsx +8 -7
- package/src/components/text-field/TextField.test.tsx +75 -117
- package/src/components/text-field/__snapshots__/TextField.test.tsx.snap +12 -17
- package/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap +6 -6
- package/src/components/tooltip/__snapshots__/Tooltip.test.tsx.snap +6 -6
- package/src/components/user-block/__snapshots__/UserBlock.test.tsx.snap +11 -11
- package/src/stories/generated/Dropdown/Demos.stories.tsx +1 -0
- package/src/testing/utils/commonTestsSuiteRTL.ts +55 -0
- package/src/testing/utils/index.ts +1 -0
- package/src/testing/utils/queries.ts +19 -0
- package/src/utils/focus/getFocusableElements.test.ts +12 -12
- package/types.d.ts +0 -2847
|
@@ -1,265 +1,70 @@
|
|
|
1
|
-
import React, { useEffect,
|
|
1
|
+
import React, { useEffect, useContext, useMemo, useRef, createContext } from 'react';
|
|
2
2
|
import isEmpty from 'lodash/isEmpty';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
"@babel/helpers - typeof";
|
|
6
|
-
|
|
7
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
8
|
-
_typeof = function (obj) {
|
|
9
|
-
return typeof obj;
|
|
10
|
-
};
|
|
11
|
-
} else {
|
|
12
|
-
_typeof = function (obj) {
|
|
13
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return _typeof(obj);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function _defineProperty(obj, key, value) {
|
|
21
|
-
if (key in obj) {
|
|
22
|
-
Object.defineProperty(obj, key, {
|
|
23
|
-
value: value,
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
obj[key] = value;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return obj;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function _extends() {
|
|
36
|
-
_extends = Object.assign || function (target) {
|
|
37
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
38
|
-
var source = arguments[i];
|
|
39
|
-
|
|
40
|
-
for (var key in source) {
|
|
41
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
42
|
-
target[key] = source[key];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return target;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return _extends.apply(this, arguments);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function ownKeys(object, enumerableOnly) {
|
|
54
|
-
var keys = Object.keys(object);
|
|
55
|
-
|
|
56
|
-
if (Object.getOwnPropertySymbols) {
|
|
57
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
58
|
-
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
59
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
60
|
-
});
|
|
61
|
-
keys.push.apply(keys, symbols);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return keys;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function _objectSpread2(target) {
|
|
68
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
69
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
70
|
-
|
|
71
|
-
if (i % 2) {
|
|
72
|
-
ownKeys(Object(source), true).forEach(function (key) {
|
|
73
|
-
_defineProperty(target, key, source[key]);
|
|
74
|
-
});
|
|
75
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
76
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
77
|
-
} else {
|
|
78
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
79
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return target;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
88
|
-
if (source == null) return {};
|
|
89
|
-
var target = {};
|
|
90
|
-
var sourceKeys = Object.keys(source);
|
|
91
|
-
var key, i;
|
|
92
|
-
|
|
93
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
94
|
-
key = sourceKeys[i];
|
|
95
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
96
|
-
target[key] = source[key];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return target;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function _objectWithoutProperties(source, excluded) {
|
|
103
|
-
if (source == null) return {};
|
|
104
|
-
|
|
105
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
106
|
-
|
|
107
|
-
var key, i;
|
|
108
|
-
|
|
109
|
-
if (Object.getOwnPropertySymbols) {
|
|
110
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
111
|
-
|
|
112
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
113
|
-
key = sourceSymbolKeys[i];
|
|
114
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
115
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
116
|
-
target[key] = source[key];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return target;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function _slicedToArray(arr, i) {
|
|
124
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function _toArray(arr) {
|
|
128
|
-
return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function _toConsumableArray(arr) {
|
|
132
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function _arrayWithoutHoles(arr) {
|
|
136
|
-
if (Array.isArray(arr)) {
|
|
137
|
-
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
|
138
|
-
|
|
139
|
-
return arr2;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function _arrayWithHoles(arr) {
|
|
144
|
-
if (Array.isArray(arr)) return arr;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function _iterableToArray(iter) {
|
|
148
|
-
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function _iterableToArrayLimit(arr, i) {
|
|
152
|
-
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
var _arr = [];
|
|
157
|
-
var _n = true;
|
|
158
|
-
var _d = false;
|
|
159
|
-
var _e = undefined;
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
163
|
-
_arr.push(_s.value);
|
|
164
|
-
|
|
165
|
-
if (i && _arr.length === i) break;
|
|
166
|
-
}
|
|
167
|
-
} catch (err) {
|
|
168
|
-
_d = true;
|
|
169
|
-
_e = err;
|
|
170
|
-
} finally {
|
|
171
|
-
try {
|
|
172
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
173
|
-
} finally {
|
|
174
|
-
if (_d) throw _e;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return _arr;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function _nonIterableSpread() {
|
|
182
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance");
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function _nonIterableRest() {
|
|
186
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
var EVENT_TYPES = ['mousedown', 'touchstart'];
|
|
190
|
-
|
|
4
|
+
const EVENT_TYPES = ['mousedown', 'touchstart'];
|
|
191
5
|
function isClickAway(target, refs) {
|
|
192
6
|
// The target element is not contained in any of the listed element references.
|
|
193
|
-
return !refs.some(
|
|
7
|
+
return !refs.some(e => {
|
|
194
8
|
var _e$current;
|
|
195
|
-
|
|
196
9
|
return e === null || e === void 0 ? void 0 : (_e$current = e.current) === null || _e$current === void 0 ? void 0 : _e$current.contains(target);
|
|
197
10
|
});
|
|
198
11
|
}
|
|
199
|
-
|
|
200
12
|
/**
|
|
201
13
|
* Listen to clicks away from the given elements and callback the passed in function.
|
|
202
14
|
*
|
|
203
15
|
* Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.
|
|
204
16
|
*/
|
|
205
17
|
function useClickAway(_ref) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
18
|
+
let {
|
|
19
|
+
callback,
|
|
20
|
+
childrenRefs
|
|
21
|
+
} = _ref;
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const {
|
|
24
|
+
current: currentRefs
|
|
25
|
+
} = childrenRefs;
|
|
211
26
|
if (!callback || !currentRefs || isEmpty(currentRefs)) {
|
|
212
27
|
return undefined;
|
|
213
28
|
}
|
|
214
|
-
|
|
215
|
-
var listener = function listener(evt) {
|
|
29
|
+
const listener = evt => {
|
|
216
30
|
if (isClickAway(evt.target, currentRefs)) {
|
|
217
31
|
callback(evt);
|
|
218
32
|
}
|
|
219
33
|
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
});
|
|
224
|
-
return function () {
|
|
225
|
-
EVENT_TYPES.forEach(function (evtType) {
|
|
226
|
-
return document.removeEventListener(evtType, listener);
|
|
227
|
-
});
|
|
34
|
+
EVENT_TYPES.forEach(evtType => document.addEventListener(evtType, listener));
|
|
35
|
+
return () => {
|
|
36
|
+
EVENT_TYPES.forEach(evtType => document.removeEventListener(evtType, listener));
|
|
228
37
|
};
|
|
229
38
|
}, [callback, childrenRefs]);
|
|
230
39
|
}
|
|
231
40
|
|
|
232
|
-
|
|
233
|
-
|
|
41
|
+
const ClickAwayAncestorContext = /*#__PURE__*/createContext(null);
|
|
234
42
|
/**
|
|
235
43
|
* Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure
|
|
236
44
|
* we take into account both the DOM tree and the React tree to detect click away.
|
|
237
45
|
*
|
|
238
46
|
* @return the react component.
|
|
239
47
|
*/
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
48
|
+
const ClickAwayProvider = _ref => {
|
|
49
|
+
let {
|
|
50
|
+
children,
|
|
51
|
+
callback,
|
|
52
|
+
childrenRefs,
|
|
53
|
+
parentRef
|
|
54
|
+
} = _ref;
|
|
55
|
+
const parentContext = useContext(ClickAwayAncestorContext);
|
|
56
|
+
const currentContext = useMemo(() => {
|
|
57
|
+
const context = {
|
|
248
58
|
childrenRefs: [],
|
|
249
|
-
|
|
250
59
|
/**
|
|
251
60
|
* Add element refs to the current context and propagate to the parent context.
|
|
252
61
|
*/
|
|
253
|
-
addRefs
|
|
254
|
-
var _context$childrenRefs;
|
|
255
|
-
|
|
62
|
+
addRefs() {
|
|
256
63
|
// Add element refs that should be considered as inside the click away context.
|
|
257
|
-
|
|
258
|
-
|
|
64
|
+
context.childrenRefs.push(...arguments);
|
|
259
65
|
if (parentContext) {
|
|
260
66
|
// Also add then to the parent context
|
|
261
|
-
parentContext.addRefs
|
|
262
|
-
|
|
67
|
+
parentContext.addRefs(...arguments);
|
|
263
68
|
if (parentRef) {
|
|
264
69
|
// The parent element is also considered as inside the parent click away context but not inside the current context
|
|
265
70
|
parentContext.addRefs(parentRef);
|
|
@@ -269,24 +74,24 @@ var ClickAwayProvider = function ClickAwayProvider(_ref) {
|
|
|
269
74
|
};
|
|
270
75
|
return context;
|
|
271
76
|
}, [parentContext, parentRef]);
|
|
272
|
-
useEffect(
|
|
273
|
-
|
|
274
|
-
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const {
|
|
79
|
+
current: currentRefs
|
|
80
|
+
} = childrenRefs;
|
|
275
81
|
if (!currentRefs) {
|
|
276
82
|
return;
|
|
277
83
|
}
|
|
278
|
-
|
|
279
|
-
currentContext.addRefs.apply(currentContext, _toConsumableArray(currentRefs));
|
|
84
|
+
currentContext.addRefs(...currentRefs);
|
|
280
85
|
}, [currentContext, childrenRefs]);
|
|
281
86
|
useClickAway({
|
|
282
|
-
callback
|
|
87
|
+
callback,
|
|
283
88
|
childrenRefs: useRef(currentContext.childrenRefs)
|
|
284
89
|
});
|
|
285
|
-
return React.createElement(ClickAwayAncestorContext.Provider, {
|
|
90
|
+
return /*#__PURE__*/React.createElement(ClickAwayAncestorContext.Provider, {
|
|
286
91
|
value: currentContext
|
|
287
92
|
}, children);
|
|
288
93
|
};
|
|
289
94
|
ClickAwayProvider.displayName = 'ClickAwayProvider';
|
|
290
95
|
|
|
291
|
-
export { ClickAwayProvider as C
|
|
96
|
+
export { ClickAwayProvider as C };
|
|
292
97
|
//# sourceMappingURL=ClickAwayProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClickAwayProvider.js","sources":["../../src/hooks/useClickAway.tsx","../../src/utils/ClickAwayProvider/ClickAwayProvider.tsx"],"sourcesContent":["import { RefObject, useEffect } from 'react';\n\nimport { Falsy } from '@lumx/react/utils/type';\n\nimport isEmpty from 'lodash/isEmpty';\n\nconst EVENT_TYPES = ['mousedown', 'touchstart'];\n\nfunction isClickAway(target: HTMLElement, refs: Array<RefObject<HTMLElement>>): boolean {\n // The target element is not contained in any of the listed element references.\n return !refs.some((e) => e?.current?.contains(target));\n}\n\nexport interface ClickAwayParameters {\n /**\n * A callback function to call when the user clicks away from the elements.\n */\n callback: EventListener | Falsy;\n /**\n * Elements considered within the click away context (clicking outside them will trigger the click away callback).\n */\n childrenRefs: RefObject<Array<RefObject<HTMLElement>>>;\n}\n\n/**\n * Listen to clicks away from the given elements and callback the passed in function.\n *\n * Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.\n */\nexport function useClickAway({ callback, childrenRefs }: ClickAwayParameters): void {\n useEffect(() => {\n const { current: currentRefs } = childrenRefs;\n if (!callback || !currentRefs || isEmpty(currentRefs)) {\n return undefined;\n }\n const listener: EventListener = (evt) => {\n if (isClickAway(evt.target as HTMLElement, currentRefs)) {\n callback(evt);\n }\n };\n\n EVENT_TYPES.forEach((evtType) => document.addEventListener(evtType, listener));\n return () => {\n EVENT_TYPES.forEach((evtType) => document.removeEventListener(evtType, listener));\n };\n }, [callback, childrenRefs]);\n}\n","import React, { createContext, RefObject, useContext, useEffect, useMemo, useRef } from 'react';\nimport { ClickAwayParameters, useClickAway } from '@lumx/react/hooks/useClickAway';\n\ninterface ContextValue {\n childrenRefs: Array<RefObject<HTMLElement>>;\n addRefs(...newChildrenRefs: Array<RefObject<HTMLElement>>): void;\n}\n\nconst ClickAwayAncestorContext = createContext<ContextValue | null>(null);\n\ninterface ClickAwayProviderProps extends ClickAwayParameters {\n /**\n * (Optional) Element that should be considered as part of the parent\n */\n parentRef?: RefObject<HTMLElement>;\n}\n\n/**\n * Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure\n * we take into account both the DOM tree and the React tree to detect click away.\n *\n * @return the react component.\n */\nexport const ClickAwayProvider: React.FC<ClickAwayProviderProps> = ({\n children,\n callback,\n childrenRefs,\n parentRef,\n}) => {\n const parentContext = useContext(ClickAwayAncestorContext);\n const currentContext = useMemo(() => {\n const context: ContextValue = {\n childrenRefs: [],\n /**\n * Add element refs to the current context and propagate to the parent context.\n */\n addRefs(...newChildrenRefs) {\n // Add element refs that should be considered as inside the click away context.\n context.childrenRefs.push(...newChildrenRefs);\n\n if (parentContext) {\n // Also add then to the parent context\n parentContext.addRefs(...newChildrenRefs);\n if (parentRef) {\n // The parent element is also considered as inside the parent click away context but not inside the current context\n parentContext.addRefs(parentRef);\n }\n }\n },\n };\n return context;\n }, [parentContext, parentRef]);\n\n useEffect(() => {\n const { current: currentRefs } = childrenRefs;\n if (!currentRefs) {\n return;\n }\n currentContext.addRefs(...currentRefs);\n }, [currentContext, childrenRefs]);\n\n useClickAway({ callback, childrenRefs: useRef(currentContext.childrenRefs) });\n return <ClickAwayAncestorContext.Provider value={currentContext}>{children}</ClickAwayAncestorContext.Provider>;\n};\nClickAwayProvider.displayName = 'ClickAwayProvider';\n"],"names":["EVENT_TYPES","isClickAway","target","refs","some","e","current","contains","useClickAway","callback","childrenRefs","useEffect","currentRefs","isEmpty","undefined","listener","evt","forEach","evtType","document","addEventListener","removeEventListener","ClickAwayAncestorContext","createContext","ClickAwayProvider","children","parentRef","parentContext","useContext","currentContext","useMemo","context","addRefs","push","useRef","displayName"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClickAwayProvider.js","sources":["../../src/hooks/useClickAway.tsx","../../src/utils/ClickAwayProvider/ClickAwayProvider.tsx"],"sourcesContent":["import { RefObject, useEffect } from 'react';\n\nimport { Falsy } from '@lumx/react/utils/type';\n\nimport isEmpty from 'lodash/isEmpty';\n\nconst EVENT_TYPES = ['mousedown', 'touchstart'];\n\nfunction isClickAway(target: HTMLElement, refs: Array<RefObject<HTMLElement>>): boolean {\n // The target element is not contained in any of the listed element references.\n return !refs.some((e) => e?.current?.contains(target));\n}\n\nexport interface ClickAwayParameters {\n /**\n * A callback function to call when the user clicks away from the elements.\n */\n callback: EventListener | Falsy;\n /**\n * Elements considered within the click away context (clicking outside them will trigger the click away callback).\n */\n childrenRefs: RefObject<Array<RefObject<HTMLElement>>>;\n}\n\n/**\n * Listen to clicks away from the given elements and callback the passed in function.\n *\n * Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.\n */\nexport function useClickAway({ callback, childrenRefs }: ClickAwayParameters): void {\n useEffect(() => {\n const { current: currentRefs } = childrenRefs;\n if (!callback || !currentRefs || isEmpty(currentRefs)) {\n return undefined;\n }\n const listener: EventListener = (evt) => {\n if (isClickAway(evt.target as HTMLElement, currentRefs)) {\n callback(evt);\n }\n };\n\n EVENT_TYPES.forEach((evtType) => document.addEventListener(evtType, listener));\n return () => {\n EVENT_TYPES.forEach((evtType) => document.removeEventListener(evtType, listener));\n };\n }, [callback, childrenRefs]);\n}\n","import React, { createContext, RefObject, useContext, useEffect, useMemo, useRef } from 'react';\nimport { ClickAwayParameters, useClickAway } from '@lumx/react/hooks/useClickAway';\n\ninterface ContextValue {\n childrenRefs: Array<RefObject<HTMLElement>>;\n addRefs(...newChildrenRefs: Array<RefObject<HTMLElement>>): void;\n}\n\nconst ClickAwayAncestorContext = createContext<ContextValue | null>(null);\n\ninterface ClickAwayProviderProps extends ClickAwayParameters {\n /**\n * (Optional) Element that should be considered as part of the parent\n */\n parentRef?: RefObject<HTMLElement>;\n}\n\n/**\n * Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure\n * we take into account both the DOM tree and the React tree to detect click away.\n *\n * @return the react component.\n */\nexport const ClickAwayProvider: React.FC<ClickAwayProviderProps> = ({\n children,\n callback,\n childrenRefs,\n parentRef,\n}) => {\n const parentContext = useContext(ClickAwayAncestorContext);\n const currentContext = useMemo(() => {\n const context: ContextValue = {\n childrenRefs: [],\n /**\n * Add element refs to the current context and propagate to the parent context.\n */\n addRefs(...newChildrenRefs) {\n // Add element refs that should be considered as inside the click away context.\n context.childrenRefs.push(...newChildrenRefs);\n\n if (parentContext) {\n // Also add then to the parent context\n parentContext.addRefs(...newChildrenRefs);\n if (parentRef) {\n // The parent element is also considered as inside the parent click away context but not inside the current context\n parentContext.addRefs(parentRef);\n }\n }\n },\n };\n return context;\n }, [parentContext, parentRef]);\n\n useEffect(() => {\n const { current: currentRefs } = childrenRefs;\n if (!currentRefs) {\n return;\n }\n currentContext.addRefs(...currentRefs);\n }, [currentContext, childrenRefs]);\n\n useClickAway({ callback, childrenRefs: useRef(currentContext.childrenRefs) });\n return <ClickAwayAncestorContext.Provider value={currentContext}>{children}</ClickAwayAncestorContext.Provider>;\n};\nClickAwayProvider.displayName = 'ClickAwayProvider';\n"],"names":["EVENT_TYPES","isClickAway","target","refs","some","e","current","contains","useClickAway","callback","childrenRefs","useEffect","currentRefs","isEmpty","undefined","listener","evt","forEach","evtType","document","addEventListener","removeEventListener","ClickAwayAncestorContext","createContext","ClickAwayProvider","children","parentRef","parentContext","useContext","currentContext","useMemo","context","addRefs","push","useRef","displayName"],"mappings":";;;AAMA,MAAMA,WAAW,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC;AAE/C,SAASC,WAAW,CAACC,MAAmB,EAAEC,IAAmC,EAAW;;EAEpF,OAAO,CAACA,IAAI,CAACC,IAAI,CAAEC,CAAC;IAAA;IAAA,OAAKA,CAAC,aAADA,CAAC,qCAADA,CAAC,CAAEC,OAAO,+CAAV,WAAYC,QAAQ,CAACL,MAAM,CAAC;IAAC;AAC1D;AAaA;AACA;AACA;AACA;AACA;AACO,SAASM,YAAY,OAAwD;EAAA,IAAvD;IAAEC,QAAQ;IAAEC;GAAmC;EACxEC,SAAS,CAAC,MAAM;IACZ,MAAM;MAAEL,OAAO,EAAEM;KAAa,GAAGF,YAAY;IAC7C,IAAI,CAACD,QAAQ,IAAI,CAACG,WAAW,IAAIC,OAAO,CAACD,WAAW,CAAC,EAAE;MACnD,OAAOE,SAAS;;IAEpB,MAAMC,QAAuB,GAAIC,GAAG,IAAK;MACrC,IAAIf,WAAW,CAACe,GAAG,CAACd,MAAM,EAAiBU,WAAW,CAAC,EAAE;QACrDH,QAAQ,CAACO,GAAG,CAAC;;KAEpB;IAEDhB,WAAW,CAACiB,OAAO,CAAEC,OAAO,IAAKC,QAAQ,CAACC,gBAAgB,CAACF,OAAO,EAAEH,QAAQ,CAAC,CAAC;IAC9E,OAAO,MAAM;MACTf,WAAW,CAACiB,OAAO,CAAEC,OAAO,IAAKC,QAAQ,CAACE,mBAAmB,CAACH,OAAO,EAAEH,QAAQ,CAAC,CAAC;KACpF;GACJ,EAAE,CAACN,QAAQ,EAAEC,YAAY,CAAC,CAAC;AAChC;;ACtCA,MAAMY,wBAAwB,gBAAGC,aAAa,CAAsB,IAAI,CAAC;AASzE;AACA;AACA;AACA;AACA;AACA;MACaC,iBAAmD,GAAG,QAK7D;EAAA,IAL8D;IAChEC,QAAQ;IACRhB,QAAQ;IACRC,YAAY;IACZgB;GACH;EACG,MAAMC,aAAa,GAAGC,UAAU,CAACN,wBAAwB,CAAC;EAC1D,MAAMO,cAAc,GAAGC,OAAO,CAAC,MAAM;IACjC,MAAMC,OAAqB,GAAG;MAC1BrB,YAAY,EAAE,EAAE;;AAE5B;AACA;MACYsB,OAAO,GAAqB;;QAExBD,OAAO,CAACrB,YAAY,CAACuB,IAAI,CAAC,YAAkB,CAAC;QAE7C,IAAIN,aAAa,EAAE;;UAEfA,aAAa,CAACK,OAAO,CAAC,YAAkB,CAAC;UACzC,IAAIN,SAAS,EAAE;;YAEXC,aAAa,CAACK,OAAO,CAACN,SAAS,CAAC;;;;KAI/C;IACD,OAAOK,OAAO;GACjB,EAAE,CAACJ,aAAa,EAAED,SAAS,CAAC,CAAC;EAE9Bf,SAAS,CAAC,MAAM;IACZ,MAAM;MAAEL,OAAO,EAAEM;KAAa,GAAGF,YAAY;IAC7C,IAAI,CAACE,WAAW,EAAE;MACd;;IAEJiB,cAAc,CAACG,OAAO,CAAC,GAAGpB,WAAW,CAAC;GACzC,EAAE,CAACiB,cAAc,EAAEnB,YAAY,CAAC,CAAC;EAElCF,YAAY,CAAC;IAAEC,QAAQ;IAAEC,YAAY,EAAEwB,MAAM,CAACL,cAAc,CAACnB,YAAY;GAAG,CAAC;EAC7E,oBAAO,oBAAC,wBAAwB,CAAC,QAAQ;IAAC,KAAK,EAAEmB;KAAiBJ,QAAQ,CAAqC;AACnH;AACAD,iBAAiB,CAACW,WAAW,GAAG,mBAAmB;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode, SyntheticEvent, ReactElement, MouseEventHandler, KeyboardEventHandler, AriaAttributes, DetailedHTMLProps, ButtonHTMLAttributes, InputHTMLAttributes, Ref, RefObject, ImgHTMLAttributes, CSSProperties, SetStateAction, Key } from 'react';
|
|
2
2
|
import { K as Kind, C as Comp, G as GenericProps, H as HasTheme, a as HorizontalAlignment, S as Size, b as Color, E as Emphasis, V as ValueOf, c as Callback, d as ColorPalette, A as Alignment, e as VerticalAlignment, O as Orientation, f as ColorVariant, T as Typography, g as TextElement, h as HeadingElement, i as AspectRatio, F as Falsy, j as FocusPoint, k as ThumbnailSize, l as ThumbnailVariant, m as GlobalSize, n as TypographyInterface } from './_internal/types.js';
|
|
3
|
-
export { A as Alignment, i as AspectRatio, b as Color, d as ColorPalette, f as ColorVariant, E as Emphasis, j as FocusPoint, m as GlobalSize, a as HorizontalAlignment, K as Kind, O as Orientation, S as Size, o as Theme, r as ThumbnailAspectRatio, k as ThumbnailSize, l as ThumbnailVariant, T as Typography, q as TypographyCustom, n as TypographyInterface, p as TypographyTitleCustom, e as VerticalAlignment } from './_internal/types.js';
|
|
3
|
+
export { A as Alignment, i as AspectRatio, c as Callback, b as Color, d as ColorPalette, f as ColorVariant, E as Emphasis, j as FocusPoint, G as GenericProps, m as GlobalSize, h as HeadingElement, a as HorizontalAlignment, K as Kind, O as Orientation, S as Size, g as TextElement, o as Theme, r as ThumbnailAspectRatio, k as ThumbnailSize, l as ThumbnailVariant, T as Typography, q as TypographyCustom, n as TypographyInterface, p as TypographyTitleCustom, e as VerticalAlignment } from './_internal/types.js';
|
|
4
4
|
|
|
5
5
|
interface AlertDialogProps extends Omit<DialogProps, 'header' | 'footer'> {
|
|
6
6
|
/** Message variant. */
|
|
@@ -177,6 +177,12 @@ interface AutocompleteProps extends GenericProps, HasTheme {
|
|
|
177
177
|
* @see {@link DropdownProps#onInfiniteScroll}
|
|
178
178
|
*/
|
|
179
179
|
onInfiniteScroll?(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Props forwarded to the underlying TextField component.
|
|
182
|
+
* Only the props not managed by the Autocomplete can be set.
|
|
183
|
+
* @see {@link TextFieldProps}
|
|
184
|
+
*/
|
|
185
|
+
textFieldProps?: TextFieldProps;
|
|
180
186
|
}
|
|
181
187
|
/**
|
|
182
188
|
* Autocomplete component.
|
|
@@ -813,6 +819,8 @@ interface DropdownProps extends GenericProps {
|
|
|
813
819
|
placement?: Placement;
|
|
814
820
|
/** Whether the focus should be set on the list when the dropdown is open or not. */
|
|
815
821
|
shouldFocusOnOpen?: boolean;
|
|
822
|
+
/** Whether the dropdown should be rendered into a DOM node that exists outside the DOM hierarchy of the parent component. */
|
|
823
|
+
usePortal?: boolean;
|
|
816
824
|
/** Whether the focus should go back on the anchor when dropdown closes and focus is within. */
|
|
817
825
|
focusAnchorOnClose?: boolean;
|
|
818
826
|
/**
|
|
@@ -2683,4 +2691,4 @@ interface UserBlockProps extends GenericProps, HasTheme {
|
|
|
2683
2691
|
*/
|
|
2684
2692
|
declare const UserBlock: Comp<UserBlockProps, HTMLDivElement>;
|
|
2685
2693
|
|
|
2686
|
-
export { AlertDialog, AlertDialogProps, Autocomplete, AutocompleteMultiple, AutocompleteMultipleProps, AutocompleteProps, Avatar, AvatarProps, AvatarSize, Badge, BadgeProps, Button, ButtonEmphasis, ButtonGroup, ButtonGroupProps, ButtonProps, Checkbox, CheckboxProps, Chip, ChipGroup, ChipGroupProps, ChipProps, CommentBlock, CommentBlockProps, CommentBlockVariant, DatePicker, DatePickerControlled, DatePickerControlledProps, DatePickerField, DatePickerFieldProps, DatePickerProps, Dialog, DialogProps, DialogSizes, Divider, DividerProps, DragHandle, DragHandleProps, Dropdown, DropdownProps, Elevation, ExpansionPanel, ExpansionPanelProps, Flag, FlagProps, FlexBox, FlexBoxProps, FlexHorizontalAlignment, FlexVerticalAlignment, GapSize, GenericBlock, GenericBlockGapSize, GenericBlockProps, Grid, GridItem, GridItemProps, GridProps, Heading, HeadingLevelProvider, HeadingLevelProviderProps, HeadingProps, Icon, IconButton, IconButtonProps, IconProps, IconSizes, ImageBlock, ImageBlockCaptionPosition, ImageBlockProps, ImageBlockSize, InlineList, InlineListProps, InputHelper, InputHelperProps, InputLabel, InputLabelProps, Lightbox, LightboxProps, Link, LinkPreview, LinkPreviewProps, LinkProps, List, ListDivider, ListDividerProps, ListItem, ListItemProps, ListItemSize, ListProps, ListSubheader, ListSubheaderProps, MarginAutoAlignment, Message, MessageProps, Mosaic, MosaicProps, Notification, NotificationProps, Offset, Placement, Popover, PopoverProps, PostBlock, PostBlockProps, Progress, ProgressProps, ProgressTracker, ProgressTrackerProps, ProgressTrackerProvider, ProgressTrackerProviderProps, ProgressTrackerStep, ProgressTrackerStepPanel, ProgressTrackerStepPanelProps, ProgressTrackerStepProps, ProgressVariant, RadioButton, RadioButtonProps, RadioGroup, RadioGroupProps, Select, SelectMultiple, SelectMultipleField, SelectMultipleProps, SelectProps, SelectVariant, SideNavigation, SideNavigationItem, SideNavigationItemProps, SideNavigationProps, SkeletonCircle, SkeletonCircleProps, SkeletonRectangle, SkeletonRectangleProps, SkeletonRectangleVariant, SkeletonTypography, SkeletonTypographyProps, Slider, SliderProps, Slides, SlidesProps, Slideshow, SlideshowControls, SlideshowControlsProps, SlideshowItem, SlideshowItemProps, SlideshowProps, Switch, SwitchProps, Tab, TabList, TabListLayout, TabListProps, TabPanel, TabPanelProps, TabProps, TabProvider, TabProviderProps, Table, TableBody, TableBodyProps, TableCell, TableCellProps, TableCellVariant, TableHeader, TableHeaderProps, TableProps, TableRow, TableRowProps, Text, TextField, TextFieldProps, TextProps, ThOrder, Thumbnail, ThumbnailProps, Toolbar, ToolbarProps, Tooltip, TooltipPlacement, TooltipProps, Uploader, UploaderProps, UploaderSize, UploaderVariant, UserBlock, UserBlockProps, UserBlockSize, clamp, isClickable, useFocusPointStyle, useHeadingLevel };
|
|
2694
|
+
export { AlertDialog, AlertDialogProps, Autocomplete, AutocompleteMultiple, AutocompleteMultipleProps, AutocompleteProps, Avatar, AvatarProps, AvatarSize, Badge, BadgeProps, BaseButtonProps, Button, ButtonEmphasis, ButtonGroup, ButtonGroupProps, ButtonProps, ButtonSize, Checkbox, CheckboxProps, Chip, ChipGroup, ChipGroupProps, ChipProps, CommentBlock, CommentBlockProps, CommentBlockVariant, DatePicker, DatePickerControlled, DatePickerControlledProps, DatePickerField, DatePickerFieldProps, DatePickerProps, Dialog, DialogProps, DialogSizes, Divider, DividerProps, DragHandle, DragHandleProps, Dropdown, DropdownProps, Elevation, ExpansionPanel, ExpansionPanelProps, Flag, FlagProps, FlexBox, FlexBoxProps, FlexHorizontalAlignment, FlexVerticalAlignment, GapSize, GenericBlock, GenericBlockGapSize, GenericBlockProps, Grid, GridItem, GridItemProps, GridProps, Heading, HeadingLevelProvider, HeadingLevelProviderProps, HeadingProps, Icon, IconButton, IconButtonProps, IconProps, IconSizes, ImageBlock, ImageBlockCaptionPosition, ImageBlockProps, ImageBlockSize, InlineList, InlineListProps, InputHelper, InputHelperProps, InputLabel, InputLabelProps, Lightbox, LightboxProps, Link, LinkPreview, LinkPreviewProps, LinkProps, List, ListDivider, ListDividerProps, ListItem, ListItemProps, ListItemSize, ListProps, ListSubheader, ListSubheaderProps, MarginAutoAlignment, Message, MessageProps, Mosaic, MosaicProps, Notification, NotificationProps, Offset, Placement, Popover, PopoverProps, PostBlock, PostBlockProps, Progress, ProgressProps, ProgressTracker, ProgressTrackerProps, ProgressTrackerProvider, ProgressTrackerProviderProps, ProgressTrackerStep, ProgressTrackerStepPanel, ProgressTrackerStepPanelProps, ProgressTrackerStepProps, ProgressVariant, RadioButton, RadioButtonProps, RadioGroup, RadioGroupProps, Select, SelectMultiple, SelectMultipleField, SelectMultipleProps, SelectProps, SelectVariant, SideNavigation, SideNavigationItem, SideNavigationItemProps, SideNavigationProps, SkeletonCircle, SkeletonCircleProps, SkeletonRectangle, SkeletonRectangleProps, SkeletonRectangleVariant, SkeletonTypography, SkeletonTypographyProps, Slider, SliderProps, Slides, SlidesProps, Slideshow, SlideshowControls, SlideshowControlsProps, SlideshowItem, SlideshowItemProps, SlideshowProps, Switch, SwitchProps, Tab, TabList, TabListLayout, TabListProps, TabPanel, TabPanelProps, TabProps, TabProvider, TabProviderProps, Table, TableBody, TableBodyProps, TableCell, TableCellProps, TableCellVariant, TableHeader, TableHeaderProps, TableProps, TableRow, TableRowProps, Text, TextField, TextFieldProps, TextProps, ThOrder, Thumbnail, ThumbnailProps, Toolbar, ToolbarProps, Tooltip, TooltipPlacement, TooltipProps, Uploader, UploaderProps, UploaderSize, UploaderVariant, UserBlock, UserBlockProps, UserBlockSize, clamp, isClickable, useFocusPointStyle, useHeadingLevel };
|