@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.
Files changed (106) hide show
  1. package/index.d.ts +4 -15
  2. package/index.js +13966 -64
  3. package/index.js.map +1 -0
  4. package/package.json +3 -3
  5. package/utils/index.js +159 -3
  6. package/utils/index.js.map +1 -0
  7. package/_internal/035c132d.js +0 -314
  8. package/_internal/0b9c76cb.js +0 -5
  9. package/_internal/0ea95af1.js +0 -819
  10. package/_internal/230173a8.js +0 -12
  11. package/_internal/2a3d237c.js +0 -11
  12. package/_internal/2c2b6a89.js +0 -51
  13. package/_internal/3181f000.js +0 -13
  14. package/_internal/36bd7352.js +0 -218
  15. package/_internal/3864a6c1.js +0 -436
  16. package/_internal/3a1facc0.js +0 -17
  17. package/_internal/49bbeed3.js +0 -5
  18. package/_internal/4daccdd5.js +0 -24
  19. package/_internal/4f4c0582.js +0 -2169
  20. package/_internal/5cef5e8c.js +0 -74
  21. package/_internal/6a60381c.js +0 -117
  22. package/_internal/6f084a40.js +0 -111
  23. package/_internal/76ddefd4.js +0 -61
  24. package/_internal/78df9309.js +0 -19
  25. package/_internal/7ad474e4.js +0 -98
  26. package/_internal/7b293665.js +0 -19
  27. package/_internal/7daf0f24.js +0 -76
  28. package/_internal/825ac334.js +0 -129
  29. package/_internal/827b804a.js +0 -5
  30. package/_internal/8bce732e.js +0 -8
  31. package/_internal/9d1336a1.js +0 -18
  32. package/_internal/a38bdcd0.js +0 -49
  33. package/_internal/b326655a.js +0 -682
  34. package/_internal/b83e864b.js +0 -76
  35. package/_internal/bace1bf1.js +0 -103
  36. package/_internal/c57190eb.js +0 -146
  37. package/_internal/components/alert-dialog/index-284fed80.js +0 -163
  38. package/_internal/components/autocomplete/__mockData__/index-96fc7ea7.js +0 -27
  39. package/_internal/components/autocomplete/index-27a49d5d.js +0 -261
  40. package/_internal/components/avatar/index-b8bc3cae.js +0 -83
  41. package/_internal/components/badge/index-9880f056.js +0 -81
  42. package/_internal/components/button/index-d919f96d.js +0 -47
  43. package/_internal/components/checkbox/index-dd478de9.js +0 -143
  44. package/_internal/components/chip/index-7f84cdbd.js +0 -102
  45. package/_internal/components/comment-block/index-e942de30.js +0 -138
  46. package/_internal/components/date-picker/index-a258d3ce.js +0 -596
  47. package/_internal/components/dialog/index-c7066813.js +0 -238
  48. package/_internal/components/divider/index-b6934baf.js +0 -50
  49. package/_internal/components/drag-handle/index-80e5af6c.js +0 -52
  50. package/_internal/components/dropdown/index-cebfc268.js +0 -147
  51. package/_internal/components/expansion-panel/index-9d45a211.js +0 -167
  52. package/_internal/components/flag/index-33e9d909.js +0 -59
  53. package/_internal/components/flex-box/index-0d6b6b43.js +0 -56
  54. package/_internal/components/generic-block/index-836c4352.js +0 -124
  55. package/_internal/components/grid/index-8c16a4f1.js +0 -104
  56. package/_internal/components/grid-column/index-4a2f56bb.js +0 -59
  57. package/_internal/components/heading/index-fd558a9a.js +0 -53
  58. package/_internal/components/icon/index-e7b9b40e.js +0 -1
  59. package/_internal/components/image-block/index-7021c2f1.js +0 -110
  60. package/_internal/components/image-lightbox/index-27017547.js +0 -759
  61. package/_internal/components/inline-list/index-52efec7f.js +0 -74
  62. package/_internal/components/input-helper/index-5a837e7c.js +0 -71
  63. package/_internal/components/input-label/index-0113f382.js +0 -59
  64. package/_internal/components/lightbox/index-fad5a9f2.js +0 -155
  65. package/_internal/components/link/index-008bae4b.js +0 -72
  66. package/_internal/components/link-preview/index-3e9c32f2.js +0 -117
  67. package/_internal/components/list/index-da88c6e9.js +0 -71
  68. package/_internal/components/message/index-17b568f2.js +0 -98
  69. package/_internal/components/mosaic/index-2d40e01c.js +0 -95
  70. package/_internal/components/navigation/index-dc17c639.js +0 -225
  71. package/_internal/components/notification/index-a1101015.js +0 -146
  72. package/_internal/components/popover/index-dbca63f1.js +0 -2
  73. package/_internal/components/popover-dialog/index-654d2abc.js +0 -66
  74. package/_internal/components/post-block/index-4b6b4dcb.js +0 -109
  75. package/_internal/components/progress/index-6f578c31.js +0 -182
  76. package/_internal/components/progress-tracker/index-700bc4c2.js +0 -309
  77. package/_internal/components/radio-button/index-89b725af.js +0 -149
  78. package/_internal/components/select/index-2755aa32.js +0 -458
  79. package/_internal/components/side-navigation/index-0bbe1fdd.js +0 -165
  80. package/_internal/components/skeleton/index-b2f8501c.js +0 -166
  81. package/_internal/components/slider/index-4f9b891b.js +0 -311
  82. package/_internal/components/slideshow/index-d4604589.js +0 -150
  83. package/_internal/components/switch/index-58fe0f0c.js +0 -122
  84. package/_internal/components/table/index-d541aa88.js +0 -297
  85. package/_internal/components/tabs/index-af1538d6.js +0 -298
  86. package/_internal/components/text/index-5bfc6d5e.js +0 -1
  87. package/_internal/components/text-field/index-47c98d09.js +0 -360
  88. package/_internal/components/thumbnail/index-71545d95.js +0 -41
  89. package/_internal/components/toolbar/index-7041a5a6.js +0 -61
  90. package/_internal/components/tooltip/index-8bb97e60.js +0 -327
  91. package/_internal/components/uploader/index-8f6f55de.js +0 -153
  92. package/_internal/components/user-block/index-70d4ce8f.js +0 -145
  93. package/_internal/d0e3f49e.js +0 -23
  94. package/_internal/de24f857.js +0 -3
  95. package/_internal/e806b848.js +0 -8
  96. package/_internal/e913a3af.js +0 -117
  97. package/_internal/ea04260d.js +0 -28
  98. package/_internal/eaf6c45a.js +0 -3
  99. package/_internal/ebdcb0c7.js +0 -60
  100. package/_internal/ef5d1aac.js +0 -3
  101. package/_internal/f0d7d6ea.js +0 -29
  102. package/_internal/utils/ClickAwayProvider/index-1234ce76.js +0 -94
  103. package/_internal/utils/MaterialThemeSwitcher/index-8d22de5a.js +0 -48
  104. package/_internal/utils/Portal/index-6e0a7404.js +0 -44
  105. package/_internal/utils/disabled/index-075b99c3.js +0 -36
  106. package/_internal/utils/type/index-ea9fc197.js +0 -2
