@multiplatform.one/table 7.69.2 → 7.71.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/cjs/components/DataTable/DataTableCardControls.cjs +74 -12
- package/dist/cjs/components/DataTable/DataTableCardControls.native.js +83 -12
- package/dist/cjs/components/DataTable/DataTableCardControls.native.js.map +1 -1
- package/dist/cjs/components/DataTable/DataTableDocumentList.cjs +180 -114
- package/dist/cjs/components/DataTable/DataTableDocumentList.native.js +193 -124
- package/dist/cjs/components/DataTable/DataTableDocumentList.native.js.map +1 -1
- package/dist/cjs/components/DataTable/DataTableMobileCards.cjs +260 -127
- package/dist/cjs/components/DataTable/DataTableMobileCards.native.js +287 -156
- package/dist/cjs/components/DataTable/DataTableMobileCards.native.js.map +1 -1
- package/dist/cjs/components/DataTable/DataTableRoot.cjs +34 -5
- package/dist/cjs/components/DataTable/DataTableRoot.native.js +36 -5
- package/dist/cjs/components/DataTable/DataTableRoot.native.js.map +1 -1
- package/dist/cjs/components/DataTable/PhonePager.cjs +56 -0
- package/dist/cjs/components/DataTable/PhonePager.native.js +60 -0
- package/dist/cjs/components/DataTable/PhonePager.native.js.map +1 -0
- package/dist/cjs/components/DataTable/index.native.js +64 -7
- package/dist/cjs/components/DataTable/index.native.js.map +1 -1
- package/dist/cjs/components/DataTable/rowSlotParts.cjs +158 -0
- package/dist/cjs/components/DataTable/rowSlotParts.native.js +170 -0
- package/dist/cjs/components/DataTable/rowSlotParts.native.js.map +1 -0
- package/dist/cjs/components/DataTable/rowSlots.cjs +150 -0
- package/dist/cjs/components/DataTable/rowSlots.native.js +239 -0
- package/dist/cjs/components/DataTable/rowSlots.native.js.map +1 -0
- package/dist/cjs/components/DataTableFilterButton/index.cjs +25 -3
- package/dist/cjs/components/DataTableFilterButton/index.native.js +25 -3
- package/dist/cjs/components/DataTableFilterButton/index.native.js.map +1 -1
- package/dist/cjs/components/DataTablePagination/index.cjs +23 -0
- package/dist/cjs/components/DataTablePagination/index.native.js +25 -0
- package/dist/cjs/components/DataTablePagination/index.native.js.map +1 -1
- package/dist/cjs/components/DataTableToolbar/glyph.cjs +54 -0
- package/dist/cjs/components/DataTableToolbar/glyph.native.js +57 -0
- package/dist/cjs/components/DataTableToolbar/glyph.native.js.map +1 -0
- package/dist/cjs/components/DataTableToolbar/index.cjs +206 -114
- package/dist/cjs/components/DataTableToolbar/index.native.js +217 -112
- package/dist/cjs/components/DataTableToolbar/index.native.js.map +1 -1
- package/dist/cjs/index.cjs +5 -1
- package/dist/cjs/index.native.js +5 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/components/DataTable/DataTableCardControls.mjs +74 -13
- package/dist/esm/components/DataTable/DataTableCardControls.mjs.map +1 -1
- package/dist/esm/components/DataTable/DataTableCardControls.native.js +83 -13
- package/dist/esm/components/DataTable/DataTableCardControls.native.js.map +1 -1
- package/dist/esm/components/DataTable/DataTableDocumentList.mjs +179 -113
- package/dist/esm/components/DataTable/DataTableDocumentList.mjs.map +1 -1
- package/dist/esm/components/DataTable/DataTableDocumentList.native.js +192 -123
- package/dist/esm/components/DataTable/DataTableDocumentList.native.js.map +1 -1
- package/dist/esm/components/DataTable/DataTableMobileCards.mjs +261 -129
- package/dist/esm/components/DataTable/DataTableMobileCards.mjs.map +1 -1
- package/dist/esm/components/DataTable/DataTableMobileCards.native.js +288 -158
- package/dist/esm/components/DataTable/DataTableMobileCards.native.js.map +1 -1
- package/dist/esm/components/DataTable/DataTableRoot.mjs +36 -7
- package/dist/esm/components/DataTable/DataTableRoot.mjs.map +1 -1
- package/dist/esm/components/DataTable/DataTableRoot.native.js +38 -7
- package/dist/esm/components/DataTable/DataTableRoot.native.js.map +1 -1
- package/dist/esm/components/DataTable/PhonePager.mjs +31 -0
- package/dist/esm/components/DataTable/PhonePager.mjs.map +1 -0
- package/dist/esm/components/DataTable/PhonePager.native.js +32 -0
- package/dist/esm/components/DataTable/PhonePager.native.js.map +1 -0
- package/dist/esm/components/DataTable/index.native.js +67 -10
- package/dist/esm/components/DataTable/index.native.js.map +1 -1
- package/dist/esm/components/DataTable/rowSlotParts.mjs +130 -0
- package/dist/esm/components/DataTable/rowSlotParts.mjs.map +1 -0
- package/dist/esm/components/DataTable/rowSlotParts.native.js +139 -0
- package/dist/esm/components/DataTable/rowSlotParts.native.js.map +1 -0
- package/dist/esm/components/DataTable/rowSlots.mjs +121 -0
- package/dist/esm/components/DataTable/rowSlots.mjs.map +1 -0
- package/dist/esm/components/DataTable/rowSlots.native.js +207 -0
- package/dist/esm/components/DataTable/rowSlots.native.js.map +1 -0
- package/dist/esm/components/DataTableFilterButton/index.mjs +24 -3
- package/dist/esm/components/DataTableFilterButton/index.mjs.map +1 -1
- package/dist/esm/components/DataTableFilterButton/index.native.js +24 -3
- package/dist/esm/components/DataTableFilterButton/index.native.js.map +1 -1
- package/dist/esm/components/DataTablePagination/index.mjs +23 -0
- package/dist/esm/components/DataTablePagination/index.mjs.map +1 -1
- package/dist/esm/components/DataTablePagination/index.native.js +25 -0
- package/dist/esm/components/DataTablePagination/index.native.js.map +1 -1
- package/dist/esm/components/DataTableToolbar/glyph.mjs +27 -0
- package/dist/esm/components/DataTableToolbar/glyph.mjs.map +1 -0
- package/dist/esm/components/DataTableToolbar/glyph.native.js +27 -0
- package/dist/esm/components/DataTableToolbar/glyph.native.js.map +1 -0
- package/dist/esm/components/DataTableToolbar/index.mjs +211 -119
- package/dist/esm/components/DataTableToolbar/index.mjs.map +1 -1
- package/dist/esm/components/DataTableToolbar/index.native.js +222 -117
- package/dist/esm/components/DataTableToolbar/index.native.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/jsx/components/DataTable/DataTableCardControls.mjs +74 -13
- package/dist/jsx/components/DataTable/DataTableCardControls.mjs.map +1 -1
- package/dist/jsx/components/DataTable/DataTableCardControls.native.js +83 -12
- package/dist/jsx/components/DataTable/DataTableCardControls.native.js.map +1 -1
- package/dist/jsx/components/DataTable/DataTableDocumentList.mjs +179 -113
- package/dist/jsx/components/DataTable/DataTableDocumentList.mjs.map +1 -1
- package/dist/jsx/components/DataTable/DataTableDocumentList.native.js +193 -124
- package/dist/jsx/components/DataTable/DataTableDocumentList.native.js.map +1 -1
- package/dist/jsx/components/DataTable/DataTableMobileCards.mjs +261 -129
- package/dist/jsx/components/DataTable/DataTableMobileCards.mjs.map +1 -1
- package/dist/jsx/components/DataTable/DataTableMobileCards.native.js +287 -156
- package/dist/jsx/components/DataTable/DataTableMobileCards.native.js.map +1 -1
- package/dist/jsx/components/DataTable/DataTableRoot.mjs +36 -7
- package/dist/jsx/components/DataTable/DataTableRoot.mjs.map +1 -1
- package/dist/jsx/components/DataTable/DataTableRoot.native.js +36 -5
- package/dist/jsx/components/DataTable/DataTableRoot.native.js.map +1 -1
- package/dist/jsx/components/DataTable/PhonePager.mjs +31 -0
- package/dist/jsx/components/DataTable/PhonePager.mjs.map +1 -0
- package/dist/jsx/components/DataTable/PhonePager.native.js +60 -0
- package/dist/jsx/components/DataTable/PhonePager.native.js.map +1 -0
- package/dist/jsx/components/DataTable/index.native.js +64 -7
- package/dist/jsx/components/DataTable/index.native.js.map +1 -1
- package/dist/jsx/components/DataTable/rowSlotParts.mjs +130 -0
- package/dist/jsx/components/DataTable/rowSlotParts.mjs.map +1 -0
- package/dist/jsx/components/DataTable/rowSlotParts.native.js +170 -0
- package/dist/jsx/components/DataTable/rowSlotParts.native.js.map +1 -0
- package/dist/jsx/components/DataTable/rowSlots.mjs +121 -0
- package/dist/jsx/components/DataTable/rowSlots.mjs.map +1 -0
- package/dist/jsx/components/DataTable/rowSlots.native.js +239 -0
- package/dist/jsx/components/DataTable/rowSlots.native.js.map +1 -0
- package/dist/jsx/components/DataTableFilterButton/index.mjs +24 -3
- package/dist/jsx/components/DataTableFilterButton/index.mjs.map +1 -1
- package/dist/jsx/components/DataTableFilterButton/index.native.js +25 -3
- package/dist/jsx/components/DataTableFilterButton/index.native.js.map +1 -1
- package/dist/jsx/components/DataTablePagination/index.mjs +23 -0
- package/dist/jsx/components/DataTablePagination/index.mjs.map +1 -1
- package/dist/jsx/components/DataTablePagination/index.native.js +25 -0
- package/dist/jsx/components/DataTablePagination/index.native.js.map +1 -1
- package/dist/jsx/components/DataTableToolbar/glyph.mjs +27 -0
- package/dist/jsx/components/DataTableToolbar/glyph.mjs.map +1 -0
- package/dist/jsx/components/DataTableToolbar/glyph.native.js +57 -0
- package/dist/jsx/components/DataTableToolbar/glyph.native.js.map +1 -0
- package/dist/jsx/components/DataTableToolbar/index.mjs +211 -119
- package/dist/jsx/components/DataTableToolbar/index.mjs.map +1 -1
- package/dist/jsx/components/DataTableToolbar/index.native.js +217 -112
- package/dist/jsx/components/DataTableToolbar/index.native.js.map +1 -1
- package/dist/jsx/index.js +2 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +2 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/index.native.js +5 -1
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +12 -12
- package/src/components/DataTable/DataTable.spec.tsx +12 -9
- package/src/components/DataTable/DataTable.stories.tsx +110 -43
- package/src/components/DataTable/DataTableCardControls.tsx +103 -24
- package/src/components/DataTable/DataTableDocumentList.stories.tsx +113 -0
- package/src/components/DataTable/DataTableDocumentList.tsx +210 -120
- package/src/components/DataTable/DataTableMobileCards.tsx +280 -147
- package/src/components/DataTable/DataTableRoot.tsx +56 -5
- package/src/components/DataTable/PhonePager.tsx +44 -0
- package/src/components/DataTable/cardLayout.spec.tsx +20 -12
- package/src/components/DataTable/cardToolbar.spec.tsx +31 -26
- package/src/components/DataTable/dataTableCardControls.spec.tsx +10 -9
- package/src/components/DataTable/dataTableDocumentList.spec.tsx +98 -10
- package/src/components/DataTable/dataTableMobileCards.spec.tsx +29 -14
- package/src/components/DataTable/index.native.tsx +90 -9
- package/src/components/DataTable/nativeCardParity.spec.tsx +15 -0
- package/src/components/DataTable/pageRange.spec.tsx +12 -1
- package/src/components/DataTable/rowSlotParts.tsx +184 -0
- package/src/components/DataTable/rowSlots.ts +239 -0
- package/src/components/DataTable/smallTableFooter.spec.tsx +10 -0
- package/src/components/DataTableFilterButton/DataTableFilterButton.spec.tsx +3 -3
- package/src/components/DataTableFilterButton/index.tsx +30 -2
- package/src/components/DataTablePagination/index.tsx +30 -0
- package/src/components/DataTableToolbar/DataTableToolbar.spec.tsx +10 -0
- package/src/components/DataTableToolbar/DataTableToolbar.stories.tsx +16 -7
- package/src/components/DataTableToolbar/compactRow.spec.tsx +197 -0
- package/src/components/DataTableToolbar/glyph.ts +33 -0
- package/src/components/DataTableToolbar/index.tsx +269 -131
- package/src/components/Table/accessibility.spec.tsx +4 -3
- package/src/components/noMiddotJoin.spec.tsx +315 -0
- package/src/components/phoneBottomAccessory.spec.tsx +218 -0
- package/src/components/phoneCardPolish.spec.tsx +214 -0
- package/src/components/phoneCardsDefault.spec.tsx +34 -6
- package/src/components/phonePager.spec.tsx +141 -0
- package/src/components/tableDropdowns.spec.tsx +4 -3
- package/src/index.ts +5 -0
- package/src/types.ts +23 -0
- package/types/components/DataTable/DataTableCardControls.d.ts +12 -0
- package/types/components/DataTable/DataTableCardControls.d.ts.map +1 -1
- package/types/components/DataTable/DataTableDocumentList.d.ts +13 -7
- package/types/components/DataTable/DataTableDocumentList.d.ts.map +1 -1
- package/types/components/DataTable/DataTableMobileCards.d.ts +38 -12
- package/types/components/DataTable/DataTableMobileCards.d.ts.map +1 -1
- package/types/components/DataTable/DataTableRoot.d.ts +1 -1
- package/types/components/DataTable/DataTableRoot.d.ts.map +1 -1
- package/types/components/DataTable/PhonePager.d.ts +24 -0
- package/types/components/DataTable/PhonePager.d.ts.map +1 -0
- package/types/components/DataTable/index.native.d.ts +1 -1
- package/types/components/DataTable/index.native.d.ts.map +1 -1
- package/types/components/DataTable/rowSlotParts.d.ts +30 -0
- package/types/components/DataTable/rowSlotParts.d.ts.map +1 -0
- package/types/components/DataTable/rowSlots.d.ts +74 -0
- package/types/components/DataTable/rowSlots.d.ts.map +1 -0
- package/types/components/DataTableFilterButton/index.d.ts +1 -0
- package/types/components/DataTableFilterButton/index.d.ts.map +1 -1
- package/types/components/DataTablePagination/index.d.ts +5 -0
- package/types/components/DataTablePagination/index.d.ts.map +1 -1
- package/types/components/DataTableToolbar/glyph.d.ts +65 -0
- package/types/components/DataTableToolbar/glyph.d.ts.map +1 -0
- package/types/components/DataTableToolbar/index.d.ts +24 -0
- package/types/components/DataTableToolbar/index.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +23 -0
- package/types/types.d.ts.map +1 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LC-261 NO-MIDDOT-JOIN: where each value of a phone row or card goes.
|
|
3
|
+
*
|
|
4
|
+
* A compact record is two lines. Each secondary value is its own element in
|
|
5
|
+
* a slot chosen by its role, never one string of values joined by " · ":
|
|
6
|
+
*
|
|
7
|
+
* leading media, a circle
|
|
8
|
+
* line 1 title | status (a tone dot and one word) | key (#n) | actions
|
|
9
|
+
* line 2 subtitle (the one descriptor or contact) | facts (icon + value)
|
|
10
|
+
* | stamp (the time, trailing, secondary ink)
|
|
11
|
+
*
|
|
12
|
+
* The slot comes from the column's `meta.role` when one is set, so an app
|
|
13
|
+
* or a DocType overrides any default by setting it (DoctypeListScreen's
|
|
14
|
+
* `columnOverrides`, or a DataTable column's `meta`). Without one it comes
|
|
15
|
+
* from the column: its field, its Frappe fieldtype and options
|
|
16
|
+
* (`meta.fieldtype`, `meta.options`), its alignment, and last its value.
|
|
17
|
+
*
|
|
18
|
+
* role slot default
|
|
19
|
+
* title title Frappe title_field; else the first text column
|
|
20
|
+
* media media Frappe image_field; an avatar or image column, an
|
|
21
|
+
* image URL
|
|
22
|
+
* indicator status Select / status-like fields, a `statusTone`, ids
|
|
23
|
+
* status, state
|
|
24
|
+
* subtitle subtitle Data with options Email or Phone; else the first
|
|
25
|
+
* remaining text column
|
|
26
|
+
* fact facts Int, Float, Currency, Percent, Check, numbers
|
|
27
|
+
* stamp stamp Date, Datetime, Time; modified or creation first
|
|
28
|
+
* trailing facts or stamp, by kind (Frappe numbers and dates)
|
|
29
|
+
* key key cards: a number ahead of the title (an id)
|
|
30
|
+
* actions controls row actions ride line 1; switches, ratings and
|
|
31
|
+
* other field controls keep a row of their own
|
|
32
|
+
* hidden/skip -
|
|
33
|
+
*
|
|
34
|
+
* Two facts at most, and one beside a subtitle: at phone width a second
|
|
35
|
+
* fact squeezes an email or a name down to its first letters. A value with no
|
|
36
|
+
* slot left (a second text column, a fact past the cap) is not squeezed in:
|
|
37
|
+
* it stays in the grid and the record's detail view.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import type { DataTableColumn, DataTableField } from "../../types";
|
|
41
|
+
|
|
42
|
+
export const MAX_ROW_FACTS = 2;
|
|
43
|
+
export const MAX_FACTS_BESIDE_SUBTITLE = 1;
|
|
44
|
+
|
|
45
|
+
export interface RowSlots<TCell> {
|
|
46
|
+
title: TCell | undefined;
|
|
47
|
+
media: TCell | undefined;
|
|
48
|
+
/** Cards only: numbers ahead of the title (an id), the trailing #n. */
|
|
49
|
+
keys: TCell[];
|
|
50
|
+
status: TCell[];
|
|
51
|
+
subtitle: TCell | undefined;
|
|
52
|
+
facts: TCell[];
|
|
53
|
+
stamp: TCell | undefined;
|
|
54
|
+
controls: TCell[];
|
|
55
|
+
/** Values with no slot on a compact record. */
|
|
56
|
+
overflow: TCell[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type AnyCell = { column: { id: string; columnDef: unknown }; getValue?: () => unknown };
|
|
60
|
+
|
|
61
|
+
const statusIds = new Set(["status", "priority", "workflow_state", "state"]);
|
|
62
|
+
const statusFields = new Set<DataTableField>(["select", "combobox", "togglegroup", "radiogroup"]);
|
|
63
|
+
const controlFields = new Set<DataTableField>([
|
|
64
|
+
"checkbox",
|
|
65
|
+
"switch",
|
|
66
|
+
"rating",
|
|
67
|
+
"progress",
|
|
68
|
+
"image",
|
|
69
|
+
"signature",
|
|
70
|
+
"fileupload",
|
|
71
|
+
"colorpicker",
|
|
72
|
+
"barcode",
|
|
73
|
+
"geolocation",
|
|
74
|
+
]);
|
|
75
|
+
const dateFields = new Set<DataTableField>([
|
|
76
|
+
"datepicker",
|
|
77
|
+
"datetimepicker",
|
|
78
|
+
"timepicker",
|
|
79
|
+
"daterangepicker",
|
|
80
|
+
"multidatepicker",
|
|
81
|
+
]);
|
|
82
|
+
const numberFields = new Set<DataTableField>(["stepper", "slider", "money", "duration"]);
|
|
83
|
+
const dateFieldtypes = new Set(["Date", "Datetime", "Time"]);
|
|
84
|
+
const numberFieldtypes = new Set(["Int", "Float", "Currency", "Percent", "Check", "Rating"]);
|
|
85
|
+
const stampIds = ["modified", "creation"];
|
|
86
|
+
const mediaIds = new Set(["avatar", "image", "photo", "picture", "thumbnail"]);
|
|
87
|
+
const imageUrlLike = /^(https?:)?\/\/\S+\.(png|jpe?g|gif|webp|svg|avif)(\?\S*)?$/i;
|
|
88
|
+
|
|
89
|
+
const dateLike = /^\d{4}-\d{2}-\d{2}([T ]|$)|^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
|
|
90
|
+
const numberLike = /^[+\-−]?[\d,\s]*\d(\.\d+)?%?$/;
|
|
91
|
+
const emailLike = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
92
|
+
const phoneLike = /^\+?[\d\s().-]{7,}$/;
|
|
93
|
+
|
|
94
|
+
export type ColumnKind = "media" | "date" | "number" | "contact" | "status" | "control" | "text";
|
|
95
|
+
|
|
96
|
+
function def(cell: AnyCell): DataTableColumn {
|
|
97
|
+
return cell.column.columnDef as DataTableColumn;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function value(cell: AnyCell): unknown {
|
|
101
|
+
return typeof cell.getValue === "function" ? cell.getValue() : undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** What a column holds, from its field and Frappe meta first, its value last. */
|
|
105
|
+
export function columnKind(cell: AnyCell): ColumnKind {
|
|
106
|
+
const column = def(cell);
|
|
107
|
+
const id = String(cell.column.id ?? "");
|
|
108
|
+
const role = column.meta?.role;
|
|
109
|
+
const fieldtype = column.meta?.fieldtype;
|
|
110
|
+
const options = String(column.meta?.options ?? "");
|
|
111
|
+
if (role === "actions" || id.startsWith("_")) return "control";
|
|
112
|
+
if (column.field === "image" || mediaIds.has(id) || fieldtype === "Attach Image") return "media";
|
|
113
|
+
if (column.field && controlFields.has(column.field)) return "control";
|
|
114
|
+
if (role === "indicator" || column.meta?.statusTone || statusIds.has(id)) return "status";
|
|
115
|
+
if (column.field && statusFields.has(column.field)) return "status";
|
|
116
|
+
if (fieldtype === "Select") return "status";
|
|
117
|
+
if (stampIds.includes(id)) return "date";
|
|
118
|
+
if (
|
|
119
|
+
(column.field && dateFields.has(column.field)) ||
|
|
120
|
+
(fieldtype && dateFieldtypes.has(fieldtype))
|
|
121
|
+
) {
|
|
122
|
+
return "date";
|
|
123
|
+
}
|
|
124
|
+
if (
|
|
125
|
+
(column.field && numberFields.has(column.field)) ||
|
|
126
|
+
(fieldtype && numberFieldtypes.has(fieldtype))
|
|
127
|
+
) {
|
|
128
|
+
return "number";
|
|
129
|
+
}
|
|
130
|
+
if (column.field === "phoneinput" || options === "Email" || options === "Phone") return "contact";
|
|
131
|
+
const raw = value(cell);
|
|
132
|
+
if (typeof raw === "number" || typeof raw === "boolean") return "number";
|
|
133
|
+
if (raw instanceof Date) return "date";
|
|
134
|
+
if (typeof raw === "string") {
|
|
135
|
+
const text = raw.trim();
|
|
136
|
+
if (imageUrlLike.test(text)) return "media";
|
|
137
|
+
if (dateLike.test(text)) return "date";
|
|
138
|
+
if (numberLike.test(text)) return "number";
|
|
139
|
+
if (emailLike.test(text) || phoneLike.test(text)) return "contact";
|
|
140
|
+
}
|
|
141
|
+
if (role === "trailing" || column.align === "right") return "number";
|
|
142
|
+
return "text";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isEmpty(cell: AnyCell): boolean {
|
|
146
|
+
const raw = value(cell);
|
|
147
|
+
return raw == null || (typeof raw === "string" && raw.trim() === "");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Assign a compact record's cells to slots. `keys` turns on the card's
|
|
152
|
+
* trailing #n for numbers ahead of the title; a list row has no key slot.
|
|
153
|
+
*/
|
|
154
|
+
export function resolveRowSlots<TCell extends AnyCell>(
|
|
155
|
+
cells: TCell[],
|
|
156
|
+
{ keys: withKeys = false }: { keys?: boolean } = {},
|
|
157
|
+
): RowSlots<TCell> {
|
|
158
|
+
const slots: RowSlots<TCell> = {
|
|
159
|
+
title: undefined,
|
|
160
|
+
media: undefined,
|
|
161
|
+
keys: [],
|
|
162
|
+
status: [],
|
|
163
|
+
subtitle: undefined,
|
|
164
|
+
facts: [],
|
|
165
|
+
stamp: undefined,
|
|
166
|
+
controls: [],
|
|
167
|
+
overflow: [],
|
|
168
|
+
};
|
|
169
|
+
const open: TCell[] = [];
|
|
170
|
+
const explicitFacts: TCell[] = [];
|
|
171
|
+
for (const cell of cells) {
|
|
172
|
+
const role = def(cell).meta?.role;
|
|
173
|
+
if (role === "hidden" || role === "skip") continue;
|
|
174
|
+
if (role === "title" && !slots.title) slots.title = cell;
|
|
175
|
+
else if (role === "media" && !slots.media) slots.media = cell;
|
|
176
|
+
else if (role === "key") slots.keys.push(cell);
|
|
177
|
+
else if (role === "indicator" || role === "status") slots.status.push(cell);
|
|
178
|
+
else if (role === "subtitle" && !slots.subtitle) slots.subtitle = cell;
|
|
179
|
+
else if (role === "fact") explicitFacts.push(cell);
|
|
180
|
+
else if (role === "stamp" && !slots.stamp) slots.stamp = cell;
|
|
181
|
+
else if (role === "actions") slots.controls.push(cell);
|
|
182
|
+
else open.push(cell);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const kinds = new Map(open.map((cell) => [cell, columnKind(cell)]));
|
|
186
|
+
if (!slots.title) {
|
|
187
|
+
const index = open.findIndex(
|
|
188
|
+
(cell) => kinds.get(cell) === "text" || kinds.get(cell) === "contact",
|
|
189
|
+
);
|
|
190
|
+
const title =
|
|
191
|
+
index >= 0
|
|
192
|
+
? open[index]
|
|
193
|
+
: open.find((cell) => kinds.get(cell) !== "control" && kinds.get(cell) !== "media");
|
|
194
|
+
if (title) {
|
|
195
|
+
slots.title = title;
|
|
196
|
+
if (withKeys && index > 0) {
|
|
197
|
+
for (const cell of open.slice(0, index)) {
|
|
198
|
+
if (kinds.get(cell) === "number" && def(cell).meta?.role !== "trailing") {
|
|
199
|
+
slots.keys.push(cell);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const rest = open.filter((cell) => cell !== slots.title && !slots.keys.includes(cell));
|
|
207
|
+
const facts = [...explicitFacts];
|
|
208
|
+
const dates: TCell[] = [];
|
|
209
|
+
const texts: TCell[] = [];
|
|
210
|
+
for (const cell of rest) {
|
|
211
|
+
const kind = kinds.get(cell);
|
|
212
|
+
if (kind === "control") slots.controls.push(cell);
|
|
213
|
+
else if (kind === "media") {
|
|
214
|
+
if (slots.media) slots.overflow.push(cell);
|
|
215
|
+
else slots.media = cell;
|
|
216
|
+
} else if (kind === "status") slots.status.push(cell);
|
|
217
|
+
else if (kind === "date") dates.push(cell);
|
|
218
|
+
else if (kind === "number") facts.push(cell);
|
|
219
|
+
else if (kind === "contact" && !slots.subtitle) slots.subtitle = cell;
|
|
220
|
+
else texts.push(cell);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!slots.stamp) {
|
|
224
|
+
slots.stamp =
|
|
225
|
+
stampIds.map((id) => dates.find((cell) => cell.column.id === id)).find(Boolean) ?? dates[0];
|
|
226
|
+
}
|
|
227
|
+
slots.overflow.push(...dates.filter((cell) => cell !== slots.stamp));
|
|
228
|
+
if (!slots.subtitle) slots.subtitle = texts.shift();
|
|
229
|
+
slots.overflow.push(...texts);
|
|
230
|
+
const cap = slots.subtitle ? MAX_FACTS_BESIDE_SUBTITLE : MAX_ROW_FACTS;
|
|
231
|
+
slots.facts = facts.slice(0, cap);
|
|
232
|
+
slots.overflow.push(...facts.slice(cap));
|
|
233
|
+
return slots;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** A cell with nothing in it renders no element in its slot. */
|
|
237
|
+
export function hasValue(cell: AnyCell | undefined): cell is AnyCell {
|
|
238
|
+
return Boolean(cell) && !isEmpty(cell as AnyCell);
|
|
239
|
+
}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* but its pagination footer stays at the ambient token: the pager's page
|
|
4
4
|
* controls hold the 44px press floor, so a `$3` rows-per-page Select would
|
|
5
5
|
* sit 8px short of them in one row (LC-100, LC-78).
|
|
6
|
+
*
|
|
7
|
+
* That Select is the regular-width footer: at the compact width rows per page
|
|
8
|
+
* moves into the toolbar's view menu (FZ-7889), so these render wide.
|
|
6
9
|
*/
|
|
7
10
|
|
|
8
11
|
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
@@ -14,6 +17,13 @@ import { DataTable } from "./index";
|
|
|
14
17
|
import { DataTable as NativeDataTable } from "./index.native";
|
|
15
18
|
|
|
16
19
|
vi.mock("@shopify/flash-list", () => ({ FlashList: () => null }));
|
|
20
|
+
vi.mock("tamagui", async (importOriginal) => {
|
|
21
|
+
const actual = await importOriginal<typeof import("tamagui")>();
|
|
22
|
+
return {
|
|
23
|
+
...actual,
|
|
24
|
+
useMedia: (...args: any[]) => ({ ...(actual.useMedia as any)(...args), sm: true }),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
17
27
|
|
|
18
28
|
type Row = { id: number; name: string };
|
|
19
29
|
|
|
@@ -73,9 +73,9 @@ describe("DataTableFilterButton", () => {
|
|
|
73
73
|
|
|
74
74
|
it("shows the active filter count on the trigger", async () => {
|
|
75
75
|
renderTable([emailFilter("corp")]);
|
|
76
|
-
//
|
|
77
|
-
const trigger = await screen.findByRole("button", { name: "Filter
|
|
78
|
-
expect(trigger.
|
|
76
|
+
// FZ-8039: the phone toolbar's Filter is a glyph; the count is its description.
|
|
77
|
+
const trigger = await screen.findByRole("button", { name: "Filter" });
|
|
78
|
+
expect(trigger.getAttribute("aria-description")).toBe("1 applied");
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
it("field list is a single-tab-stop listbox (LC-49 / LC-71)", async () => {
|
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
import type { FilterEditTarget } from "../DataTable/DataTableStateContext";
|
|
34
34
|
import { useDataTableState } from "../DataTable/DataTableStateContext";
|
|
35
35
|
import { FilterOperatorValueEditor } from "../FilterOperatorValueEditor";
|
|
36
|
+
import { useToolbarGlyphProps } from "../DataTableToolbar/glyph";
|
|
37
|
+
import { iconSizeForToken } from "../../utils/chromeIcons";
|
|
36
38
|
|
|
37
39
|
/** The applied-filter state: the funnel fills (Mail's filter button). */
|
|
38
40
|
function FunnelFillIcon(props: IconProps) {
|
|
@@ -99,13 +101,24 @@ export function DataTableFilterButton() {
|
|
|
99
101
|
return <FilterButton />;
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
export function DataTableFilterGlyph() {
|
|
105
|
+
return <FilterButton contentTrigger glyph />;
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
export function DataTableCardFilterButton() {
|
|
103
109
|
return <FilterButton contentTrigger />;
|
|
104
110
|
}
|
|
105
111
|
|
|
106
|
-
function FilterButton({
|
|
112
|
+
function FilterButton({
|
|
113
|
+
contentTrigger = false,
|
|
114
|
+
glyph = false,
|
|
115
|
+
}: {
|
|
116
|
+
contentTrigger?: boolean;
|
|
117
|
+
glyph?: boolean;
|
|
118
|
+
}) {
|
|
107
119
|
const ctx = useDataTableState();
|
|
108
120
|
const { knobProps } = useResolvedKnobs();
|
|
121
|
+
const glyphProps = useToolbarGlyphProps();
|
|
109
122
|
// "Back to field list" points toward the panel's start edge — directional,
|
|
110
123
|
// so the caret pair swaps under RTL (useDirection glyph-swap pattern).
|
|
111
124
|
const BackCaretIcon = useDirection() === "rtl" ? CaretRightIcon : CaretLeftIcon;
|
|
@@ -311,7 +324,22 @@ function FilterButton({ contentTrigger = false }: { contentTrigger?: boolean })
|
|
|
311
324
|
const highlightedId = flatList[highlightedIndex]?.id;
|
|
312
325
|
const keyboardHighlight = listboxFocused && wasKeyboardFocus() ? highlightedId : undefined;
|
|
313
326
|
|
|
314
|
-
const trigger = (
|
|
327
|
+
const trigger = glyph ? (
|
|
328
|
+
<Button
|
|
329
|
+
{...glyphProps}
|
|
330
|
+
size={knobProps.sizeToken}
|
|
331
|
+
aria-label={t("Filter")}
|
|
332
|
+
aria-description={
|
|
333
|
+
activeChipCount > 0 ? t("{{count}} applied", { count: activeChipCount }) : undefined
|
|
334
|
+
}
|
|
335
|
+
icon={
|
|
336
|
+
<FunnelIcon
|
|
337
|
+
size={iconSizeForToken(String(knobProps.sizeToken))}
|
|
338
|
+
weight={activeChipCount > 0 ? "fill" : "regular"}
|
|
339
|
+
/>
|
|
340
|
+
}
|
|
341
|
+
/>
|
|
342
|
+
) : (
|
|
315
343
|
<IconButton
|
|
316
344
|
icon={activeChipCount > 0 ? FunnelFillIcon : FunnelIcon}
|
|
317
345
|
aria-label={activeChipCount > 0 ? `${t("Filter")} (${activeChipCount})` : t("Filter")}
|
|
@@ -61,6 +61,11 @@ function formatRange(start: number, end: number, total: number) {
|
|
|
61
61
|
* with Ant's quick-jumper only when there is somewhere to type to. Compact
|
|
62
62
|
* inside a DataTable stays shrink-wrapped so the table's own range can sit
|
|
63
63
|
* beside it; standalone compact (reports, stories) keeps the range (LC-37).
|
|
64
|
+
*
|
|
65
|
+
* At the compact width class inside a DataTable the footer is one row: the
|
|
66
|
+
* dot pager (iOS UIPageControl) between its chevrons, no numbers, no range,
|
|
67
|
+
* no size Select. Rows per page lives in the table toolbar's view menu there
|
|
68
|
+
* (FZ-7889).
|
|
64
69
|
*/
|
|
65
70
|
export function DataTablePagination(props: DataTablePaginationProps) {
|
|
66
71
|
const ctx = useDataTableState();
|
|
@@ -192,6 +197,31 @@ export function DataTablePagination(props: DataTablePaginationProps) {
|
|
|
192
197
|
if (revertInvalid) setJumpNonce((n) => n + 1);
|
|
193
198
|
};
|
|
194
199
|
|
|
200
|
+
if (isMobile && insideTable) {
|
|
201
|
+
if (!showPager) return null;
|
|
202
|
+
return (
|
|
203
|
+
<XStack
|
|
204
|
+
role="group"
|
|
205
|
+
aria-label="Table pagination"
|
|
206
|
+
width="100%"
|
|
207
|
+
minWidth={0}
|
|
208
|
+
alignItems="center"
|
|
209
|
+
justifyContent="center"
|
|
210
|
+
{...({ "data-pagination-compact": "true" } as object)}
|
|
211
|
+
>
|
|
212
|
+
<Pagination
|
|
213
|
+
variant="dots"
|
|
214
|
+
idiom="page"
|
|
215
|
+
total={totalPages}
|
|
216
|
+
page={currentPage}
|
|
217
|
+
onPageChange={(page) => handlePageChange(page - 1)}
|
|
218
|
+
aria-label="Page"
|
|
219
|
+
padding={0}
|
|
220
|
+
/>
|
|
221
|
+
</XStack>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
195
225
|
if (!showPager && !showSize && !showRange) return null;
|
|
196
226
|
|
|
197
227
|
const iconInk = (
|
|
@@ -4,6 +4,16 @@ import { describe, expect, it, vi } from "vitest";
|
|
|
4
4
|
import type { TableView } from "../../types";
|
|
5
5
|
import { DataTableToolbar, type DataTableToolbarProps } from "./index";
|
|
6
6
|
|
|
7
|
+
// The wide toolbar. Below `$sm` the toolbar is one compact row (FZ-8039),
|
|
8
|
+
// covered by compactRow.spec.tsx.
|
|
9
|
+
vi.mock("tamagui", async (importOriginal) => {
|
|
10
|
+
const actual = await importOriginal<typeof import("tamagui")>();
|
|
11
|
+
return {
|
|
12
|
+
...actual,
|
|
13
|
+
useMedia: (...args: any[]) => ({ ...(actual.useMedia as any)(...args), sm: true }),
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
7
17
|
describe("DataTableToolbar", () => {
|
|
8
18
|
const defaultProps: DataTableToolbarProps = {
|
|
9
19
|
globalFilter: "",
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { action } from "@multiplatform.one/storybook";
|
|
2
2
|
import type { Meta } from "@storybook/react-native-web-vite";
|
|
3
|
+
import { ArrowsClockwiseIcon, DownloadSimpleIcon } from "@phosphor-icons/react";
|
|
3
4
|
import { useState } from "react";
|
|
4
5
|
import { Button } from "@multiplatform.one/forms";
|
|
5
6
|
import { XStack, YStack } from "tamagui";
|
|
6
7
|
import type { DataTableColumn, TableView } from "../../types";
|
|
7
8
|
import { DataTable } from "../DataTable";
|
|
9
|
+
import { toolbarGlyphProps } from "./glyph";
|
|
8
10
|
import { DataTableToolbar } from "./index";
|
|
9
11
|
|
|
10
12
|
const meta: Meta<typeof DataTableToolbar> = {
|
|
11
13
|
title: "Table/DataTableToolbar",
|
|
12
14
|
component: DataTableToolbar,
|
|
13
15
|
parameters: {
|
|
16
|
+
layout: "fullscreen",
|
|
14
17
|
status: { type: "stable" },
|
|
15
18
|
},
|
|
16
19
|
};
|
|
@@ -151,13 +154,19 @@ const WithCustomActionsStory = () => {
|
|
|
151
154
|
onGlobalFilterChange={setSearch}
|
|
152
155
|
onClearFilters={() => setSearch("")}
|
|
153
156
|
customActions={
|
|
154
|
-
<XStack
|
|
155
|
-
<Button
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
<XStack>
|
|
158
|
+
<Button
|
|
159
|
+
{...toolbarGlyphProps}
|
|
160
|
+
icon={<ArrowsClockwiseIcon size={20} />}
|
|
161
|
+
aria-label="Refresh"
|
|
162
|
+
onPress={() => action("refresh")()}
|
|
163
|
+
/>
|
|
164
|
+
<Button
|
|
165
|
+
{...toolbarGlyphProps}
|
|
166
|
+
icon={<DownloadSimpleIcon size={20} />}
|
|
167
|
+
aria-label="Export"
|
|
168
|
+
onPress={() => action("export")()}
|
|
169
|
+
/>
|
|
161
170
|
</XStack>
|
|
162
171
|
}
|
|
163
172
|
/>
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FZ-8039: below `$sm` (the happy-dom default, `sm: false`) and over a card
|
|
3
|
+
* list, the toolbar is the HIG `.searchable` field over the list: one search
|
|
4
|
+
* field at full width, with Filter, Sort and More as bare accent glyphs inside
|
|
5
|
+
* its trailing edge (LC-176), never a row or cluster of their own.
|
|
6
|
+
*/
|
|
7
|
+
import { MIN_PRESS_TARGET } from "@multiplatform.one/theme";
|
|
8
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
9
|
+
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
|
|
10
|
+
import { describe, expect, it, vi } from "vitest";
|
|
11
|
+
import type { DataTableColumn, FilterableField } from "../../types";
|
|
12
|
+
import { DataTable } from "../DataTable";
|
|
13
|
+
import { DataTableToolbar } from "./index";
|
|
14
|
+
|
|
15
|
+
const rows = [
|
|
16
|
+
{ id: "a", form: "Alpha", entity: "personal", year: 2023 },
|
|
17
|
+
{ id: "b", form: "Beta", entity: "business", year: 2024 },
|
|
18
|
+
];
|
|
19
|
+
const columns: DataTableColumn<(typeof rows)[number]>[] = [
|
|
20
|
+
{ accessorKey: "form", header: "Form" },
|
|
21
|
+
{ accessorKey: "entity", header: "Entity" },
|
|
22
|
+
];
|
|
23
|
+
const filterableFields: FilterableField[] = [{ id: "year", label: "Year", type: "number" }];
|
|
24
|
+
|
|
25
|
+
function renderCards(props: Record<string, unknown> = {}) {
|
|
26
|
+
return renderWithProviders(
|
|
27
|
+
<DataTable
|
|
28
|
+
data={rows}
|
|
29
|
+
columns={columns}
|
|
30
|
+
filterableFields={filterableFields}
|
|
31
|
+
layout="cards"
|
|
32
|
+
enableGlobalSearch
|
|
33
|
+
enableViews
|
|
34
|
+
onStateChange={vi.fn()}
|
|
35
|
+
{...props}
|
|
36
|
+
/>,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const transparent = new Set(["", "transparent", "rgba(0, 0, 0, 0)"]);
|
|
41
|
+
|
|
42
|
+
function glyphs(row: HTMLElement) {
|
|
43
|
+
return [...row.querySelectorAll<HTMLElement>("[data-table-toolbar-glyph]")];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe("compact toolbar row (FZ-8039)", () => {
|
|
47
|
+
it("is one unwrapped row: search, then Filter, Sort and More", () => {
|
|
48
|
+
renderCards();
|
|
49
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
50
|
+
expect(row.hasAttribute("data-table-toolbar-row")).toBe(true);
|
|
51
|
+
expect(getComputedStyle(row).flexDirection).toBe("row");
|
|
52
|
+
expect(getComputedStyle(row).flexWrap).toBe("nowrap");
|
|
53
|
+
const search = row.querySelector<HTMLElement>("[data-table-toolbar-search]")!;
|
|
54
|
+
expect(search.contains(screen.getByLabelText("Search table data"))).toBe(true);
|
|
55
|
+
expect(getComputedStyle(search).flexGrow).toBe("1");
|
|
56
|
+
expect(getComputedStyle(search).minWidth).toBe("0px");
|
|
57
|
+
const trailing = search.querySelector<HTMLElement>("[data-search-trailing]")!;
|
|
58
|
+
expect(trailing).not.toBeNull();
|
|
59
|
+
expect(glyphs(trailing)).toHaveLength(3);
|
|
60
|
+
expect(glyphs(row).map((el) => el.getAttribute("aria-label"))).toEqual([
|
|
61
|
+
"Filter",
|
|
62
|
+
"Sort rows",
|
|
63
|
+
"More table actions",
|
|
64
|
+
]);
|
|
65
|
+
expect(row.querySelector("[data-table-card-primary]")).toBeNull();
|
|
66
|
+
expect(row.querySelector("[data-table-card-secondary]")).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("draws no rule under the search over a phone document list, as on native", () => {
|
|
70
|
+
renderCards({ layout: "list" });
|
|
71
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
72
|
+
expect(parseFloat(getComputedStyle(row).borderBottomWidth || "0")).toBe(0);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("gives every glyph a 44pt-wide square, the field's height, and no plate", () => {
|
|
76
|
+
renderCards({ initialState: { sorting: [{ id: "form", desc: false }] } });
|
|
77
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
78
|
+
const all = glyphs(row);
|
|
79
|
+
expect(all).toHaveLength(3);
|
|
80
|
+
const box = row.querySelector<HTMLElement>("[data-visual-height]")!;
|
|
81
|
+
const fieldHeight = Number(box.getAttribute("data-visual-height"));
|
|
82
|
+
const square = Math.min(MIN_PRESS_TARGET, fieldHeight);
|
|
83
|
+
for (const glyph of all) {
|
|
84
|
+
const style = getComputedStyle(glyph);
|
|
85
|
+
expect(style.width).toBe(`${MIN_PRESS_TARGET}px`);
|
|
86
|
+
expect(style.minWidth).toBe(`${MIN_PRESS_TARGET}px`);
|
|
87
|
+
expect(style.minHeight).toBe(`${square}px`);
|
|
88
|
+
expect(style.paddingLeft).toBe("0px");
|
|
89
|
+
expect(style.paddingRight).toBe("0px");
|
|
90
|
+
expect(transparent.has(style.backgroundColor)).toBe(true);
|
|
91
|
+
expect(glyph.getAttribute("data-mp-tier")).not.toBe("tinted");
|
|
92
|
+
expect(glyph.textContent).toBe("");
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("abuts the glyph squares and closes the field with the last one", () => {
|
|
97
|
+
renderCards();
|
|
98
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
99
|
+
const cluster = row.querySelector<HTMLElement>("[data-table-toolbar-actions]")!;
|
|
100
|
+
const gapOf = (el: HTMLElement) =>
|
|
101
|
+
getComputedStyle(el).gap || [...el.classList].find((name) => name.startsWith("_gap-")) || "";
|
|
102
|
+
expect(["", "0px", "0"]).toContain(gapOf(cluster).replace(/^_gap-/, ""));
|
|
103
|
+
const box = row.querySelector<HTMLElement>("[data-visual-height]")!;
|
|
104
|
+
const endPad = getComputedStyle(box).paddingInlineEnd || getComputedStyle(box).paddingRight;
|
|
105
|
+
expect(endPad || "0px").toBe("0px");
|
|
106
|
+
for (const glyph of glyphs(row)) {
|
|
107
|
+
const style = getComputedStyle(glyph);
|
|
108
|
+
expect([style.marginLeft, style.marginRight].map((m) => m || "0px")).toEqual(["0px", "0px"]);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("sits on the list: one list gap above and below search, no hairline", () => {
|
|
113
|
+
// A header hairline above the list must not touch the field (rv_3e4f3da8f1c0346a).
|
|
114
|
+
renderCards();
|
|
115
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
116
|
+
const style = getComputedStyle(row);
|
|
117
|
+
expect(style.paddingBottom).not.toBe("0px");
|
|
118
|
+
expect(style.paddingTop).toBe(style.paddingBottom);
|
|
119
|
+
expect(style.borderBottomWidth || "0px").toBe("0px");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("with no search the glyphs add no padding band above the list (LC-173)", () => {
|
|
123
|
+
renderCards({ enableGlobalSearch: false });
|
|
124
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
125
|
+
const style = getComputedStyle(row);
|
|
126
|
+
expect(style.paddingTop || "0px").toBe("0px");
|
|
127
|
+
expect(style.paddingBottom || "0px").toBe("0px");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("keeps the sort identity in the glyph's description, not a label", () => {
|
|
131
|
+
renderCards({ initialState: { sorting: [{ id: "form", desc: true }] } });
|
|
132
|
+
const sort = screen.getByLabelText("Sort rows");
|
|
133
|
+
expect(sort.getAttribute("aria-description")).toBe("Form ↓");
|
|
134
|
+
expect(sort.textContent).toBe("");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("puts views and save view behind More", async () => {
|
|
138
|
+
const onSaveView = vi.fn();
|
|
139
|
+
renderWithProviders(
|
|
140
|
+
<DataTableToolbar
|
|
141
|
+
enableGlobalSearch
|
|
142
|
+
enableViews
|
|
143
|
+
views={[
|
|
144
|
+
{
|
|
145
|
+
id: "v1",
|
|
146
|
+
name: "Mine",
|
|
147
|
+
columns: {},
|
|
148
|
+
filters: [],
|
|
149
|
+
sorting: [],
|
|
150
|
+
pagination: { pageIndex: 0, pageSize: 10 },
|
|
151
|
+
},
|
|
152
|
+
]}
|
|
153
|
+
activeViewId="v1"
|
|
154
|
+
onSaveView={onSaveView}
|
|
155
|
+
/>,
|
|
156
|
+
);
|
|
157
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
158
|
+
expect(within(row).queryByLabelText("Save view")).toBeNull();
|
|
159
|
+
fireEvent.click(within(row).getByRole("button", { name: "More table actions" }));
|
|
160
|
+
const field = await waitFor(() => screen.getByRole("textbox", { name: "View name" }));
|
|
161
|
+
expect(screen.getByRole("button", { name: "Saved views" }).textContent).toContain("Mine");
|
|
162
|
+
fireEvent.change(field, { target: { value: "Next" } });
|
|
163
|
+
fireEvent.click(screen.getByRole("button", { name: "Save" }));
|
|
164
|
+
expect(onSaveView).toHaveBeenCalledWith("Next");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("sets a caller's own actions after the search field, never inside it", () => {
|
|
168
|
+
renderWithProviders(
|
|
169
|
+
<DataTableToolbar
|
|
170
|
+
enableGlobalSearch
|
|
171
|
+
customActions={
|
|
172
|
+
<>
|
|
173
|
+
<button type="button">Refresh</button>
|
|
174
|
+
<button type="button">Export</button>
|
|
175
|
+
</>
|
|
176
|
+
}
|
|
177
|
+
/>,
|
|
178
|
+
);
|
|
179
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
180
|
+
const search = row.querySelector<HTMLElement>("[data-table-toolbar-search]")!;
|
|
181
|
+
const custom = row.querySelector<HTMLElement>("[data-table-toolbar-custom]")!;
|
|
182
|
+
expect(custom).not.toBeNull();
|
|
183
|
+
expect(search.contains(screen.getByRole("button", { name: "Export" }))).toBe(false);
|
|
184
|
+
expect(custom.contains(screen.getByRole("button", { name: "Refresh" }))).toBe(true);
|
|
185
|
+
expect(search.compareDocumentPosition(custom) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("keeps a search-less row's glyphs at the trailing edge", () => {
|
|
189
|
+
renderCards({ enableGlobalSearch: false });
|
|
190
|
+
const row = screen.getByRole("toolbar", { name: "Table toolbar" });
|
|
191
|
+
expect(row.querySelector("[data-table-toolbar-search]")).toBeNull();
|
|
192
|
+
const trailing = row.querySelector<HTMLElement>("[data-table-toolbar-trailing]")!;
|
|
193
|
+
expect(getComputedStyle(trailing).flexGrow).toBe("1");
|
|
194
|
+
expect(getComputedStyle(trailing).justifyContent).toBe("flex-end");
|
|
195
|
+
expect(within(trailing).getByRole("button", { name: "More table actions" })).toBeTruthy();
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { pressSlopProps } from "@multiplatform.one/forms";
|
|
2
|
+
import { MIN_PRESS_TARGET } from "@multiplatform.one/theme";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
|
|
5
|
+
export const toolbarGlyphProps = {
|
|
6
|
+
chromeless: true,
|
|
7
|
+
accentInk: true,
|
|
8
|
+
width: MIN_PRESS_TARGET,
|
|
9
|
+
minWidth: MIN_PRESS_TARGET,
|
|
10
|
+
minHeight: MIN_PRESS_TARGET,
|
|
11
|
+
paddingHorizontal: 0,
|
|
12
|
+
sizeRecipeEscape: "LC-176 icon glyph centred on its 44pt square",
|
|
13
|
+
flexShrink: 0,
|
|
14
|
+
"data-table-toolbar-glyph": "",
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The search field's visual height, when the glyphs sit inside it. A field
|
|
19
|
+
* shorter than 44pt keeps the glyph square to its height and reaches the
|
|
20
|
+
* press target through vertical slop, like the field's own clear action.
|
|
21
|
+
*/
|
|
22
|
+
export const ToolbarGlyphFieldHeight = createContext<number | null>(null);
|
|
23
|
+
|
|
24
|
+
export function useToolbarGlyphProps() {
|
|
25
|
+
const fieldHeight = useContext(ToolbarGlyphFieldHeight);
|
|
26
|
+
if (fieldHeight == null || fieldHeight >= MIN_PRESS_TARGET) return toolbarGlyphProps;
|
|
27
|
+
return {
|
|
28
|
+
...toolbarGlyphProps,
|
|
29
|
+
height: fieldHeight,
|
|
30
|
+
minHeight: fieldHeight,
|
|
31
|
+
...pressSlopProps(fieldHeight, true, "vertical"),
|
|
32
|
+
};
|
|
33
|
+
}
|