@hitachivantara/uikit-react-lab 6.1.9 → 6.1.10

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 (68) hide show
  1. package/dist/Blade/Blade.js +134 -173
  2. package/dist/Blade/Blade.styles.js +54 -69
  3. package/dist/Blades/Blades.js +70 -101
  4. package/dist/Blades/Blades.styles.js +7 -10
  5. package/dist/Dashboard/Dashboard.js +57 -60
  6. package/dist/Dashboard/Dashboard.styles.js +6 -10
  7. package/dist/Flow/Background/Background.js +10 -16
  8. package/dist/Flow/Controls/Controls.js +77 -91
  9. package/dist/Flow/DroppableFlow.js +135 -200
  10. package/dist/Flow/Empty/Empty.js +12 -9
  11. package/dist/Flow/Empty/Empty.styles.js +12 -15
  12. package/dist/Flow/Flow.js +28 -30
  13. package/dist/Flow/Flow.styles.js +12 -18
  14. package/dist/Flow/FlowContext/FlowContext.js +22 -23
  15. package/dist/Flow/FlowContext/NodeMetaContext.js +36 -39
  16. package/dist/Flow/Minimap/Minimap.js +15 -28
  17. package/dist/Flow/Minimap/Minimap.styles.js +4 -9
  18. package/dist/Flow/Node/BaseNode.js +144 -190
  19. package/dist/Flow/Node/BaseNode.styles.js +122 -133
  20. package/dist/Flow/Node/Node.js +90 -108
  21. package/dist/Flow/Node/Node.styles.js +30 -40
  22. package/dist/Flow/Node/Parameters/ParamRenderer.js +17 -14
  23. package/dist/Flow/Node/Parameters/Select.js +33 -38
  24. package/dist/Flow/Node/Parameters/Slider.js +27 -29
  25. package/dist/Flow/Node/Parameters/Text.js +17 -17
  26. package/dist/Flow/Node/utils.js +44 -49
  27. package/dist/Flow/Sidebar/Sidebar.js +115 -137
  28. package/dist/Flow/Sidebar/Sidebar.styles.js +21 -22
  29. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroup.js +57 -60
  30. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroup.styles.js +27 -33
  31. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/DraggableSidebarGroupItem.js +27 -47
  32. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.js +14 -32
  33. package/dist/Flow/Sidebar/SidebarGroup/SidebarGroupItem/SidebarGroupItem.styles.js +17 -23
  34. package/dist/Flow/base.js +5 -5
  35. package/dist/Flow/hooks/useFlowContext.js +5 -5
  36. package/dist/Flow/hooks/useFlowInstance.js +5 -4
  37. package/dist/Flow/hooks/useFlowNode.js +92 -113
  38. package/dist/Flow/hooks/useFlowNodeMeta.js +7 -7
  39. package/dist/Flow/hooks/useNode.js +136 -154
  40. package/dist/Flow/hooks/useNodeId.js +8 -7
  41. package/dist/Flow/nodes/DashboardNode.js +64 -86
  42. package/dist/Flow/nodes/DashboardNode.styles.js +8 -14
  43. package/dist/Flow/nodes/StickyNode.js +370 -435
  44. package/dist/StepNavigation/DefaultNavigation/DefaultNavigation.js +36 -52
  45. package/dist/StepNavigation/DefaultNavigation/Step/Step.js +40 -51
  46. package/dist/StepNavigation/DefaultNavigation/Step/Step.styles.js +22 -33
  47. package/dist/StepNavigation/DefaultNavigation/utils.js +38 -30
  48. package/dist/StepNavigation/SimpleNavigation/Dot/Dot.js +24 -41
  49. package/dist/StepNavigation/SimpleNavigation/Dot/Dot.styles.js +13 -16
  50. package/dist/StepNavigation/SimpleNavigation/SimpleNavigation.js +35 -47
  51. package/dist/StepNavigation/SimpleNavigation/utils.js +10 -11
  52. package/dist/StepNavigation/StepNavigation.js +136 -179
  53. package/dist/StepNavigation/StepNavigation.styles.js +29 -32
  54. package/dist/Wizard/Wizard.js +81 -104
  55. package/dist/Wizard/Wizard.styles.js +4 -7
  56. package/dist/Wizard/WizardActions/WizardActions.js +111 -131
  57. package/dist/Wizard/WizardActions/WizardActions.styles.js +19 -20
  58. package/dist/Wizard/WizardContainer/WizardContainer.js +19 -28
  59. package/dist/Wizard/WizardContainer/WizardContainer.styles.js +8 -14
  60. package/dist/Wizard/WizardContent/WizardContent.js +103 -120
  61. package/dist/Wizard/WizardContent/WizardContent.styles.js +33 -36
  62. package/dist/Wizard/WizardContext/WizardContext.js +10 -13
  63. package/dist/Wizard/WizardTitle/WizardTitle.js +74 -79
  64. package/dist/Wizard/WizardTitle/WizardTitle.styles.js +12 -15
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +30 -81
  67. package/package.json +6 -6
  68. package/dist/StepNavigation/utils.js +0 -8
