@homebound/beam 2.347.2 → 2.348.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.
|
@@ -17,6 +17,8 @@ export interface AccordionProps<X = AccordionXss> {
|
|
|
17
17
|
*/
|
|
18
18
|
index?: number;
|
|
19
19
|
setExpandedIndex?: Dispatch<SetStateAction<number | undefined>>;
|
|
20
|
+
/** Turns the title into a button. If provided, disables expand/collapse on title text */
|
|
21
|
+
titleOnClick?: VoidFunction;
|
|
20
22
|
/** Used by Accordion list. Sets default padding to 0 for nested accordions */
|
|
21
23
|
omitPadding?: boolean;
|
|
22
24
|
/** Styles overrides for padding */
|
|
@@ -9,8 +9,8 @@ const Icon_1 = require("./Icon");
|
|
|
9
9
|
const Css_1 = require("../Css");
|
|
10
10
|
const utils_2 = require("../utils");
|
|
11
11
|
function Accordion(props) {
|
|
12
|
-
const { title, children, size, disabled = false, defaultExpanded = false, compact = false, topBorder = compact ? false : true, bottomBorder = false, index, setExpandedIndex, omitPadding = false, xss, } = props;
|
|
13
|
-
const
|
|
12
|
+
const { title, children, size, disabled = false, defaultExpanded = false, compact = false, topBorder = compact ? false : true, bottomBorder = false, index, setExpandedIndex, titleOnClick, omitPadding = false, xss, } = props;
|
|
13
|
+
const tid = (0, utils_2.useTestIds)(props, "accordion");
|
|
14
14
|
const id = (0, utils_1.useId)();
|
|
15
15
|
const [expanded, setExpanded] = (0, react_1.useState)(defaultExpanded && !disabled);
|
|
16
16
|
const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)();
|
|
@@ -36,26 +36,32 @@ function Accordion(props) {
|
|
|
36
36
|
}
|
|
37
37
|
}, [expanded, setContentHeight]);
|
|
38
38
|
(0, utils_1.useResizeObserver)({ ref: contentRef, onResize });
|
|
39
|
-
|
|
39
|
+
const toggle = (0, react_1.useCallback)(() => {
|
|
40
|
+
setExpanded((prev) => !prev);
|
|
41
|
+
if (setExpandedIndex)
|
|
42
|
+
setExpandedIndex(index);
|
|
43
|
+
}, [index, setExpandedIndex]);
|
|
44
|
+
const touchableStyle = (0, react_1.useMemo)(() => ({
|
|
45
|
+
...Css_1.Css.df.jcsb.gapPx(12).aic.p2.baseMd.outline("none").onHover.bgGray100.if(!!titleOnClick).baseSb.$,
|
|
46
|
+
...(compact && Css_1.Css.smMd.pl2.prPx(10).py1.bgGray100.mbPx(4).br8.onHover.bgGray200.$),
|
|
47
|
+
...(compact && !!titleOnClick && Css_1.Css.br0.$),
|
|
48
|
+
...(disabled && Css_1.Css.gray500.$),
|
|
49
|
+
...(isFocusVisible && Css_1.Css.boxShadow(`inset 0 0 0 2px ${Css_1.Palette.Blue700}`).$),
|
|
50
|
+
...xss,
|
|
51
|
+
}), [compact, disabled, isFocusVisible, titleOnClick, xss]);
|
|
52
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ...tid.container, css: {
|
|
40
53
|
...Css_1.Css.bGray300.if(topBorder).bt.if(bottomBorder).bb.$,
|
|
41
54
|
...(size ? Css_1.Css.wPx(accordionSizes[size]).$ : {}),
|
|
42
|
-
}, children: [(0, jsx_runtime_1.jsxs)("button", { ...
|
|
43
|
-
...Css_1.Css.df.jcsb.gapPx(12).aic.w100.p2.baseMd.outline("none").onHover.bgGray100.$,
|
|
44
|
-
...(compact && Css_1.Css.smMd.pl2.prPx(10).py1.bgGray100.mbPx(4).br8.onHover.bgGray200.$),
|
|
45
|
-
...(disabled && Css_1.Css.gray500.$),
|
|
46
|
-
...(isFocusVisible && Css_1.Css.boxShadow(`inset 0 0 0 2px ${Css_1.Palette.Blue700}`).$),
|
|
47
|
-
...xss,
|
|
48
|
-
}, onClick: () => {
|
|
49
|
-
setExpanded(!expanded);
|
|
50
|
-
if (setExpandedIndex)
|
|
51
|
-
setExpandedIndex(index);
|
|
52
|
-
}, children: [(0, jsx_runtime_1.jsx)("span", { css: Css_1.Css.fg1.tl.$, children: title }), (0, jsx_runtime_1.jsx)("span", { css: {
|
|
53
|
-
...Css_1.Css.fs0.$,
|
|
54
|
-
transition: "transform 250ms linear",
|
|
55
|
-
transform: expanded ? "rotate(180deg)" : "rotate(0deg)",
|
|
56
|
-
}, children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: "chevronDown" }) })] }), (0, jsx_runtime_1.jsx)("div", { ...testIds.details, id: id, "aria-hidden": !expanded, css: Css_1.Css.overflowHidden.h(contentHeight).add("transition", "height 250ms ease-in-out").$, children: expanded && ((0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.px2.pb2.pt1.if(omitPadding).p0.$, ref: contentRef, ...testIds.content, children: children })) })] }));
|
|
55
|
+
}, children: [titleOnClick ? ((0, jsx_runtime_1.jsxs)("div", { ...focusProps, "aria-controls": id, "aria-expanded": expanded, css: Css_1.Css.df.$, children: [(0, jsx_runtime_1.jsx)("button", { ...tid.title, disabled: disabled, css: { ...touchableStyle, ...Css_1.Css.fg0.$ }, onClick: titleOnClick, children: title }), (0, jsx_runtime_1.jsx)("button", { ...tid.toggle, disabled: disabled, css: { ...touchableStyle, ...Css_1.Css.fg1.jcfe.$ }, onClick: toggle, children: (0, jsx_runtime_1.jsx)(RotatingChevronIcon, { expanded: expanded }) })] })) : ((0, jsx_runtime_1.jsxs)("button", { ...tid.title, ...focusProps, "aria-controls": id, "aria-expanded": expanded, disabled: disabled, css: { ...Css_1.Css.w100.$, ...touchableStyle }, onClick: toggle, children: [(0, jsx_runtime_1.jsx)("span", { css: Css_1.Css.fg1.tl.$, children: title }), (0, jsx_runtime_1.jsx)(RotatingChevronIcon, { expanded: expanded })] })), (0, jsx_runtime_1.jsx)("div", { ...tid.details, id: id, "aria-hidden": !expanded, css: Css_1.Css.overflowHidden.h(contentHeight).add("transition", "height 250ms ease-in-out").$, children: expanded && ((0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.px2.pb2.pt1.if(omitPadding).p0.$, ref: contentRef, ...tid.content, children: children })) })] }));
|
|
57
56
|
}
|
|
58
57
|
exports.Accordion = Accordion;
|
|
58
|
+
function RotatingChevronIcon(props) {
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)("span", { css: {
|
|
60
|
+
...Css_1.Css.fs0.$,
|
|
61
|
+
transition: "transform 250ms linear",
|
|
62
|
+
transform: props.expanded ? "rotate(180deg)" : "rotate(0deg)",
|
|
63
|
+
}, children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: "chevronDown" }) }));
|
|
64
|
+
}
|
|
59
65
|
const accordionSizes = {
|
|
60
66
|
xs: 240,
|
|
61
67
|
sm: 360,
|