@hitachivantara/uikit-react-lab 5.22.2 → 5.23.0

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.
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("@emotion/react/jsx-runtime");
4
+ const React = require("react");
5
+ const uikitReactCore = require("@hitachivantara/uikit-react-core");
6
+ const Blade_styles = require("./Blade.styles.cjs");
7
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
8
+ const React__default = /* @__PURE__ */ _interopDefault(React);
9
+ const HvBlade = (props) => {
10
+ const {
11
+ id: idProp,
12
+ className,
13
+ classes: classesProp,
14
+ expanded,
15
+ defaultExpanded = false,
16
+ label,
17
+ labelVariant = "label",
18
+ headingLevel,
19
+ onChange,
20
+ disabled = false,
21
+ children,
22
+ fullWidth,
23
+ buttonProps,
24
+ containerProps,
25
+ ...others
26
+ } = uikitReactCore.useDefaultProps("HvBlade", props);
27
+ const { classes, cx } = Blade_styles.useClasses(classesProp);
28
+ const [isExpanded, setIsExpanded] = uikitReactCore.useControlled(
29
+ expanded,
30
+ Boolean(defaultExpanded)
31
+ );
32
+ const handleAction = React.useCallback(
33
+ (event) => {
34
+ if (!disabled) {
35
+ onChange?.(event, !isExpanded);
36
+ setIsExpanded(!isExpanded);
37
+ return true;
38
+ }
39
+ return false;
40
+ },
41
+ [disabled, onChange, isExpanded, setIsExpanded]
42
+ );
43
+ const handleClick = React.useCallback(
44
+ (event) => {
45
+ handleAction(event);
46
+ event.preventDefault();
47
+ event.stopPropagation();
48
+ },
49
+ [handleAction]
50
+ );
51
+ const handleKeyDown = React.useCallback(
52
+ (event) => {
53
+ let isEventHandled = false;
54
+ const { key } = event;
55
+ if (event.altKey || event.ctrlKey || event.metaKey || event.currentTarget !== event.target) {
56
+ return;
57
+ }
58
+ switch (key) {
59
+ case "Enter":
60
+ case " ":
61
+ isEventHandled = handleAction(event);
62
+ break;
63
+ default:
64
+ return;
65
+ }
66
+ if (isEventHandled) {
67
+ event.preventDefault();
68
+ event.stopPropagation();
69
+ }
70
+ },
71
+ [handleAction]
72
+ );
73
+ const id = uikitReactCore.useUniqueId(idProp, "hvblade");
74
+ const bladeHeaderId = uikitReactCore.setId(id, "button");
75
+ const bladeContainerId = uikitReactCore.setId(id, "container");
76
+ const bladeHeader = React.useMemo(() => {
77
+ const buttonLabel = typeof label === "function" ? label(isExpanded) : label;
78
+ const bladeButton = /* @__PURE__ */ jsxRuntime.jsx(
79
+ uikitReactCore.HvTypography,
80
+ {
81
+ id: bladeHeaderId,
82
+ component: "div",
83
+ role: "button",
84
+ className: cx(classes.button, {
85
+ [classes.disabled]: disabled,
86
+ [classes.textOnlyLabel]: typeof buttonLabel === "string"
87
+ }),
88
+ style: { flexShrink: headingLevel === void 0 ? 0 : void 0 },
89
+ disabled,
90
+ tabIndex: 0,
91
+ onKeyDown: handleKeyDown,
92
+ onClick: handleClick,
93
+ variant: labelVariant,
94
+ "aria-expanded": isExpanded,
95
+ "aria-controls": bladeContainerId,
96
+ ...buttonProps,
97
+ children: buttonLabel
98
+ }
99
+ );
100
+ return headingLevel === void 0 ? bladeButton : /* @__PURE__ */ jsxRuntime.jsx(
101
+ uikitReactCore.HvTypography,
102
+ {
103
+ component: `h${headingLevel}`,
104
+ variant: labelVariant,
105
+ className: classes.heading,
106
+ style: { flexShrink: 0 },
107
+ children: bladeButton
108
+ }
109
+ );
110
+ }, [
111
+ bladeContainerId,
112
+ bladeHeaderId,
113
+ buttonProps,
114
+ classes.button,
115
+ classes.disabled,
116
+ classes.heading,
117
+ classes.textOnlyLabel,
118
+ cx,
119
+ disabled,
120
+ handleClick,
121
+ handleKeyDown,
122
+ headingLevel,
123
+ isExpanded,
124
+ label,
125
+ labelVariant
126
+ ]);
127
+ const bladeRef = React__default.default.useRef(null);
128
+ const maxWidthRef = React__default.default.useRef(0);
129
+ React.useEffect(() => {
130
+ if (bladeRef.current) {
131
+ maxWidthRef.current = bladeRef.current.parentElement?.clientWidth || 0;
132
+ }
133
+ }, []);
134
+ const { style: containerStyle, ...otherContainerProps } = containerProps || {};
135
+ return /* @__PURE__ */ jsxRuntime.jsxs(
136
+ "div",
137
+ {
138
+ ref: bladeRef,
139
+ id: idProp,
140
+ className: cx(classes.root, className, {
141
+ [classes.fullWidth]: fullWidth,
142
+ [classes.expanded]: isExpanded
143
+ }),
144
+ ...others,
145
+ children: [
146
+ bladeHeader,
147
+ /* @__PURE__ */ jsxRuntime.jsx(
148
+ "div",
149
+ {
150
+ id: bladeContainerId,
151
+ role: "region",
152
+ "aria-labelledby": bladeHeaderId,
153
+ className: classes.container,
154
+ hidden: !isExpanded,
155
+ style: {
156
+ ...containerStyle,
157
+ maxWidth: isExpanded ? maxWidthRef.current : 0
158
+ },
159
+ ...otherContainerProps,
160
+ children
161
+ }
162
+ )
163
+ ]
164
+ }
165
+ );
166
+ };
167
+ exports.bladeClasses = Blade_styles.staticClasses;
168
+ exports.HvBlade = HvBlade;
169
+ //# sourceMappingURL=Blade.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blade.cjs","sources":["../../../src/Blade/Blade.tsx"],"sourcesContent":["import React, {\n SyntheticEvent,\n useCallback,\n useMemo,\n HTMLAttributes,\n useEffect,\n} from \"react\";\n\nimport {\n ExtractNames,\n HvBaseProps,\n HvTypography,\n HvTypographyVariants,\n setId,\n useControlled,\n useDefaultProps,\n useUniqueId,\n} from \"@hitachivantara/uikit-react-core\";\n\nimport { staticClasses, useClasses } from \"./Blade.styles\";\n\nexport { staticClasses as bladeClasses };\n\nexport type HvBladeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvBladeProps\n extends HvBaseProps<HTMLDivElement, \"onChange\" | \"children\"> {\n /**\n * The content that will be rendered within the blade.\n */\n children: React.ReactNode;\n\n /**\n * The content of the blade's button.\n *\n * If a render function is provided, it will be called with the expanded state as an argument.\n */\n label?: React.ReactNode | ((expanded: boolean) => React.ReactNode);\n /**\n * Typography variant for the blade's button label.\n */\n labelVariant?: HvTypographyVariants;\n /**\n * Heading Level to apply to blade button.\n *\n * If 'undefined', the button will not have a header wrapper.\n */\n headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;\n\n /**\n * Indicates whether the blade is expanded or not.\n *\n * When defined the expanded state becomes controlled.\n *\n * @default undefined\n */\n expanded?: boolean;\n /**\n * Specifies the initial expanded state of the blade when it is uncontrolled.\n */\n defaultExpanded?: boolean;\n\n /**\n * Callback function triggered when the blade's button is pressed.\n * It receives the event and the new expanded state as arguments.\n *\n * If the blade is uncontrolled, this new state will be effective.\n * If the blade is controlled, it is up to the parent component to manage this state.\n *\n * @param {SyntheticEvent} event The event source of the callback.\n * @param {boolean} value The new value.\n */\n onChange?: (event: React.SyntheticEvent, value: boolean) => void;\n\n /**\n * Specifies whether the blade is disabled. If true, the blade cannot be interacted with.\n */\n disabled?: boolean;\n\n /**\n * If true, the blade will take up the maximum width of the container when expanded.\n */\n fullWidth?: boolean;\n\n /**\n * Props to be passed to the button that toggles the blade's expanded state.\n * This can be used to further customize the appearance or behavior of the blade's button,\n * e.g. to set the aria-label attribute.\n */\n buttonProps?: HTMLAttributes<HTMLDivElement>;\n /**\n * Props to be passed to the container div that holds the blade's children.\n * This can be used to further customize the appearance or behavior of the blade's content area.\n */\n containerProps?: HTMLAttributes<HTMLDivElement>;\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes?: HvBladeClasses;\n}\n\n/**\n * A blade is a design element that expands horizontally to reveal information, similar to an accordion.\n *\n * It is usually stacked horizontally with other blades and works best when used within a flex container.\n * The `HvBlades` component is recommended for this purpose, as it also provides better management of the\n * blades' expanded state.\n */\nexport const HvBlade = (props: HvBladeProps) => {\n const {\n id: idProp,\n className,\n classes: classesProp,\n expanded,\n defaultExpanded = false,\n label,\n labelVariant = \"label\",\n headingLevel,\n onChange,\n disabled = false,\n children,\n fullWidth,\n buttonProps,\n containerProps,\n ...others\n } = useDefaultProps(\"HvBlade\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [isExpanded, setIsExpanded] = useControlled(\n expanded,\n Boolean(defaultExpanded)\n );\n\n const handleAction = useCallback(\n (event: SyntheticEvent) => {\n if (!disabled) {\n onChange?.(event, !isExpanded);\n\n // This will only run if uncontrolled\n setIsExpanded(!isExpanded);\n\n return true;\n }\n return false;\n },\n [disabled, onChange, isExpanded, setIsExpanded]\n );\n\n const handleClick = useCallback(\n (event: SyntheticEvent) => {\n handleAction(event);\n event.preventDefault();\n event.stopPropagation();\n },\n [handleAction]\n );\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n let isEventHandled = false;\n const { key } = event;\n\n if (\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.currentTarget !== event.target\n ) {\n return;\n }\n switch (key) {\n case \"Enter\":\n case \" \":\n isEventHandled = handleAction(event);\n break;\n default:\n return;\n }\n\n if (isEventHandled) {\n event.preventDefault();\n event.stopPropagation();\n }\n },\n [handleAction]\n );\n\n const id = useUniqueId(idProp, \"hvblade\");\n const bladeHeaderId = setId(id, \"button\");\n const bladeContainerId = setId(id, \"container\");\n const bladeHeader = useMemo(() => {\n const buttonLabel = typeof label === \"function\" ? label(isExpanded) : label;\n\n const bladeButton = (\n <HvTypography\n id={bladeHeaderId}\n component=\"div\"\n role=\"button\"\n className={cx(classes.button, {\n [classes.disabled]: disabled,\n [classes.textOnlyLabel]: typeof buttonLabel === \"string\",\n })}\n style={{ flexShrink: headingLevel === undefined ? 0 : undefined }}\n disabled={disabled}\n tabIndex={0}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n variant={labelVariant}\n aria-expanded={isExpanded}\n aria-controls={bladeContainerId}\n {...buttonProps}\n >\n {buttonLabel}\n </HvTypography>\n );\n return headingLevel === undefined ? (\n bladeButton\n ) : (\n <HvTypography\n component={`h${headingLevel}`}\n variant={labelVariant}\n className={classes.heading}\n style={{ flexShrink: 0 }}\n >\n {bladeButton}\n </HvTypography>\n );\n }, [\n bladeContainerId,\n bladeHeaderId,\n buttonProps,\n classes.button,\n classes.disabled,\n classes.heading,\n classes.textOnlyLabel,\n cx,\n disabled,\n handleClick,\n handleKeyDown,\n headingLevel,\n isExpanded,\n label,\n labelVariant,\n ]);\n\n const bladeRef = React.useRef<HTMLDivElement>(null);\n const maxWidthRef = React.useRef<number>(0);\n useEffect(() => {\n if (bladeRef.current) {\n maxWidthRef.current = bladeRef.current.parentElement?.clientWidth || 0;\n }\n }, []);\n\n const { style: containerStyle, ...otherContainerProps } =\n containerProps || {};\n\n return (\n <div\n ref={bladeRef}\n id={idProp}\n className={cx(classes.root, className, {\n [classes.fullWidth]: fullWidth,\n [classes.expanded]: isExpanded,\n })}\n {...others}\n >\n {bladeHeader}\n <div\n id={bladeContainerId}\n role=\"region\"\n aria-labelledby={bladeHeaderId}\n className={classes.container}\n hidden={!isExpanded}\n style={{\n ...containerStyle,\n maxWidth: isExpanded ? maxWidthRef.current : 0,\n }}\n {...otherContainerProps}\n >\n {children}\n </div>\n </div>\n );\n};\n"],"names":["useDefaultProps","useClasses","useControlled","useCallback","useUniqueId","setId","useMemo","jsx","HvTypography","React","useEffect","jsxs"],"mappings":";;;;;;;;AA4Ga,MAAA,UAAU,CAAC,UAAwB;AACxC,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACDA,eAAgB,gBAAA,WAAW,KAAK;AAEpC,QAAM,EAAE,SAAS,GAAG,IAAIC,wBAAW,WAAW;AAExC,QAAA,CAAC,YAAY,aAAa,IAAIC,eAAA;AAAA,IAClC;AAAA,IACA,QAAQ,eAAe;AAAA,EAAA;AAGzB,QAAM,eAAeC,MAAA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AAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACDJ,2BAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,IAAI;AAAA,YACJ,MAAK;AAAA,YACL,mBAAiB;AAAA,YACjB,WAAW,QAAQ;AAAA,YACnB,QAAQ,CAAC;AAAA,YACT,OAAO;AAAA,cACL,GAAG;AAAA,cACH,UAAU,aAAa,YAAY,UAAU;AAAA,YAC/C;AAAA,YACC,GAAG;AAAA,YAEH;AAAA,UAAA;AAAA,QACH;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;;;"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const uikitReactCore = require("@hitachivantara/uikit-react-core");
4
+ const uikitStyles = require("@hitachivantara/uikit-styles");
5
+ const { staticClasses, useClasses } = uikitReactCore.createClasses("HvBlade", {
6
+ root: {
7
+ position: "relative",
8
+ display: "flex",
9
+ minWidth: 72,
10
+ "& + $root": {
11
+ marginLeft: uikitStyles.theme.spacing("sm")
12
+ },
13
+ transition: "flex-grow 600ms linear",
14
+ zIndex: 0,
15
+ color: uikitStyles.theme.colors.secondary,
16
+ backgroundColor: uikitStyles.theme.colors.atmo1,
17
+ borderRadius: uikitStyles.theme.radii.round,
18
+ border: `1px solid ${uikitStyles.theme.colors.atmo4}`
19
+ },
20
+ expanded: {},
21
+ fullWidth: {
22
+ flexGrow: 0,
23
+ "&$expanded": {
24
+ flexGrow: 1
25
+ }
26
+ },
27
+ heading: {},
28
+ button: {
29
+ height: "100%",
30
+ minWidth: 70,
31
+ "&[disabled], &:active": {
32
+ outline: "none"
33
+ },
34
+ "&:focus": {
35
+ outline: "none",
36
+ background: uikitStyles.theme.colors.containerBackgroundHover
37
+ },
38
+ "&:hover": {
39
+ background: uikitStyles.theme.colors.containerBackgroundHover
40
+ },
41
+ "&:focus-visible": {
42
+ ...uikitReactCore.outlineStyles,
43
+ zIndex: 1
44
+ },
45
+ cursor: "pointer"
46
+ },
47
+ textOnlyLabel: {
48
+ padding: uikitStyles.theme.spacing("xs", "sm")
49
+ },
50
+ container: {
51
+ display: "inline-block",
52
+ height: "100%",
53
+ width: "100%",
54
+ minWidth: 0,
55
+ overflowX: "hidden",
56
+ maxWidth: 0,
57
+ transition: "max-width 600ms linear"
58
+ },
59
+ disabled: {
60
+ cursor: "not-allowed",
61
+ color: uikitStyles.theme.colors.secondary_60,
62
+ "&:focus": {
63
+ background: "none"
64
+ },
65
+ "&:hover": {
66
+ background: "none"
67
+ }
68
+ }
69
+ });
70
+ exports.staticClasses = staticClasses;
71
+ exports.useClasses = useClasses;
72
+ //# sourceMappingURL=Blade.styles.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blade.styles.cjs","sources":["../../../src/Blade/Blade.styles.tsx"],"sourcesContent":["import { createClasses, outlineStyles } from \"@hitachivantara/uikit-react-core\";\nimport { theme } from \"@hitachivantara/uikit-styles\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvBlade\", {\n root: {\n position: \"relative\",\n\n display: \"flex\",\n minWidth: 72,\n\n \"& + $root\": {\n marginLeft: theme.spacing(\"sm\"),\n },\n\n transition: \"flex-grow 600ms linear\",\n\n zIndex: 0,\n\n color: theme.colors.secondary,\n backgroundColor: theme.colors.atmo1,\n borderRadius: theme.radii.round,\n border: `1px solid ${theme.colors.atmo4}`,\n },\n expanded: {},\n\n fullWidth: {\n flexGrow: 0,\n\n \"&$expanded\": {\n flexGrow: 1,\n },\n },\n\n heading: {},\n\n button: {\n height: \"100%\",\n minWidth: 70,\n\n \"&[disabled], &:active\": {\n outline: \"none\",\n },\n\n \"&:focus\": {\n outline: \"none\",\n background: theme.colors.containerBackgroundHover,\n },\n\n \"&:hover\": {\n background: theme.colors.containerBackgroundHover,\n },\n\n \"&:focus-visible\": {\n ...outlineStyles,\n zIndex: 1,\n },\n\n cursor: \"pointer\",\n },\n textOnlyLabel: {\n padding: theme.spacing(\"xs\", \"sm\"),\n },\n\n container: {\n display: \"inline-block\",\n height: \"100%\",\n width: \"100%\",\n\n minWidth: 0,\n\n overflowX: \"hidden\",\n\n maxWidth: 0,\n transition: \"max-width 600ms linear\",\n },\n\n disabled: {\n cursor: \"not-allowed\",\n color: theme.colors.secondary_60,\n\n \"&:focus\": {\n background: \"none\",\n },\n\n \"&:hover\": {\n background: \"none\",\n },\n },\n});\n"],"names":["createClasses","theme","outlineStyles"],"mappings":";;;;AAGO,MAAM,EAAE,eAAe,eAAeA,eAAAA,cAAc,WAAW;AAAA,EACpE,MAAM;AAAA,IACJ,UAAU;AAAA,IAEV,SAAS;AAAA,IACT,UAAU;AAAA,IAEV,aAAa;AAAA,MACX,YAAYC,YAAAA,MAAM,QAAQ,IAAI;AAAA,IAChC;AAAA,IAEA,YAAY;AAAA,IAEZ,QAAQ;AAAA,IAER,OAAOA,YAAAA,MAAM,OAAO;AAAA,IACpB,iBAAiBA,YAAAA,MAAM,OAAO;AAAA,IAC9B,cAAcA,YAAAA,MAAM,MAAM;AAAA,IAC1B,QAAQ,aAAaA,YAAM,MAAA,OAAO,KAAK;AAAA,EACzC;AAAA,EACA,UAAU,CAAC;AAAA,EAEX,WAAW;AAAA,IACT,UAAU;AAAA,IAEV,cAAc;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AAAA,EAEA,SAAS,CAAC;AAAA,EAEV,QAAQ;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,IAEV,yBAAyB;AAAA,MACvB,SAAS;AAAA,IACX;AAAA,IAEA,WAAW;AAAA,MACT,SAAS;AAAA,MACT,YAAYA,YAAAA,MAAM,OAAO;AAAA,IAC3B;AAAA,IAEA,WAAW;AAAA,MACT,YAAYA,YAAAA,MAAM,OAAO;AAAA,IAC3B;AAAA,IAEA,mBAAmB;AAAA,MACjB,GAAGC,eAAA;AAAA,MACH,QAAQ;AAAA,IACV;AAAA,IAEA,QAAQ;AAAA,EACV;AAAA,EACA,eAAe;AAAA,IACb,SAASD,YAAA,MAAM,QAAQ,MAAM,IAAI;AAAA,EACnC;AAAA,EAEA,WAAW;AAAA,IACT,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,OAAO;AAAA,IAEP,UAAU;AAAA,IAEV,WAAW;AAAA,IAEX,UAAU;AAAA,IACV,YAAY;AAAA,EACd;AAAA,EAEA,UAAU;AAAA,IACR,QAAQ;AAAA,IACR,OAAOA,YAAAA,MAAM,OAAO;AAAA,IAEpB,WAAW;AAAA,MACT,YAAY;AAAA,IACd;AAAA,IAEA,WAAW;AAAA,MACT,YAAY;AAAA,IACd;AAAA,EACF;AACF,CAAC;;;"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("@emotion/react/jsx-runtime");
4
+ const React = require("react");
5
+ const uikitReactCore = require("@hitachivantara/uikit-react-core");
6
+ const Blades_styles = require("./Blades.styles.cjs");
7
+ function getExpandedBlades(defaultExpanded, children, atMostOneExpanded, atLeastOneExpanded) {
8
+ const childrenArray = React.Children.toArray(children);
9
+ const expandedBlades = defaultExpanded ?? childrenArray.map((child, i) => {
10
+ const childIsControlled = child?.props?.expanded !== void 0;
11
+ const childIsExpanded = childIsControlled ? child?.props?.expanded : child?.props?.defaultExpanded;
12
+ return childIsExpanded ? i : void 0;
13
+ }).filter((v) => v !== void 0);
14
+ const numberOfExpandedBlades = expandedBlades.length;
15
+ if (atLeastOneExpanded && numberOfExpandedBlades === 0 && childrenArray.length > 0) {
16
+ return [0];
17
+ }
18
+ if (atMostOneExpanded && numberOfExpandedBlades > 1) {
19
+ return [expandedBlades[0]];
20
+ }
21
+ return expandedBlades;
22
+ }
23
+ const HvBlades = (props) => {
24
+ const {
25
+ id,
26
+ className,
27
+ classes: classesProp,
28
+ children,
29
+ expanded: expandedProp,
30
+ defaultExpanded,
31
+ atMostOneExpanded = false,
32
+ atLeastOneExpanded = false,
33
+ fullWidthBlades = false,
34
+ onChange,
35
+ ...others
36
+ } = uikitReactCore.useDefaultProps("HvBlades", props);
37
+ const { classes, cx } = Blades_styles.useClasses(classesProp);
38
+ const [expanded, setExpanded] = uikitReactCore.useControlled(
39
+ expandedProp,
40
+ () => getExpandedBlades(
41
+ defaultExpanded,
42
+ children,
43
+ atMostOneExpanded,
44
+ atLeastOneExpanded
45
+ )
46
+ );
47
+ const onChildChangeInterceptor = React.useCallback(
48
+ (index, childOnChange, event, isExpanded) => {
49
+ const newValue = [];
50
+ if (atMostOneExpanded) {
51
+ if (isExpanded) {
52
+ newValue.push(index);
53
+ }
54
+ } else {
55
+ newValue.push(...expanded);
56
+ if (isExpanded) {
57
+ newValue.push(index);
58
+ } else {
59
+ newValue.splice(newValue.indexOf(index), 1);
60
+ }
61
+ }
62
+ if (atLeastOneExpanded && newValue.length === 0) {
63
+ newValue.push(index);
64
+ }
65
+ childOnChange?.(event, isExpanded);
66
+ onChange?.(event, newValue);
67
+ setExpanded(newValue);
68
+ },
69
+ [onChange, expanded, setExpanded, atMostOneExpanded, atLeastOneExpanded]
70
+ );
71
+ const modifiedChildren = React.useMemo(() => {
72
+ return React.Children.map(children, (child, i) => {
73
+ const childIsExpanded = expanded.includes(i);
74
+ return React.cloneElement(child, {
75
+ expanded: childIsExpanded,
76
+ fullWidth: child?.props?.fullWidth ?? fullWidthBlades,
77
+ buttonProps: {
78
+ ...child?.props?.buttonProps,
79
+ "aria-disabled": (
80
+ // If the accordion panel associated with an accordion header is visible,
81
+ // and if the accordion does not permit the panel to be collapsed, the header
82
+ // button element has aria-disabled set to true.
83
+ child?.props?.disabled || childIsExpanded && atMostOneExpanded && expanded.length === 1 ? true : void 0
84
+ )
85
+ },
86
+ onChange: (event, isExpanded) => onChildChangeInterceptor(
87
+ i,
88
+ child?.props?.onChange,
89
+ event,
90
+ isExpanded
91
+ )
92
+ });
93
+ });
94
+ }, [
95
+ children,
96
+ expanded,
97
+ fullWidthBlades,
98
+ atMostOneExpanded,
99
+ onChildChangeInterceptor
100
+ ]);
101
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { id, className: cx(classes.root, className), ...others, children: modifiedChildren });
102
+ };
103
+ exports.bladesClasses = Blades_styles.staticClasses;
104
+ exports.HvBlades = HvBlades;
105
+ //# sourceMappingURL=Blades.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blades.cjs","sources":["../../../src/Blades/Blades.tsx"],"sourcesContent":["import React, {\n SyntheticEvent,\n useCallback,\n useMemo,\n Children,\n cloneElement,\n} from \"react\";\n\nimport {\n ExtractNames,\n HvBaseProps,\n useDefaultProps,\n useControlled,\n} from \"@hitachivantara/uikit-react-core\";\n\nimport { staticClasses, useClasses } from \"./Blades.styles\";\n\nexport { staticClasses as bladesClasses };\n\nexport type HvBladesClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvBladesProps\n extends HvBaseProps<HTMLDivElement, \"onChange\" | \"children\"> {\n /**\n * Array of indices representing the expanded state of each blade.\n *\n * When defined, the expanded state of the blades becomes controlled.\n */\n expanded?: number[];\n /**\n * Initial expanded state of the blades when in an uncontrolled state.\n *\n * It's an array of indices representing the blades that should be initially expanded.\n */\n defaultExpanded?: number[];\n\n /**\n * If true, ensures that only one blade can be expanded at a time.\n */\n atMostOneExpanded?: boolean;\n /**\n * If true, ensures that at least one blade is always expanded.\n */\n atLeastOneExpanded?: boolean;\n\n /**\n * If true, the blades will take up the full width of the container by default.\n */\n fullWidthBlades?: boolean;\n\n /**\n * Callback function triggered when the expanded state of any blade changes.\n * It receives the event and the new array of expanded indices as arguments.\n *\n * If uncontrolled, this new state will be effective.\n * If controlled, it is up to the parent component to manage this state.\n *\n * @param {SyntheticEvent} event The event source of the callback.\n * @param {number[]} value Array of indices of the blades that are expanded.\n */\n onChange?: (event: SyntheticEvent, value: number[]) => void;\n\n /**\n * The blades to be rendered within the group.\n * Must be instances of `HvBlade`, otherwise the behavior is undefined and will most likely break.\n */\n children: React.ReactNode;\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes?: HvBladesClasses;\n}\n\nfunction getExpandedBlades(\n defaultExpanded: number[] | undefined,\n children: React.ReactNode,\n atMostOneExpanded: boolean,\n atLeastOneExpanded: boolean\n) {\n const childrenArray = Children.toArray(children);\n const expandedBlades =\n defaultExpanded ??\n childrenArray\n .map((child: any, i: number) => {\n const childIsControlled = child?.props?.expanded !== undefined;\n const childIsExpanded = childIsControlled\n ? child?.props?.expanded\n : child?.props?.defaultExpanded;\n\n return childIsExpanded ? i : undefined;\n })\n .filter((v) => v !== undefined);\n\n const numberOfExpandedBlades = expandedBlades.length;\n if (\n atLeastOneExpanded &&\n numberOfExpandedBlades === 0 &&\n childrenArray.length > 0\n ) {\n return [0];\n }\n if (atMostOneExpanded && numberOfExpandedBlades > 1) {\n return [expandedBlades[0]];\n }\n\n return expandedBlades;\n}\n\n/**\n * `HvBlades` is a component that groups multiple `HvBlade` components.\n *\n * It allows for better control over the expanded state of blades, suitable for both\n * controlled and uncontrolled scenarios.\n */\nexport const HvBlades = (props: HvBladesProps) => {\n const {\n id,\n className,\n classes: classesProp,\n children,\n expanded: expandedProp,\n defaultExpanded,\n atMostOneExpanded = false,\n atLeastOneExpanded = false,\n fullWidthBlades = false,\n onChange,\n ...others\n } = useDefaultProps(\"HvBlades\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [expanded, setExpanded] = useControlled(expandedProp, () =>\n getExpandedBlades(\n defaultExpanded,\n children,\n atMostOneExpanded,\n atLeastOneExpanded\n )\n );\n\n const onChildChangeInterceptor = useCallback(\n (\n index: number,\n childOnChange: (event: SyntheticEvent, isExpanded: boolean) => void,\n event: SyntheticEvent,\n isExpanded: boolean\n ) => {\n const newValue: number[] = [];\n if (atMostOneExpanded) {\n if (isExpanded) {\n newValue.push(index);\n }\n } else {\n newValue.push(...expanded);\n if (isExpanded) {\n newValue.push(index);\n } else {\n newValue.splice(newValue.indexOf(index), 1);\n }\n }\n\n if (atLeastOneExpanded && newValue.length === 0) {\n newValue.push(index);\n }\n\n childOnChange?.(event, isExpanded);\n\n onChange?.(event, newValue);\n\n // This will only run if uncontrolled\n setExpanded(newValue);\n },\n [onChange, expanded, setExpanded, atMostOneExpanded, atLeastOneExpanded]\n );\n\n const modifiedChildren = useMemo(() => {\n return Children.map(children, (child: any, i: number) => {\n const childIsExpanded = expanded.includes(i);\n\n return cloneElement(child, {\n expanded: childIsExpanded,\n fullWidth: child?.props?.fullWidth ?? fullWidthBlades,\n buttonProps: {\n ...child?.props?.buttonProps,\n \"aria-disabled\":\n // If the accordion panel associated with an accordion header is visible,\n // and if the accordion does not permit the panel to be collapsed, the header\n // button element has aria-disabled set to true.\n child?.props?.disabled ||\n (childIsExpanded && atMostOneExpanded && expanded.length === 1)\n ? true\n : undefined,\n },\n onChange: (\n event: React.ChangeEvent<HTMLInputElement>,\n isExpanded: boolean\n ) =>\n onChildChangeInterceptor(\n i,\n child?.props?.onChange,\n event,\n isExpanded\n ),\n });\n });\n }, [\n children,\n expanded,\n fullWidthBlades,\n atMostOneExpanded,\n onChildChangeInterceptor,\n ]);\n\n return (\n <div id={id} className={cx(classes.root, className)} {...others}>\n {modifiedChildren}\n </div>\n );\n};\n"],"names":["Children","useDefaultProps","useClasses","useControlled","useCallback","useMemo","cloneElement","jsx"],"mappings":";;;;;;AAyEA,SAAS,kBACP,iBACA,UACA,mBACA,oBACA;AACM,QAAA,gBAAgBA,MAAAA,SAAS,QAAQ,QAAQ;AAC/C,QAAM,iBACJ,mBACA,cACG,IAAI,CAAC,OAAY,MAAc;AACxB,UAAA,oBAAoB,OAAO,OAAO,aAAa;AACrD,UAAM,kBAAkB,oBACpB,OAAO,OAAO,WACd,OAAO,OAAO;AAElB,WAAO,kBAAkB,IAAI;AAAA,EAAA,CAC9B,EACA,OAAO,CAAC,MAAM,MAAM,MAAS;AAElC,QAAM,yBAAyB,eAAe;AAC9C,MACE,sBACA,2BAA2B,KAC3B,cAAc,SAAS,GACvB;AACA,WAAO,CAAC,CAAC;AAAA,EACX;AACI,MAAA,qBAAqB,y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,CAAC;AAE3C,aAAOM,MAAAA,aAAa,OAAO;AAAA,QACzB,UAAU;AAAA,QACV,WAAW,OAAO,OAAO,aAAa;AAAA,QACtC,aAAa;AAAA,UACX,GAAG,OAAO,OAAO;AAAA,UACjB;AAAA;AAAA;AAAA;AAAA,YAIE,OAAO,OAAO,YACb,mBAAmB,qBAAqB,SAAS,WAAW,IACzD,OACA;AAAA;AAAA,QACR;AAAA,QACA,UAAU,CACR,OACA,eAEA;AAAA,UACE;AAAA,UACA,OAAO,OAAO;AAAA,UACd;AAAA,UACA;AAAA,QACF;AAAA,MAAA,CACH;AAAA,IAAA,CACF;AAAA,EAAA,GACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAGC,SAAAC,2BAAA,IAAC,OAAI,EAAA,IAAQ,WAAW,GAAG,QAAQ,MAAM,SAAS,GAAI,GAAG,QACtD,UACH,iBAAA,CAAA;AAEJ;;;"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const uikitReactCore = require("@hitachivantara/uikit-react-core");
4
+ const { staticClasses, useClasses } = uikitReactCore.createClasses("HvBlades", {
5
+ root: {
6
+ position: "relative",
7
+ display: "flex"
8
+ }
9
+ });
10
+ exports.staticClasses = staticClasses;
11
+ exports.useClasses = useClasses;
12
+ //# sourceMappingURL=Blades.styles.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blades.styles.cjs","sources":["../../../src/Blades/Blades.styles.tsx"],"sourcesContent":["import { createClasses } from \"@hitachivantara/uikit-react-core\";\n\nexport const { staticClasses, useClasses } = createClasses(\"HvBlades\", {\n root: {\n position: \"relative\",\n\n display: \"flex\",\n },\n});\n"],"names":["createClasses"],"mappings":";;;AAEO,MAAM,EAAE,eAAe,eAAeA,eAAAA,cAAc,YAAY;AAAA,EACrE,MAAM;AAAA,IACJ,UAAU;AAAA,IAEV,SAAS;AAAA,EACX;AACF,CAAC;;;"}
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const Blade_styles = require("./Blade/Blade.styles.cjs");
4
+ const Blade = require("./Blade/Blade.cjs");
5
+ const Blades_styles = require("./Blades/Blades.styles.cjs");
6
+ const Blades = require("./Blades/Blades.cjs");
3
7
  const Dashboard_styles = require("./Dashboard/Dashboard.styles.cjs");