@@ -1,175 +1,136 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useCallback, useMemo, useRef, useState, useEffect } from "react";
3
- import { useDefaultProps, useControlled, useUniqueId, setId, HvTypography } from "@hitachivantara/uikit-react-core";
4
1
  import { useClasses } from "./Blade.styles.js";
5
- import { staticClasses } from "./Blade.styles.js";
6
- const HvBlade = (props) => {
7
- const {
8
- id: idProp,
9
- className,
10
- classes: classesProp,
11
- expanded,
12
- defaultExpanded = false,
13
- label,
14
- labelVariant = "label",
15
- headingLevel,
16
- onChange,
17
- disabled = false,
18
- children,
19
- fullWidth,
20
- buttonProps,
21
- containerProps,
22
- ...others
23
- } = useDefaultProps("HvBlade", props);
24
- const { classes, cx } = useClasses(classesProp);
25
- const [isExpanded, setIsExpanded] = useControlled(
26
- expanded,
27
- Boolean(defaultExpanded)
28
- );
29
- const handleAction = useCallback(
30
- (event) => {
31
- if (!disabled) {
32
- onChange?.(event, !isExpanded);
33
- setIsExpanded(!isExpanded);
34
- return true;
35
- }
36
- return false;
37
- },
38
- [disabled, onChange, isExpanded, setIsExpanded]
39
- );
40
- const handleClick = useCallback(
41
- (event) => {
42
- handleAction(event);
43
- event.preventDefault();
44
- event.stopPropagation();
45
- },
46
- [handleAction]
47
- );
48
- const handleKeyDown = useCallback(
49
- (event) => {
50
- let isEventHandled = false;
51
- const { key } = event;
52
- if (event.altKey || event.ctrlKey || event.metaKey || event.currentTarget !== event.target) {
53
- return;
54
- }
55
- switch (key) {
56
- case "Enter":
57
- case " ":
58
- isEventHandled = handleAction(event);
59
- break;
60
- default:
61
- return;
62
- }
63
- if (isEventHandled) {
64
- event.preventDefault();
65
- event.stopPropagation();
66
- }
67
- },
68
- [handleAction]
69
- );
70
- const id = useUniqueId(idProp);
71
- const bladeHeaderId = setId(id, "button");
72
- const bladeContainerId = setId(id, "container");
73
- const bladeHeader = useMemo(() => {
74
- const buttonLabel = typeof label === "function" ? label(isExpanded) : label;
75
- const bladeButton = /* @__PURE__ */ jsx(
76
- HvTypography,
77
- {
78
- id: bladeHeaderId,
79
- component: "div",
80
- role: "button",
81
- className: cx(classes.button, {
82
- [classes.textOnlyLabel]: typeof buttonLabel === "string",
83
- [classes.disabled]: disabled
84
- }),
85
- style: { flexShrink: headingLevel === void 0 ? 0 : void 0 },
86
- disabled,
87
- tabIndex: 0,
88
- onKeyDown: handleKeyDown,
89
- onClick: handleClick,
90
- variant: labelVariant,
91
- "aria-expanded": isExpanded,
92
- "aria-controls": bladeContainerId,
93
- ...buttonProps,
94
- children: buttonLabel
95
- }
96
- );
97
- return headingLevel === void 0 ? bladeButton : /* @__PURE__ */ jsx(
98
- HvTypography,
99
- {
100
- component: `h${headingLevel}`,
101
- variant: labelVariant,
102
- className: classes.heading,
103
- style: { flexShrink: 0 },
104
- children: bladeButton
105
- }
106
- );
107
- }, [
108
- bladeContainerId,
109
- bladeHeaderId,
110
- buttonProps,
111
- classes.button,
112
- classes.disabled,
113
- classes.heading,
114
- classes.textOnlyLabel,
115
- cx,
116
- disabled,
117
- handleClick,
118
- handleKeyDown,
119
- headingLevel,
120
- isExpanded,
121
- label,
122
- labelVariant
123
- ]);
124
- const bladeRef = useRef(null);
125
- const [maxWidth, setMaxWidth] = useState(void 0);
126
- useEffect(() => {
127
- if (!bladeRef.current) return;
128
- const resizeObserver = new ResizeObserver((entries) => {
129
- setMaxWidth(entries[0].target.clientWidth);
130
- });
131
- resizeObserver.observe(
132
- // using the blade's container as reference max-width is more stable
133
- bladeRef.current.parentElement ?? bladeRef.current
134
- );
135
- return () => {
136
- resizeObserver.disconnect();
137
- };
138
- }, [isExpanded]);
139
- const { style: containerStyle, ...otherContainerProps } = containerProps || {};
140
- return /* @__PURE__ */ jsxs(
141
- "div",
142
- {
143
- ref: bladeRef,
144
- id: idProp,
145
- className: cx(classes.root, className, {
146
- [classes.fullWidth]: fullWidth,
147
- [classes.expanded]: isExpanded
148
- }),
149
- ...others,
150
- children: [
151
- bladeHeader,
152
- /* @__PURE__ */ jsx(
153
- "div",
154
- {
155
- id: bladeContainerId,
156
- role: "region",
157
- "aria-labelledby": bladeHeaderId,
158
- className: classes.container,
159
- hidden: !isExpanded,
160
- style: {
161
- ...containerStyle,
162
- maxWidth: isExpanded ? maxWidth : 0
163
- },
164
- ...otherContainerProps,
165
- children
166
- }
167
- )
168
- ]
169
- }
170
- );
171
- };
172
- export {
173
- HvBlade,
174
- staticClasses as bladeClasses
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import { HvTypography, setId, useControlled, useDefaultProps, useUniqueId } from "@hitachivantara/uikit-react-core";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/Blade/Blade.tsx
6
+ /**
7
+ * A blade is a design element that expands horizontally to reveal information, similar to an accordion.
8
+ *
9
+ * It is usually stacked horizontally with other blades and works best when used within a flex container.
10
+ * The `HvBlades` component is recommended for this purpose, as it also provides better management of the
11
+ * blades' expanded state.
12
+ */
13
+ var HvBlade = (props) => {
14
+ const { id: idProp, className, classes: classesProp, expanded, defaultExpanded = false, label, labelVariant = "label", headingLevel, onChange, disabled = false, children, fullWidth, buttonProps, containerProps, ...others } = useDefaultProps("HvBlade", props);
15
+ const { classes, cx } = useClasses(classesProp);
16
+ const [isExpanded, setIsExpanded] = useControlled(expanded, Boolean(defaultExpanded));
17
+ const handleAction = useCallback((event) => {
18
+ if (!disabled) {
19
+ onChange?.(event, !isExpanded);
20
+ setIsExpanded(!isExpanded);
21
+ return true;
22
+ }
23
+ return false;
24
+ }, [
25
+ disabled,
26
+ onChange,
27
+ isExpanded,
28
+ setIsExpanded
29
+ ]);
30
+ const handleClick = useCallback((event) => {
31
+ handleAction(event);
32
+ event.preventDefault();
33
+ event.stopPropagation();
34
+ }, [handleAction]);
35
+ const handleKeyDown = useCallback((event) => {
36
+ let isEventHandled = false;
37
+ const { key } = event;
38
+ if (event.altKey || event.ctrlKey || event.metaKey || event.currentTarget !== event.target) return;
39
+ switch (key) {
40
+ case "Enter":
41
+ case " ":
42
+ isEventHandled = handleAction(event);
43
+ break;
44
+ default: return;
45
+ }
46
+ if (isEventHandled) {
47
+ event.preventDefault();
48
+ event.stopPropagation();
49
+ }
50
+ }, [handleAction]);
51
+ const id = useUniqueId(idProp);
52
+ const bladeHeaderId = setId(id, "button");
53
+ const bladeContainerId = setId(id, "container");
54
+ const bladeHeader = useMemo(() => {
55
+ const buttonLabel = typeof label === "function" ? label(isExpanded) : label;
56
+ const bladeButton = /* @__PURE__ */ jsx(HvTypography, {
57
+ id: bladeHeaderId,
58
+ component: "div",
59
+ role: "button",
60
+ className: cx(classes.button, {
61
+ [classes.textOnlyLabel]: typeof buttonLabel === "string",
62
+ [classes.disabled]: disabled
63
+ }),
64
+ style: { flexShrink: headingLevel === void 0 ? 0 : void 0 },
65
+ disabled,
66
+ tabIndex: 0,
67
+ onKeyDown: handleKeyDown,
68
+ onClick: handleClick,
69
+ variant: labelVariant,
70
+ "aria-expanded": isExpanded,
71
+ "aria-controls": bladeContainerId,
72
+ ...buttonProps,
73
+ children: buttonLabel
74
+ });
75
+ return headingLevel === void 0 ? bladeButton : /* @__PURE__ */ jsx(HvTypography, {
76
+ component: `h${headingLevel}`,
77
+ variant: labelVariant,
78
+ className: classes.heading,
79
+ style: { flexShrink: 0 },
80
+ children: bladeButton
81
+ });
82
+ }, [
83
+ bladeContainerId,
84
+ bladeHeaderId,
85
+ buttonProps,
86
+ classes.button,
87
+ classes.disabled,
88
+ classes.heading,
89
+ classes.textOnlyLabel,
90
+ cx,
91
+ disabled,
92
+ handleClick,
93
+ handleKeyDown,
94
+ headingLevel,
95
+ isExpanded,
96
+ label,
97
+ labelVariant
98
+ ]);
99
+ const bladeRef = useRef(null);
100
+ const [maxWidth, setMaxWidth] = useState(void 0);
101
+ useEffect(() => {
102
+ if (!bladeRef.current) return;
103
+ const resizeObserver = new ResizeObserver((entries) => {
104
+ setMaxWidth(entries[0].target.clientWidth);
105
+ });
106
+ resizeObserver.observe(bladeRef.current.parentElement ?? bladeRef.current);
107
+ return () => {
108
+ resizeObserver.disconnect();
109
+ };
110
+ }, [isExpanded]);
111
+ const { style: containerStyle, ...otherContainerProps } = containerProps || {};
112
+ return /* @__PURE__ */ jsxs("div", {
113
+ ref: bladeRef,
114
+ id: idProp,
115
+ className: cx(classes.root, className, {
116
+ [classes.fullWidth]: fullWidth,
117
+ [classes.expanded]: isExpanded
118
+ }),
119
+ ...others,
120
+ children: [bladeHeader, /* @__PURE__ */ jsx("div", {
121
+ id: bladeContainerId,
122
+ role: "region",
123
+ "aria-labelledby": bladeHeaderId,
124
+ className: classes.container,
125
+ hidden: !isExpanded,
126
+ style: {
127
+ ...containerStyle,
128
+ maxWidth: isExpanded ? maxWidth : 0
129
+ },
130
+ ...otherContainerProps,
131
+ children
132
+ })]
133
+ });
175
134
  };
135
+ //#endregion
136
+ export { HvBlade };
@@ -1,71 +1,56 @@
1
1
  import { createClasses, outlineStyles } from "@hitachivantara/uikit-react-core";
2
- import { theme } from "@hitachivantara/uikit-styles";
3
- const { staticClasses, useClasses } = createClasses("HvBlade", {
4
- root: {
5
- position: "relative",
6
- display: "flex",
7
- minWidth: 72,
8
- "& + $root": {
9
- marginLeft: theme.spacing("sm")
10
- },
11
- transition: "flex-grow 600ms linear",
12
- zIndex: 0,
13
- color: theme.colors.text,
14
- backgroundColor: theme.colors.bgContainer,
15
- borderRadius: theme.radii.round,
16
- border: `1px solid ${theme.colors.border}`
17
- },
18
- expanded: {},
19
- fullWidth: {
20
- flexGrow: 0,
21
- "&$expanded": {
22
- flexGrow: 1
23
- }
24
- },
25
- heading: {},
26
- button: {
27
- height: "100%",
28
- minWidth: 70,
29
- "&[disabled], &:active": {
30
- outline: "none"
31
- },
32
- "&:focus": {
33
- outline: "none",
34
- background: theme.colors.bgHover
35
- },
36
- "&:hover": {
37
- background: theme.colors.bgHover
38
- },
39
- "&:focus-visible": {
40
- ...outlineStyles,
41
- zIndex: 1
42
- },
43
- cursor: "pointer"
44
- },
45
- textOnlyLabel: {
46
- padding: theme.spacing("xs", "sm")
47
- },
48
- container: {
49
- display: "inline-block",
50
- height: "100%",
51
- width: "100%",
52
- minWidth: 0,
53
- overflowX: "hidden",
54
- maxWidth: 0,
55
- transition: "max-width 600ms linear"
56
- },
57
- disabled: {
58
- cursor: "not-allowed",
59
- color: theme.colors.textDisabled,
60
- "&:focus": {
61
- background: "none"
62
- },
63
- "&:hover": {
64
- background: "none"
65
- }
66
- }
2
+ import { theme as theme$1 } from "@hitachivantara/uikit-styles";
3
+ //#region src/Blade/Blade.styles.tsx
4
+ var { staticClasses, useClasses } = createClasses("HvBlade", {
5
+ root: {
6
+ position: "relative",
7
+ display: "flex",
8
+ minWidth: 72,
9
+ "& + $root": { marginLeft: theme$1.spacing("sm") },
10
+ transition: "flex-grow 600ms linear",
11
+ zIndex: 0,
12
+ color: theme$1.colors.text,
13
+ backgroundColor: theme$1.colors.bgContainer,
14
+ borderRadius: theme$1.radii.round,
15
+ border: `1px solid ${theme$1.colors.border}`
16
+ },
17
+ expanded: {},
18
+ fullWidth: {
19
+ flexGrow: 0,
20
+ "&$expanded": { flexGrow: 1 }
21
+ },
22
+ heading: {},
23
+ button: {
24
+ height: "100%",
25
+ minWidth: 70,
26
+ "&[disabled], &:active": { outline: "none" },
27
+ "&:focus": {
28
+ outline: "none",
29
+ background: theme$1.colors.bgHover
30
+ },
31
+ "&:hover": { background: theme$1.colors.bgHover },
32
+ "&:focus-visible": {
33
+ ...outlineStyles,
34
+ zIndex: 1
35
+ },
36
+ cursor: "pointer"
37
+ },
38
+ textOnlyLabel: { padding: theme$1.spacing("xs", "sm") },
39
+ container: {
40
+ display: "inline-block",
41
+ height: "100%",
42
+ width: "100%",
43
+ minWidth: 0,
44
+ overflowX: "hidden",
45
+ maxWidth: 0,
46
+ transition: "max-width 600ms linear"
47
+ },
48
+ disabled: {
49
+ cursor: "not-allowed",
50
+ color: theme$1.colors.textDisabled,
51
+ "&:focus": { background: "none" },
52
+ "&:hover": { background: "none" }
53
+ }
67
54
  });
68
- export {
69
- staticClasses,
70
- useClasses
71
- };
55
+ //#endregion
56
+ export { staticClasses, useClasses };
@@ -1,105 +1,74 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { useCallback, useMemo, Children, cloneElement } from "react";
3
- import { useDefaultProps, useControlled } from "@hitachivantara/uikit-react-core";
4
1
  import { useClasses } from "./Blades.styles.js";
5
- import { staticClasses } from "./Blades.styles.js";
2
+ import { Children, cloneElement, useCallback, useMemo } from "react";
3
+ import { useControlled, useDefaultProps } from "@hitachivantara/uikit-react-core";
4
+ import { jsx } from "react/jsx-runtime";
5
+ //#region src/Blades/Blades.tsx
6
6
  function getExpandedBlades(defaultExpanded, children, atMostOneExpanded, atLeastOneExpanded) {
7
- const childrenArray = Children.toArray(children);
8
- const expandedBlades = defaultExpanded ?? childrenArray.map((child, i) => {
9
- const childIsControlled = child?.props?.expanded !== void 0;
10
- const childIsExpanded = childIsControlled ? child?.props?.expanded : child?.props?.defaultExpanded;
11
- return childIsExpanded ? i : void 0;
12
- }).filter((v) => v !== void 0);
13
- const numberOfExpandedBlades = expandedBlades.length;
14
- if (atLeastOneExpanded && numberOfExpandedBlades === 0 && childrenArray.length > 0) {
15
- return [0];
16
- }
17
- if (atMostOneExpanded && numberOfExpandedBlades > 1) {
18
- return [expandedBlades[0]];
19
- }
20
- return expandedBlades;
7
+ const childrenArray = Children.toArray(children);
8
+ const expandedBlades = defaultExpanded ?? childrenArray.map((child, i) => {
9
+ return (child?.props?.expanded !== void 0 ? child?.props?.expanded : child?.props?.defaultExpanded) ? i : void 0;
10
+ }).filter((v) => v !== void 0);
11
+ const numberOfExpandedBlades = expandedBlades.length;
12
+ if (atLeastOneExpanded && numberOfExpandedBlades === 0 && childrenArray.length > 0) return [0];
13
+ if (atMostOneExpanded && numberOfExpandedBlades > 1) return [expandedBlades[0]];
14
+ return expandedBlades;
21
15
  }
22
- const HvBlades = (props) => {
23
- const {
24
- id,
25
- className,
26
- classes: classesProp,
27
- children,
28
- expanded: expandedProp,
29
- defaultExpanded,
30
- atMostOneExpanded = false,
31
- atLeastOneExpanded = false,
32
- fullWidthBlades = false,
33
- onChange,
34
- ...others
35
- } = useDefaultProps("HvBlades", props);
36
- const { classes, cx } = useClasses(classesProp);
37
- const [expanded, setExpanded] = useControlled(
38
- expandedProp,
39
- () => getExpandedBlades(
40
- defaultExpanded,
41
- children,
42
- atMostOneExpanded,
43
- atLeastOneExpanded
44
- )
45
- );
46
- const onChildChangeInterceptor = useCallback(
47
- (index, childOnChange, event, isExpanded) => {
48
- const newValue = [];
49
- if (atMostOneExpanded) {
50
- if (isExpanded) {
51
- newValue.push(index);
52
- }
53
- } else {
54
- newValue.push(...expanded);
55
- if (isExpanded) {
56
- newValue.push(index);
57
- } else {
58
- newValue.splice(newValue.indexOf(index), 1);
59
- }
60
- }
61
- if (atLeastOneExpanded && newValue.length === 0) {
62
- newValue.push(index);
63
- }
64
- childOnChange?.(event, isExpanded);
65
- onChange?.(event, newValue);
66
- setExpanded(newValue);
67
- },
68
- [onChange, expanded, setExpanded, atMostOneExpanded, atLeastOneExpanded]
69
- );
70
- const modifiedChildren = useMemo(() => {
71
- return Children.map(children, (child, i) => {
72
- const childIsExpanded = expanded.includes(i);
73
- return cloneElement(child, {
74
- expanded: childIsExpanded,
75
- fullWidth: child?.props?.fullWidth ?? fullWidthBlades,
76
- buttonProps: {
77
- ...child?.props?.buttonProps,
78
- "aria-disabled": (
79
- // If the accordion panel associated with an accordion header is visible,
80
- // and if the accordion does not permit the panel to be collapsed, the header
81
- // button element has aria-disabled set to true.
82
- child?.props?.disabled || childIsExpanded && atMostOneExpanded && expanded.length === 1 ? true : void 0
83
- )
84
- },
85
- onChange: (event, isExpanded) => onChildChangeInterceptor(
86
- i,
87
- child?.props?.onChange,
88
- event,
89
- isExpanded
90
- )
91
- });
92
- });
93
- }, [
94
- children,
95
- expanded,
96
- fullWidthBlades,
97
- atMostOneExpanded,
98
- onChildChangeInterceptor
99
- ]);
100
- return /* @__PURE__ */ jsx("div", { id, className: cx(classes.root, className), ...others, children: modifiedChildren });
101
- };
102
- export {
103
- HvBlades,
104
- staticClasses as bladesClasses
16
+ /**
17
+ * `HvBlades` is a component that groups multiple `HvBlade` components.
18
+ *
19
+ * It allows for better control over the expanded state of blades, suitable for both
20
+ * controlled and uncontrolled scenarios.
21
+ */
22
+ var HvBlades = (props) => {
23
+ const { id, className, classes: classesProp, children, expanded: expandedProp, defaultExpanded, atMostOneExpanded = false, atLeastOneExpanded = false, fullWidthBlades = false, onChange, ...others } = useDefaultProps("HvBlades", props);
24
+ const { classes, cx } = useClasses(classesProp);
25
+ const [expanded, setExpanded] = useControlled(expandedProp, () => getExpandedBlades(defaultExpanded, children, atMostOneExpanded, atLeastOneExpanded));
26
+ const onChildChangeInterceptor = useCallback((index, childOnChange, event, isExpanded) => {
27
+ const newValue = [];
28
+ if (atMostOneExpanded) {
29
+ if (isExpanded) newValue.push(index);
30
+ } else {
31
+ newValue.push(...expanded);
32
+ if (isExpanded) newValue.push(index);
33
+ else newValue.splice(newValue.indexOf(index), 1);
34
+ }
35
+ if (atLeastOneExpanded && newValue.length === 0) newValue.push(index);
36
+ childOnChange?.(event, isExpanded);
37
+ onChange?.(event, newValue);
38
+ setExpanded(newValue);
39
+ }, [
40
+ onChange,
41
+ expanded,
42
+ setExpanded,
43
+ atMostOneExpanded,
44
+ atLeastOneExpanded
45
+ ]);
46
+ const modifiedChildren = useMemo(() => {
47
+ return Children.map(children, (child, i) => {
48
+ const childIsExpanded = expanded.includes(i);
49
+ return cloneElement(child, {
50
+ expanded: childIsExpanded,
51
+ fullWidth: child?.props?.fullWidth ?? fullWidthBlades,
52
+ buttonProps: {
53
+ ...child?.props?.buttonProps,
54
+ "aria-disabled": child?.props?.disabled || childIsExpanded && atMostOneExpanded && expanded.length === 1 ? true : void 0
55
+ },
56
+ onChange: (event, isExpanded) => onChildChangeInterceptor(i, child?.props?.onChange, event, isExpanded)
57
+ });
58
+ });
59
+ }, [
60
+ children,
61
+ expanded,
62
+ fullWidthBlades,
63
+ atMostOneExpanded,
64
+ onChildChangeInterceptor
65
+ ]);
66
+ return /* @__PURE__ */ jsx("div", {
67
+ id,
68
+ className: cx(classes.root, className),
69
+ ...others,
70
+ children: modifiedChildren
71
+ });
105
72
  };
73
+ //#endregion
74
+ export { HvBlades };
@@ -1,11 +1,8 @@
1
1
  import { createClasses } from "@hitachivantara/uikit-react-core";
2
- const { staticClasses, useClasses } = createClasses("HvBlades", {
3
- root: {
4
- position: "relative",
5
- display: "flex"
6
- }
7
- });
8
- export {
9
- staticClasses,
10
- useClasses
11
- };
2
+ //#region src/Blades/Blades.styles.tsx
3
+ var { staticClasses, useClasses } = createClasses("HvBlades", { root: {
4
+ position: "relative",
5
+ display: "flex"
6
+ } });
7
+ //#endregion
8
+ export { staticClasses, useClasses };