@homebound/beam 2.180.0 → 2.181.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,20 @@
|
|
|
1
|
+
import { Dispatch, ReactNode, SetStateAction } from "react";
|
|
2
|
+
export interface AccordionProps {
|
|
3
|
+
title: ReactNode;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
defaultExpanded?: boolean;
|
|
7
|
+
size?: AccordionSize;
|
|
8
|
+
/** Adds a top border (enabled by default) */
|
|
9
|
+
topBorder?: boolean;
|
|
10
|
+
/** Adds a bottom border (disabled by default) */
|
|
11
|
+
bottomBorder?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Used by AccordionList
|
|
14
|
+
* Allows multiple accordions to be expanded simultaneously (enabled by default)
|
|
15
|
+
*/
|
|
16
|
+
index?: number;
|
|
17
|
+
setExpandedIndex?: Dispatch<SetStateAction<number | undefined>>;
|
|
18
|
+
}
|
|
19
|
+
export declare function Accordion(props: AccordionProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare type AccordionSize = "xs" | "sm" | "md" | "lg";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Accordion = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const utils_1 = require("@react-aria/utils");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const react_aria_1 = require("react-aria");
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
function Accordion(props) {
|
|
10
|
+
const { title, children, size, disabled = false, defaultExpanded = false, topBorder = true, bottomBorder = false, index, setExpandedIndex, } = props;
|
|
11
|
+
const testIds = (0, index_1.useTestIds)(props, "accordion");
|
|
12
|
+
const id = (0, utils_1.useId)();
|
|
13
|
+
const [expanded, setExpanded] = (0, react_1.useState)(defaultExpanded);
|
|
14
|
+
const { isFocusVisible, focusProps } = (0, react_aria_1.useFocusRing)();
|
|
15
|
+
(0, react_1.useEffect)(() => { setExpanded(defaultExpanded); }, [defaultExpanded]);
|
|
16
|
+
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, testIds.container, { css: {
|
|
17
|
+
...index_1.Css.bGray400.if(topBorder).bt.if(bottomBorder).bb.$,
|
|
18
|
+
...(size ? index_1.Css.wPx(accordionSizes[size]).$ : {}),
|
|
19
|
+
} }, { children: [(0, jsx_runtime_1.jsxs)("button", Object.assign({}, testIds.title, focusProps, { "aria-controls": id, "aria-expanded": expanded, disabled: disabled, css: {
|
|
20
|
+
...index_1.Css.df.jcsb.gap2.aic.w100.p2.baseEm.outline("none").addIn(":hover", index_1.Css.bgGray100.$).$,
|
|
21
|
+
...(disabled && index_1.Css.gray500.$),
|
|
22
|
+
...(isFocusVisible && index_1.Css.boxShadow(`inset 0 0 0 2px ${index_1.Palette.LightBlue700}`).$),
|
|
23
|
+
}, onClick: () => {
|
|
24
|
+
setExpanded(!expanded);
|
|
25
|
+
if (setExpandedIndex)
|
|
26
|
+
setExpandedIndex(index);
|
|
27
|
+
} }, { children: [(0, jsx_runtime_1.jsx)("span", { children: title }, void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({ css: {
|
|
28
|
+
transition: "transform 250ms linear",
|
|
29
|
+
transform: expanded ? "rotate(180deg)" : "rotate(0deg)",
|
|
30
|
+
} }, { children: (0, jsx_runtime_1.jsx)(index_1.Icon, { icon: "chevronDown" }, void 0) }), void 0)] }), void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({}, testIds.details, { id: id, "aria-hidden": !expanded, css: {
|
|
31
|
+
// Use max-height for grow/shrink animation (remove close animation for AccordionList to avoid delays)
|
|
32
|
+
...index_1.Css.overflowHidden.maxhPx(1000).add("transition", `max-height ${expanded || !index ? "250ms" : "0"} ease-in-out`).$,
|
|
33
|
+
...(!expanded || disabled ? index_1.Css.maxh0.$ : {}),
|
|
34
|
+
} }, { children: (0, jsx_runtime_1.jsx)("div", Object.assign({ css: index_1.Css.px2.pb2.pt1.$ }, { children: children }), void 0) }), void 0)] }), void 0));
|
|
35
|
+
}
|
|
36
|
+
exports.Accordion = Accordion;
|
|
37
|
+
const accordionSizes = {
|
|
38
|
+
xs: 240,
|
|
39
|
+
sm: 360,
|
|
40
|
+
md: 480,
|
|
41
|
+
lg: 600,
|
|
42
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AccordionProps, AccordionSize } from "./Accordion";
|
|
2
|
+
interface AccordionListProps {
|
|
3
|
+
accordions: AccordionProps[];
|
|
4
|
+
/** Allows multiple accordions to be expanded simultaneously (enabled by default) */
|
|
5
|
+
allowMultipleExpanded?: boolean;
|
|
6
|
+
size?: AccordionSize;
|
|
7
|
+
}
|
|
8
|
+
export declare function AccordionList(props: AccordionListProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccordionList = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const react_1 = require("@emotion/react");
|
|
6
|
+
const react_2 = require("react");
|
|
7
|
+
const __1 = require("..");
|
|
8
|
+
const Accordion_1 = require("./Accordion");
|
|
9
|
+
function AccordionList(props) {
|
|
10
|
+
const { accordions, size, allowMultipleExpanded = true } = props;
|
|
11
|
+
const [expandedIndex, setExpandedIndex] = (0, react_2.useState)();
|
|
12
|
+
const tid = (0, __1.useTestIds)(props, "accordionList");
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: accordions.map((accordionProps, index, arr) => ((0, react_1.createElement)(Accordion_1.Accordion, { ...accordionProps, ...tid, key: index, size: size, bottomBorder: index === arr.length - 1, defaultExpanded: !allowMultipleExpanded && expandedIndex === index, index: index, setExpandedIndex: setExpandedIndex }))) }, void 0));
|
|
14
|
+
}
|
|
15
|
+
exports.AccordionList = AccordionList;
|