@hitachivantara/uikit-react-lab 5.27.11 → 5.27.13
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/dist/cjs/Blade/Blade.cjs
CHANGED
|
@@ -4,8 +4,6 @@ const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const uikitReactCore = require("@hitachivantara/uikit-react-core");
|
|
6
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
7
|
const HvBlade = (props) => {
|
|
10
8
|
const {
|
|
11
9
|
id: idProp,
|
|
@@ -124,13 +122,22 @@ const HvBlade = (props) => {
|
|
|
124
122
|
label,
|
|
125
123
|
labelVariant
|
|
126
124
|
]);
|
|
127
|
-
const bladeRef =
|
|
128
|
-
const
|
|
125
|
+
const bladeRef = React.useRef(null);
|
|
126
|
+
const [maxWidth, setMaxWidth] = React.useState(void 0);
|
|
129
127
|
React.useEffect(() => {
|
|
130
128
|
if (bladeRef.current) {
|
|
131
|
-
|
|
129
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
130
|
+
setMaxWidth(entries[0].target.clientWidth);
|
|
131
|
+
});
|
|
132
|
+
resizeObserver.observe(
|
|
133
|
+
// using the blade's container as reference max-width is more stable
|
|
134
|
+
bladeRef.current.parentElement ?? bladeRef.current
|
|
135
|
+
);
|
|
136
|
+
return () => {
|
|
137
|
+
resizeObserver.disconnect();
|
|
138
|
+
};
|
|
132
139
|
}
|
|
133
|
-
}, []);
|
|
140
|
+
}, [isExpanded]);
|
|
134
141
|
const { style: containerStyle, ...otherContainerProps } = containerProps || {};
|
|
135
142
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
136
143
|
"div",
|
|
@@ -154,7 +161,7 @@ const HvBlade = (props) => {
|
|
|
154
161
|
hidden: !isExpanded,
|
|
155
162
|
style: {
|
|
156
163
|
...containerStyle,
|
|
157
|
-
maxWidth: isExpanded ?
|
|
164
|
+
maxWidth: isExpanded ? maxWidth : 0
|
|
158
165
|
},
|
|
159
166
|
...otherContainerProps,
|
|
160
167
|
children
|
|
@@ -1 +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;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,cAAcA,MAAA;AAAA,IAClB,CAAC,UAA0B;AACzB,mBAAa,KAAK;AAClB,YAAM,eAAe;AACrB,YAAM,gBAAgB;AAAA,IACxB;AAAA,IACA,CAAC,YAAY;AAAA,EAAA;AAGf,QAAM,gBAAgBA,MAAA;AAAA,IACpB,CAAC,UAA+C;AAC9C,UAAI,iBAAiB;AACf,YAAA,EAAE,IAAQ,IAAA;AAGd,UAAA,MAAM,UACN,MAAM,WACN,MA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GAED;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAEK,QAAA,WAAWC,eAAAA,QAAM,OAAuB,IAAI;AAC5C,QAAA,cAAcA,eAAAA,QAAM,OAAe,CAAC;AAC1CC,QAAAA,UAAU,MAAM;AACd,QAAI,SAAS,SAAS;AACpB,kBAAY,UAAU,SAAS,QAAQ,eAAe,eAAe;AAAA,IACvE;AAAA,EACF,GAAG,CAAE,CAAA;AAEL,QAAM,EAAE,OAAO,gBAAgB,GAAG,oBAAoB,IACpD,kBAAkB;AAGlB,SAAAC,2BAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,IAAI;AAAA,MACJ,WAAW,GAAG,QAAQ,MAAM,WAAW;AAAA,QACrC,CAAC,QAAQ,SAAS,GAAG;AAAA,QACrB,CAAC,QAAQ,QAAQ,GAAG;AAAA,MAAA,CACrB;AAAA,MACA,GAAG;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;;;"}
|
|
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 useRef,\n useState,\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 = useRef<HTMLDivElement>(null);\n const [maxWidth, setMaxWidth] = useState<number | undefined>(undefined);\n useEffect(() => {\n if (bladeRef.current) {\n const resizeObserver = new ResizeObserver((entries) => {\n setMaxWidth(entries[0].target.clientWidth);\n });\n resizeObserver.observe(\n // using the blade's container as reference max-width is more stable\n bladeRef.current.parentElement ?? bladeRef.current\n );\n return () => {\n resizeObserver.disconnect();\n };\n }\n }, [isExpanded]);\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 ? maxWidth : 0,\n }}\n {...otherContainerProps}\n >\n {children}\n </div>\n </div>\n );\n};\n"],"names":["useDefaultProps","useClasses","useControlled","useCallback","useUniqueId","setId","useMemo","jsx","HvTypography","useRef","useState","useEffect","jsxs"],"mappings":";;;;;;AA8Ga,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;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,cAAcA,MAAA;AAAA,IAClB,CAAC,UAA0B;AACzB,mBAAa,KAAK;AAClB,YAAM,eAAe;AACrB,YAAM,gBAAgB;AAAA,IACxB;AAAA,IACA,CAAC,YAAY;AAAA,EAAA;AAGf,QAAM,gBAAgBA,MAAA;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,KAAK;AAAA,QACX,KAAK;AAAA,QACL,KAAK;AACH,2BAAiB,aAAa,KAAK;AACnC;AAAA,QACF;AACE;AAAA,MACJ;AAEA,UAAI,gBA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allback, useMemo, useRef, useState, useEffect } from "react";
|
|
3
3
|
import { useDefaultProps, useControlled, useUniqueId, setId, HvTypography } from "@hitachivantara/uikit-react-core";
|
|
4
4
|
import { useClasses } from "./Blade.styles.js";
|
|
5
5
|
import { staticClasses } from "./Blade.styles.js";
|
|
@@ -121,13 +121,22 @@ const HvBlade = (props) => {
|
|
|
121
121
|
label,
|
|
122
122
|
labelVariant
|
|
123
123
|
]);
|
|
124
|
-
const bladeRef =
|
|
125
|
-
const
|
|
124
|
+
const bladeRef = useRef(null);
|
|
125
|
+
const [maxWidth, setMaxWidth] = useState(void 0);
|
|
126
126
|
useEffect(() => {
|
|
127
127
|
if (bladeRef.current) {
|
|
128
|
-
|
|
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
|
+
};
|
|
129
138
|
}
|
|
130
|
-
}, []);
|
|
139
|
+
}, [isExpanded]);
|
|
131
140
|
const { style: containerStyle, ...otherContainerProps } = containerProps || {};
|
|
132
141
|
return /* @__PURE__ */ jsxs(
|
|
133
142
|
"div",
|
|
@@ -151,7 +160,7 @@ const HvBlade = (props) => {
|
|
|
151
160
|
hidden: !isExpanded,
|
|
152
161
|
style: {
|
|
153
162
|
...containerStyle,
|
|
154
|
-
maxWidth: isExpanded ?
|
|
163
|
+
maxWidth: isExpanded ? maxWidth : 0
|
|
155
164
|
},
|
|
156
165
|
...otherContainerProps,
|
|
157
166
|
children
|
|
@@ -1 +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;A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AAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,IAAI;AAAA,MACJ,WAAW,GAAG,QAAQ,MAAM,WAAW;AAAA,QACrC,CAAC,QAAQ,SAAS,GAAG;AAAA,QACrB,CAAC,QAAQ,QAAQ,GAAG;AAAA,MAAA,CACrB;AAAA,MACA,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACD;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;"}
|
|
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 useRef,\n useState,\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 = useRef<HTMLDivElement>(null);\n const [maxWidth, setMaxWidth] = useState<number | undefined>(undefined);\n useEffect(() => {\n if (bladeRef.current) {\n const resizeObserver = new ResizeObserver((entries) => {\n setMaxWidth(entries[0].target.clientWidth);\n });\n resizeObserver.observe(\n // using the blade's container as reference max-width is more stable\n bladeRef.current.parentElement ?? bladeRef.current\n );\n return () => {\n resizeObserver.disconnect();\n };\n }\n }, [isExpanded]);\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 ? maxWidth : 0,\n }}\n {...otherContainerProps}\n >\n {children}\n </div>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;AA8Ga,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,sB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;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACD;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,WAAW;AAAA,YACpC;AAAA,YACC,GAAG;AAAA,YAEH;AAAA,UAAA;AAAA,QACH;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/uikit-react-lab",
|
|
3
|
-
"version": "5.27.
|
|
3
|
+
"version": "5.27.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Hitachi Vantara UI Kit Team",
|
|
6
6
|
"description": "Contributed React components for the NEXT UI Kit.",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@dnd-kit/core": "^6.1.0",
|
|
33
33
|
"@dnd-kit/modifiers": "^6.0.1",
|
|
34
34
|
"@emotion/css": "^11.11.0",
|
|
35
|
-
"@hitachivantara/uikit-react-core": "^5.
|
|
35
|
+
"@hitachivantara/uikit-react-core": "^5.52.1",
|
|
36
36
|
"@hitachivantara/uikit-react-icons": "^5.8.4",
|
|
37
37
|
"@hitachivantara/uikit-styles": "^5.20.0",
|
|
38
38
|
"@types/react-grid-layout": "^1.3.5",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"access": "public",
|
|
51
51
|
"directory": "package"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "c76d6549485802b5fdcc6737f946a6a6291c4e34",
|
|
54
54
|
"main": "dist/cjs/index.cjs",
|
|
55
55
|
"exports": {
|
|
56
56
|
".": {
|