@lumx/react 3.20.1-alpha.27 → 3.20.1-alpha.29
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/index.js +14033 -63
- package/index.js.map +1 -1
- package/package.json +7 -13
- package/utils/index.js +158 -3
- package/utils/index.js.map +1 -1
- package/_internal/Button-2b55a913.js +0 -97
- package/_internal/Button-2b55a913.js.map +0 -1
- package/_internal/ButtonRoot-823f3e9c.js +0 -117
- package/_internal/ButtonRoot-823f3e9c.js.map +0 -1
- package/_internal/Chip-e1e85810.js +0 -143
- package/_internal/Chip-e1e85810.js.map +0 -1
- package/_internal/ClickAwayProvider-1204f237.js +0 -95
- package/_internal/ClickAwayProvider-1204f237.js.map +0 -1
- package/_internal/DisabledStateContext-ea04260d.js +0 -29
- package/_internal/DisabledStateContext-ea04260d.js.map +0 -1
- package/_internal/HeadingLevelProvider-ebdcb0c7.js +0 -61
- package/_internal/HeadingLevelProvider-ebdcb0c7.js.map +0 -1
- package/_internal/IconButton-be160cb0.js +0 -77
- package/_internal/IconButton-be160cb0.js.map +0 -1
- package/_internal/ImageCaption-fcf5720c.js +0 -75
- package/_internal/ImageCaption-fcf5720c.js.map +0 -1
- package/_internal/List-dbf4297f.js +0 -791
- package/_internal/List-dbf4297f.js.map +0 -1
- package/_internal/PopoverDialog-193a0918.js +0 -655
- package/_internal/PopoverDialog-193a0918.js.map +0 -1
- package/_internal/Portal-3f86608e.js +0 -45
- package/_internal/Portal-3f86608e.js.map +0 -1
- package/_internal/RawClickable-2c2b6a89.js +0 -52
- package/_internal/RawClickable-2c2b6a89.js.map +0 -1
- package/_internal/Slides-2d267d8c.js +0 -679
- package/_internal/Slides-2d267d8c.js.map +0 -1
- package/_internal/ThemeContext-3181f000.js +0 -14
- package/_internal/ThemeContext-3181f000.js.map +0 -1
- package/_internal/Thumbnail-0872250e.js +0 -314
- package/_internal/Thumbnail-0872250e.js.map +0 -1
- package/_internal/check-circle-de24f857.js +0 -4
- package/_internal/check-circle-de24f857.js.map +0 -1
- package/_internal/chevron-right-827b804a.js +0 -6
- package/_internal/chevron-right-827b804a.js.map +0 -1
- package/_internal/chevron-up-0b9c76cb.js +0 -6
- package/_internal/chevron-up-0b9c76cb.js.map +0 -1
- package/_internal/close-circle-ef5d1aac.js +0 -4
- package/_internal/close-circle-ef5d1aac.js.map +0 -1
- package/_internal/close-eaf6c45a.js +0 -4
- package/_internal/close-eaf6c45a.js.map +0 -1
- package/_internal/components/alert-dialog-a6ed922b.js +0 -163
- package/_internal/components/alert-dialog-a6ed922b.js.map +0 -1
- package/_internal/components/autocomplete-c97b7698.js +0 -261
- package/_internal/components/autocomplete-c97b7698.js.map +0 -1
- package/_internal/components/avatar-d2214a61.js +0 -83
- package/_internal/components/avatar-d2214a61.js.map +0 -1
- package/_internal/components/badge-8390e590.js +0 -81
- package/_internal/components/badge-8390e590.js.map +0 -1
- package/_internal/components/button-b05f8f0c.js +0 -47
- package/_internal/components/button-b05f8f0c.js.map +0 -1
- package/_internal/components/checkbox-346834f8.js +0 -143
- package/_internal/components/checkbox-346834f8.js.map +0 -1
- package/_internal/components/chip-e3a6330f.js +0 -102
- package/_internal/components/chip-e3a6330f.js.map +0 -1
- package/_internal/components/comment-block-b1acc69f.js +0 -138
- package/_internal/components/comment-block-b1acc69f.js.map +0 -1
- package/_internal/components/date-picker-582c4925.js +0 -2
- package/_internal/components/date-picker-582c4925.js.map +0 -1
- package/_internal/components/dialog-785646aa.js +0 -238
- package/_internal/components/dialog-785646aa.js.map +0 -1
- package/_internal/components/divider-116af6b9.js +0 -50
- package/_internal/components/divider-116af6b9.js.map +0 -1
- package/_internal/components/drag-handle-6b073866.js +0 -52
- package/_internal/components/drag-handle-6b073866.js.map +0 -1
- package/_internal/components/dropdown-c0c0cfe8.js +0 -147
- package/_internal/components/dropdown-c0c0cfe8.js.map +0 -1
- package/_internal/components/expansion-panel-1de1d1ff.js +0 -167
- package/_internal/components/expansion-panel-1de1d1ff.js.map +0 -1
- package/_internal/components/flag-7c9d3abf.js +0 -59
- package/_internal/components/flag-7c9d3abf.js.map +0 -1
- package/_internal/components/flex-box-10423fa5.js +0 -56
- package/_internal/components/flex-box-10423fa5.js.map +0 -1
- package/_internal/components/generic-block-b79f163a.js +0 -128
- package/_internal/components/generic-block-b79f163a.js.map +0 -1
- package/_internal/components/grid-6f1b5a41.js +0 -104
- package/_internal/components/grid-6f1b5a41.js.map +0 -1
- package/_internal/components/grid-column-ee504283.js +0 -58
- package/_internal/components/grid-column-ee504283.js.map +0 -1
- package/_internal/components/heading-d4c66a34.js +0 -53
- package/_internal/components/heading-d4c66a34.js.map +0 -1
- package/_internal/components/icon-7c79ab42.js +0 -2
- package/_internal/components/icon-7c79ab42.js.map +0 -1
- package/_internal/components/image-block-762eb669.js +0 -110
- package/_internal/components/image-block-762eb669.js.map +0 -1
- package/_internal/components/image-lightbox-10fef304.js +0 -759
- package/_internal/components/image-lightbox-10fef304.js.map +0 -1
- package/_internal/components/inline-list-e6f19a98.js +0 -74
- package/_internal/components/inline-list-e6f19a98.js.map +0 -1
- package/_internal/components/input-helper-64153099.js +0 -71
- package/_internal/components/input-helper-64153099.js.map +0 -1
- package/_internal/components/input-label-2feb0bb0.js +0 -59
- package/_internal/components/input-label-2feb0bb0.js.map +0 -1
- package/_internal/components/lightbox-dcc9a7a0.js +0 -155
- package/_internal/components/lightbox-dcc9a7a0.js.map +0 -1
- package/_internal/components/link-f9421eab.js +0 -72
- package/_internal/components/link-f9421eab.js.map +0 -1
- package/_internal/components/link-preview-5c7e3878.js +0 -117
- package/_internal/components/link-preview-5c7e3878.js.map +0 -1
- package/_internal/components/list-f29e54b7.js +0 -71
- package/_internal/components/list-f29e54b7.js.map +0 -1
- package/_internal/components/message-aa3e3f76.js +0 -98
- package/_internal/components/message-aa3e3f76.js.map +0 -1
- package/_internal/components/mosaic-b4b35fa7.js +0 -94
- package/_internal/components/mosaic-b4b35fa7.js.map +0 -1
- package/_internal/components/navigation-8357dbe6.js +0 -225
- package/_internal/components/navigation-8357dbe6.js.map +0 -1
- package/_internal/components/notification-ec4cf95f.js +0 -143
- package/_internal/components/notification-ec4cf95f.js.map +0 -1
- package/_internal/components/popover-a674dd8d.js +0 -3
- package/_internal/components/popover-a674dd8d.js.map +0 -1
- package/_internal/components/post-block-bb3d3cbf.js +0 -109
- package/_internal/components/post-block-bb3d3cbf.js.map +0 -1
- package/_internal/components/progress-f39c3fa2.js +0 -182
- package/_internal/components/progress-f39c3fa2.js.map +0 -1
- package/_internal/components/progress-tracker-997931ac.js +0 -309
- package/_internal/components/progress-tracker-997931ac.js.map +0 -1
- package/_internal/components/radio-button-559a4863.js +0 -149
- package/_internal/components/radio-button-559a4863.js.map +0 -1
- package/_internal/components/select-8295a416.js +0 -457
- package/_internal/components/select-8295a416.js.map +0 -1
- package/_internal/components/side-navigation-40ee8bda.js +0 -164
- package/_internal/components/side-navigation-40ee8bda.js.map +0 -1
- package/_internal/components/skeleton-c66516ee.js +0 -166
- package/_internal/components/skeleton-c66516ee.js.map +0 -1
- package/_internal/components/slider-efbfbc45.js +0 -311
- package/_internal/components/slider-efbfbc45.js.map +0 -1
- package/_internal/components/slideshow-c5faf531.js +0 -151
- package/_internal/components/slideshow-c5faf531.js.map +0 -1
- package/_internal/components/switch-a26a5a72.js +0 -121
- package/_internal/components/switch-a26a5a72.js.map +0 -1
- package/_internal/components/table-c43ec4a5.js +0 -297
- package/_internal/components/table-c43ec4a5.js.map +0 -1
- package/_internal/components/tabs-4037fe57.js +0 -298
- package/_internal/components/tabs-4037fe57.js.map +0 -1
- package/_internal/components/text-851c62f8.js +0 -2
- package/_internal/components/text-851c62f8.js.map +0 -1
- package/_internal/components/text-field-82adaeb4.js +0 -359
- package/_internal/components/text-field-82adaeb4.js.map +0 -1
- package/_internal/components/thumbnail-f1784929.js +0 -42
- package/_internal/components/thumbnail-f1784929.js.map +0 -1
- package/_internal/components/toolbar-a43533a2.js +0 -61
- package/_internal/components/toolbar-a43533a2.js.map +0 -1
- package/_internal/components/tooltip-aa48ddda.js +0 -327
- package/_internal/components/tooltip-aa48ddda.js.map +0 -1
- package/_internal/components/uploader-7bc3adaa.js +0 -153
- package/_internal/components/uploader-7bc3adaa.js.map +0 -1
- package/_internal/components/user-block-fc03f01a.js +0 -144
- package/_internal/components/user-block-fc03f01a.js.map +0 -1
- package/_internal/constants-b9e57936.js +0 -2155
- package/_internal/constants-b9e57936.js.map +0 -1
- package/_internal/constants-d0e3f49e.js +0 -24
- package/_internal/constants-d0e3f49e.js.map +0 -1
- package/_internal/context-9d1336a1.js +0 -19
- package/_internal/context-9d1336a1.js.map +0 -1
- package/_internal/forwardRef-15f62847.js +0 -70
- package/_internal/forwardRef-15f62847.js.map +0 -1
- package/_internal/getFocusableElements-230173a8.js +0 -13
- package/_internal/getFocusableElements-230173a8.js.map +0 -1
- package/_internal/index-192f8ada.js +0 -103
- package/_internal/index-192f8ada.js.map +0 -1
- package/_internal/index-8e7fecb5.js +0 -436
- package/_internal/index-8e7fecb5.js.map +0 -1
- package/_internal/index-b06353f2.js +0 -117
- package/_internal/index-b06353f2.js.map +0 -1
- package/_internal/information-49bbeed3.js +0 -6
- package/_internal/information-49bbeed3.js.map +0 -1
- package/_internal/isComponent-b9762ff1.js +0 -18
- package/_internal/isComponent-b9762ff1.js.map +0 -1
- package/_internal/isComponentType-e806b848.js +0 -9
- package/_internal/isComponentType-e806b848.js.map +0 -1
- package/_internal/mergeRefs-f0d7d6ea.js +0 -30
- package/_internal/mergeRefs-f0d7d6ea.js.map +0 -1
- package/_internal/state-db358714.js +0 -130
- package/_internal/state-db358714.js.map +0 -1
- package/_internal/useBooleanState-2a3d237c.js +0 -12
- package/_internal/useBooleanState-2a3d237c.js.map +0 -1
- package/_internal/useCallbackOnEscape-0b220f9c.js +0 -62
- package/_internal/useCallbackOnEscape-0b220f9c.js.map +0 -1
- package/_internal/useDisableBodyScroll-36bd7352.js +0 -219
- package/_internal/useDisableBodyScroll-36bd7352.js.map +0 -1
- package/_internal/useDisableStateProps-69e16b7c.js +0 -36
- package/_internal/useDisableStateProps-69e16b7c.js.map +0 -1
- package/_internal/useFocusTrap-3114e5e8.js +0 -112
- package/_internal/useFocusTrap-3114e5e8.js.map +0 -1
- package/_internal/useId-3a1facc0.js +0 -18
- package/_internal/useId-3a1facc0.js.map +0 -1
- package/_internal/useRovingTabIndex-7daf0f24.js +0 -77
- package/_internal/useRovingTabIndex-7daf0f24.js.map +0 -1
- package/_internal/useTransitionVisibility-321fdbfa.js +0 -50
- package/_internal/useTransitionVisibility-321fdbfa.js.map +0 -1
- package/_internal/wrapChildrenIconWithSpaces-f1e91251.js +0 -20
- package/_internal/wrapChildrenIconWithSpaces-f1e91251.js.map +0 -1
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/core": "^3.20.1-alpha.
|
|
10
|
-
"@lumx/icons": "^3.20.1-alpha.
|
|
9
|
+
"@lumx/core": "^3.20.1-alpha.29",
|
|
10
|
+
"@lumx/icons": "^3.20.1-alpha.29",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@babel/preset-typescript": "^7.26.0",
|
|
21
21
|
"@chromatic-com/storybook": "^4.1.1",
|
|
22
22
|
"@rollup/plugin-babel": "^6.0.4",
|
|
23
|
-
"@rollup/plugin-commonjs": "^
|
|
23
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
24
24
|
"@rollup/plugin-node-resolve": "16.0.0",
|
|
25
25
|
"@storybook/addon-a11y": "^9.1.4",
|
|
26
26
|
"@storybook/addon-docs": "^9.1.4",
|
|
@@ -35,17 +35,13 @@
|
|
|
35
35
|
"@types/react": "^17.0.2",
|
|
36
36
|
"@types/react-dom": "^17.0.2",
|
|
37
37
|
"@types/react-is": "^17.0.2",
|
|
38
|
-
"@vitest/ui": "^
|
|
38
|
+
"@vitest/ui": "^3.0.0",
|
|
39
39
|
"autoprefixer": "^9.7.4",
|
|
40
|
-
"babel-loader": "^8.0.6",
|
|
41
40
|
"chromatic": "^13.1.4",
|
|
42
|
-
"core-js": "^3.6.4",
|
|
43
41
|
"focus-visible": "^5.0.2",
|
|
44
42
|
"glob": "^7.1.6",
|
|
45
|
-
"install-peers-cli": "^2.2.0",
|
|
46
|
-
"is-ci": "^2.0.0",
|
|
47
43
|
"jsdom": "^27.2.0",
|
|
48
|
-
"
|
|
44
|
+
"lodash": "4.17.21",
|
|
49
45
|
"react": "^17.0.2",
|
|
50
46
|
"react-dom": "^17.0.2",
|
|
51
47
|
"rollup": "3.29.5",
|
|
@@ -59,8 +55,7 @@
|
|
|
59
55
|
"typescript": "^5.4.3",
|
|
60
56
|
"vite": "^6.3.5",
|
|
61
57
|
"vite-tsconfig-paths": "^5.1.4",
|
|
62
|
-
"vitest": "^
|
|
63
|
-
"yargs": "^15.4.1"
|
|
58
|
+
"vitest": "^3.0.0"
|
|
64
59
|
},
|
|
65
60
|
"peerDependencies": {
|
|
66
61
|
"lodash": "4.17.21",
|
|
@@ -90,11 +85,10 @@
|
|
|
90
85
|
},
|
|
91
86
|
"scripts": {
|
|
92
87
|
"build": "rollup -c",
|
|
93
|
-
"prepare": "install-peers || exit 0",
|
|
94
88
|
"test": "vitest run",
|
|
95
89
|
"start:storybook": "storybook dev -p 9000",
|
|
96
90
|
"build:storybook": "storybook build"
|
|
97
91
|
},
|
|
98
92
|
"sideEffects": false,
|
|
99
|
-
"version": "3.20.1-alpha.
|
|
93
|
+
"version": "3.20.1-alpha.29"
|
|
100
94
|
}
|
package/utils/index.js
CHANGED
|
@@ -1,4 +1,159 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import React__default, { useContext, useEffect, useMemo, useRef, createContext } from 'react';
|
|
2
|
+
import { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';
|
|
3
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
|
|
6
|
+
const DisabledStateContext = /*#__PURE__*/React__default.createContext({
|
|
7
|
+
state: null
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Disabled state provider.
|
|
11
|
+
* All nested LumX Design System components inherit this disabled state.
|
|
12
|
+
*/
|
|
13
|
+
function DisabledStateProvider({
|
|
14
|
+
children,
|
|
15
|
+
...value
|
|
16
|
+
}) {
|
|
17
|
+
return /*#__PURE__*/jsx(DisabledStateContext.Provider, {
|
|
18
|
+
value: value,
|
|
19
|
+
children: children
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get DisabledState context value
|
|
25
|
+
*/
|
|
26
|
+
function useDisabledStateContext() {
|
|
27
|
+
return useContext(DisabledStateContext);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const EVENT_TYPES = ['mousedown', 'touchstart'];
|
|
31
|
+
function isClickAway(targets, refs) {
|
|
32
|
+
// The targets elements are not contained in any of the listed element references.
|
|
33
|
+
return !refs.some(ref => targets.some(target => ref?.current?.contains(target)));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Listen to clicks away from the given elements and callback the passed in function.
|
|
37
|
+
*
|
|
38
|
+
* Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.
|
|
39
|
+
*/
|
|
40
|
+
function useClickAway({
|
|
41
|
+
callback,
|
|
42
|
+
childrenRefs
|
|
43
|
+
}) {
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const {
|
|
46
|
+
current: currentRefs
|
|
47
|
+
} = childrenRefs;
|
|
48
|
+
if (!callback || !currentRefs || isEmpty(currentRefs)) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const listener = evt => {
|
|
52
|
+
const targets = [evt.composedPath?.()[0], evt.target];
|
|
53
|
+
if (isClickAway(targets, currentRefs)) {
|
|
54
|
+
callback(evt);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
EVENT_TYPES.forEach(evtType => document.addEventListener(evtType, listener));
|
|
58
|
+
return () => {
|
|
59
|
+
EVENT_TYPES.forEach(evtType => document.removeEventListener(evtType, listener));
|
|
60
|
+
};
|
|
61
|
+
}, [callback, childrenRefs]);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ClickAwayAncestorContext = /*#__PURE__*/createContext(null);
|
|
65
|
+
/**
|
|
66
|
+
* Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure
|
|
67
|
+
* we take into account both the DOM tree and the React tree to detect click away.
|
|
68
|
+
*
|
|
69
|
+
* @return the react component.
|
|
70
|
+
*/
|
|
71
|
+
const ClickAwayProvider = ({
|
|
72
|
+
children,
|
|
73
|
+
callback,
|
|
74
|
+
childrenRefs,
|
|
75
|
+
parentRef
|
|
76
|
+
}) => {
|
|
77
|
+
const parentContext = useContext(ClickAwayAncestorContext);
|
|
78
|
+
const currentContext = useMemo(() => {
|
|
79
|
+
const context = {
|
|
80
|
+
childrenRefs: [],
|
|
81
|
+
/**
|
|
82
|
+
* Add element refs to the current context and propagate to the parent context.
|
|
83
|
+
*/
|
|
84
|
+
addRefs(...newChildrenRefs) {
|
|
85
|
+
// Add element refs that should be considered as inside the click away context.
|
|
86
|
+
context.childrenRefs.push(...newChildrenRefs);
|
|
87
|
+
if (parentContext) {
|
|
88
|
+
// Also add then to the parent context
|
|
89
|
+
parentContext.addRefs(...newChildrenRefs);
|
|
90
|
+
if (parentRef) {
|
|
91
|
+
// The parent element is also considered as inside the parent click away context but not inside the current context
|
|
92
|
+
parentContext.addRefs(parentRef);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return context;
|
|
98
|
+
}, [parentContext, parentRef]);
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
const {
|
|
101
|
+
current: currentRefs
|
|
102
|
+
} = childrenRefs;
|
|
103
|
+
if (!currentRefs) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
currentContext.addRefs(...currentRefs);
|
|
107
|
+
}, [currentContext, childrenRefs]);
|
|
108
|
+
useClickAway({
|
|
109
|
+
callback,
|
|
110
|
+
childrenRefs: useRef(currentContext.childrenRefs)
|
|
111
|
+
});
|
|
112
|
+
return /*#__PURE__*/jsx(ClickAwayAncestorContext.Provider, {
|
|
113
|
+
value: currentContext,
|
|
114
|
+
children: children
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
ClickAwayProvider.displayName = 'ClickAwayProvider';
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Portal initializing function.
|
|
121
|
+
* If it does not provide a container, the Portal children will render in classic React tree and not in a portal.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
const PortalContext = /*#__PURE__*/React__default.createContext(() => ({
|
|
125
|
+
container: document.body
|
|
126
|
+
}));
|
|
127
|
+
/**
|
|
128
|
+
* Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)
|
|
129
|
+
*/
|
|
130
|
+
const PortalProvider = PortalContext.Provider;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Render children in a portal outside the current DOM position
|
|
134
|
+
* (defaults to `document.body` but can be customized with the PortalContextProvider)
|
|
135
|
+
*/
|
|
136
|
+
const Portal = ({
|
|
137
|
+
children,
|
|
138
|
+
enabled = true
|
|
139
|
+
}) => {
|
|
140
|
+
const init = React__default.useContext(PortalContext);
|
|
141
|
+
const context = React__default.useMemo(() => {
|
|
142
|
+
return enabled ? init() : null;
|
|
143
|
+
},
|
|
144
|
+
// Only update on 'enabled'
|
|
145
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
146
|
+
[enabled]);
|
|
147
|
+
React__default.useLayoutEffect(() => {
|
|
148
|
+
return context?.teardown;
|
|
149
|
+
}, [context?.teardown, enabled]);
|
|
150
|
+
if (!context?.container) {
|
|
151
|
+
return /*#__PURE__*/jsx(Fragment, {
|
|
152
|
+
children: children
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return /*#__PURE__*/createPortal(children, context.container);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export { ClickAwayProvider, DisabledStateProvider, Portal, PortalProvider, useDisabledStateContext };
|
|
4
159
|
//# sourceMappingURL=index.js.map
|
package/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/disabled/DisabledStateContext.tsx","../../src/hooks/useClickAway.tsx","../../src/utils/ClickAwayProvider/ClickAwayProvider.tsx","../../src/utils/Portal/PortalProvider.tsx","../../src/utils/Portal/Portal.tsx"],"sourcesContent":["import React, { useContext } from 'react';\n\n/** Disable state */\ntype DisabledStateContextValue =\n | {\n state: 'disabled';\n }\n | { state: undefined | null };\n\nexport const DisabledStateContext = React.createContext<DisabledStateContextValue>({ state: null });\n\nexport type DisabledStateProviderProps = DisabledStateContextValue & {\n children: React.ReactNode;\n};\n\n/**\n * Disabled state provider.\n * All nested LumX Design System components inherit this disabled state.\n */\nexport function DisabledStateProvider({ children, ...value }: DisabledStateProviderProps) {\n return <DisabledStateContext.Provider value={value}>{children}</DisabledStateContext.Provider>;\n}\n\n/**\n * Get DisabledState context value\n */\nexport function useDisabledStateContext(): DisabledStateContextValue {\n return useContext(DisabledStateContext);\n}\n","import { RefObject, useEffect } from 'react';\n\nimport { Falsy } from '@lumx/react/utils/type';\nimport { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';\n\nconst EVENT_TYPES = ['mousedown', 'touchstart'];\n\nfunction isClickAway(targets: HTMLElement[], refs: Array<RefObject<HTMLElement>>): boolean {\n // The targets elements are not contained in any of the listed element references.\n return !refs.some((ref) => targets.some((target) => ref?.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 const targets = [evt.composedPath?.()[0], evt.target] as HTMLElement[];\n if (isClickAway(targets, 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 { 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 * Children\n */\n children?: React.ReactNode;\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","import React from 'react';\n\ntype Container = DocumentFragment | Element;\n\n/**\n * Portal initializing function.\n * If it does not provide a container, the Portal children will render in classic React tree and not in a portal.\n */\nexport type PortalInit = () => {\n container?: Container;\n teardown?: () => void;\n};\n\nexport const PortalContext = React.createContext<PortalInit>(() => ({ container: document.body }));\n\nexport interface PortalProviderProps {\n children?: React.ReactNode;\n value: PortalInit;\n}\n\n/**\n * Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)\n */\nexport const PortalProvider: React.FC<PortalProviderProps> = PortalContext.Provider;\n","import React from 'react';\nimport { createPortal } from 'react-dom';\nimport { PortalContext } from './PortalProvider';\n\nexport interface PortalProps {\n enabled?: boolean;\n children: React.ReactNode;\n}\n\n/**\n * Render children in a portal outside the current DOM position\n * (defaults to `document.body` but can be customized with the PortalContextProvider)\n */\nexport const Portal: React.FC<PortalProps> = ({ children, enabled = true }) => {\n const init = React.useContext(PortalContext);\n const context = React.useMemo(\n () => {\n return enabled ? init() : null;\n },\n // Only update on 'enabled'\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [enabled],\n );\n\n React.useLayoutEffect(() => {\n return context?.teardown;\n }, [context?.teardown, enabled]);\n\n if (!context?.container) {\n return <>{children}</>;\n }\n return createPortal(children, context.container);\n};\n"],"names":["DisabledStateContext","React","createContext","state","DisabledStateProvider","children","value","_jsx","Provider","useDisabledStateContext","useContext","EVENT_TYPES","isClickAway","targets","refs","some","ref","target","current","contains","useClickAway","callback","childrenRefs","useEffect","currentRefs","isEmpty","undefined","listener","evt","composedPath","forEach","evtType","document","addEventListener","removeEventListener","ClickAwayAncestorContext","ClickAwayProvider","parentRef","parentContext","currentContext","useMemo","context","addRefs","newChildrenRefs","push","useRef","displayName","PortalContext","container","body","PortalProvider","Portal","enabled","init","useLayoutEffect","teardown","_Fragment","createPortal"],"mappings":";;;;;AASO,MAAMA,oBAAoB,gBAAGC,cAAK,CAACC,aAAa,CAA4B;AAAEC,EAAAA,KAAK,EAAE,IAAA;AAAK,CAAC,CAAC,CAAA;AAMnG;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAAC;EAAEC,QAAQ;EAAE,GAAGC,KAAAA;AAAkC,CAAC,EAAE;AACtF,EAAA,oBAAOC,GAAA,CAACP,oBAAoB,CAACQ,QAAQ,EAAA;AAACF,IAAAA,KAAK,EAAEA,KAAM;AAAAD,IAAAA,QAAA,EAAEA,QAAAA;AAAQ,GAAgC,CAAC,CAAA;AAClG,CAAA;;AAEA;AACA;AACA;AACO,SAASI,uBAAuBA,GAA8B;EACjE,OAAOC,UAAU,CAACV,oBAAoB,CAAC,CAAA;AAC3C;;ACvBA,MAAMW,WAAW,GAAG,CAAC,WAAW,EAAE,YAAY,CAAC,CAAA;AAE/C,SAASC,WAAWA,CAACC,OAAsB,EAAEC,IAAmC,EAAW;AACvF;EACA,OAAO,CAACA,IAAI,CAACC,IAAI,CAAEC,GAAG,IAAKH,OAAO,CAACE,IAAI,CAAEE,MAAM,IAAKD,GAAG,EAAEE,OAAO,EAAEC,QAAQ,CAACF,MAAM,CAAC,CAAC,CAAC,CAAA;AACxF,CAAA;AAaA;AACA;AACA;AACA;AACA;A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ACA;AACA;AACA;;AAMO,MAAMC,aAAa,gBAAG9C,cAAK,CAACC,aAAa,CAAa,OAAO;EAAE8C,SAAS,EAAEhB,QAAQ,CAACiB,IAAAA;AAAK,CAAC,CAAC,CAAC,CAAA;AAOlG;AACA;AACA;AACaC,MAAAA,cAA6C,GAAGH,aAAa,CAACvC;;ACd3E;AACA;AACA;AACA;AACO,MAAM2C,MAA6B,GAAGA,CAAC;EAAE9C,QAAQ;AAAE+C,EAAAA,OAAO,GAAG,IAAA;AAAK,CAAC,KAAK;AAC3E,EAAA,MAAMC,IAAI,GAAGpD,cAAK,CAACS,UAAU,CAACqC,aAAa,CAAC,CAAA;AAC5C,EAAA,MAAMN,OAAO,GAAGxC,cAAK,CAACuC,OAAO,CACzB,MAAM;AACF,IAAA,OAAOY,OAAO,GAAGC,IAAI,EAAE,GAAG,IAAI,CAAA;GACjC;AACD;AACA;EACA,CAACD,OAAO,CACZ,CAAC,CAAA;EAEDnD,cAAK,CAACqD,eAAe,CAAC,MAAM;IACxB,OAAOb,OAAO,EAAEc,QAAQ,CAAA;GAC3B,EAAE,CAACd,OAAO,EAAEc,QAAQ,EAAEH,OAAO,CAAC,CAAC,CAAA;AAEhC,EAAA,IAAI,CAACX,OAAO,EAAEO,SAAS,EAAE;IACrB,oBAAOzC,GAAA,CAAAiD,QAAA,EAAA;AAAAnD,MAAAA,QAAA,EAAGA,QAAAA;AAAQ,KAAG,CAAC,CAAA;AAC1B,GAAA;AACA,EAAA,oBAAOoD,YAAY,CAACpD,QAAQ,EAAEoC,OAAO,CAACO,SAAS,CAAC,CAAA;AACpD;;;;"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { f as forwardRef, c as classNames } from './forwardRef-15f62847.js';
|
|
2
|
-
import { i as isComponent } from './isComponent-b9762ff1.js';
|
|
3
|
-
import { getRootClassName, getBasicClass } from '@lumx/core/js/utils/className';
|
|
4
|
-
import { u as useTheme, T as ThemeProvider } from './ThemeContext-3181f000.js';
|
|
5
|
-
import { B as ButtonRoot } from './ButtonRoot-823f3e9c.js';
|
|
6
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
-
import { T as Text } from './index-b06353f2.js';
|
|
8
|
-
import { Emphasis, Size, Theme } from '@lumx/core/js/constants';
|
|
9
|
-
import { I as Icon } from './index-192f8ada.js';
|
|
10
|
-
|
|
11
|
-
const ButtonEmphasis = Emphasis;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Defines the props of the component.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Component display name.
|
|
19
|
-
*/
|
|
20
|
-
const COMPONENT_NAME = 'Button';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Component default class name and class prefix.
|
|
24
|
-
*/
|
|
25
|
-
const CLASSNAME = getRootClassName(COMPONENT_NAME);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Component default props.
|
|
29
|
-
*/
|
|
30
|
-
const DEFAULT_PROPS = {
|
|
31
|
-
emphasis: Emphasis.high,
|
|
32
|
-
size: Size.m
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Button component.
|
|
37
|
-
*
|
|
38
|
-
* @param props Component props.
|
|
39
|
-
* @param ref Component ref.
|
|
40
|
-
* @return React element.
|
|
41
|
-
*/
|
|
42
|
-
const Button = forwardRef((props, ref) => {
|
|
43
|
-
const defaultTheme = useTheme() || Theme.light;
|
|
44
|
-
const {
|
|
45
|
-
children,
|
|
46
|
-
className,
|
|
47
|
-
emphasis = DEFAULT_PROPS.emphasis,
|
|
48
|
-
leftIcon,
|
|
49
|
-
rightIcon,
|
|
50
|
-
size = DEFAULT_PROPS.size,
|
|
51
|
-
theme = defaultTheme,
|
|
52
|
-
...forwardedProps
|
|
53
|
-
} = props;
|
|
54
|
-
const buttonClassName = classNames(className, getBasicClass({
|
|
55
|
-
prefix: CLASSNAME,
|
|
56
|
-
type: 'hasLeftIcon',
|
|
57
|
-
value: !!leftIcon
|
|
58
|
-
}), getBasicClass({
|
|
59
|
-
prefix: CLASSNAME,
|
|
60
|
-
type: 'hasRightIcon',
|
|
61
|
-
value: !!rightIcon
|
|
62
|
-
}));
|
|
63
|
-
return /*#__PURE__*/jsxs(ButtonRoot, {
|
|
64
|
-
ref: ref,
|
|
65
|
-
emphasis,
|
|
66
|
-
size,
|
|
67
|
-
theme,
|
|
68
|
-
...forwardedProps,
|
|
69
|
-
className: buttonClassName,
|
|
70
|
-
variant: "button",
|
|
71
|
-
children: [leftIcon &&
|
|
72
|
-
/*#__PURE__*/
|
|
73
|
-
// Theme is handled in the button scss
|
|
74
|
-
jsx(ThemeProvider, {
|
|
75
|
-
value: undefined,
|
|
76
|
-
children: /*#__PURE__*/jsx(Icon, {
|
|
77
|
-
icon: leftIcon
|
|
78
|
-
})
|
|
79
|
-
}), children && (isComponent(Text)(children) ? children : /*#__PURE__*/jsx("span", {
|
|
80
|
-
children: children
|
|
81
|
-
})), rightIcon &&
|
|
82
|
-
/*#__PURE__*/
|
|
83
|
-
// Theme is handled in the button scss
|
|
84
|
-
jsx(ThemeProvider, {
|
|
85
|
-
value: undefined,
|
|
86
|
-
children: /*#__PURE__*/jsx(Icon, {
|
|
87
|
-
icon: rightIcon
|
|
88
|
-
})
|
|
89
|
-
})]
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
Button.displayName = COMPONENT_NAME;
|
|
93
|
-
Button.className = CLASSNAME;
|
|
94
|
-
Button.defaultProps = DEFAULT_PROPS;
|
|
95
|
-
|
|
96
|
-
export { ButtonEmphasis as B, Button as a };
|
|
97
|
-
//# sourceMappingURL=Button-2b55a913.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Button-2b55a913.js","sources":["../../src/components/button/Button.tsx"],"sourcesContent":["import classNames from 'classnames';\n\nimport { Emphasis, Icon, Size, Theme, Text, ThemeProvider } from '@lumx/react';\nimport { isComponent } from '@lumx/react/utils/type';\nimport { getBasicClass, getRootClassName } from '@lumx/core/js/utils/className';\nimport { useTheme } from '@lumx/react/utils/theme/ThemeContext';\nimport { forwardRef } from '@lumx/react/utils/react/forwardRef';\n\nimport { BaseButtonProps, ButtonRoot } from './ButtonRoot';\n\n/**\n * Button emphasis definition.\n * @deprecated Use Emphasis instead.\n */\nexport const ButtonEmphasis = Emphasis;\n\n/**\n * Defines the props of the component.\n */\nexport interface ButtonProps extends BaseButtonProps {\n /** Left icon (SVG path). */\n leftIcon?: string;\n /** Right icon (SVG path). */\n rightIcon?: string;\n /** When `true`, the button gets as large as possible. */\n fullWidth?: boolean;\n /** Children */\n children?: React.ReactNode;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Button';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<ButtonProps> = {\n emphasis: Emphasis.high,\n size: Size.m,\n};\n\n/**\n * Button component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Button = forwardRef<ButtonProps, HTMLButtonElement | HTMLAnchorElement>((props, ref) => {\n const defaultTheme = useTheme() || Theme.light;\n const {\n children,\n className,\n emphasis = DEFAULT_PROPS.emphasis,\n leftIcon,\n rightIcon,\n size = DEFAULT_PROPS.size,\n theme = defaultTheme,\n ...forwardedProps\n } = props;\n\n const buttonClassName = classNames(\n className,\n getBasicClass({ prefix: CLASSNAME, type: 'hasLeftIcon', value: !!leftIcon }),\n getBasicClass({ prefix: CLASSNAME, type: 'hasRightIcon', value: !!rightIcon }),\n );\n\n return (\n <ButtonRoot\n ref={ref}\n {...{ emphasis, size, theme, ...forwardedProps }}\n className={buttonClassName}\n variant=\"button\"\n >\n {leftIcon && (\n // Theme is handled in the button scss\n <ThemeProvider value={undefined}>\n <Icon icon={leftIcon} />\n </ThemeProvider>\n )}\n {children && (isComponent(Text)(children) ? children : <span>{children}</span>)}\n {rightIcon && (\n // Theme is handled in the button scss\n <ThemeProvider value={undefined}>\n <Icon icon={rightIcon} />\n </ThemeProvider>\n )}\n </ButtonRoot>\n );\n});\nButton.displayName = COMPONENT_NAME;\nButton.className = CLASSNAME;\nButton.defaultProps = DEFAULT_PROPS;\n"],"names":["ButtonEmphasis","Emphasis","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","emphasis","high","size","Size","m","Button","forwardRef","props","ref","defaultTheme","useTheme","Theme","light","children","className","leftIcon","rightIcon","theme","forwardedProps","buttonClassName","classNames","getBasicClass","prefix","type","value","_jsxs","ButtonRoot","variant","_jsx","ThemeProvider","undefined","Icon","icon","isComponent","Text","displayName","defaultProps"],"mappings":";;;;;;;;;;AAcO,MAAMA,cAAc,GAAGC,SAAQ;;AAEtC;AACA;AACA;;AAYA;AACA;AACA;AACA,MAAMC,cAAc,GAAG,QAAQ,CAAA;;AAE/B;AACA;AACA;AACA,MAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAc,CAAC,CAAA;;AAElD;AACA;AACA;AACA,MAAMG,aAAmC,GAAG;EACxCC,QAAQ,EAAEL,QAAQ,CAACM,IAAI;EACvBC,IAAI,EAAEC,IAAI,CAACC,CAAAA;AACf,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,MAAM,GAAGC,UAAU,CAAqD,CAACC,KAAK,EAAEC,GAAG,KAAK;EACjG,MAAMC,YAAY,GAAGC,QAAQ,EAAE,IAAIC,KAAK,CAACC,KAAK,CAAA;EAC9C,MAAM;IACFC,QAAQ;IACRC,SAAS;IACTd,QAAQ,GAAGD,aAAa,CAACC,QAAQ;IACjCe,QAAQ;IACRC,SAAS;IACTd,IAAI,GAAGH,aAAa,CAACG,IAAI;AACzBe,IAAAA,KAAK,GAAGR,YAAY;IACpB,GAAGS,cAAAA;AACP,GAAC,GAAGX,KAAK,CAAA;AAET,EAAA,MAAMY,eAAe,GAAGC,UAAU,CAC9BN,SAAS,EACTO,a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;AAC5BQ,MAAM,CAAC+B,YAAY,GAAGrC,aAAa;;;;"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { f as forwardRef, c as classNames } from './forwardRef-15f62847.js';
|
|
2
|
-
import './constants-d0e3f49e.js';
|
|
3
|
-
import { handleBasicClasses } from '@lumx/core/js/utils/className';
|
|
4
|
-
import { R as RawClickable } from './RawClickable-2c2b6a89.js';
|
|
5
|
-
import { jsx } from 'react/jsx-runtime';
|
|
6
|
-
import { u as useDisableStateProps } from './useDisableStateProps-69e16b7c.js';
|
|
7
|
-
import { Emphasis, Theme, ColorPalette, CSS_PREFIX } from '@lumx/core/js/constants';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Component display name.
|
|
11
|
-
*/
|
|
12
|
-
const COMPONENT_NAME = 'ButtonRoot';
|
|
13
|
-
const BUTTON_WRAPPER_CLASSNAME = `${CSS_PREFIX}-button-wrapper`;
|
|
14
|
-
const BUTTON_CLASSNAME = `${CSS_PREFIX}-button`;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Render a button wrapper with the ButtonRoot inside.
|
|
18
|
-
*
|
|
19
|
-
* @param props Component props.
|
|
20
|
-
* @return React element.
|
|
21
|
-
*/
|
|
22
|
-
const renderButtonWrapper = props => {
|
|
23
|
-
const {
|
|
24
|
-
color,
|
|
25
|
-
emphasis,
|
|
26
|
-
variant,
|
|
27
|
-
fullWidth
|
|
28
|
-
} = props;
|
|
29
|
-
const adaptedColor = emphasis === Emphasis.low && (color === ColorPalette.light ? ColorPalette.dark : ColorPalette.light);
|
|
30
|
-
const wrapperClassName = classNames(handleBasicClasses({
|
|
31
|
-
color: adaptedColor,
|
|
32
|
-
prefix: BUTTON_WRAPPER_CLASSNAME,
|
|
33
|
-
variant,
|
|
34
|
-
fullWidth
|
|
35
|
-
}));
|
|
36
|
-
const buttonProps = {
|
|
37
|
-
...props,
|
|
38
|
-
hasBackground: false
|
|
39
|
-
};
|
|
40
|
-
return /*#__PURE__*/jsx("div", {
|
|
41
|
-
className: wrapperClassName,
|
|
42
|
-
children: /*#__PURE__*/jsx(ButtonRoot, {
|
|
43
|
-
...buttonProps
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* ButtonRoot component.
|
|
50
|
-
*
|
|
51
|
-
* @param props Component props.
|
|
52
|
-
* @param ref Component ref.
|
|
53
|
-
* @return React element.
|
|
54
|
-
*/
|
|
55
|
-
const ButtonRoot = forwardRef((props, ref) => {
|
|
56
|
-
const {
|
|
57
|
-
isAnyDisabled,
|
|
58
|
-
disabledStateProps,
|
|
59
|
-
otherProps
|
|
60
|
-
} = useDisableStateProps(props);
|
|
61
|
-
const {
|
|
62
|
-
'aria-label': ariaLabel,
|
|
63
|
-
children,
|
|
64
|
-
className,
|
|
65
|
-
color,
|
|
66
|
-
emphasis,
|
|
67
|
-
hasBackground,
|
|
68
|
-
isSelected,
|
|
69
|
-
isActive,
|
|
70
|
-
isFocused,
|
|
71
|
-
isHovered,
|
|
72
|
-
linkAs,
|
|
73
|
-
size,
|
|
74
|
-
theme,
|
|
75
|
-
variant,
|
|
76
|
-
fullWidth,
|
|
77
|
-
...forwardedProps
|
|
78
|
-
} = otherProps;
|
|
79
|
-
const adaptedColor = color || emphasis !== Emphasis.high && theme === Theme.dark && ColorPalette.light || emphasis === Emphasis.high && ColorPalette.primary || ColorPalette.dark;
|
|
80
|
-
if (hasBackground) {
|
|
81
|
-
return renderButtonWrapper({
|
|
82
|
-
...props,
|
|
83
|
-
ref,
|
|
84
|
-
variant,
|
|
85
|
-
color: adaptedColor
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
const buttonClassName = classNames(className, handleBasicClasses({
|
|
89
|
-
color: adaptedColor,
|
|
90
|
-
emphasis,
|
|
91
|
-
isSelected,
|
|
92
|
-
isDisabled: props.isDisabled || props['aria-disabled'],
|
|
93
|
-
isActive,
|
|
94
|
-
isFocused,
|
|
95
|
-
isHovered,
|
|
96
|
-
prefix: BUTTON_CLASSNAME,
|
|
97
|
-
size,
|
|
98
|
-
theme: emphasis === Emphasis.high && theme,
|
|
99
|
-
variant,
|
|
100
|
-
fullWidth
|
|
101
|
-
}));
|
|
102
|
-
return /*#__PURE__*/jsx(RawClickable, {
|
|
103
|
-
as: linkAs || (forwardedProps.href ? 'a' : 'button'),
|
|
104
|
-
...forwardedProps,
|
|
105
|
-
...disabledStateProps,
|
|
106
|
-
"aria-disabled": isAnyDisabled,
|
|
107
|
-
"aria-label": ariaLabel,
|
|
108
|
-
ref: ref,
|
|
109
|
-
className: buttonClassName,
|
|
110
|
-
children: children
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
ButtonRoot.displayName = COMPONENT_NAME;
|
|
114
|
-
ButtonRoot.defaultProps = {};
|
|
115
|
-
|
|
116
|
-
export { ButtonRoot as B };
|
|
117
|
-
//# sourceMappingURL=ButtonRoot-823f3e9c.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonRoot-823f3e9c.js","sources":["../../src/components/button/ButtonRoot.tsx"],"sourcesContent":["import { AriaAttributes, ButtonHTMLAttributes, DetailedHTMLProps, RefObject } from 'react';\nimport classNames from 'classnames';\n\nimport { ColorPalette, Emphasis, Size, Theme } from '@lumx/react';\nimport { CSS_PREFIX } from '@lumx/react/constants';\nimport { GenericProps, HasTheme } from '@lumx/react/utils/type';\nimport { handleBasicClasses } from '@lumx/core/js/utils/className';\nimport { forwardRef } from '@lumx/react/utils/react/forwardRef';\nimport { HasAriaDisabled } from '@lumx/react/utils/type/HasAriaDisabled';\nimport { RawClickable } from '@lumx/react/utils/react/RawClickable';\nimport { useDisableStateProps } from '@lumx/react/utils/disabled';\n\ntype HTMLButtonProps = DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>;\n\n/**\n * Button size definition.\n */\nexport type ButtonSize = Extract<Size, 's' | 'm'>;\n\nexport interface BaseButtonProps\n extends GenericProps,\n Pick<AriaAttributes, 'aria-expanded' | 'aria-haspopup' | 'aria-pressed' | 'aria-label'>,\n HasTheme,\n HasAriaDisabled {\n /** Color variant. */\n color?: ColorPalette;\n /** Emphasis variant. */\n emphasis?: Emphasis;\n /** Whether or not the button has a background color in low emphasis. */\n hasBackground?: boolean;\n /** Native anchor href property. It determines whether the Button will be a <button> or an <a>. */\n href?: string;\n /** Whether the component is disabled or not. */\n isDisabled?: boolean;\n /** Whether the component is selected or not (unsupported in `high` emphasis). */\n isSelected?: boolean;\n /** Native button name property. */\n name?: string;\n /** Size variant. */\n size?: ButtonSize;\n /** Native anchor target property. */\n target?: '_self' | '_blank' | '_parent' | '_top';\n /** Native button type. */\n type?: HTMLButtonProps['type'];\n /** Custom react component for the link (can be used to inject react router Link). */\n linkAs?: 'a' | any;\n}\n\nexport interface ButtonRootProps extends BaseButtonProps {\n variant: 'button' | 'icon';\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'ButtonRoot';\n\nexport const BUTTON_WRAPPER_CLASSNAME = `${CSS_PREFIX}-button-wrapper`;\nexport const BUTTON_CLASSNAME = `${CSS_PREFIX}-button`;\n\n/**\n * Render a button wrapper with the ButtonRoot inside.\n *\n * @param props Component props.\n * @return React element.\n */\nconst renderButtonWrapper: React.FC<ButtonRootProps> = (props) => {\n const { color, emphasis, variant, fullWidth } = props;\n\n const adaptedColor =\n emphasis === Emphasis.low && (color === ColorPalette.light ? ColorPalette.dark : ColorPalette.light);\n\n const wrapperClassName = classNames(\n handleBasicClasses({\n color: adaptedColor,\n prefix: BUTTON_WRAPPER_CLASSNAME,\n variant,\n fullWidth,\n }),\n );\n const buttonProps = { ...props, hasBackground: false };\n\n return (\n <div className={wrapperClassName}>\n {/* eslint-disable-next-line @typescript-eslint/no-use-before-define */}\n <ButtonRoot {...buttonProps} />\n </div>\n );\n};\n\n/**\n * ButtonRoot component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const ButtonRoot = forwardRef<ButtonRootProps, HTMLButtonElement | HTMLAnchorElement>((props, ref) => {\n const { isAnyDisabled, disabledStateProps, otherProps } = useDisableStateProps(props);\n const {\n 'aria-label': ariaLabel,\n children,\n className,\n color,\n emphasis,\n hasBackground,\n isSelected,\n isActive,\n isFocused,\n isHovered,\n linkAs,\n size,\n theme,\n variant,\n fullWidth,\n ...forwardedProps\n } = otherProps;\n\n const adaptedColor =\n color ||\n (emphasis !== Emphasis.high && theme === Theme.dark && ColorPalette.light) ||\n (emphasis === Emphasis.high && ColorPalette.primary) ||\n ColorPalette.dark;\n\n if (hasBackground) {\n return renderButtonWrapper({ ...props, ref, variant, color: adaptedColor });\n }\n\n const buttonClassName = classNames(\n className,\n handleBasicClasses({\n color: adaptedColor,\n emphasis,\n isSelected,\n isDisabled: props.isDisabled || props['aria-disabled'],\n isActive,\n isFocused,\n isHovered,\n prefix: BUTTON_CLASSNAME,\n size,\n theme: emphasis === Emphasis.high && theme,\n variant,\n fullWidth,\n }),\n );\n\n return (\n <RawClickable\n as={linkAs || (forwardedProps.href ? 'a' : 'button')}\n {...forwardedProps}\n {...disabledStateProps}\n aria-disabled={isAnyDisabled}\n aria-label={ariaLabel}\n ref={ref as RefObject<HTMLButtonElement>}\n className={buttonClassName}\n >\n {children}\n </RawClickable>\n );\n});\nButtonRoot.displayName = COMPONENT_NAME;\nButtonRoot.defaultProps = {};\n"],"names":["COMPONENT_NAME","BUTTON_WRAPPER_CLASSNAME","CSS_PREFIX","BUTTON_CLASSNAME","renderButtonWrapper","props","color","emphasis","variant","fullWidth","adaptedColor","Emphasis","low","ColorPalette","light","dark","wrapperClassName","classNames","handleBasicClasses","prefix","buttonProps","hasBackground","_jsx","className","children","ButtonRoot","forwardRef","ref","isAnyDisabled","disabledStateProps","otherProps","useDisableStateProps","ariaLabel","isSelected","isActive","isFocused","isHovered","linkAs","size","theme","forwardedProps","high","Theme","primary","buttonClassName","isDisabled","RawClickable","as","href","displayName","defaultProps"],"m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AA;IACTC,EAAE,EAAEV,MAAM,KAAKG,cAAc,CAACQ,IAAI,GAAG,GAAG,GAAG,QAAQ,CAAE;AAAA,IAAA,GACjDR,cAAc;AAAA,IAAA,GACdX,kBAAkB;AACtB,IAAA,eAAA,EAAeD,aAAc;AAC7B,IAAA,YAAA,EAAYI,SAAU;AACtBL,IAAAA,GAAG,EAAEA,GAAoC;AACzCJ,IAAAA,SAAS,EAAEqB,eAAgB;AAAApB,IAAAA,QAAA,EAE1BA,QAAAA;AAAQ,GACC,CAAC,CAAA;AAEvB,CAAC,EAAC;AACFC,UAAU,CAACwB,WAAW,GAAGjD,cAAc,CAAA;AACvCyB,UAAU,CAACyB,YAAY,GAAG,EAAE;;;;"}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { f as forwardRef, c as classNames } from './forwardRef-15f62847.js';
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
import { getRootClassName, handleBasicClasses } from '@lumx/core/js/utils/className';
|
|
4
|
-
import { onEnterPressed } from '@lumx/core/js/utils';
|
|
5
|
-
import { u as useTheme } from './ThemeContext-3181f000.js';
|
|
6
|
-
import { u as useDisableStateProps } from './useDisableStateProps-69e16b7c.js';
|
|
7
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
8
|
-
import { Size, Theme, ColorPalette } from '@lumx/core/js/constants';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Wrap mouse event handler to stop event propagation.
|
|
12
|
-
*
|
|
13
|
-
* @param handler The mouse handler to wrap.
|
|
14
|
-
* @return Mouse handler stopping propagation.
|
|
15
|
-
*/
|
|
16
|
-
function useStopPropagation(handler) {
|
|
17
|
-
return useCallback(evt => {
|
|
18
|
-
if (!evt || !handler) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
handler(evt);
|
|
22
|
-
evt.stopPropagation();
|
|
23
|
-
}, [handler]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Component display name.
|
|
28
|
-
*/
|
|
29
|
-
const COMPONENT_NAME = 'Chip';
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Component default class name and class prefix.
|
|
33
|
-
*/
|
|
34
|
-
const CLASSNAME = getRootClassName(COMPONENT_NAME);
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Component default props.
|
|
38
|
-
*/
|
|
39
|
-
const DEFAULT_PROPS = {
|
|
40
|
-
size: Size.m
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Chip component.
|
|
45
|
-
*
|
|
46
|
-
* @param props Component props.
|
|
47
|
-
* @param ref Component ref.
|
|
48
|
-
* @return React element.
|
|
49
|
-
*/
|
|
50
|
-
const Chip = forwardRef((props, ref) => {
|
|
51
|
-
const defaultTheme = useTheme() || Theme.light;
|
|
52
|
-
const {
|
|
53
|
-
isAnyDisabled,
|
|
54
|
-
disabledStateProps,
|
|
55
|
-
otherProps
|
|
56
|
-
} = useDisableStateProps(props);
|
|
57
|
-
const {
|
|
58
|
-
after,
|
|
59
|
-
before,
|
|
60
|
-
children,
|
|
61
|
-
className,
|
|
62
|
-
color,
|
|
63
|
-
isClickable: propIsClickable,
|
|
64
|
-
isHighlighted,
|
|
65
|
-
isSelected,
|
|
66
|
-
onAfterClick,
|
|
67
|
-
onBeforeClick,
|
|
68
|
-
onClick,
|
|
69
|
-
size = DEFAULT_PROPS.size,
|
|
70
|
-
theme = defaultTheme,
|
|
71
|
-
href,
|
|
72
|
-
onKeyDown,
|
|
73
|
-
...forwardedProps
|
|
74
|
-
} = otherProps;
|
|
75
|
-
const hasOnClick = Boolean(props.onClick);
|
|
76
|
-
const isButton = hasOnClick && !href;
|
|
77
|
-
const isClickable = Boolean(hasOnClick) || Boolean(href) || propIsClickable;
|
|
78
|
-
|
|
79
|
-
// Adapt color to the theme.
|
|
80
|
-
const chipColor = color || (theme === Theme.light ? ColorPalette.dark : ColorPalette.light);
|
|
81
|
-
const handleOnBeforeClick = useStopPropagation(onBeforeClick);
|
|
82
|
-
const handleOnAfterClick = useStopPropagation(onAfterClick);
|
|
83
|
-
const handleKeyDown = evt => {
|
|
84
|
-
onKeyDown?.(evt);
|
|
85
|
-
if (onClick) {
|
|
86
|
-
onEnterPressed(onClick)(evt);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
return (
|
|
90
|
-
/*#__PURE__*/
|
|
91
|
-
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
92
|
-
jsxs("a", {
|
|
93
|
-
role: isButton ? 'button' : undefined,
|
|
94
|
-
tabIndex: isClickable && !disabledStateProps.disabled ? 0 : undefined,
|
|
95
|
-
...forwardedProps,
|
|
96
|
-
href: !disabledStateProps.disabled ? href : undefined,
|
|
97
|
-
ref: ref,
|
|
98
|
-
className: classNames(className, handleBasicClasses({
|
|
99
|
-
clickable: isClickable,
|
|
100
|
-
color: chipColor,
|
|
101
|
-
isDisabled: isAnyDisabled,
|
|
102
|
-
hasAfter: Boolean(after),
|
|
103
|
-
hasBefore: Boolean(before),
|
|
104
|
-
highlighted: Boolean(isHighlighted),
|
|
105
|
-
prefix: CLASSNAME,
|
|
106
|
-
selected: Boolean(isSelected),
|
|
107
|
-
size,
|
|
108
|
-
unselected: Boolean(!isSelected)
|
|
109
|
-
})),
|
|
110
|
-
"aria-disabled": isClickable && isAnyDisabled || undefined,
|
|
111
|
-
onClick: onClick || undefined,
|
|
112
|
-
onKeyDown: handleKeyDown,
|
|
113
|
-
children: [before &&
|
|
114
|
-
/*#__PURE__*/
|
|
115
|
-
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
116
|
-
jsx("div", {
|
|
117
|
-
className: classNames(`${CLASSNAME}__before`, {
|
|
118
|
-
[`${CLASSNAME}__before--is-clickable`]: !!onBeforeClick
|
|
119
|
-
}),
|
|
120
|
-
onClick: handleOnBeforeClick,
|
|
121
|
-
children: before
|
|
122
|
-
}), /*#__PURE__*/jsx("div", {
|
|
123
|
-
className: `${CLASSNAME}__label`,
|
|
124
|
-
children: children
|
|
125
|
-
}), after &&
|
|
126
|
-
/*#__PURE__*/
|
|
127
|
-
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
|
|
128
|
-
jsx("div", {
|
|
129
|
-
className: classNames(`${CLASSNAME}__after`, {
|
|
130
|
-
[`${CLASSNAME}__after--is-clickable`]: !!onAfterClick
|
|
131
|
-
}),
|
|
132
|
-
onClick: handleOnAfterClick,
|
|
133
|
-
children: after
|
|
134
|
-
})]
|
|
135
|
-
})
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
Chip.displayName = COMPONENT_NAME;
|
|
139
|
-
Chip.className = CLASSNAME;
|
|
140
|
-
Chip.defaultProps = DEFAULT_PROPS;
|
|
141
|
-
|
|
142
|
-
export { Chip as C };
|
|
143
|
-
//# sourceMappingURL=Chip-e1e85810.js.map
|