@homebound/beam 2.180.0 → 2.181.1
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/components/Accordion.d.ts +20 -0
- package/dist/components/Accordion.js +42 -0
- package/dist/components/AccordionList.d.ts +9 -0
- package/dist/components/AccordionList.js +15 -0
- package/dist/components/Table/GridTable.js +0 -1
- package/dist/components/Table/RowState.js +10 -6
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -410,7 +410,6 @@ function calcColumnSizes(columns, tableWidth, tableMinWidthPx = 0) {
|
|
|
410
410
|
}, { claimedPercentages: 0, claimedPixels: 0, totalFr: 0 });
|
|
411
411
|
// This is our "fake but for some reason it lines up better" fr calc
|
|
412
412
|
function fr(myFr) {
|
|
413
|
-
console.log("tableWidth", tableWidth);
|
|
414
413
|
// If the tableWidth, then return a pixel value
|
|
415
414
|
if (tableWidth) {
|
|
416
415
|
const widthBasis = Math.max(tableWidth, tableMinWidthPx);
|
|
@@ -70,28 +70,32 @@ class RowState {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
loadSelected(rows) {
|
|
73
|
-
const selectedRows = rows.filter(row => row.initSelected);
|
|
74
|
-
// Initialize with selected rows as defined
|
|
73
|
+
const selectedRows = rows.filter((row) => row.initSelected);
|
|
74
|
+
// Initialize with selected rows as defined
|
|
75
75
|
const map = new Map();
|
|
76
|
-
selectedRows.forEach(row => {
|
|
76
|
+
selectedRows.forEach((row) => {
|
|
77
77
|
map.set(row.id, "checked");
|
|
78
78
|
});
|
|
79
79
|
this.selectedRows.merge(map);
|
|
80
80
|
}
|
|
81
81
|
// Updates the list of rows and regenerates the collapsedRows property if needed.
|
|
82
82
|
setRows(rows) {
|
|
83
|
-
// If the set of rows are different
|
|
84
|
-
if (rows !== this.rows
|
|
83
|
+
// If the set of rows are different
|
|
84
|
+
if (rows !== this.rows) {
|
|
85
85
|
const currentCollapsedIds = this.collapsedIds;
|
|
86
86
|
// Create a list of the (maybe) new rows that should be initially collapsed
|
|
87
87
|
const maybeNewCollapsedRows = flattenRows(rows).filter((r) => r.initCollapsed);
|
|
88
|
+
// Check against local storage for collapsed state only if this is the first render of "data" (non-header or totals) rows.
|
|
89
|
+
const checkLocalStorage = this.persistCollapse && !this.rows.some((r) => r.kind !== "totals" && r.kind !== "header");
|
|
88
90
|
// If the list of collapsed rows are different, then determine which are net-new rows and should be added to the newCollapsedIds array
|
|
89
91
|
if (currentCollapsedIds.length !== maybeNewCollapsedRows.length ||
|
|
90
92
|
!currentCollapsedIds.every((id) => maybeNewCollapsedRows.some((r) => r.id === id))) {
|
|
91
93
|
// Flatten out the existing rows to make checking for new rows easier
|
|
92
94
|
const flattenedExistingIds = flattenRows(this.rows).map((r) => r.id);
|
|
93
95
|
const newCollapsedIds = maybeNewCollapsedRows
|
|
94
|
-
.filter((maybeNewRow) => !flattenedExistingIds.includes(maybeNewRow.id)
|
|
96
|
+
.filter((maybeNewRow) => !flattenedExistingIds.includes(maybeNewRow.id) &&
|
|
97
|
+
// Using `!` on `this.persistCollapse!` as `checkLocalStorage` ensures this.persistCollapse is truthy
|
|
98
|
+
(!checkLocalStorage || readLocalCollapseState(this.persistCollapse).includes(maybeNewRow.id)))
|
|
95
99
|
.map((row) => row.id);
|
|
96
100
|
// If there are new rows that should be collapsed then update the collapsedRows arrays
|
|
97
101
|
if (newCollapsedIds.length > 0) {
|