@homebound/beam 2.251.0 → 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;
@@ -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
  };
@@ -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 }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.251.0",
3
+ "version": "2.252.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",