@lumx/react 3.20.1-alpha.36 → 3.20.1-alpha.38
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.d.ts +4 -15
- package/index.js +13966 -64
- package/index.js.map +1 -0
- package/package.json +3 -3
- package/utils/index.js +159 -3
- package/utils/index.js.map +1 -0
- package/_internal/035c132d.js +0 -314
- package/_internal/0b9c76cb.js +0 -5
- package/_internal/0ea95af1.js +0 -819
- package/_internal/230173a8.js +0 -12
- package/_internal/2a3d237c.js +0 -11
- package/_internal/2c2b6a89.js +0 -51
- package/_internal/3181f000.js +0 -13
- package/_internal/36bd7352.js +0 -218
- package/_internal/3864a6c1.js +0 -436
- package/_internal/3a1facc0.js +0 -17
- package/_internal/49bbeed3.js +0 -5
- package/_internal/4daccdd5.js +0 -24
- package/_internal/4f4c0582.js +0 -2169
- package/_internal/5cef5e8c.js +0 -74
- package/_internal/6a60381c.js +0 -117
- package/_internal/6f084a40.js +0 -111
- package/_internal/76ddefd4.js +0 -61
- package/_internal/78df9309.js +0 -19
- package/_internal/7ad474e4.js +0 -98
- package/_internal/7b293665.js +0 -19
- package/_internal/7daf0f24.js +0 -76
- package/_internal/825ac334.js +0 -129
- package/_internal/827b804a.js +0 -5
- package/_internal/8bce732e.js +0 -8
- package/_internal/9d1336a1.js +0 -18
- package/_internal/a38bdcd0.js +0 -49
- package/_internal/b326655a.js +0 -682
- package/_internal/b83e864b.js +0 -76
- package/_internal/bace1bf1.js +0 -103
- package/_internal/c57190eb.js +0 -146
- package/_internal/components/alert-dialog/index-284fed80.js +0 -163
- package/_internal/components/autocomplete/__mockData__/index-96fc7ea7.js +0 -27
- package/_internal/components/autocomplete/index-27a49d5d.js +0 -261
- package/_internal/components/avatar/index-b8bc3cae.js +0 -83
- package/_internal/components/badge/index-9880f056.js +0 -81
- package/_internal/components/button/index-d919f96d.js +0 -47
- package/_internal/components/checkbox/index-dd478de9.js +0 -143
- package/_internal/components/chip/index-7f84cdbd.js +0 -102
- package/_internal/components/comment-block/index-e942de30.js +0 -138
- package/_internal/components/date-picker/index-a258d3ce.js +0 -596
- package/_internal/components/dialog/index-c7066813.js +0 -238
- package/_internal/components/divider/index-b6934baf.js +0 -50
- package/_internal/components/drag-handle/index-80e5af6c.js +0 -52
- package/_internal/components/dropdown/index-cebfc268.js +0 -147
- package/_internal/components/expansion-panel/index-9d45a211.js +0 -167
- package/_internal/components/flag/index-33e9d909.js +0 -59
- package/_internal/components/flex-box/index-0d6b6b43.js +0 -56
- package/_internal/components/generic-block/index-836c4352.js +0 -124
- package/_internal/components/grid/index-8c16a4f1.js +0 -104
- package/_internal/components/grid-column/index-4a2f56bb.js +0 -59
- package/_internal/components/heading/index-fd558a9a.js +0 -53
- package/_internal/components/icon/index-e7b9b40e.js +0 -1
- package/_internal/components/image-block/index-7021c2f1.js +0 -110
- package/_internal/components/image-lightbox/index-27017547.js +0 -759
- package/_internal/components/inline-list/index-52efec7f.js +0 -74
- package/_internal/components/input-helper/index-5a837e7c.js +0 -71
- package/_internal/components/input-label/index-0113f382.js +0 -59
- package/_internal/components/lightbox/index-fad5a9f2.js +0 -155
- package/_internal/components/link/index-008bae4b.js +0 -72
- package/_internal/components/link-preview/index-3e9c32f2.js +0 -117
- package/_internal/components/list/index-da88c6e9.js +0 -71
- package/_internal/components/message/index-17b568f2.js +0 -98
- package/_internal/components/mosaic/index-2d40e01c.js +0 -95
- package/_internal/components/navigation/index-dc17c639.js +0 -225
- package/_internal/components/notification/index-a1101015.js +0 -146
- package/_internal/components/popover/index-dbca63f1.js +0 -2
- package/_internal/components/popover-dialog/index-654d2abc.js +0 -66
- package/_internal/components/post-block/index-4b6b4dcb.js +0 -109
- package/_internal/components/progress/index-6f578c31.js +0 -182
- package/_internal/components/progress-tracker/index-700bc4c2.js +0 -309
- package/_internal/components/radio-button/index-89b725af.js +0 -149
- package/_internal/components/select/index-2755aa32.js +0 -458
- package/_internal/components/side-navigation/index-0bbe1fdd.js +0 -165
- package/_internal/components/skeleton/index-b2f8501c.js +0 -166
- package/_internal/components/slider/index-4f9b891b.js +0 -311
- package/_internal/components/slideshow/index-d4604589.js +0 -150
- package/_internal/components/switch/index-58fe0f0c.js +0 -122
- package/_internal/components/table/index-d541aa88.js +0 -297
- package/_internal/components/tabs/index-af1538d6.js +0 -298
- package/_internal/components/text/index-5bfc6d5e.js +0 -1
- package/_internal/components/text-field/index-47c98d09.js +0 -360
- package/_internal/components/thumbnail/index-71545d95.js +0 -41
- package/_internal/components/toolbar/index-7041a5a6.js +0 -61
- package/_internal/components/tooltip/index-8bb97e60.js +0 -327
- package/_internal/components/uploader/index-8f6f55de.js +0 -153
- package/_internal/components/user-block/index-70d4ce8f.js +0 -145
- package/_internal/d0e3f49e.js +0 -23
- package/_internal/de24f857.js +0 -3
- package/_internal/e806b848.js +0 -8
- package/_internal/e913a3af.js +0 -117
- package/_internal/ea04260d.js +0 -28
- package/_internal/eaf6c45a.js +0 -3
- package/_internal/ebdcb0c7.js +0 -60
- package/_internal/ef5d1aac.js +0 -3
- package/_internal/f0d7d6ea.js +0 -29
- package/_internal/utils/ClickAwayProvider/index-1234ce76.js +0 -94
- package/_internal/utils/MaterialThemeSwitcher/index-8d22de5a.js +0 -48
- package/_internal/utils/Portal/index-6e0a7404.js +0 -44
- package/_internal/utils/disabled/index-075b99c3.js +0 -36
- package/_internal/utils/type/index-ea9fc197.js +0 -2
package/_internal/de24f857.js
DELETED
package/_internal/e806b848.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Similar to `isComponent` but more precise as it's not based on the component `displayName` but on the component function reference.
|
|
5
|
-
*/
|
|
6
|
-
const isComponentType = type => node => /*#__PURE__*/React__default.isValidElement(node) && node.type === type;
|
|
7
|
-
|
|
8
|
-
export { isComponentType as i };
|
package/_internal/e913a3af.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import { getRootClassName, getTypographyClassName, handleBasicClasses, fontColorClass } from '@lumx/core/js/utils/className';
|
|
3
|
-
import React__default from 'react';
|
|
4
|
-
import { u as useTooltipContext } from './9d1336a1.js';
|
|
5
|
-
import { V as VISUALLY_HIDDEN } from './d0e3f49e.js';
|
|
6
|
-
import { u as useMergeRefs } from './f0d7d6ea.js';
|
|
7
|
-
import { f as forwardRef } from './8bce732e.js';
|
|
8
|
-
import { w as wrapChildrenIconWithSpaces } from './7b293665.js';
|
|
9
|
-
import { jsx } from 'react/jsx-runtime';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Compute a tooltip label based on a label element `innerText` if the text overflows.
|
|
13
|
-
* Updates dynamically on content changes (but not on resize!)
|
|
14
|
-
*/
|
|
15
|
-
const useOverflowTooltipLabel = content => {
|
|
16
|
-
const parentTooltip = useTooltipContext();
|
|
17
|
-
const [tooltipLabel, setTooltipLabel] = React__default.useState(undefined);
|
|
18
|
-
const [labelElement, setLabelElement] = React__default.useState(null);
|
|
19
|
-
React__default.useLayoutEffect(() => {
|
|
20
|
-
if (
|
|
21
|
-
// Not inside a tooltip
|
|
22
|
-
!parentTooltip && labelElement &&
|
|
23
|
-
// Not inside a visually hidden
|
|
24
|
-
!labelElement?.closest(`.${VISUALLY_HIDDEN}`) &&
|
|
25
|
-
// Text overflows
|
|
26
|
-
labelElement.offsetWidth < labelElement.scrollWidth) {
|
|
27
|
-
// Set tooltip label
|
|
28
|
-
setTooltipLabel(labelElement.innerText);
|
|
29
|
-
} else {
|
|
30
|
-
setTooltipLabel(undefined);
|
|
31
|
-
}
|
|
32
|
-
}, [labelElement, parentTooltip, content]);
|
|
33
|
-
return {
|
|
34
|
-
labelRef: setLabelElement,
|
|
35
|
-
tooltipLabel
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Component display name.
|
|
41
|
-
*/
|
|
42
|
-
const COMPONENT_NAME = 'Text';
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Component default class name and class prefix.
|
|
46
|
-
*/
|
|
47
|
-
const CLASSNAME = getRootClassName(COMPONENT_NAME);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Component default props.
|
|
51
|
-
*/
|
|
52
|
-
const DEFAULT_PROPS = {};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Text component.
|
|
56
|
-
*
|
|
57
|
-
* @param props Component props.
|
|
58
|
-
* @param ref Component ref.
|
|
59
|
-
* @return React element.
|
|
60
|
-
*/
|
|
61
|
-
const Text = forwardRef((props, ref) => {
|
|
62
|
-
const {
|
|
63
|
-
as: Component,
|
|
64
|
-
children,
|
|
65
|
-
className,
|
|
66
|
-
color,
|
|
67
|
-
colorVariant,
|
|
68
|
-
noWrap,
|
|
69
|
-
typography,
|
|
70
|
-
truncate,
|
|
71
|
-
whiteSpace,
|
|
72
|
-
style,
|
|
73
|
-
...forwardedProps
|
|
74
|
-
} = props;
|
|
75
|
-
const typographyClass = typography && getTypographyClassName(typography);
|
|
76
|
-
|
|
77
|
-
// Truncate mode
|
|
78
|
-
const truncateLinesStyle = typeof truncate === 'object' && truncate.lines > 1 && {
|
|
79
|
-
'--lumx-text-truncate-lines': truncate.lines
|
|
80
|
-
};
|
|
81
|
-
const isTruncatedMultiline = !!truncateLinesStyle;
|
|
82
|
-
const isTruncated = !!truncate;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Add custom white-space style if specified
|
|
86
|
-
* Disabled if noWrap is specified
|
|
87
|
-
* Disabled if truncated on one-line
|
|
88
|
-
* */
|
|
89
|
-
const whiteSpaceStyle = !noWrap && !(isTruncated && !isTruncatedMultiline) && whiteSpace && {
|
|
90
|
-
'--lumx-text-white-space': whiteSpace
|
|
91
|
-
};
|
|
92
|
-
const {
|
|
93
|
-
tooltipLabel,
|
|
94
|
-
labelRef
|
|
95
|
-
} = useOverflowTooltipLabel(children);
|
|
96
|
-
return /*#__PURE__*/jsx(Component, {
|
|
97
|
-
ref: useMergeRefs(ref, labelRef),
|
|
98
|
-
className: classNames(className, handleBasicClasses({
|
|
99
|
-
prefix: CLASSNAME,
|
|
100
|
-
isTruncated: isTruncated && !isTruncatedMultiline,
|
|
101
|
-
isTruncatedMultiline
|
|
102
|
-
}), typographyClass, fontColorClass(color, colorVariant), noWrap && `${CLASSNAME}--no-wrap`),
|
|
103
|
-
title: tooltipLabel,
|
|
104
|
-
style: {
|
|
105
|
-
...truncateLinesStyle,
|
|
106
|
-
...whiteSpaceStyle,
|
|
107
|
-
...style
|
|
108
|
-
},
|
|
109
|
-
...forwardedProps,
|
|
110
|
-
children: wrapChildrenIconWithSpaces(children)
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
Text.displayName = COMPONENT_NAME;
|
|
114
|
-
Text.className = CLASSNAME;
|
|
115
|
-
Text.defaultProps = DEFAULT_PROPS;
|
|
116
|
-
|
|
117
|
-
export { Text as T, useOverflowTooltipLabel as u };
|
package/_internal/ea04260d.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import React__default, { useContext } from 'react';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
const DisabledStateContext = /*#__PURE__*/React__default.createContext({
|
|
5
|
-
state: null
|
|
6
|
-
});
|
|
7
|
-
/**
|
|
8
|
-
* Disabled state provider.
|
|
9
|
-
* All nested LumX Design System components inherit this disabled state.
|
|
10
|
-
*/
|
|
11
|
-
function DisabledStateProvider({
|
|
12
|
-
children,
|
|
13
|
-
...value
|
|
14
|
-
}) {
|
|
15
|
-
return /*#__PURE__*/jsx(DisabledStateContext.Provider, {
|
|
16
|
-
value: value,
|
|
17
|
-
children: children
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get DisabledState context value
|
|
23
|
-
*/
|
|
24
|
-
function useDisabledStateContext() {
|
|
25
|
-
return useContext(DisabledStateContext);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { DisabledStateProvider as D, useDisabledStateContext as u };
|
package/_internal/eaf6c45a.js
DELETED
package/_internal/ebdcb0c7.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Typography } from '@lumx/core/js/constants';
|
|
2
|
-
import React__default, { createContext } from 'react';
|
|
3
|
-
import { jsx } from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
/** The maximum authorized heading level. */
|
|
6
|
-
const MAX_HEADING_LEVEL = 6;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Typography to use by default depending on the heading level.
|
|
10
|
-
*/
|
|
11
|
-
const DEFAULT_TYPOGRAPHY_BY_LEVEL = {
|
|
12
|
-
h1: Typography.display1,
|
|
13
|
-
h2: Typography.headline,
|
|
14
|
-
h3: Typography.title,
|
|
15
|
-
h4: Typography.subtitle2,
|
|
16
|
-
h5: Typography.subtitle1,
|
|
17
|
-
h6: Typography.body2
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const defaultContext = {
|
|
21
|
-
level: 1,
|
|
22
|
-
headingElement: 'h1'
|
|
23
|
-
};
|
|
24
|
-
const HeadingLevelContext = /*#__PURE__*/createContext(defaultContext);
|
|
25
|
-
|
|
26
|
-
const useHeadingLevel = () => {
|
|
27
|
-
const {
|
|
28
|
-
level = 1,
|
|
29
|
-
headingElement = 'h1'
|
|
30
|
-
} = React__default.useContext(HeadingLevelContext);
|
|
31
|
-
return {
|
|
32
|
-
level,
|
|
33
|
-
headingElement
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Provide a new heading level context.
|
|
39
|
-
*/
|
|
40
|
-
const HeadingLevelProvider = ({
|
|
41
|
-
children,
|
|
42
|
-
level
|
|
43
|
-
}) => {
|
|
44
|
-
const {
|
|
45
|
-
level: contextLevel
|
|
46
|
-
} = useHeadingLevel();
|
|
47
|
-
const incrementedLevel = level || contextLevel + 1;
|
|
48
|
-
/** Don't allow a level beyond the maximum level. */
|
|
49
|
-
const nextLevel = incrementedLevel > MAX_HEADING_LEVEL ? MAX_HEADING_LEVEL : incrementedLevel;
|
|
50
|
-
const headingElement = `h${nextLevel}`;
|
|
51
|
-
return /*#__PURE__*/jsx(HeadingLevelContext.Provider, {
|
|
52
|
-
value: {
|
|
53
|
-
level: nextLevel,
|
|
54
|
-
headingElement
|
|
55
|
-
},
|
|
56
|
-
children: children
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export { DEFAULT_TYPOGRAPHY_BY_LEVEL as D, HeadingLevelProvider as H, useHeadingLevel as u };
|
package/_internal/ef5d1aac.js
DELETED
package/_internal/f0d7d6ea.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Merge refs into a single function ref.
|
|
5
|
-
*
|
|
6
|
-
* @param refs React references to merge.
|
|
7
|
-
* @return the merged ref.
|
|
8
|
-
*/
|
|
9
|
-
function mergeRefs(...refs) {
|
|
10
|
-
return value => refs.forEach(ref => {
|
|
11
|
-
if (typeof ref === 'function') {
|
|
12
|
-
ref(value);
|
|
13
|
-
} else if (ref) {
|
|
14
|
-
// eslint-disable-next-line no-param-reassign
|
|
15
|
-
ref.current = value;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Same as `mergeRefs` but memoized
|
|
22
|
-
*/
|
|
23
|
-
const useMergeRefs = (...refs) => {
|
|
24
|
-
return useMemo(() => mergeRefs(...refs),
|
|
25
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
-
refs);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { mergeRefs as m, useMergeRefs as u };
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useEffect, useContext, useMemo, useRef, createContext } from 'react';
|
|
2
|
-
import isEmpty from 'lodash/isEmpty';
|
|
3
|
-
import { jsx } from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
const EVENT_TYPES = ['mousedown', 'touchstart'];
|
|
6
|
-
function isClickAway(targets, refs) {
|
|
7
|
-
// The targets elements are not contained in any of the listed element references.
|
|
8
|
-
return !refs.some(ref => targets.some(target => ref?.current?.contains(target)));
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Listen to clicks away from the given elements and callback the passed in function.
|
|
12
|
-
*
|
|
13
|
-
* Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.
|
|
14
|
-
*/
|
|
15
|
-
function useClickAway({
|
|
16
|
-
callback,
|
|
17
|
-
childrenRefs
|
|
18
|
-
}) {
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
const {
|
|
21
|
-
current: currentRefs
|
|
22
|
-
} = childrenRefs;
|
|
23
|
-
if (!callback || !currentRefs || isEmpty(currentRefs)) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
const listener = evt => {
|
|
27
|
-
const targets = [evt.composedPath?.()[0], evt.target];
|
|
28
|
-
if (isClickAway(targets, currentRefs)) {
|
|
29
|
-
callback(evt);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
EVENT_TYPES.forEach(evtType => document.addEventListener(evtType, listener));
|
|
33
|
-
return () => {
|
|
34
|
-
EVENT_TYPES.forEach(evtType => document.removeEventListener(evtType, listener));
|
|
35
|
-
};
|
|
36
|
-
}, [callback, childrenRefs]);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const ClickAwayAncestorContext = /*#__PURE__*/createContext(null);
|
|
40
|
-
/**
|
|
41
|
-
* Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure
|
|
42
|
-
* we take into account both the DOM tree and the React tree to detect click away.
|
|
43
|
-
*
|
|
44
|
-
* @return the react component.
|
|
45
|
-
*/
|
|
46
|
-
const ClickAwayProvider = ({
|
|
47
|
-
children,
|
|
48
|
-
callback,
|
|
49
|
-
childrenRefs,
|
|
50
|
-
parentRef
|
|
51
|
-
}) => {
|
|
52
|
-
const parentContext = useContext(ClickAwayAncestorContext);
|
|
53
|
-
const currentContext = useMemo(() => {
|
|
54
|
-
const context = {
|
|
55
|
-
childrenRefs: [],
|
|
56
|
-
/**
|
|
57
|
-
* Add element refs to the current context and propagate to the parent context.
|
|
58
|
-
*/
|
|
59
|
-
addRefs(...newChildrenRefs) {
|
|
60
|
-
// Add element refs that should be considered as inside the click away context.
|
|
61
|
-
context.childrenRefs.push(...newChildrenRefs);
|
|
62
|
-
if (parentContext) {
|
|
63
|
-
// Also add then to the parent context
|
|
64
|
-
parentContext.addRefs(...newChildrenRefs);
|
|
65
|
-
if (parentRef) {
|
|
66
|
-
// The parent element is also considered as inside the parent click away context but not inside the current context
|
|
67
|
-
parentContext.addRefs(parentRef);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return context;
|
|
73
|
-
}, [parentContext, parentRef]);
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
const {
|
|
76
|
-
current: currentRefs
|
|
77
|
-
} = childrenRefs;
|
|
78
|
-
if (!currentRefs) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
currentContext.addRefs(...currentRefs);
|
|
82
|
-
}, [currentContext, childrenRefs]);
|
|
83
|
-
useClickAway({
|
|
84
|
-
callback,
|
|
85
|
-
childrenRefs: useRef(currentContext.childrenRefs)
|
|
86
|
-
});
|
|
87
|
-
return /*#__PURE__*/jsx(ClickAwayAncestorContext.Provider, {
|
|
88
|
-
value: currentContext,
|
|
89
|
-
children: children
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
ClickAwayProvider.displayName = 'ClickAwayProvider';
|
|
93
|
-
|
|
94
|
-
export { ClickAwayProvider };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { Switch } from '../../components/switch/index-58fe0f0c.js';
|
|
4
|
-
import { Alignment } from '@lumx/core/js/constants';
|
|
5
|
-
|
|
6
|
-
const globalState = {
|
|
7
|
-
isEnabled: false,
|
|
8
|
-
styleSheet: null
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/** Toggle apply the material CSS override. */
|
|
12
|
-
async function toggleMaterialTheme(wasEnabled) {
|
|
13
|
-
globalState.isEnabled = !wasEnabled;
|
|
14
|
-
|
|
15
|
-
// Inject the material theme CSS file.
|
|
16
|
-
if (!globalState.styleSheet) {
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
const cssCode = await import('!!raw-loader!@lumx/core/css/material.css');
|
|
20
|
-
|
|
21
|
-
// Inject CSS override in a <style> node in <head>
|
|
22
|
-
const style = document.createElement('style');
|
|
23
|
-
style.textContent = cssCode.default;
|
|
24
|
-
document.head.appendChild(style);
|
|
25
|
-
globalState.styleSheet = style.sheet;
|
|
26
|
-
}
|
|
27
|
-
// Disable/Enable stylesheet
|
|
28
|
-
globalState.styleSheet.disabled = !globalState.isEnabled;
|
|
29
|
-
}
|
|
30
|
-
const MaterialThemeSwitcher = ({
|
|
31
|
-
theme
|
|
32
|
-
}) => {
|
|
33
|
-
const [isEnabled, setEnabled] = useState(globalState.isEnabled);
|
|
34
|
-
const toggleTheme = useCallback(() => setEnabled(wasEnabled => {
|
|
35
|
-
toggleMaterialTheme(wasEnabled);
|
|
36
|
-
return !wasEnabled;
|
|
37
|
-
}), []);
|
|
38
|
-
return /*#__PURE__*/jsx(Switch, {
|
|
39
|
-
className: "material-theme-switcher",
|
|
40
|
-
isChecked: isEnabled,
|
|
41
|
-
onChange: toggleTheme,
|
|
42
|
-
position: Alignment.right,
|
|
43
|
-
theme: theme,
|
|
44
|
-
children: "Material theme"
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export { MaterialThemeSwitcher, toggleMaterialTheme };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
|
-
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Portal initializing function.
|
|
7
|
-
* If it does not provide a container, the Portal children will render in classic React tree and not in a portal.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const PortalContext = /*#__PURE__*/React__default.createContext(() => ({
|
|
11
|
-
container: document.body
|
|
12
|
-
}));
|
|
13
|
-
/**
|
|
14
|
-
* Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)
|
|
15
|
-
*/
|
|
16
|
-
const PortalProvider = PortalContext.Provider;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Render children in a portal outside the current DOM position
|
|
20
|
-
* (defaults to `document.body` but can be customized with the PortalContextProvider)
|
|
21
|
-
*/
|
|
22
|
-
const Portal = ({
|
|
23
|
-
children,
|
|
24
|
-
enabled = true
|
|
25
|
-
}) => {
|
|
26
|
-
const init = React__default.useContext(PortalContext);
|
|
27
|
-
const context = React__default.useMemo(() => {
|
|
28
|
-
return enabled ? init() : null;
|
|
29
|
-
},
|
|
30
|
-
// Only update on 'enabled'
|
|
31
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
-
[enabled]);
|
|
33
|
-
React__default.useLayoutEffect(() => {
|
|
34
|
-
return context?.teardown;
|
|
35
|
-
}, [context?.teardown, enabled]);
|
|
36
|
-
if (!context?.container) {
|
|
37
|
-
return /*#__PURE__*/jsx(Fragment, {
|
|
38
|
-
children: children
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return /*#__PURE__*/createPortal(children, context.container);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export { Portal, PortalProvider };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { u as useDisabledStateContext } from '../../ea04260d.js';
|
|
2
|
-
export { D as DisabledStateProvider } from '../../ea04260d.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Resolve disabled state from props.
|
|
6
|
-
* (handles `disabled`, `isDisabled` and `aria-disabled`)
|
|
7
|
-
*
|
|
8
|
-
* @params component props
|
|
9
|
-
*/
|
|
10
|
-
function useDisableStateProps(props) {
|
|
11
|
-
const {
|
|
12
|
-
disabled,
|
|
13
|
-
isDisabled = disabled,
|
|
14
|
-
'aria-disabled': ariaDisabled,
|
|
15
|
-
onClick,
|
|
16
|
-
onChange,
|
|
17
|
-
...otherProps
|
|
18
|
-
} = props;
|
|
19
|
-
const disabledStateContext = useDisabledStateContext();
|
|
20
|
-
const disabledStateProps = {
|
|
21
|
-
disabled: disabledStateContext?.state === 'disabled' || isDisabled,
|
|
22
|
-
'aria-disabled': ariaDisabled === true || ariaDisabled === 'true'
|
|
23
|
-
};
|
|
24
|
-
const isAnyDisabled = disabledStateProps['aria-disabled'] || disabledStateProps.disabled;
|
|
25
|
-
if (!isAnyDisabled) {
|
|
26
|
-
otherProps.onClick = onClick;
|
|
27
|
-
otherProps.onChange = onChange;
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
disabledStateProps,
|
|
31
|
-
otherProps: otherProps,
|
|
32
|
-
isAnyDisabled
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { useDisableStateProps, useDisabledStateContext };
|