@@ -1,74 +0,0 @@
1
- import classNames from 'classnames';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { u as useTheme } from './3181f000.js';
4
- import { FlexBox } from './components/flex-box/index-0d6b6b43.js';
5
- import { T as Text } from './e913a3af.js';
6
-
7
- /** Internal component used to render image captions */
8
- const ImageCaption = props => {
9
- const defaultTheme = useTheme();
10
- const {
11
- baseClassName,
12
- theme = defaultTheme,
13
- as = 'figcaption',
14
- title,
15
- titleProps,
16
- description,
17
- descriptionProps,
18
- tags,
19
- captionStyle,
20
- align,
21
- truncate
22
- } = props;
23
- if (!title && !description && !tags) return null;
24
- const titleColor = {
25
- color: theme === 'dark' ? 'light' : 'dark'
26
- };
27
- const baseColor = {
28
- color: theme === 'dark' ? 'light' : 'dark',
29
- colorVariant: 'L2'
30
- };
31
-
32
- // Display description as string or HTML
33
- const descriptionContent = typeof description === 'string' ? {
34
- children: description
35
- } : {
36
- dangerouslySetInnerHTML: description
37
- };
38
- return /*#__PURE__*/jsxs(FlexBox, {
39
- as: as,
40
- className: classNames(baseClassName && `${baseClassName}__wrapper`),
41
- style: captionStyle,
42
- orientation: "vertical",
43
- vAlign: align,
44
- hAlign: align === 'center' ? align : undefined,
45
- gap: "regular",
46
- children: [(title || description) && /*#__PURE__*/jsxs(Text, {
47
- as: "p",
48
- className: classNames(baseClassName && `${baseClassName}__caption`),
49
- truncate: truncate,
50
- ...baseColor,
51
- children: [title && /*#__PURE__*/jsx(Text, {
52
- ...titleProps,
53
- as: "span",
54
- className: classNames(titleProps?.className, baseClassName && `${baseClassName}__title`),
55
- typography: "subtitle1",
56
- ...titleColor,
57
- children: title
58
- }), ' ', description && /*#__PURE__*/jsx(Text, {
59
- ...descriptionProps,
60
- as: "span",
61
- className: classNames(descriptionProps?.className, baseClassName && `${baseClassName}__description`),
62
- typography: "body1",
63
- ...descriptionContent
64
- })]
65
- }), tags && /*#__PURE__*/jsx(FlexBox, {
66
- className: classNames(baseClassName && `${baseClassName}__tags`),
67
- orientation: "horizontal",
68
- vAlign: align,
69
- children: tags
70
- })]
71
- });
72
- };
73
-
74
- export { ImageCaption as I };
@@ -1,117 +0,0 @@
1
- import classNames from 'classnames';
2
- import './d0e3f49e.js';
3
- import { handleBasicClasses } from '@lumx/core/js/utils/className';
4
- import { f as forwardRef } from './8bce732e.js';
5
- import { R as RawClickable } from './2c2b6a89.js';
6
- import { jsx } from 'react/jsx-runtime';
7
- import { useDisableStateProps } from './utils/disabled/index-075b99c3.js';
8
- import { Emphasis, Theme, ColorPalette, CSS_PREFIX } from '@lumx/core/js/constants';
9
-
10
- /**
11
- * Component display name.
12
- */
13
- const COMPONENT_NAME = 'ButtonRoot';
14
- const BUTTON_WRAPPER_CLASSNAME = `${CSS_PREFIX}-button-wrapper`;
15
- const BUTTON_CLASSNAME = `${CSS_PREFIX}-button`;
16
-
17
- /**
18
- * Render a button wrapper with the ButtonRoot inside.
19
- *
20
- * @param props Component props.
21
- * @return React element.
22
- */
23
- const renderButtonWrapper = props => {
24
- const {
25
- color,
26
- emphasis,
27
- variant,
28
- fullWidth
29
- } = props;
30
- const adaptedColor = emphasis === Emphasis.low && (color === ColorPalette.light ? ColorPalette.dark : ColorPalette.light);
31
- const wrapperClassName = classNames(handleBasicClasses({
32
- color: adaptedColor,
33
- prefix: BUTTON_WRAPPER_CLASSNAME,
34
- variant,
35
- fullWidth
36
- }));
37
- const buttonProps = {
38
- ...props,
39
- hasBackground: false
40
- };
41
- return /*#__PURE__*/jsx("div", {
42
- className: wrapperClassName,
43
- children: /*#__PURE__*/jsx(ButtonRoot, {
44
- ...buttonProps
45
- })
46
- });
47
- };
48
-
49
- /**
50
- * ButtonRoot component.
51
- *
52
- * @param props Component props.
53
- * @param ref Component ref.
54
- * @return React element.
55
- */
56
- const ButtonRoot = forwardRef((props, ref) => {
57
- const {
58
- isAnyDisabled,
59
- disabledStateProps,
60
- otherProps
61
- } = useDisableStateProps(props);
62
- const {
63
- 'aria-label': ariaLabel,
64
- children,
65
- className,
66
- color,
67
- emphasis,
68
- hasBackground,
69
- isSelected,
70
- isActive,
71
- isFocused,
72
- isHovered,
73
- linkAs,
74
- size,
75
- theme,
76
- variant,
77
- fullWidth,
78
- ...forwardedProps
79
- } = otherProps;
80
- const adaptedColor = color || emphasis !== Emphasis.high && theme === Theme.dark && ColorPalette.light || emphasis === Emphasis.high && ColorPalette.primary || ColorPalette.dark;
81
- if (hasBackground) {
82
- return renderButtonWrapper({
83
- ...props,
84
- ref,
85
- variant,
86
- color: adaptedColor
87
- });
88
- }
89
- const buttonClassName = classNames(className, handleBasicClasses({
90
- color: adaptedColor,
91
- emphasis,
92
- isSelected,
93
- isDisabled: props.isDisabled || props['aria-disabled'],
94
- isActive,
95
- isFocused,
96
- isHovered,
97
- prefix: BUTTON_CLASSNAME,
98
- size,
99
- theme: emphasis === Emphasis.high && theme,
100
- variant,
101
- fullWidth
102
- }));
103
- return /*#__PURE__*/jsx(RawClickable, {
104
- as: linkAs || (forwardedProps.href ? 'a' : 'button'),
105
- ...forwardedProps,
106
- ...disabledStateProps,
107
- "aria-disabled": isAnyDisabled,
108
- "aria-label": ariaLabel,
109
- ref: ref,
110
- className: buttonClassName,
111
- children: children
112
- });
113
- });
114
- ButtonRoot.displayName = COMPONENT_NAME;
115
- ButtonRoot.defaultProps = {};
116
-
117
- export { ButtonRoot as B };
@@ -1,111 +0,0 @@
1
- import { useEffect } from 'react';
2
- import { D as DOCUMENT } from './d0e3f49e.js';
3
- import { g as getFocusableElements } from './230173a8.js';
4
- import { m as makeListenerTowerContext } from './76ddefd4.js';
5
-
6
- /**
7
- * Get first and last elements focusable in an element.
8
- *
9
- * @param parentElement The element in which to search focusable elements.
10
- * @return first and last focusable elements
11
- */
12
- function getFirstAndLastFocusable(parentElement) {
13
- const focusableElements = getFocusableElements(parentElement);
14
-
15
- // First non disabled element.
16
- const first = focusableElements[0];
17
- // Last non disabled element.
18
- const last = focusableElements[focusableElements.length - 1];
19
- if (last && first) {
20
- return {
21
- first,
22
- last
23
- };
24
- }
25
- return {};
26
- }
27
-
28
- const FOCUS_TRAPS = makeListenerTowerContext();
29
-
30
- /**
31
- * Trap 'Tab' focus switch inside the `focusZoneElement`.
32
- *
33
- * If multiple focus trap are activated, only the last one is maintained and when a focus trap closes, the previous one
34
- * gets activated again.
35
- *
36
- * @param focusZoneElement The element in which to trap the focus.
37
- * @param focusElement The element to focus when the focus trap is activated (otherwise the first focusable element
38
- * will be focused).
39
- */
40
- function useFocusTrap(focusZoneElement, focusElement) {
41
- useEffect(() => {
42
- // Body element can be undefined in SSR context.
43
- const rootElement = DOCUMENT?.body;
44
- if (!rootElement || !focusZoneElement) {
45
- return undefined;
46
- }
47
-
48
- // Use the shadow root as focusZoneElement when available
49
- const focusZoneElementOrShadowRoot = focusZoneElement.shadowRoot || focusZoneElement;
50
-
51
- // Trap 'Tab' key down focus switch into the focus zone.
52
- const trapTabFocusInFocusZone = evt => {
53
- const {
54
- key
55
- } = evt;
56
- if (key !== 'Tab') {
57
- return;
58
- }
59
- const focusable = getFirstAndLastFocusable(focusZoneElementOrShadowRoot);
60
-
61
- // Prevent focus switch if no focusable available.
62
- if (!focusable.first) {
63
- evt.preventDefault();
64
- return;
65
- }
66
- const activeElement = focusZoneElement.shadowRoot ? focusZoneElement.shadowRoot.activeElement : document.activeElement;
67
- if (
68
- // No previous focus
69
- !activeElement ||
70
- // Previous focus is at the end of the focus zone.
71
- !evt.shiftKey && activeElement === focusable.last ||
72
- // Previous focus is outside the focus zone
73
- !focusZoneElementOrShadowRoot.contains(activeElement)) {
74
- focusable.first.focus();
75
- evt.preventDefault();
76
- return;
77
- }
78
- if (
79
- // Focus order reversed
80
- evt.shiftKey &&
81
- // Previous focus is at the start of the focus zone.
82
- activeElement === focusable.first) {
83
- focusable.last.focus();
84
- evt.preventDefault();
85
- }
86
- };
87
- const focusTrap = {
88
- enable: () => rootElement.addEventListener('keydown', trapTabFocusInFocusZone),
89
- disable: () => rootElement.removeEventListener('keydown', trapTabFocusInFocusZone)
90
- };
91
-
92
- // SETUP:
93
- if (focusElement && focusZoneElementOrShadowRoot.contains(focusElement)) {
94
- // Focus the given element.
95
- focusElement.focus({
96
- preventScroll: true
97
- });
98
- } else {
99
- // Focus the first focusable element in the zone.
100
- getFirstAndLastFocusable(focusZoneElementOrShadowRoot).first?.focus({
101
- preventScroll: true
102
- });
103
- }
104
- FOCUS_TRAPS.register(focusTrap);
105
-
106
- // TEARDOWN:
107
- return () => FOCUS_TRAPS.unregister(focusTrap);
108
- }, [focusElement, focusZoneElement]);
109
- }
110
-
111
- export { getFirstAndLastFocusable as g, useFocusTrap as u };
@@ -1,61 +0,0 @@
1
- import { D as DOCUMENT } from './d0e3f49e.js';
2
- import { onEscapePressed } from '@lumx/core/js/utils';
3
- import { useEffect } from 'react';
4
- import last from 'lodash/last';
5
- import pull from 'lodash/pull';
6
-
7
- /**
8
- * Keep track of listeners, only the last registered listener gets activated at any point (previously registered
9
- * listener are disabled).
10
- * When a listener gets unregistered, the previously registered listener gets enabled again.
11
- */
12
- function makeListenerTowerContext() {
13
- const LISTENERS = [];
14
- return {
15
- register(listener) {
16
- // Disable previous listener.
17
- last(LISTENERS)?.disable();
18
- // Keep track of current listener.
19
- LISTENERS.push(listener);
20
- // Enable current listener.
21
- listener.enable();
22
- },
23
- unregister(listener) {
24
- // Disable current listener.
25
- listener.disable();
26
- // Remove current listener.
27
- pull(LISTENERS, listener);
28
- // Enable previous listener.
29
- last(LISTENERS)?.enable();
30
- }
31
- };
32
- }
33
-
34
- const LISTENERS = makeListenerTowerContext();
35
-
36
- /**
37
- * Register a global listener on 'Escape' key pressed.
38
- *
39
- * If multiple listener are registered, only the last one is maintained. When a listener is unregistered, the previous
40
- * one gets activated again.
41
- *
42
- * @param callback Callback
43
- * @param closeOnEscape Disables the hook when false
44
- */
45
- function useCallbackOnEscape(callback, closeOnEscape = true) {
46
- useEffect(() => {
47
- const rootElement = DOCUMENT?.body;
48
- if (!closeOnEscape || !callback || !rootElement) {
49
- return undefined;
50
- }
51
- const onKeyDown = onEscapePressed(callback);
52
- const listener = {
53
- enable: () => rootElement.addEventListener('keydown', onKeyDown),
54
- disable: () => rootElement.removeEventListener('keydown', onKeyDown)
55
- };
56
- LISTENERS.register(listener);
57
- return () => LISTENERS.unregister(listener);
58
- }, [callback, closeOnEscape]);
59
- }
60
-
61
- export { makeListenerTowerContext as m, useCallbackOnEscape as u };
@@ -1,19 +0,0 @@
1
- import get from 'lodash/get';
2
-
3
- /**
4
- * Properties of a component to use to determine it's name.
5
- * In the order of preference.
6
- */
7
- const NAME_PROPERTIES = ['type', 'type.displayName', 'displayName', 'name', 'type.name', 'props.mdxType', '_reactInternalFiber.elementType.name'];
8
- /**
9
- * Create a predicate function that checks if a ReactNode is a react element from the given component.
10
- *
11
- * @param component React function component or the component name
12
- * @return predicate returning true if value is instance of the component
13
- */
14
- const isComponent = component => instance => {
15
- const componentName = typeof component === 'string' ? component : component.displayName;
16
- return !!get(instance, '$$typeof') && NAME_PROPERTIES.some(nameProperty => get(instance, nameProperty) === componentName);
17
- };
18
-
19
- export { isComponent as i };
@@ -1,98 +0,0 @@
1
- import classNames from 'classnames';
2
- import isEmpty from 'lodash/isEmpty';
3
- import { getRootClassName, getBasicClass } from '@lumx/core/js/utils/className';
4
- import { u as useTheme, T as ThemeProvider } from './3181f000.js';
5
- import { f as forwardRef } from './8bce732e.js';
6
- import { B as ButtonRoot } from './6a60381c.js';
7
- import { jsxs, jsx } from 'react/jsx-runtime';
8
- import { i as isComponent } from './78df9309.js';
9
- import { T as Text } from './e913a3af.js';
10
- import { Emphasis, Size, Theme } from '@lumx/core/js/constants';
11
- import { I as Icon } from './bace1bf1.js';
12
-
13
- const ButtonEmphasis = Emphasis;
14
-
15
- /**
16
- * Defines the props of the component.
17
- */
18
-
19
- /**
20
- * Component display name.
21
- */
22
- const COMPONENT_NAME = 'Button';
23
-
24
- /**
25
- * Component default class name and class prefix.
26
- */
27
- const CLASSNAME = getRootClassName(COMPONENT_NAME);
28
-
29
- /**
30
- * Component default props.
31
- */
32
- const DEFAULT_PROPS = {
33
- emphasis: Emphasis.high,
34
- size: Size.m
35
- };
36
-
37
- /**
38
- * Button component.
39
- *
40
- * @param props Component props.
41
- * @param ref Component ref.
42
- * @return React element.
43
- */
44
- const Button = forwardRef((props, ref) => {
45
- const defaultTheme = useTheme() || Theme.light;
46
- const {
47
- children,
48
- className,
49
- emphasis = DEFAULT_PROPS.emphasis,
50
- leftIcon,
51
- rightIcon,
52
- size = DEFAULT_PROPS.size,
53
- theme = defaultTheme,
54
- ...forwardedProps
55
- } = props;
56
- const buttonClassName = classNames(className, getBasicClass({
57
- prefix: CLASSNAME,
58
- type: 'hasLeftIcon',
59
- value: !isEmpty(leftIcon)
60
- }), getBasicClass({
61
- prefix: CLASSNAME,
62
- type: 'hasRightIcon',
63
- value: !isEmpty(rightIcon)
64
- }));
65
- return /*#__PURE__*/jsxs(ButtonRoot, {
66
- ref: ref,
67
- emphasis,
68
- size,
69
- theme,
70
- ...forwardedProps,
71
- className: buttonClassName,
72
- variant: "button",
73
- children: [leftIcon && !isEmpty(leftIcon) &&
74
- /*#__PURE__*/
75
- // Theme is handled in the button scss
76
- jsx(ThemeProvider, {
77
- value: undefined,
78
- children: /*#__PURE__*/jsx(Icon, {
79
- icon: leftIcon
80
- })
81
- }), children && (isComponent(Text)(children) ? children : /*#__PURE__*/jsx("span", {
82
- children: children
83
- })), rightIcon && !isEmpty(rightIcon) &&
84
- /*#__PURE__*/
85
- // Theme is handled in the button scss
86
- jsx(ThemeProvider, {
87
- value: undefined,
88
- children: /*#__PURE__*/jsx(Icon, {
89
- icon: rightIcon
90
- })
91
- })]
92
- });
93
- });
94
- Button.displayName = COMPONENT_NAME;
95
- Button.className = CLASSNAME;
96
- Button.defaultProps = DEFAULT_PROPS;
97
-
98
- export { ButtonEmphasis as B, Button as a };
@@ -1,19 +0,0 @@
1
- import React__default, { Children } from 'react';
2
- import { i as isComponentType } from './e806b848.js';
3
- import { I as Icon } from './bace1bf1.js';
4
-
5
- /** Force wrap spaces around icons to make sure they are never stuck against text. */
6
- function wrapChildrenIconWithSpaces(children) {
7
- if (children === null || children === undefined) return undefined;
8
- return Children.toArray(children).flatMap(child => {
9
- if (isComponentType(Icon)(child)) {
10
- return [' ', child, ' '];
11
- }
12
- if (/*#__PURE__*/React__default.isValidElement(child) && child.props && typeof child.props === 'object' && 'children' in child.props) {
13
- return /*#__PURE__*/React__default.cloneElement(child, undefined, wrapChildrenIconWithSpaces(child.props.children));
14
- }
15
- return child;
16
- });
17
- }
18
-
19
- export { wrapChildrenIconWithSpaces as w };
@@ -1,76 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- const useRovingTabIndex = ({
4
- parentRef,
5
- elementSelector,
6
- keepTabIndex,
7
- onElementFocus,
8
- extraDependencies = []
9
- }) => {
10
- useEffect(() => {
11
- const parent = parentRef?.current;
12
- if (!parent) {
13
- return undefined;
14
- }
15
- const elements = parent.querySelectorAll(elementSelector);
16
- const initialFocusableElement = parent?.querySelector(`${elementSelector}[tabindex="0"]`);
17
- const handleKeyDown = index => evt => {
18
- let newTabFocus = index;
19
- if (!(evt.key === 'ArrowRight' || evt.key === 'ArrowLeft')) {
20
- return;
21
- }
22
- if (evt.key === 'ArrowRight') {
23
- // Move right
24
- newTabFocus += 1;
25
- // If we're at the end, go to the start
26
- if (newTabFocus >= elements.length) {
27
- newTabFocus = 0;
28
- }
29
- } else if (evt.key === 'ArrowLeft') {
30
- // Move left
31
- newTabFocus -= 1;
32
- if (newTabFocus < 0) {
33
- // If we're at the start, move to the end
34
- newTabFocus = elements.length - 1;
35
- }
36
- }
37
- const newElement = elements[newTabFocus];
38
- newElement?.focus();
39
-
40
- // When an element is focused using roving tab index, trigger the onElementFocus callback
41
- if (newElement && onElementFocus) {
42
- onElementFocus(newElement);
43
- }
44
- if (keepTabIndex) {
45
- evt.currentTarget.setAttribute('tabindex', '-1');
46
- newElement?.setAttribute('tabindex', '0');
47
- }
48
- };
49
- if (elements?.length > 0) {
50
- elements.forEach((el, key) => {
51
- // if no element has tabindex set to 0, set the first element as focusable
52
- if (!initialFocusableElement && key === 0) {
53
- el.setAttribute('tabindex', '0');
54
- // set all other to -1
55
- } else if (initialFocusableElement !== el) {
56
- el.setAttribute('tabindex', '-1');
57
- }
58
- // add event listener
59
- el.addEventListener('keydown', handleKeyDown(key));
60
- });
61
- }
62
-
63
- // Cleanup listeners
64
- return () => {
65
- if (elements?.length > 0) {
66
- elements.forEach((el, key) => {
67
- el.removeEventListener('keydown', handleKeyDown(key));
68
- });
69
- }
70
- };
71
- },
72
- // eslint-disable-next-line react-hooks/exhaustive-deps
73
- [parentRef, ...extraDependencies]);
74
- };
75
-
76
- export { useRovingTabIndex as u };