@homebound/beam 2.250.1 → 2.252.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
import { Margin, Only, Xss } from "../Css";
|
|
3
|
-
type ChipType = "caution" | "warning" | "success" | "light" | "dark" | "neutral";
|
|
3
|
+
type ChipType = "caution" | "warning" | "success" | "light" | "dark" | "neutral" | "darkMode";
|
|
4
4
|
export declare const ChipTypes: Record<ChipType, ChipType>;
|
|
5
5
|
export interface ChipProps<X> {
|
|
6
6
|
text: string;
|
package/dist/components/Chip.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.ChipTypes = {
|
|
|
14
14
|
light: "light",
|
|
15
15
|
dark: "dark",
|
|
16
16
|
neutral: "neutral",
|
|
17
|
+
darkMode: "darkMode",
|
|
17
18
|
};
|
|
18
19
|
/** Kinda like a chip, but read-only, so no `onClick` or `hover`. */
|
|
19
20
|
function Chip({ type = exports.ChipTypes.neutral, ...props }) {
|
|
@@ -38,4 +39,5 @@ const typeStyles = {
|
|
|
38
39
|
light: Css_1.Css.bgWhite.$,
|
|
39
40
|
dark: Css_1.Css.bgGray900.white.$,
|
|
40
41
|
neutral: Css_1.Css.bgGray200.$,
|
|
42
|
+
darkMode: Css_1.Css.bgGray700.white.$,
|
|
41
43
|
};
|
|
@@ -64,6 +64,8 @@ export interface GridStyleDef {
|
|
|
64
64
|
allWhite?: boolean;
|
|
65
65
|
bordered?: boolean;
|
|
66
66
|
rowHover?: boolean;
|
|
67
|
+
/** Defines the vertical alignment of the content of the cells for the whole table (not including the 'header' rows). Defaults to `center` */
|
|
68
|
+
vAlign?: "top" | "center" | "bottom";
|
|
67
69
|
}
|
|
68
70
|
export declare const getTableStyles: (props?: GridStyleDef) => GridStyle;
|
|
69
71
|
export declare const totalsRowHeight = 52;
|
|
@@ -7,12 +7,13 @@ const utils_1 = require("../../utils");
|
|
|
7
7
|
function memoizedTableStyles() {
|
|
8
8
|
const cache = {};
|
|
9
9
|
return (props = {}) => {
|
|
10
|
-
const { inlineEditing = false, grouped = false, rowHeight = "flexible", cellHighlight = false, allWhite = false, bordered = false, } = props;
|
|
10
|
+
const { inlineEditing = false, grouped = false, rowHeight = "flexible", cellHighlight = false, allWhite = false, bordered = false, vAlign = "center", } = props;
|
|
11
11
|
const key = (0, utils_1.safeKeys)(props)
|
|
12
12
|
.sort()
|
|
13
13
|
.map((k) => `${k}_${props[k]}`)
|
|
14
14
|
.join("|");
|
|
15
15
|
if (!cache[key]) {
|
|
16
|
+
const alignItems = vAlign === "center" ? "center" : vAlign === "top" ? "flex-start" : "flex-end";
|
|
16
17
|
const groupedLevels = {
|
|
17
18
|
0: {
|
|
18
19
|
cellCss: {
|
|
@@ -44,7 +45,7 @@ function memoizedTableStyles() {
|
|
|
44
45
|
.py0.boxShadow(`inset 0 -1px 0 ${Css_1.Palette.Gray200}`)
|
|
45
46
|
.addIn("&:not(:last-of-type)", Css_1.Css.boxShadow(`inset -1px -1px 0 ${Css_1.Palette.Gray200}`).$).$,
|
|
46
47
|
cellCss: {
|
|
47
|
-
...Css_1.Css.gray900.xs.bgWhite.
|
|
48
|
+
...Css_1.Css.gray900.xs.bgWhite.ai(alignItems).pxPx(12).boxShadow(`inset 0 -1px 0 ${Css_1.Palette.Gray200}`).$,
|
|
48
49
|
...(rowHeight === "flexible" ? Css_1.Css.pyPx(12).$ : Css_1.Css.nowrap.hPx(inlineEditing ? 48 : 36).$),
|
|
49
50
|
...(cellHighlight ? { "&:hover": Css_1.Css.bgGray100.$ } : {}),
|
|
50
51
|
...(bordered && { "&:first-of-type": Css_1.Css.bl.bGray200.$, "&:last-of-type": Css_1.Css.br.bGray200.$ }),
|
package/dist/utils/rtl.d.ts
CHANGED
|
@@ -17,5 +17,18 @@ export declare function cellOf(r: RenderResult, tableTestId: string, rowNum: num
|
|
|
17
17
|
export declare function cellAnd(r: RenderResult, row: number, column: number, testId: string): HTMLElement;
|
|
18
18
|
export declare function row(r: RenderResult, row: number, tableTestId?: string): HTMLElement;
|
|
19
19
|
export declare function rowAnd(r: RenderResult, rowNum: number, testId: string): HTMLElement;
|
|
20
|
+
/** Intended to be used to generate a human-readable text
|
|
21
|
+
* representation of a GridTable using the markdown table syntax.
|
|
22
|
+
* * Example Use: expect(tableSnapshot(r)).toMatchInlineSnapshot(`
|
|
23
|
+
"
|
|
24
|
+
| Name | Value |
|
|
25
|
+
| ------------------------ | ----- |
|
|
26
|
+
| Row 1 | 200 |
|
|
27
|
+
| Row 2 with a longer name | 300 |
|
|
28
|
+
| Row 3 | 1000 |
|
|
29
|
+
"
|
|
30
|
+
`);
|
|
31
|
+
* */
|
|
32
|
+
export declare function tableSnapshot(r: RenderResult): string;
|
|
20
33
|
/** RTL wrapper for Beam's SuperDrawer/Modal context. */
|
|
21
34
|
export declare const withBeamRTL: Wrapper;
|
package/dist/utils/rtl.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withBeamRTL = exports.rowAnd = exports.row = exports.cellAnd = exports.cellOf = exports.cell = exports.render = exports.withRouter = exports.newLocation = exports.wait = exports.typeAndWait = exports.type = exports.select = exports.input = exports.getOptions = exports.click = exports.change = void 0;
|
|
3
|
+
exports.withBeamRTL = exports.tableSnapshot = exports.rowAnd = exports.row = exports.cellAnd = exports.cellOf = exports.cell = exports.render = exports.withRouter = exports.newLocation = exports.wait = exports.typeAndWait = exports.type = exports.select = exports.input = exports.getOptions = exports.click = exports.change = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const rtl_react_router_utils_1 = require("@homebound/rtl-react-router-utils");
|
|
6
6
|
Object.defineProperty(exports, "newLocation", { enumerable: true, get: function () { return rtl_react_router_utils_1.newLocation; } });
|
|
@@ -60,6 +60,75 @@ function rowAnd(r, rowNum, testId) {
|
|
|
60
60
|
return e.querySelector(`[data-testid="${testId}"]`) || fail(`Element not found ${(0, react_1.prettyDOM)(e)}`);
|
|
61
61
|
}
|
|
62
62
|
exports.rowAnd = rowAnd;
|
|
63
|
+
/** Intended to be used to generate a human-readable text
|
|
64
|
+
* representation of a GridTable using the markdown table syntax.
|
|
65
|
+
* * Example Use: expect(tableSnapshot(r)).toMatchInlineSnapshot(`
|
|
66
|
+
"
|
|
67
|
+
| Name | Value |
|
|
68
|
+
| ------------------------ | ----- |
|
|
69
|
+
| Row 1 | 200 |
|
|
70
|
+
| Row 2 with a longer name | 300 |
|
|
71
|
+
| Row 3 | 1000 |
|
|
72
|
+
"
|
|
73
|
+
`);
|
|
74
|
+
* */
|
|
75
|
+
function tableSnapshot(r) {
|
|
76
|
+
const tableEl = r.getByTestId("gridTable");
|
|
77
|
+
const dataRows = Array.from(tableEl.querySelectorAll("[data-gridrow]"));
|
|
78
|
+
const hasExpandableHeader = !!tableEl.querySelector(`[data-testid="expandableColumn"]`);
|
|
79
|
+
const tableDataAsStrings = dataRows.map((row) => {
|
|
80
|
+
return Array.from(row.childNodes).map(getTextFromTableCellNode);
|
|
81
|
+
});
|
|
82
|
+
return toMarkupTableString({ tableRows: tableDataAsStrings, hasExpandableHeader });
|
|
83
|
+
}
|
|
84
|
+
exports.tableSnapshot = tableSnapshot;
|
|
85
|
+
function toMarkupTableString({ tableRows, hasExpandableHeader, }) {
|
|
86
|
+
// Find the largest width of each column to set a consistent width for each row
|
|
87
|
+
const columnWidths = tableRows.reduce((acc, row) => {
|
|
88
|
+
row.forEach((cell, columnIndex) => {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
const cellWidth = (_a = cell === null || cell === void 0 ? void 0 : cell.length) !== null && _a !== void 0 ? _a : 0;
|
|
91
|
+
const currentMaxWidth = (_b = acc.get(columnIndex)) !== null && _b !== void 0 ? _b : 0;
|
|
92
|
+
if (cellWidth > currentMaxWidth || !currentMaxWidth)
|
|
93
|
+
acc.set(columnIndex, cellWidth);
|
|
94
|
+
});
|
|
95
|
+
return acc;
|
|
96
|
+
}, new Map());
|
|
97
|
+
const wrapTableRowEnds = (str) => `| ${str} |`;
|
|
98
|
+
const rowsWithPaddingAndDividers = tableRows.map((tableCells) => {
|
|
99
|
+
const formattedRow = tableCells
|
|
100
|
+
.map((cell, columnIndex) => {
|
|
101
|
+
var _a;
|
|
102
|
+
const cellWidth = (_a = columnWidths.get(columnIndex)) !== null && _a !== void 0 ? _a : 0;
|
|
103
|
+
return (cell === null || cell === void 0 ? void 0 : cell.padEnd(cellWidth, " ")) || "";
|
|
104
|
+
})
|
|
105
|
+
.join(" | ");
|
|
106
|
+
return wrapTableRowEnds(formattedRow);
|
|
107
|
+
});
|
|
108
|
+
const headerDivider = Array.from(columnWidths.values())
|
|
109
|
+
.map((width) => { var _a; return (_a = "-".repeat(width)) !== null && _a !== void 0 ? _a : ""; })
|
|
110
|
+
.join(" | ");
|
|
111
|
+
const headerDividerRowNumber = hasExpandableHeader ? 2 : 1;
|
|
112
|
+
rowsWithPaddingAndDividers.splice(headerDividerRowNumber, 0, wrapTableRowEnds(headerDivider));
|
|
113
|
+
// Pad a newline on top and bottom for cleaner diffs
|
|
114
|
+
return `\n${rowsWithPaddingAndDividers.join("\n")}\n`;
|
|
115
|
+
}
|
|
116
|
+
/** Prefer showing a `value` from a mocked input vs. the combined text content from an inputs markup */
|
|
117
|
+
function getTextFromTableCellNode(node) {
|
|
118
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
119
|
+
const element = node;
|
|
120
|
+
const maybeInput = element.getElementsByTagName("input")[0];
|
|
121
|
+
if (maybeInput)
|
|
122
|
+
return maybeInput.value;
|
|
123
|
+
const maybeTextarea = element.getElementsByTagName("textarea")[0];
|
|
124
|
+
if (maybeTextarea)
|
|
125
|
+
return maybeTextarea.value;
|
|
126
|
+
const maybeSelect = element.getElementsByTagName("select")[0];
|
|
127
|
+
if (maybeSelect)
|
|
128
|
+
return maybeSelect.value;
|
|
129
|
+
}
|
|
130
|
+
return node.textContent;
|
|
131
|
+
}
|
|
63
132
|
/** RTL wrapper for Beam's SuperDrawer/Modal context. */
|
|
64
133
|
exports.withBeamRTL = {
|
|
65
134
|
wrap: (c) => (0, jsx_runtime_1.jsx)(components_1.BeamProvider, { children: c }),
|