4
8
  const Dashboard = require("./Dashboard/Dashboard.cjs");
5
9
  const Flow_styles = require("./Flow/Flow.styles.cjs");
@@ -32,6 +36,10 @@ const WizardContent = require("./Wizard/WizardContent/WizardContent.cjs");
32
36
  const WizardContext = require("./Wizard/WizardContext/WizardContext.cjs");
33
37
  const WizardTitle_styles = require("./Wizard/WizardTitle/WizardTitle.styles.cjs");
34
38
  const WizardTitle = require("./Wizard/WizardTitle/WizardTitle.cjs");
39
+ exports.bladeClasses = Blade_styles.staticClasses;
40
+ exports.HvBlade = Blade.HvBlade;
41
+ exports.bladesClasses = Blades_styles.staticClasses;
42
+ exports.HvBlades = Blades.HvBlades;
35
43
  exports.dashboardClasses = Dashboard_styles.staticClasses;
36
44
  exports.HvDashboard = Dashboard.HvDashboard;
37
45
  exports.flowClasses = Flow_styles.staticClasses;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,168 @@
1
+ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
+ import React, { useCallback, useMemo, useEffect } from "react";
3
+ import { useDefaultProps, useControlled, useUniqueId, setId, HvTypography } from "@hitachivantara/uikit-react-core";
4
+ 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, "hvblade");
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.disabled]: disabled,
83
+ [classes.textOnlyLabel]: typeof buttonLabel === "string"
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 = React.useRef(null);
125
+ const maxWidthRef = React.useRef(0);
126
+ useEffect(() => {
127
+ if (bladeRef.current) {
128
+ maxWidthRef.current = bladeRef.current.parentElement?.clientWidth || 0;
129
+ }
130
+ }, []);
131
+ const { style: containerStyle, ...otherContainerProps } = containerProps || {};
132
+ return /* @__PURE__ */ jsxs(
133
+ "div",
134
+ {
135
+ ref: bladeRef,
136
+ id: idProp,
137
+ className: cx(classes.root, className, {
138
+ [classes.fullWidth]: fullWidth,
139
+ [classes.expanded]: isExpanded
140
+ }),
141
+ ...others,
142
+ children: [
143
+ bladeHeader,
144
+ /* @__PURE__ */ jsx(
145
+ "div",
146
+ {
147
+ id: bladeContainerId,
148
+ role: "region",
149
+ "aria-labelledby": bladeHeaderId,
150
+ className: classes.container,
151
+ hidden: !isExpanded,
152
+ style: {
153
+ ...containerStyle,
154
+ maxWidth: isExpanded ? maxWidthRef.current : 0
155
+ },
156
+ ...otherContainerProps,
157
+ children
158
+ }
159
+ )
160
+ ]
161
+ }
162
+ );
163
+ };
164
+ export {
165
+ HvBlade,
166
+ staticClasses as bladeClasses
167
+ };
168
+ //# sourceMappingURL=Blade.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Blade.js","sources":["../../../src/Blade/Blade.tsx"],"sourcesContent":["import React, {\n SyntheticEvent,\n useCallback,\n useMemo,\n HTMLAttributes,\n useEffect,\n} from \"react\";\n\nimport {\n ExtractNames,\n HvBaseProps,\n HvTypography,\n HvTypographyVariants,\n setId,\n useControlled,\n useDefaultProps,\n useUniqueId,\n} from \"@hitachivantara/uikit-react-core\";\n\nimport { staticClasses, useClasses } from \"./Blade.styles\";\n\nexport { staticClasses as bladeClasses };\n\nexport type HvBladeClasses = ExtractNames<typeof useClasses>;\n\nexport interface HvBladeProps\n extends HvBaseProps<HTMLDivElement, \"onChange\" | \"children\"> {\n /**\n * The content that will be rendered within the blade.\n */\n children: React.ReactNode;\n\n /**\n * The content of the blade's button.\n *\n * If a render function is provided, it will be called with the expanded state as an argument.\n */\n label?: React.ReactNode | ((expanded: boolean) => React.ReactNode);\n /**\n * Typography variant for the blade's button label.\n */\n labelVariant?: HvTypographyVariants;\n /**\n * Heading Level to apply to blade button.\n *\n * If 'undefined', the button will not have a header wrapper.\n */\n headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;\n\n /**\n * Indicates whether the blade is expanded or not.\n *\n * When defined the expanded state becomes controlled.\n *\n * @default undefined\n */\n expanded?: boolean;\n /**\n * Specifies the initial expanded state of the blade when it is uncontrolled.\n */\n defaultExpanded?: boolean;\n\n /**\n * Callback function triggered when the blade's button is pressed.\n * It receives the event and the new expanded state as arguments.\n *\n * If the blade is uncontrolled, this new state will be effective.\n * If the blade is controlled, it is up to the parent component to manage this state.\n *\n * @param {SyntheticEvent} event The event source of the callback.\n * @param {boolean} value The new value.\n */\n onChange?: (event: React.SyntheticEvent, value: boolean) => void;\n\n /**\n * Specifies whether the blade is disabled. If true, the blade cannot be interacted with.\n */\n disabled?: boolean;\n\n /**\n * If true, the blade will take up the maximum width of the container when expanded.\n */\n fullWidth?: boolean;\n\n /**\n * Props to be passed to the button that toggles the blade's expanded state.\n * This can be used to further customize the appearance or behavior of the blade's button,\n * e.g. to set the aria-label attribute.\n */\n buttonProps?: HTMLAttributes<HTMLDivElement>;\n /**\n * Props to be passed to the container div that holds the blade's children.\n * This can be used to further customize the appearance or behavior of the blade's content area.\n */\n containerProps?: HTMLAttributes<HTMLDivElement>;\n /**\n * A Jss Object used to override or extend the styles applied.\n */\n classes?: HvBladeClasses;\n}\n\n/**\n * A blade is a design element that expands horizontally to reveal information, similar to an accordion.\n *\n * It is usually stacked horizontally with other blades and works best when used within a flex container.\n * The `HvBlades` component is recommended for this purpose, as it also provides better management of the\n * blades' expanded state.\n */\nexport const HvBlade = (props: HvBladeProps) => {\n const {\n id: idProp,\n className,\n classes: classesProp,\n expanded,\n defaultExpanded = false,\n label,\n labelVariant = \"label\",\n headingLevel,\n onChange,\n disabled = false,\n children,\n fullWidth,\n buttonProps,\n containerProps,\n ...others\n } = useDefaultProps(\"HvBlade\", props);\n\n const { classes, cx } = useClasses(classesProp);\n\n const [isExpanded, setIsExpanded] = useControlled(\n expanded,\n Boolean(defaultExpanded)\n );\n\n const handleAction = useCallback(\n (event: SyntheticEvent) => {\n if (!disabled) {\n onChange?.(event, !isExpanded);\n\n // This will only run if uncontrolled\n setIsExpanded(!isExpanded);\n\n return true;\n }\n return false;\n },\n [disabled, onChange, isExpanded, setIsExpanded]\n );\n\n const handleClick = useCallback(\n (event: SyntheticEvent) => {\n handleAction(event);\n event.preventDefault();\n event.stopPropagation();\n },\n [handleAction]\n );\n\n const handleKeyDown = useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n let isEventHandled = false;\n const { key } = event;\n\n if (\n event.altKey ||\n event.ctrlKey ||\n event.metaKey ||\n event.currentTarget !== event.target\n ) {\n return;\n }\n switch (key) {\n case \"Enter\":\n case \" \":\n isEventHandled = handleAction(event);\n break;\n default:\n return;\n }\n\n if (isEventHandled) {\n event.preventDefault();\n event.stopPropagation();\n }\n },\n [handleAction]\n );\n\n const id = useUniqueId(idProp, \"hvblade\");\n const bladeHeaderId = setId(id, \"button\");\n const bladeContainerId = setId(id, \"container\");\n const bladeHeader = useMemo(() => {\n const buttonLabel = typeof label === \"function\" ? label(isExpanded) : label;\n\n const bladeButton = (\n <HvTypography\n id={bladeHeaderId}\n component=\"div\"\n role=\"button\"\n className={cx(classes.button, {\n [classes.disabled]: disabled,\n [classes.textOnlyLabel]: typeof buttonLabel === \"string\",\n })}\n style={{ flexShrink: headingLevel === undefined ? 0 : undefined }}\n disabled={disabled}\n tabIndex={0}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n variant={labelVariant}\n aria-expanded={isExpanded}\n aria-controls={bladeContainerId}\n {...buttonProps}\n >\n {buttonLabel}\n </HvTypography>\n );\n return headingLevel === undefined ? (\n bladeButton\n ) : (\n <HvTypography\n component={`h${headingLevel}`}\n variant={labelVariant}\n className={classes.heading}\n style={{ flexShrink: 0 }}\n >\n {bladeButton}\n </HvTypography>\n );\n }, [\n bladeContainerId,\n bladeHeaderId,\n buttonProps,\n classes.button,\n classes.disabled,\n classes.heading,\n classes.textOnlyLabel,\n cx,\n disabled,\n handleClick,\n handleKeyDown,\n headingLevel,\n isExpanded,\n label,\n labelVariant,\n ]);\n\n const bladeRef = React.useRef<HTMLDivElement>(null);\n const maxWidthRef = React.useRef<number>(0);\n useEffect(() => {\n if (bladeRef.current) {\n maxWidthRef.current = bladeRef.current.parentElement?.clientWidth || 0;\n }\n }, []);\n\n const { style: containerStyle, ...otherContainerProps } =\n containerProps || {};\n\n return (\n <div\n ref={bladeRef}\n id={idProp}\n className={cx(classes.root, className, {\n [classes.fullWidth]: fullWidth,\n [classes.expanded]: isExpanded,\n })}\n {...others}\n >\n {bladeHeader}\n <div\n id={bladeContainerId}\n role=\"region\"\n aria-labelledby={bladeHeaderId}\n className={classes.container}\n hidden={!isExpanded}\n style={{\n ...containerStyle,\n maxWidth: isExpanded ? maxWidthRef.current : 0,\n }}\n {...otherContainerProps}\n >\n {children}\n </div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;AA4Ga,MAAA,UAAU,CAAC,UAAwB;AACxC,QAAA;AAAA,IACJ,IAAI;AAAA,IACJ;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD,gBAAgB,WAAW,KAAK;AAEpC,QAAM,EAAE,SAAS,GAAG,IAAI,WAAW,WAAW;AAExC,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC;AAAA,IACA,QAAQ,eAAe;AAAA,EAAA;AAGzB,QAAM,eAAe;AAAA,IACnB,CAAC,UAA0B;AACzB,UAAI,CAAC,UAAU;AACF,mBAAA,OAAO,CAAC,UAAU;AAG7B,sBAAc,CAAC,UAAU;AAElB,eAAA;AAAA,MACT;AACO,aAAA;AAAA,IACT;AAAA,IACA,CAAC,UAAU,UAAU,YAAY,aAAa;AAAA,EAAA;AAGhD,QAAM,cAAc;AAAA,IAClB,CAAC,UAA0B;AACzB,mBAAa,KAAK;AAClB,YAAM,eAAe;AACrB,YAAM,gBAAgB;AAAA,IACxB;AAAA,IACA,CAAC,YAAY;AAAA,EAAA;AAGf,QAAM,gBAAgB;AAAA,IACpB,CAAC,UAA+C;AAC9C,UAAI,iBAAiB;AACf,YAAA,EAAE,IAAQ,IAAA;AAGd,UAAA,MAAM,UACN,MAAM,WACN,MAAM,WACN,MAAM,kBAAkB,MAAM,QAC9B;AACA;AAAA,MACF;AACA,cAAQ,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