@homebound/beam 2.106.4 → 2.109.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.
- package/dist/components/Modal/Modal.d.ts +2 -0
- package/dist/components/Modal/Modal.js +2 -2
- package/dist/components/Table/CollapseToggle.d.ts +1 -0
- package/dist/components/Table/CollapseToggle.js +1 -0
- package/dist/components/Table/GridTable.d.ts +9 -3
- package/dist/components/Table/GridTable.js +14 -1
- package/dist/components/Table/RowState.d.ts +5 -0
- package/dist/components/Table/RowState.js +79 -5
- package/dist/components/Table/SelectToggle.d.ts +4 -0
- package/dist/components/Table/SelectToggle.js +18 -0
- package/dist/components/Table/columns.d.ts +16 -4
- package/dist/components/Table/columns.js +46 -6
- package/dist/components/Table/index.d.ts +1 -0
- package/dist/components/Table/index.js +1 -0
- package/dist/components/Table/visitor.d.ts +2 -0
- package/dist/components/Table/visitor.js +14 -0
- package/dist/forms/BoundCheckboxField.d.ts +1 -1
- package/dist/inputs/Checkbox.d.ts +1 -6
- package/dist/inputs/Checkbox.js +5 -3
- package/dist/utils/useTestIds.d.ts +2 -0
- package/dist/utils/useTestIds.js +2 -1
- package/package.json +1 -1
|
@@ -21,6 +21,8 @@ export interface ModalProps {
|
|
|
21
21
|
onClose?: Callback;
|
|
22
22
|
/** Imperative API for interacting with the Modal */
|
|
23
23
|
api?: MutableRefObject<ModalApi | undefined>;
|
|
24
|
+
/** Adds a border for the header. */
|
|
25
|
+
drawHeaderBorder?: boolean;
|
|
24
26
|
}
|
|
25
27
|
export declare type ModalApi = {
|
|
26
28
|
setSize: (size: ModalProps["size"]) => void;
|
|
@@ -20,7 +20,7 @@ const utils_1 = require("../../utils");
|
|
|
20
20
|
* Provides underlay, modal container, and header. Will disable scrolling of page under the modal.
|
|
21
21
|
*/
|
|
22
22
|
function Modal(props) {
|
|
23
|
-
const { size = "md", content, forceScrolling, api } = props;
|
|
23
|
+
const { size = "md", content, forceScrolling, api, drawHeaderBorder = false } = props;
|
|
24
24
|
const isFixedHeight = typeof size !== "string";
|
|
25
25
|
const ref = (0, react_1.useRef)(null);
|
|
26
26
|
const { modalBodyDiv, modalFooterDiv, modalHeaderDiv, drawerContentStack } = (0, BeamContext_1.useBeamContext)();
|
|
@@ -69,7 +69,7 @@ function Modal(props) {
|
|
|
69
69
|
.df.fdc.wPx(width)
|
|
70
70
|
.mh((0, Css_1.px)(defaultMinHeight))
|
|
71
71
|
.if(isFixedHeight)
|
|
72
|
-
.hPx(height).$, ref: ref }, overlayProps, dialogProps, modalProps, testId, { children: [(0, jsx_runtime_1.jsxs)("header", Object.assign({ css: Css_1.Css.df.p3.fs0.$ }, { children: [(0, jsx_runtime_1.jsx)("h1", Object.assign({ css: Css_1.Css.fg1.xl2Em.gray900.$, ref: modalHeaderRef }, titleProps, testId.title), void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css.fs0.pl1.$ }, { children: (0, jsx_runtime_1.jsx)(IconButton_1.IconButton, Object.assign({ icon: "x", onClick: closeModal }, testId.titleClose), void 0) }), void 0)] }), void 0), (0, jsx_runtime_1.jsxs)("main", Object.assign({ ref: contentRef, css: Css_1.Css.fg1.overflowYAuto.if(hasScroll).bb.bGray200.if(!!forceScrolling).overflowYScroll.$ }, { children: [content, (0, jsx_runtime_1.jsx)("div", { ref: modalBodyRef }, void 0)] }), void 0), (0, jsx_runtime_1.jsx)("footer", Object.assign({ css: Css_1.Css.fs0.$ }, { children: (0, jsx_runtime_1.jsx)("div", { ref: modalFooterRef }, void 0) }), void 0)] }), void 0) }), void 0) }), void 0) }, void 0));
|
|
72
|
+
.hPx(height).$, ref: ref }, overlayProps, dialogProps, modalProps, testId, { children: [(0, jsx_runtime_1.jsxs)("header", Object.assign({ css: Css_1.Css.df.p3.fs0.if(drawHeaderBorder).bb.bGray200.$ }, { children: [(0, jsx_runtime_1.jsx)("h1", Object.assign({ css: Css_1.Css.fg1.xl2Em.gray900.$, ref: modalHeaderRef }, titleProps, testId.title), void 0), (0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css.fs0.pl1.$ }, { children: (0, jsx_runtime_1.jsx)(IconButton_1.IconButton, Object.assign({ icon: "x", onClick: closeModal }, testId.titleClose), void 0) }), void 0)] }), void 0), (0, jsx_runtime_1.jsxs)("main", Object.assign({ ref: contentRef, css: Css_1.Css.fg1.overflowYAuto.if(hasScroll).bb.bGray200.if(!!forceScrolling).overflowYScroll.$ }, { children: [content, (0, jsx_runtime_1.jsx)("div", { ref: modalBodyRef }, void 0)] }), void 0), (0, jsx_runtime_1.jsx)("footer", Object.assign({ css: Css_1.Css.fs0.$ }, { children: (0, jsx_runtime_1.jsx)("div", { ref: modalFooterRef }, void 0) }), void 0)] }), void 0) }), void 0) }), void 0) }, void 0));
|
|
73
73
|
}
|
|
74
74
|
exports.Modal = Modal;
|
|
75
75
|
function ModalHeader({ children }) {
|
|
@@ -2,4 +2,5 @@ import { GridDataRow } from "..";
|
|
|
2
2
|
export interface GridTableCollapseToggleProps {
|
|
3
3
|
row: GridDataRow<any>;
|
|
4
4
|
}
|
|
5
|
+
/** Provides a chevron icons to collapse/un-collapse for parent/child tables. */
|
|
5
6
|
export declare function CollapseToggle(props: GridTableCollapseToggleProps): import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const components_1 = require("..");
|
|
7
7
|
const hooks_1 = require("../../hooks");
|
|
8
|
+
/** Provides a chevron icons to collapse/un-collapse for parent/child tables. */
|
|
8
9
|
function CollapseToggle(props) {
|
|
9
10
|
const { row } = props;
|
|
10
11
|
const { rowState } = (0, react_1.useContext)(components_1.RowStateContext);
|
|
@@ -169,13 +169,17 @@ export interface GridTableProps<R extends Kinded, S, X> {
|
|
|
169
169
|
persistCollapse?: string;
|
|
170
170
|
xss?: X;
|
|
171
171
|
/** Experimental API allowing one to scroll to a table index. Primarily intended for stories at the moment */
|
|
172
|
-
api?: MutableRefObject<GridTableApi | undefined>;
|
|
172
|
+
api?: MutableRefObject<GridTableApi<R> | undefined>;
|
|
173
173
|
/** Experimental, expecting to be removed - Specify the element in which the table should resize its columns against. If not set, the table will resize columns based on its owns container's width */
|
|
174
174
|
resizeTarget?: MutableRefObject<HTMLElement | null>;
|
|
175
175
|
}
|
|
176
176
|
/** NOTE: This API is experimental and primarily intended for story and testing purposes */
|
|
177
|
-
export declare type GridTableApi = {
|
|
177
|
+
export declare type GridTableApi<R extends Kinded> = {
|
|
178
178
|
scrollToIndex: (index: number) => void;
|
|
179
|
+
/** Returns the ids of currently-selected rows. */
|
|
180
|
+
getSelectedRowIds(): string[];
|
|
181
|
+
/** Returns the currently-selected rows. */
|
|
182
|
+
getSelectedRows(): GridDataRow<R>[];
|
|
179
183
|
};
|
|
180
184
|
/**
|
|
181
185
|
* Renders data in our table layout.
|
|
@@ -242,6 +246,7 @@ export declare type GridColumn<R extends Kinded, S = {}> = {
|
|
|
242
246
|
/** This column's sort by value (if server-side sorting). */
|
|
243
247
|
serverSideSortKey?: S;
|
|
244
248
|
};
|
|
249
|
+
export declare const nonKindGridColumnKeys: string[];
|
|
245
250
|
/** Allows rendering a specific cell. */
|
|
246
251
|
declare type RenderCellFn<R extends Kinded> = (idx: number, css: Properties, content: ReactNode, row: R, rowStyle: RowStyle<R> | undefined) => ReactNode;
|
|
247
252
|
/** Defines row-specific styling for each given row `kind` in `R` */
|
|
@@ -298,7 +303,8 @@ export declare type GridDataRow<R extends Kinded> = {
|
|
|
298
303
|
children?: GridDataRow<R>[];
|
|
299
304
|
/** Whether to pin this sort to the first/last of its parent's children. */
|
|
300
305
|
pin?: "first" | "last";
|
|
301
|
-
} & DiscriminateUnion<R, "kind", R["kind"]
|
|
306
|
+
} & IfAny<R, {}, DiscriminateUnion<R, "kind", R["kind"]>>;
|
|
307
|
+
declare type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
302
308
|
/** Return the content for a given column def applied to a given row. */
|
|
303
309
|
export declare function applyRowFn<R extends Kinded>(column: GridColumn<R>, row: GridDataRow<R>): ReactNode | GridCellContent;
|
|
304
310
|
export declare function matchesFilter(maybeContent: ReactNode | GridCellContent, filter: string): boolean;
|
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.matchesFilter = exports.applyRowFn = exports.calcColumnSizes = exports.GridTable = exports.setGridTableDefaults = exports.setDefaultStyle = exports.setRunningInJest = exports.emptyCell = exports.DESC = exports.ASC = void 0;
|
|
25
|
+
exports.matchesFilter = exports.applyRowFn = exports.nonKindGridColumnKeys = exports.calcColumnSizes = exports.GridTable = exports.setGridTableDefaults = exports.setDefaultStyle = exports.setRunningInJest = exports.emptyCell = exports.DESC = exports.ASC = void 0;
|
|
26
26
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
27
27
|
const memoize_one_1 = __importDefault(require("memoize-one"));
|
|
28
28
|
const mobx_react_1 = require("mobx-react");
|
|
@@ -39,6 +39,7 @@ const RowState_1 = require("./RowState");
|
|
|
39
39
|
const SortHeader_1 = require("./SortHeader");
|
|
40
40
|
const sortRows_1 = require("./sortRows");
|
|
41
41
|
const useSortState_1 = require("./useSortState");
|
|
42
|
+
const visitor_1 = require("./visitor");
|
|
42
43
|
const Css_1 = require("../../Css");
|
|
43
44
|
const hooks_1 = require("../../hooks");
|
|
44
45
|
const tinycolor2_1 = __importDefault(require("tinycolor2"));
|
|
@@ -95,6 +96,17 @@ function GridTable(props) {
|
|
|
95
96
|
if (api) {
|
|
96
97
|
api.current = {
|
|
97
98
|
scrollToIndex: (index) => virtuosoRef.current && virtuosoRef.current.scrollToIndex(index),
|
|
99
|
+
getSelectedRowIds: () => rowState.selectedIds,
|
|
100
|
+
getSelectedRows() {
|
|
101
|
+
const ids = rowState.selectedIds;
|
|
102
|
+
const selected = [];
|
|
103
|
+
(0, visitor_1.visit)(rows, (row) => {
|
|
104
|
+
if (ids.includes(row.id)) {
|
|
105
|
+
selected.push(row);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return selected;
|
|
109
|
+
},
|
|
98
110
|
};
|
|
99
111
|
}
|
|
100
112
|
const [sortState, setSortKey] = (0, useSortState_1.useSortState)(columns, sorting);
|
|
@@ -416,6 +428,7 @@ function calcColumnSizes(columns, firstLastColumnWidth, tableWidth, tableMinWidt
|
|
|
416
428
|
return !firstLastColumnWidth ? sizes : [`${firstLastColumnWidth}px`, ...sizes, `${firstLastColumnWidth}px`];
|
|
417
429
|
}
|
|
418
430
|
exports.calcColumnSizes = calcColumnSizes;
|
|
431
|
+
exports.nonKindGridColumnKeys = ["w", "mw", "align", "clientSideSort", "serverSideSortKey"];
|
|
419
432
|
function getIndentationCss(style, rowStyle, columnIndex, maybeContent) {
|
|
420
433
|
// Look for cell-specific indent or row-specific indent (row-specific is only one the first column)
|
|
421
434
|
const indent = (isGridCellContent(maybeContent) && maybeContent.indent) || (columnIndex === 0 && (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.indent));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { MutableRefObject } from "react";
|
|
2
2
|
import { GridDataRow } from "./GridTable";
|
|
3
|
+
export declare type SelectedState = "checked" | "unchecked" | "partial";
|
|
3
4
|
/**
|
|
4
5
|
* Stores the collapsed & selected state of rows.
|
|
5
6
|
*
|
|
@@ -19,10 +20,14 @@ export declare class RowState {
|
|
|
19
20
|
private rows;
|
|
20
21
|
private persistCollapse;
|
|
21
22
|
private readonly collapsedRows;
|
|
23
|
+
private readonly selectedRows;
|
|
22
24
|
/**
|
|
23
25
|
* Creates the `RowState` for a given `GridTable`.
|
|
24
26
|
*/
|
|
25
27
|
constructor(rows: MutableRefObject<GridDataRow<any>[]>, persistCollapse: string | undefined);
|
|
28
|
+
get selectedIds(): string[];
|
|
29
|
+
getSelected(id: string): SelectedState;
|
|
30
|
+
selectRow(id: string, selected: boolean): void;
|
|
26
31
|
get collapsedIds(): string[];
|
|
27
32
|
isCollapsed(id: string): boolean;
|
|
28
33
|
toggleCollapsed(id: string): void;
|
|
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.RowStateContext = exports.RowState = void 0;
|
|
7
7
|
const mobx_1 = require("mobx");
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
// A parent row can be partially selected when some children are selected/some aren't.
|
|
11
|
-
// export type SelectedState = "checked" | "unchecked" | "partial";
|
|
9
|
+
const visitor_1 = require("./visitor");
|
|
12
10
|
/**
|
|
13
11
|
* Stores the collapsed & selected state of rows.
|
|
14
12
|
*
|
|
@@ -25,19 +23,74 @@ const react_1 = __importDefault(require("react"));
|
|
|
25
23
|
* changes.
|
|
26
24
|
*/
|
|
27
25
|
class RowState {
|
|
28
|
-
// Coming in future PR
|
|
29
|
-
// readonly selectedRows = new ObservableMap<string, "checked" | "unchecked" | "partial">();
|
|
30
26
|
/**
|
|
31
27
|
* Creates the `RowState` for a given `GridTable`.
|
|
32
28
|
*/
|
|
33
29
|
constructor(rows, persistCollapse) {
|
|
34
30
|
this.rows = rows;
|
|
35
31
|
this.persistCollapse = persistCollapse;
|
|
32
|
+
this.selectedRows = new mobx_1.ObservableMap();
|
|
36
33
|
this.collapsedRows = new mobx_1.ObservableSet(persistCollapse ? readLocalCollapseState(persistCollapse) : []);
|
|
37
34
|
// Make ourselves an observable so that mobx will do caching of .collapseIds so
|
|
38
35
|
// that it'll be a stable identity for GridTable to useMemo against.
|
|
39
36
|
(0, mobx_1.makeAutoObservable)(this, { rows: false }); // as any b/c rows is private, so the mapped type doesn't see it
|
|
40
37
|
}
|
|
38
|
+
get selectedIds() {
|
|
39
|
+
// Return only ids that are fully checked, i.e. not partial
|
|
40
|
+
const ids = [...this.selectedRows.entries()].filter(([, v]) => v === "checked").map(([k]) => k);
|
|
41
|
+
// Hide our header marker
|
|
42
|
+
const headerIndex = ids.indexOf("header");
|
|
43
|
+
if (headerIndex > -1) {
|
|
44
|
+
ids.splice(headerIndex, 1);
|
|
45
|
+
}
|
|
46
|
+
return ids;
|
|
47
|
+
}
|
|
48
|
+
// Should be called in an Observer/useComputed to trigger re-renders
|
|
49
|
+
getSelected(id) {
|
|
50
|
+
// We may not have every row in here, i.e. on 1st page load or after clicking here, so assume unchecked
|
|
51
|
+
return this.selectedRows.get(id) || "unchecked";
|
|
52
|
+
}
|
|
53
|
+
selectRow(id, selected) {
|
|
54
|
+
if (id === "header") {
|
|
55
|
+
// Select/unselect all has special behavior
|
|
56
|
+
if (selected) {
|
|
57
|
+
// Just mash the header + all rows + children as selected
|
|
58
|
+
const map = new Map();
|
|
59
|
+
map.set("header", "checked");
|
|
60
|
+
(0, visitor_1.visit)(this.rows.current, (row) => map.set(row.id, "checked"));
|
|
61
|
+
this.selectedRows.replace(map);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Similarly "unmash" all rows + children.
|
|
65
|
+
this.selectedRows.clear();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// This is the regular/non-header behavior to just add/remove the individual row id,
|
|
70
|
+
// plus percolate the change down-to-child + up-to-parents.
|
|
71
|
+
// Find the clicked on row
|
|
72
|
+
const curr = findRow(this.rows.current, id);
|
|
73
|
+
if (!curr) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Everything here & down is deterministically on/off
|
|
77
|
+
const map = new Map();
|
|
78
|
+
(0, visitor_1.visit)([curr.row], (row) => map.set(row.id, selected ? "checked" : "unchecked"));
|
|
79
|
+
// Now walk up the parents and see if they are now-all-checked/now-all-unchecked/some-of-each
|
|
80
|
+
for (const parent of [...curr.parents].reverse()) {
|
|
81
|
+
if (parent.children) {
|
|
82
|
+
const children = parent.children.map((row) => map.get(row.id) || this.getSelected(row.id));
|
|
83
|
+
map.set(parent.id, deriveParentSelected(children));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// And do the header + top-level "children" as a final one-off
|
|
87
|
+
const children = this.rows.current
|
|
88
|
+
.filter((row) => row.id !== "header")
|
|
89
|
+
.map((row) => map.get(row.id) || this.getSelected(row.id));
|
|
90
|
+
map.set("header", deriveParentSelected(children));
|
|
91
|
+
this.selectedRows.merge(map);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
41
94
|
get collapsedIds() {
|
|
42
95
|
return [...this.collapsedRows.values()];
|
|
43
96
|
}
|
|
@@ -100,3 +153,24 @@ function readLocalCollapseState(persistCollapse) {
|
|
|
100
153
|
const collapsedGridRowIds = localStorage.getItem(persistCollapse);
|
|
101
154
|
return collapsedGridRowIds ? JSON.parse(collapsedGridRowIds) : [];
|
|
102
155
|
}
|
|
156
|
+
/** Finds a row by id, and returns it + any parents. */
|
|
157
|
+
function findRow(rows, id) {
|
|
158
|
+
// This is technically an array of "maybe FoundRow"
|
|
159
|
+
const todo = rows.map((row) => ({ row, parents: [] }));
|
|
160
|
+
while (todo.length > 0) {
|
|
161
|
+
const curr = todo.pop();
|
|
162
|
+
if (curr.row.id === id) {
|
|
163
|
+
return curr;
|
|
164
|
+
}
|
|
165
|
+
else if (curr.row.children) {
|
|
166
|
+
// Search our children and pass along us as the parent
|
|
167
|
+
todo.push(...curr.row.children.map((child) => ({ row: child, parents: [...curr.parents, curr.row] })));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
function deriveParentSelected(children) {
|
|
173
|
+
const allChecked = children.every((child) => child === "checked");
|
|
174
|
+
const allUnchecked = children.every((child) => child === "unchecked");
|
|
175
|
+
return allChecked ? "checked" : allUnchecked ? "unchecked" : "partial";
|
|
176
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectToggle = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const RowState_1 = require("./RowState");
|
|
7
|
+
const index_1 = require("../../hooks/index");
|
|
8
|
+
const index_2 = require("../../inputs/index");
|
|
9
|
+
/** Provides a checkbox to show/drive this row's selected state. */
|
|
10
|
+
function SelectToggle({ id }) {
|
|
11
|
+
const { rowState } = (0, react_1.useContext)(RowState_1.RowStateContext);
|
|
12
|
+
const state = (0, index_1.useComputed)(() => rowState.getSelected(id), [rowState]);
|
|
13
|
+
const selected = state === "checked" ? true : state === "unchecked" ? false : "indeterminate";
|
|
14
|
+
return ((0, jsx_runtime_1.jsx)(index_2.Checkbox, { label: "Select", checkboxOnly: true, selected: selected, onChange: (selected) => {
|
|
15
|
+
rowState.selectRow(id, selected);
|
|
16
|
+
} }, void 0));
|
|
17
|
+
}
|
|
18
|
+
exports.SelectToggle = SelectToggle;
|
|
@@ -8,7 +8,19 @@ export declare function dateColumn<T extends Kinded, S = {}>(columnDef: GridColu
|
|
|
8
8
|
export declare function numericColumn<T extends Kinded, S = {}>(columnDef: GridColumn<T, S>): GridColumn<T, S>;
|
|
9
9
|
/** Provides default styling for a GridColumn representing an Action. */
|
|
10
10
|
export declare function actionColumn<T extends Kinded, S = {}>(columnDef: GridColumn<T, S>): GridColumn<T, S>;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Provides default styling for a GridColumn containing a checkbox.
|
|
13
|
+
*
|
|
14
|
+
* We allow either no `columnDef` at all, or a partial column def (i.e. to say a Totals row should
|
|
15
|
+
* not have a `SelectToggle`, b/c we can provide the default behavior a `SelectToggle` for basically
|
|
16
|
+
* all rows.
|
|
17
|
+
*/
|
|
18
|
+
export declare function selectColumn<T extends Kinded, S = {}>(columnDef?: Partial<GridColumn<T, S>>): GridColumn<T, S>;
|
|
19
|
+
/**
|
|
20
|
+
* Provides default styling for a GridColumn containing a collapse icon.
|
|
21
|
+
*
|
|
22
|
+
* We allow either no `columnDef` at all, or a partial column def (i.e. to say a Totals row should
|
|
23
|
+
* not have a `CollapseToggle`, b/c we can provide the default behavior a `CollapseToggle` for basically
|
|
24
|
+
* all rows.
|
|
25
|
+
*/
|
|
26
|
+
export declare function collapseColumn<T extends Kinded, S = {}>(columnDef?: Partial<GridColumn<T, S>>): GridColumn<T, S>;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.collapseColumn = exports.selectColumn = exports.actionColumn = exports.numericColumn = exports.dateColumn = exports.column = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
+
const CollapseToggle_1 = require("./CollapseToggle");
|
|
6
|
+
const GridTable_1 = require("./GridTable");
|
|
7
|
+
const SelectToggle_1 = require("./SelectToggle");
|
|
8
|
+
const index_1 = require("../../utils/index");
|
|
4
9
|
/** Provides default styling for a GridColumn representing a Date. */
|
|
5
10
|
function column(columnDef) {
|
|
6
11
|
return { ...columnDef };
|
|
@@ -22,15 +27,50 @@ function actionColumn(columnDef) {
|
|
|
22
27
|
return { clientSideSort: false, ...columnDef, align: "center" };
|
|
23
28
|
}
|
|
24
29
|
exports.actionColumn = actionColumn;
|
|
25
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Provides default styling for a GridColumn containing a checkbox.
|
|
32
|
+
*
|
|
33
|
+
* We allow either no `columnDef` at all, or a partial column def (i.e. to say a Totals row should
|
|
34
|
+
* not have a `SelectToggle`, b/c we can provide the default behavior a `SelectToggle` for basically
|
|
35
|
+
* all rows.
|
|
36
|
+
*/
|
|
26
37
|
function selectColumn(columnDef) {
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
const base = {
|
|
39
|
+
...nonKindDefaults(),
|
|
40
|
+
clientSideSort: false,
|
|
41
|
+
align: "center",
|
|
42
|
+
// Defining `w: 48px` to accommodate for the `16px` wide checkbox and `16px` of padding on either side.
|
|
43
|
+
w: "48px",
|
|
44
|
+
// Use any of the user's per-row kind methods if they have them.
|
|
45
|
+
...columnDef,
|
|
46
|
+
};
|
|
47
|
+
return (0, index_1.newMethodMissingProxy)(base, (key) => {
|
|
48
|
+
return (row) => ({ content: (0, jsx_runtime_1.jsx)(SelectToggle_1.SelectToggle, { id: row.id }, void 0) });
|
|
49
|
+
});
|
|
29
50
|
}
|
|
30
51
|
exports.selectColumn = selectColumn;
|
|
31
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Provides default styling for a GridColumn containing a collapse icon.
|
|
54
|
+
*
|
|
55
|
+
* We allow either no `columnDef` at all, or a partial column def (i.e. to say a Totals row should
|
|
56
|
+
* not have a `CollapseToggle`, b/c we can provide the default behavior a `CollapseToggle` for basically
|
|
57
|
+
* all rows.
|
|
58
|
+
*/
|
|
32
59
|
function collapseColumn(columnDef) {
|
|
33
|
-
|
|
34
|
-
|
|
60
|
+
const base = {
|
|
61
|
+
...nonKindDefaults(),
|
|
62
|
+
clientSideSort: false,
|
|
63
|
+
align: "center",
|
|
64
|
+
// Defining `w: 38px` based on the designs
|
|
65
|
+
w: "38px",
|
|
66
|
+
...columnDef,
|
|
67
|
+
};
|
|
68
|
+
return (0, index_1.newMethodMissingProxy)(base, (key) => {
|
|
69
|
+
return (row) => ({ content: (0, jsx_runtime_1.jsx)(CollapseToggle_1.CollapseToggle, { row: row }, void 0) });
|
|
70
|
+
});
|
|
35
71
|
}
|
|
36
72
|
exports.collapseColumn = collapseColumn;
|
|
73
|
+
// Keep keys like `w` and `mw` from hitting the method missing proxy
|
|
74
|
+
function nonKindDefaults() {
|
|
75
|
+
return Object.fromEntries(GridTable_1.nonKindGridColumnKeys.map((key) => [key, undefined]));
|
|
76
|
+
}
|
|
@@ -5,6 +5,7 @@ export { GridSortContext } from "./GridSortContext";
|
|
|
5
5
|
export { ASC, DESC, GridTable, setDefaultStyle, setGridTableDefaults } from "./GridTable";
|
|
6
6
|
export type { Direction, GridCellAlignment, GridCellContent, GridColumn, GridDataRow, GridRowStyles, GridSortConfig, GridStyle, GridTableDefaults, GridTableProps, GridTableXss, Kinded, RowStyle, setRunningInJest, } from "./GridTable";
|
|
7
7
|
export { RowState, RowStateContext } from "./RowState";
|
|
8
|
+
export * from "./SelectToggle";
|
|
8
9
|
export { simpleDataRows, simpleHeader, simpleRows } from "./simpleHelpers";
|
|
9
10
|
export type { SimpleHeaderAndDataOf, SimpleHeaderAndDataWith } from "./simpleHelpers";
|
|
10
11
|
export { SortHeader } from "./SortHeader";
|
|
@@ -24,6 +24,7 @@ Object.defineProperty(exports, "setGridTableDefaults", { enumerable: true, get:
|
|
|
24
24
|
var RowState_1 = require("./RowState");
|
|
25
25
|
Object.defineProperty(exports, "RowState", { enumerable: true, get: function () { return RowState_1.RowState; } });
|
|
26
26
|
Object.defineProperty(exports, "RowStateContext", { enumerable: true, get: function () { return RowState_1.RowStateContext; } });
|
|
27
|
+
__exportStar(require("./SelectToggle"), exports);
|
|
27
28
|
var simpleHelpers_1 = require("./simpleHelpers");
|
|
28
29
|
Object.defineProperty(exports, "simpleDataRows", { enumerable: true, get: function () { return simpleHelpers_1.simpleDataRows; } });
|
|
29
30
|
Object.defineProperty(exports, "simpleHeader", { enumerable: true, get: function () { return simpleHelpers_1.simpleHeader; } });
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.visit = void 0;
|
|
4
|
+
function visit(rows, fn) {
|
|
5
|
+
const todo = [...rows];
|
|
6
|
+
while (todo.length > 0) {
|
|
7
|
+
const row = todo.pop();
|
|
8
|
+
fn(row);
|
|
9
|
+
if (row.children) {
|
|
10
|
+
todo.push(...row.children);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.visit = visit;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FieldState } from "@homebound/form-state";
|
|
2
2
|
import { CheckboxProps } from "../inputs";
|
|
3
|
-
export declare type BoundCheckboxFieldProps = Omit<CheckboxProps, "
|
|
3
|
+
export declare type BoundCheckboxFieldProps = Omit<CheckboxProps, "selected" | "onChange" | "label"> & {
|
|
4
4
|
field: FieldState<any, boolean | null | undefined>;
|
|
5
5
|
/** Make optional so that callers can override if they want to. */
|
|
6
6
|
onChange?: (values: boolean) => void;
|
|
@@ -2,17 +2,12 @@ import { ReactNode } from "react";
|
|
|
2
2
|
export interface CheckboxProps {
|
|
3
3
|
label: string;
|
|
4
4
|
checkboxOnly?: boolean;
|
|
5
|
+
selected: boolean | "indeterminate";
|
|
5
6
|
/** Handler that is called when the element's selection state changes. */
|
|
6
7
|
onChange: (selected: boolean) => void;
|
|
7
8
|
/** Additional text displayed below label */
|
|
8
9
|
description?: string;
|
|
9
10
|
disabled?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Indeterminism is presentational only.
|
|
12
|
-
* The indeterminate visual representation remains regardless of user interaction.
|
|
13
|
-
*/
|
|
14
|
-
indeterminate?: boolean;
|
|
15
|
-
selected?: boolean;
|
|
16
11
|
errorMsg?: string;
|
|
17
12
|
helperText?: string | ReactNode;
|
|
18
13
|
/** Callback fired when focus removes from the component */
|
package/dist/inputs/Checkbox.js
CHANGED
|
@@ -7,12 +7,14 @@ const react_aria_1 = require("react-aria");
|
|
|
7
7
|
const react_stately_1 = require("react-stately");
|
|
8
8
|
const CheckboxBase_1 = require("./CheckboxBase");
|
|
9
9
|
function Checkbox(props) {
|
|
10
|
-
const { label,
|
|
11
|
-
|
|
10
|
+
const { label, disabled: isDisabled = false, selected, ...otherProps } = props;
|
|
11
|
+
// Treat indeterminate as false so that clicking on indeterminate always goes --> true.
|
|
12
|
+
const isSelected = selected === true;
|
|
13
|
+
const isIndeterminate = selected === "indeterminate";
|
|
14
|
+
const ariaProps = { isSelected, isDisabled, isIndeterminate, ...otherProps };
|
|
12
15
|
const checkboxProps = { ...ariaProps, "aria-label": label };
|
|
13
16
|
const ref = (0, react_1.useRef)(null);
|
|
14
17
|
const toggleState = (0, react_stately_1.useToggleState)(ariaProps);
|
|
15
|
-
const isSelected = toggleState.isSelected;
|
|
16
18
|
const { inputProps } = (0, react_aria_1.useCheckbox)(checkboxProps, toggleState, ref);
|
|
17
19
|
return ((0, jsx_runtime_1.jsx)(CheckboxBase_1.CheckboxBase, Object.assign({ ariaProps: ariaProps, isDisabled: isDisabled, isIndeterminate: isIndeterminate, isSelected: isSelected, inputProps: inputProps, label: label }, otherProps), void 0));
|
|
18
20
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare type TestIds = Record<string, object>;
|
|
2
2
|
export declare function useTestIds(props: object, defaultPrefix?: string): Record<string, object>;
|
|
3
|
+
/** Uses `object` for any keys that exist on it, otherwise calls `methodMissing` fn. */
|
|
4
|
+
export declare function newMethodMissingProxy<T extends object, Y>(object: T, methodMissing: (key: string) => Y): T & Record<string, Y>;
|
package/dist/utils/useTestIds.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useTestIds = void 0;
|
|
3
|
+
exports.newMethodMissingProxy = exports.useTestIds = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Provides a way to easily generate `data-testid`s.
|
|
6
6
|
*
|
|
@@ -59,3 +59,4 @@ function newMethodMissingProxy(object, methodMissing) {
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
+
exports.newMethodMissingProxy = newMethodMissingProxy;
|