@tonycodes-ui/mortar 0.28.1 → 0.29.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/CHANGELOG.md +19 -2
- package/bin/mortar.mjs +16 -4
- package/catalog.json +630 -355
- package/cli/audit.mjs +24 -9
- package/cli/data.mjs +5 -0
- package/cli/packet.mjs +39 -3
- package/cli/render.mjs +315 -0
- package/cli/tools.mjs +24 -2
- package/dist/agent-data.json +1 -1
- package/dist/application.d.ts +2 -33
- package/dist/application.js +2 -56
- package/dist/data-grid.d.ts +2 -0
- package/dist/data-grid.js +4 -0
- package/dist/grid.d.ts +102 -0
- package/dist/grid.js +371 -0
- package/dist/table-core.d.ts +54 -0
- package/dist/table-core.js +59 -0
- package/docs/agents.md +17 -1
- package/docs/data-grid.md +155 -0
- package/package.json +17 -3
- package/skills/mortar/SKILL.md +1 -1
- package/src/application.tsx +15 -114
- package/src/data-grid.ts +13 -0
- package/src/data.css +64 -1
- package/src/foundation.css +3 -1
- package/src/grid.tsx +906 -0
- package/src/table-core.tsx +128 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type SortDirection = "ascending" | "descending";
|
|
3
|
+
export interface TableSort {
|
|
4
|
+
key: string;
|
|
5
|
+
direction: SortDirection;
|
|
6
|
+
}
|
|
7
|
+
export interface DataTableColumn<T> {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
render: (row: T) => ReactNode;
|
|
11
|
+
/** `end` aligns numbers and amounts to the trailing edge. */
|
|
12
|
+
align?: "start" | "end";
|
|
13
|
+
/** Enable header sorting. Supply sortValue unless row[key] is a string, number or Date. */
|
|
14
|
+
sortable?: boolean;
|
|
15
|
+
sortValue?: (row: T) => string | number | Date | null | undefined;
|
|
16
|
+
/** CSS width, e.g. "12rem" or "30%". */
|
|
17
|
+
width?: string;
|
|
18
|
+
/** Clip long values to one line with an ellipsis. */
|
|
19
|
+
truncate?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* How long the column stays as the table narrows (its own width, not the
|
|
22
|
+
* screen's): `medium` hides below 480px, `low` below 768px. The first
|
|
23
|
+
* column always shows. Hidden columns leave the accessibility tree too, so
|
|
24
|
+
* keep what people need in visible columns or on the detail page.
|
|
25
|
+
*/
|
|
26
|
+
priority?: "high" | "medium" | "low";
|
|
27
|
+
/**
|
|
28
|
+
* `end` pins the column to the trailing edge while the table scrolls
|
|
29
|
+
* sideways, so a row-actions or status column stays reachable.
|
|
30
|
+
*/
|
|
31
|
+
pin?: "end";
|
|
32
|
+
}
|
|
33
|
+
/** Responsive attributes shared by a column's `col`, header and cells. */
|
|
34
|
+
export declare function columnLayout<T>(col: DataTableColumn<T>, index: number): {
|
|
35
|
+
"data-priority": "low" | "medium" | undefined;
|
|
36
|
+
"data-pin": "end" | undefined;
|
|
37
|
+
};
|
|
38
|
+
export declare const isEmpty: (v: unknown) => v is "" | null | undefined;
|
|
39
|
+
export declare function compareValues(a: unknown, b: unknown): number;
|
|
40
|
+
/** Stable sort; empty values always sort last regardless of direction. */
|
|
41
|
+
export declare function sortRows<T>(rows: T[], column: Pick<DataTableColumn<T>, "key" | "sortValue">, direction: SortDirection): T[];
|
|
42
|
+
export declare function SelectAll({ checked, partial, onChange, }: {
|
|
43
|
+
checked: boolean;
|
|
44
|
+
partial: boolean;
|
|
45
|
+
onChange: () => void;
|
|
46
|
+
}): import("react").JSX.Element;
|
|
47
|
+
/** Buckets ordered rows by group; groups keep their first-appearance order in the unsorted rows. */
|
|
48
|
+
export declare function groupRows<T>(rows: T[], ordered: T[], groupBy: (row: T) => string): [string, T[]][];
|
|
49
|
+
/** Full-width header row that labels the rows of its tbody. */
|
|
50
|
+
export declare function TableGroupRow({ label, span, }: {
|
|
51
|
+
label: string;
|
|
52
|
+
span: number;
|
|
53
|
+
}): import("react").JSX.Element;
|
|
54
|
+
export declare const columnAlign: (align?: "start" | "end") => "end" | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Table building blocks shared by DataTable and DataGrid. Internal: the public
|
|
3
|
+
// types are re-exported from application.tsx and the package entry.
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
/** Responsive attributes shared by a column's `col`, header and cells. */
|
|
6
|
+
export function columnLayout(col, index) {
|
|
7
|
+
return {
|
|
8
|
+
"data-priority": index > 0 && col.priority && col.priority !== "high"
|
|
9
|
+
? col.priority
|
|
10
|
+
: undefined,
|
|
11
|
+
"data-pin": col.pin,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const collator = new Intl.Collator(undefined, {
|
|
15
|
+
numeric: true,
|
|
16
|
+
sensitivity: "base",
|
|
17
|
+
});
|
|
18
|
+
export const isEmpty = (v) => v === null || v === undefined || v === "";
|
|
19
|
+
export function compareValues(a, b) {
|
|
20
|
+
if (isEmpty(a) || isEmpty(b))
|
|
21
|
+
return isEmpty(a) === isEmpty(b) ? 0 : isEmpty(a) ? 1 : -1;
|
|
22
|
+
if (a instanceof Date && b instanceof Date)
|
|
23
|
+
return a.getTime() - b.getTime();
|
|
24
|
+
if (typeof a === "number" && typeof b === "number")
|
|
25
|
+
return a - b;
|
|
26
|
+
return collator.compare(String(a), String(b));
|
|
27
|
+
}
|
|
28
|
+
/** Stable sort; empty values always sort last regardless of direction. */
|
|
29
|
+
export function sortRows(rows, column, direction) {
|
|
30
|
+
const value = column.sortValue ||
|
|
31
|
+
((row) => row[column.key]);
|
|
32
|
+
const sign = direction === "ascending" ? 1 : -1;
|
|
33
|
+
return rows
|
|
34
|
+
.map((row, index) => ({ row, index, v: value(row) }))
|
|
35
|
+
.sort((a, b) =>
|
|
36
|
+
// Empty values sort last in both directions, so only real values flip.
|
|
37
|
+
(isEmpty(a.v) || isEmpty(b.v) ? 1 : sign) * compareValues(a.v, b.v) ||
|
|
38
|
+
a.index - b.index)
|
|
39
|
+
.map((entry) => entry.row);
|
|
40
|
+
}
|
|
41
|
+
export function SelectAll({ checked, partial, onChange, }) {
|
|
42
|
+
const ref = useRef(null);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (ref.current)
|
|
45
|
+
ref.current.indeterminate = partial;
|
|
46
|
+
}, [partial]);
|
|
47
|
+
return (_jsx("input", { ref: ref, type: "checkbox", "aria-label": "Select all rows", checked: checked, onChange: onChange }));
|
|
48
|
+
}
|
|
49
|
+
/** Buckets ordered rows by group; groups keep their first-appearance order in the unsorted rows. */
|
|
50
|
+
export function groupRows(rows, ordered, groupBy) {
|
|
51
|
+
const groups = new Map(rows.map((row) => [groupBy(row), []]));
|
|
52
|
+
ordered.forEach((row) => groups.get(groupBy(row)).push(row));
|
|
53
|
+
return [...groups];
|
|
54
|
+
}
|
|
55
|
+
/** Full-width header row that labels the rows of its tbody. */
|
|
56
|
+
export function TableGroupRow({ label, span, }) {
|
|
57
|
+
return (_jsx("tr", { className: "m-table-group", children: _jsx("th", { colSpan: span, scope: "rowgroup", children: label }) }));
|
|
58
|
+
}
|
|
59
|
+
export const columnAlign = (align) => align === "end" ? "end" : undefined;
|
package/docs/agents.md
CHANGED
|
@@ -77,6 +77,7 @@ npx mortar component DataTable
|
|
|
77
77
|
npx mortar packet AppShell DataTable
|
|
78
78
|
npx mortar packet --brief "an admin screen listing invoices with filters"
|
|
79
79
|
npx mortar audit .
|
|
80
|
+
npx mortar audit . --render http://localhost:5173/,http://localhost:5173/settings
|
|
80
81
|
npx mortar guide theming
|
|
81
82
|
```
|
|
82
83
|
|
|
@@ -88,7 +89,7 @@ Add `--json` for machine-readable output. `mortar audit` exits with status 1 whe
|
|
|
88
89
|
2. **Packet.** Call `get_build_packet` with the components you picked, or with the brief. Compose from it: the contracts list every prop, and the page templates show complete page patterns to follow.
|
|
89
90
|
3. **Compose.** Use named imports from `@tonycodes-ui/mortar` and the exact props and values in each contract. Keep product names, data, routes, permissions and actions in props and slots. Theme with `ThemeProvider` and tokens (`get_guide theming`). Never copy a component's source, wrap it repeatedly, or override `.m-*` classes or `[data-m-component]` in your CSS. When replacing an unlabeled native `<input>`, move search icons onto `leadingIcon`/`trailingIcon` and units onto `prefix`/`suffix`; do not keep `relative`/`absolute` chrome around a labeled `Input`, and do not put static text in `action` (that slot is for an attached Button or menu).
|
|
90
91
|
For an iOS, iPadOS or Android app, use the SwiftUI package and the Compose library (`get_guide native`). A component's contract names its native equivalent under `native`, and a packet for a native brief lists every component the native libraries have.
|
|
91
|
-
4. **Audit.** Run `audit_app` (or `npx mortar audit`) and fix what it finds, then run the app's own typecheck and build. Verify in a browser: mobile and desktop, light and dark, keyboard and focus, and loading, empty and error states.
|
|
92
|
+
4. **Audit.** Run `audit_app` (or `npx mortar audit`) and fix what it finds, then run the app's own typecheck and build. With the app running, add the page URLs (`render`, or `--render`) to check what rendered. Verify in a browser: mobile and desktop, light and dark, keyboard and focus, and loading, empty and error states.
|
|
92
93
|
5. **Contribute.** If a shared pattern is missing or a component is wrong, fix it in the kit, not in the app. Open a pull request at [github.com/tonycodes/mortar](https://github.com/tonycodes/mortar) following [CONTRIBUTING.md](../CONTRIBUTING.md) and [AGENTS.md](../AGENTS.md) (`get_guide contributing`). Maintainer review and CI decide what merges; agents never approve, merge or publish their own changes.
|
|
93
94
|
|
|
94
95
|
## The audit
|
|
@@ -124,6 +125,21 @@ Add `--json` for machine-readable output. `mortar audit` exits with status 1 whe
|
|
|
124
125
|
|
|
125
126
|
The audit is a fast scanner, not a type checker. It checks JSX body children when a component's contract has no `children` slot (for example `<Switch>…</Switch>`). It does not see props passed through a spread (`{...props}`), components re-exported or wrapped under another name, class names built at runtime, or markup in `.vue`, `.svelte`, `.astro` or `.html` files. Run the app's typecheck and build as well.
|
|
126
127
|
|
|
128
|
+
### Rendered checks
|
|
129
|
+
|
|
130
|
+
`--render` (or `audit_app`'s `render` argument) takes comma-separated URLs of the running app. After the source scan, each page opens in a headless browser at 390px and 1280px, in light and dark, and the audit checks what actually rendered. It only reads the pages: it never clicks, types or submits. It needs Playwright in the app (`npm install -D playwright` and `npx playwright install chromium`); set `MORTAR_CHROME` to use another Chromium.
|
|
131
|
+
|
|
132
|
+
| Rule | Severity | Finds |
|
|
133
|
+
| ----------------------- | -------- | -------------------------------------------------------------------------------------------------------- |
|
|
134
|
+
| `render-error` | error | A console error or uncaught exception, or a page that does not load |
|
|
135
|
+
| `render-missing-styles` | error | Mortar components on a page without Mortar's tokens, so `styles.css` is not loaded |
|
|
136
|
+
| `render-box-sizing` | error | Mortar controls with content-box sizing, usually because Tailwind is not imported before Mortar's styles |
|
|
137
|
+
| `render-row-height` | warning | Mortar controls side by side in one row at different heights |
|
|
138
|
+
| `render-label-align` | warning | A Mortar field label that is not start-aligned, usually inherited from a parent's `text-align` |
|
|
139
|
+
| `render-overflow` | warning | A page that scrolls sideways at 390px |
|
|
140
|
+
|
|
141
|
+
Each problem is reported once, with the widths and appearances it showed in when it was not all of them. Rendered checks cover the states a page shows when it loads; open dialogs, menus and error states are not reached. Keep checking those in a browser.
|
|
142
|
+
|
|
127
143
|
A clean audit means the audit found none of the problems above. It is not proof that a page is built only from Mortar components: hand-written layout, typography or animation in the app's own markup is invisible to it unless it touches Mortar's classes, colours, or an obvious ancestor/native-element visual override. Do not report a passing audit as that proof. To show a page is composed from the kit, point to the components it renders (each root carries `data-m-component`) and to [what you can extend](theming.md#what-you-can-extend).
|
|
128
144
|
|
|
129
145
|
## Agent skill
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# DataGrid
|
|
2
|
+
|
|
3
|
+
`DataGrid` is the interactive table for large or server-driven data: multi-column sort, column filters, search, selection across pages, paging, hidden and pinned columns, and row virtualization for tens of thousands of rows. It ships from its own entry point, `@tonycodes-ui/mortar/data-grid`, and renders the same markup and styles as `DataTable`, so the two look the same side by side.
|
|
4
|
+
|
|
5
|
+
## DataGrid or DataTable
|
|
6
|
+
|
|
7
|
+
| Use | When |
|
|
8
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| `DataTable` | A few hundred rows or fewer, single-column sort, your own toolbar. It has no extra dependencies. |
|
|
10
|
+
| `DataGrid` | Thousands of rows, data the server sorts and pages, or people need filters, search, multi-sort, hidden or pinned columns. |
|
|
11
|
+
|
|
12
|
+
Moving from `DataTable` is mostly a rename: `DataGridColumn` takes every `DataTableColumn` field, and `caption`, `rows`, `rowLabel`, `selectedIds`, `onSelectionChange`, `bulkActions`, `rowHref`, `empty`, `loading`, `error`, `density` and `striped` work the same way. `sort` becomes a list of sort levels.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
The grid's engine, [TanStack Table](https://tanstack.com/table) and [TanStack Virtual](https://tanstack.com/virtual), are optional peer dependencies. Install them only in apps that import the grid:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @tanstack/react-table @tanstack/react-virtual
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The grid needs both packages whenever it is imported, even when it isn't virtualized. Mortar's stylesheet already includes the grid's styles, so there is nothing else to import.
|
|
23
|
+
|
|
24
|
+
In server mode, always pass `rowCount`. Without it the grid counts only the rows it was given, so paging shows a single page.
|
|
25
|
+
|
|
26
|
+
## Client mode
|
|
27
|
+
|
|
28
|
+
In client mode (the default) the grid sorts, filters, searches and pages every row in the browser. Pass all the rows.
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { Badge, Button } from "@tonycodes-ui/mortar";
|
|
32
|
+
import { DataGrid, type DataGridColumn } from "@tonycodes-ui/mortar/data-grid";
|
|
33
|
+
|
|
34
|
+
const columns: DataGridColumn<Invoice>[] = [
|
|
35
|
+
{
|
|
36
|
+
key: "number",
|
|
37
|
+
label: "Invoice",
|
|
38
|
+
render: (r) => r.number,
|
|
39
|
+
sortable: true,
|
|
40
|
+
pin: "start",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key: "customer",
|
|
44
|
+
label: "Customer",
|
|
45
|
+
render: (r) => r.customer,
|
|
46
|
+
sortable: true,
|
|
47
|
+
filter: "text",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
key: "amount",
|
|
51
|
+
label: "Amount",
|
|
52
|
+
render: (r) => money.format(r.amount),
|
|
53
|
+
align: "end",
|
|
54
|
+
sortable: true,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: "status",
|
|
58
|
+
label: "Status",
|
|
59
|
+
render: (r) => <Badge tone={tone[r.status]}>{r.status}</Badge>,
|
|
60
|
+
filter: { options: statusOptions },
|
|
61
|
+
pin: "end",
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
<DataGrid
|
|
66
|
+
caption="Invoices"
|
|
67
|
+
rows={invoices}
|
|
68
|
+
columns={columns}
|
|
69
|
+
rowLabel={(r) => r.number}
|
|
70
|
+
searchable
|
|
71
|
+
virtualize
|
|
72
|
+
selectedIds={selected}
|
|
73
|
+
onSelectionChange={setSelected}
|
|
74
|
+
bulkActions={<Button variant="secondary">Mark as paid</Button>}
|
|
75
|
+
noun="invoices"
|
|
76
|
+
/>;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`render` controls what a cell shows. Sorting, filters and search use the raw value instead: `sortValue(row)` for sorting and `filterValue(row)` for filters and search, both defaulting to `row[key]`. Give dates and amounts a `sortValue` that returns the `Date` or number, and a `filterValue` that returns the text people will type.
|
|
80
|
+
|
|
81
|
+
## Server mode
|
|
82
|
+
|
|
83
|
+
With `mode="server"` the grid never sorts, filters or pages rows itself. It reports what people asked for, and you fetch the matching page and its total.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
const [sort, setSort] = useState<TableSort[]>([
|
|
87
|
+
{ key: "issued", direction: "descending" },
|
|
88
|
+
]);
|
|
89
|
+
const [filters, setFilters] = useState<DataGridFilters>({});
|
|
90
|
+
const [search, setSearch] = useState("");
|
|
91
|
+
const [pagination, setPagination] = useState({ page: 1, pageSize: 50 });
|
|
92
|
+
const { data, isLoading, error } = useInvoices({
|
|
93
|
+
sort,
|
|
94
|
+
filters,
|
|
95
|
+
search,
|
|
96
|
+
pagination,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
<DataGrid
|
|
100
|
+
caption="Invoices"
|
|
101
|
+
mode="server"
|
|
102
|
+
rows={data?.rows ?? []}
|
|
103
|
+
rowCount={data?.total ?? 0}
|
|
104
|
+
columns={columns}
|
|
105
|
+
rowLabel={(r) => r.number}
|
|
106
|
+
sort={sort}
|
|
107
|
+
onSortChange={setSort}
|
|
108
|
+
filters={filters}
|
|
109
|
+
onFiltersChange={setFilters}
|
|
110
|
+
searchable
|
|
111
|
+
search={search}
|
|
112
|
+
onSearchChange={setSearch}
|
|
113
|
+
pagination={pagination}
|
|
114
|
+
onPaginationChange={setPagination}
|
|
115
|
+
loading={isLoading}
|
|
116
|
+
error={error?.message}
|
|
117
|
+
/>;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Put the state in your request key, so a change fetches again. Filtering or searching returns to page 1.
|
|
121
|
+
|
|
122
|
+
## State
|
|
123
|
+
|
|
124
|
+
Every piece of state is controlled when you pass its value and its `on…Change` callback, and kept by the grid when you pass only a `default…` value (or nothing):
|
|
125
|
+
|
|
126
|
+
| State | Controlled | Uncontrolled |
|
|
127
|
+
| -------------- | ---------------------------------------- | ---------------------- |
|
|
128
|
+
| Sort levels | `sort`, `onSortChange` | `defaultSort` |
|
|
129
|
+
| Column filters | `filters`, `onFiltersChange` | `defaultFilters` |
|
|
130
|
+
| Search | `search`, `onSearchChange` | `defaultSearch` |
|
|
131
|
+
| Hidden columns | `hiddenColumns`, `onHiddenColumnsChange` | `defaultHiddenColumns` |
|
|
132
|
+
| Paging | `pagination`, `onPaginationChange` | `defaultPagination` |
|
|
133
|
+
| Selection | `selectedIds`, `onSelectionChange` | none |
|
|
134
|
+
|
|
135
|
+
Hidden columns and sort levels are plain arrays, so they are easy to save per user.
|
|
136
|
+
|
|
137
|
+
## Behaviour
|
|
138
|
+
|
|
139
|
+
- **Sorting.** Click a header to sort; click again to reverse, and a third time to remove the sort. Shift-click adds the column as another level; numbered badges show the order. Empty values sort last in both directions, as in `DataTable`.
|
|
140
|
+
- **Filters and search.** A column with `filter: "text"` gets a text box that matches part of the value, ignoring case; `filter: { options }` gets a choice that matches exactly. `searchable` adds a field that searches every column's filter value. The status region announces the number of matching rows, and when nothing matches the grid offers to clear the filters.
|
|
141
|
+
- **Selection.** "Select all" selects every matching row in client mode and the loaded page in server mode, and keeps selections made elsewhere. Selected ids may include rows that are not loaded.
|
|
142
|
+
- **Paging or virtualization.** Pass `pagination` to page rows, or `virtualize` to render only the rows in view. Virtualization needs a fixed height: `maxHeight`, which defaults to 32rem when virtualizing. Without either, every row renders.
|
|
143
|
+
- **Columns.** People can hide any column but the first from the Columns menu; set `hideable: false` to keep one. `pin: "start"` or `pin: "end"` keeps a column in view while the grid scrolls sideways. `priority` hides secondary columns on narrow grids, as in `DataTable`.
|
|
144
|
+
|
|
145
|
+
## Accessibility
|
|
146
|
+
|
|
147
|
+
The grid is a semantic table with a caption, `scope` on headers and `aria-sort` on the sorted column. A virtualized grid sets `aria-rowcount` and each row's `aria-rowindex`, so screen readers know where they are in the full set. Every row checkbox is named from `rowLabel`. Check keyboard use and focus in your own toolbar content and bulk actions.
|
|
148
|
+
|
|
149
|
+
## Performance
|
|
150
|
+
|
|
151
|
+
With 100,000 client-side rows in the playground, sorting takes about 250ms, searching about 300ms, and scrolling stays at one frame (about 17ms) with fewer than 30 rows in the page. `tests/browser/data-grid-performance.spec.mjs` holds the budget. Keep `columns` stable (define them outside the component or memoise them): a new array every render rebuilds the grid's column definitions.
|
|
152
|
+
|
|
153
|
+
## Not yet
|
|
154
|
+
|
|
155
|
+
Column resizing and reordering, grouping with totals, expandable detail rows and inline editing are planned and not in this version.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonycodes-ui/mortar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Mortar: a shared design foundation, application and marketing UI for React and Tailwind.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
"./email": {
|
|
54
54
|
"types": "./dist/email.d.ts",
|
|
55
55
|
"import": "./dist/email.js"
|
|
56
|
+
},
|
|
57
|
+
"./data-grid": {
|
|
58
|
+
"types": "./dist/data-grid.d.ts",
|
|
59
|
+
"import": "./dist/data-grid.js"
|
|
56
60
|
}
|
|
57
61
|
},
|
|
58
62
|
"sideEffects": [
|
|
@@ -78,11 +82,19 @@
|
|
|
78
82
|
"react": "^19.0.0",
|
|
79
83
|
"react-dom": "^19.0.0",
|
|
80
84
|
"tailwindcss": "^4.0.0",
|
|
81
|
-
"@react-email/components": "^1.0.12"
|
|
85
|
+
"@react-email/components": "^1.0.12",
|
|
86
|
+
"@tanstack/react-table": "^9.3.1",
|
|
87
|
+
"@tanstack/react-virtual": "^3.14.28"
|
|
82
88
|
},
|
|
83
89
|
"peerDependenciesMeta": {
|
|
84
90
|
"@react-email/components": {
|
|
85
91
|
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@tanstack/react-table": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"@tanstack/react-virtual": {
|
|
97
|
+
"optional": true
|
|
86
98
|
}
|
|
87
99
|
},
|
|
88
100
|
"dependencies": {
|
|
@@ -102,7 +114,9 @@
|
|
|
102
114
|
"@playwright/test": "^1.63.0",
|
|
103
115
|
"@axe-core/playwright": "^4.13.0",
|
|
104
116
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
105
|
-
"@react-email/components": "^1.0.12"
|
|
117
|
+
"@react-email/components": "^1.0.12",
|
|
118
|
+
"@tanstack/react-table": "^9.3.1",
|
|
119
|
+
"@tanstack/react-virtual": "^3.14.28"
|
|
106
120
|
},
|
|
107
121
|
"license": "MIT",
|
|
108
122
|
"publishConfig": {
|
package/skills/mortar/SKILL.md
CHANGED
|
@@ -14,7 +14,7 @@ Mortar is an MIT React 19 + Tailwind 4 UI kit. Its agent tooling ships in the pa
|
|
|
14
14
|
3. **Compose** following the defaults below.
|
|
15
15
|
4. **Emails.** Build transactional emails from `@tonycodes-ui/mortar/email` (`get_guide email`), never from the app components.
|
|
16
16
|
5. **Native apps.** For iPhone, iPad and Android, use Mortar for SwiftUI and Mortar for Jetpack Compose (`get_guide native`): each component's contract names its native equivalent. Build what they don't have from the platform's own controls, styled with `MortarTokens`.
|
|
17
|
-
6. **Audit.** Run `audit_app` on the application (`npx mortar audit`), fix every error and review the warnings, then rerun it with the app's build and typecheck.
|
|
17
|
+
6. **Audit.** Run `audit_app` on the application (`npx mortar audit`), fix every error and review the warnings, then rerun it with the app's build and typecheck. With the app running, pass its page URLs as `render` (`npx mortar audit . --render <url>`) to check the rendered pages too.
|
|
18
18
|
7. **Verify** in a browser and report the actual results.
|
|
19
19
|
|
|
20
20
|
## Defaults
|
package/src/application.tsx
CHANGED
|
@@ -709,47 +709,21 @@ export function MetricGroup({
|
|
|
709
709
|
/>
|
|
710
710
|
);
|
|
711
711
|
}
|
|
712
|
-
export type
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
width?: string;
|
|
728
|
-
/** Clip long values to one line with an ellipsis. */
|
|
729
|
-
truncate?: boolean;
|
|
730
|
-
/**
|
|
731
|
-
* How long the column stays as the table narrows (its own width, not the
|
|
732
|
-
* screen's): `medium` hides below 480px, `low` below 768px. The first
|
|
733
|
-
* column always shows. Hidden columns leave the accessibility tree too, so
|
|
734
|
-
* keep what people need in visible columns or on the detail page.
|
|
735
|
-
*/
|
|
736
|
-
priority?: "high" | "medium" | "low";
|
|
737
|
-
/**
|
|
738
|
-
* `end` pins the column to the trailing edge while the table scrolls
|
|
739
|
-
* sideways, so a row-actions or status column stays reachable.
|
|
740
|
-
*/
|
|
741
|
-
pin?: "end";
|
|
742
|
-
}
|
|
743
|
-
/** Responsive attributes shared by a column's `col`, header and cells. */
|
|
744
|
-
function columnLayout<T>(col: DataTableColumn<T>, index: number) {
|
|
745
|
-
return {
|
|
746
|
-
"data-priority":
|
|
747
|
-
index > 0 && col.priority && col.priority !== "high"
|
|
748
|
-
? col.priority
|
|
749
|
-
: undefined,
|
|
750
|
-
"data-pin": col.pin,
|
|
751
|
-
};
|
|
752
|
-
}
|
|
712
|
+
export type {
|
|
713
|
+
SortDirection,
|
|
714
|
+
TableSort,
|
|
715
|
+
DataTableColumn,
|
|
716
|
+
} from "./table-core.js";
|
|
717
|
+
import {
|
|
718
|
+
columnAlign,
|
|
719
|
+
columnLayout,
|
|
720
|
+
groupRows,
|
|
721
|
+
SelectAll,
|
|
722
|
+
sortRows,
|
|
723
|
+
TableGroupRow,
|
|
724
|
+
type DataTableColumn,
|
|
725
|
+
type TableSort,
|
|
726
|
+
} from "./table-core.js";
|
|
753
727
|
export interface DataTableProps<T extends { id: string }> {
|
|
754
728
|
caption: string;
|
|
755
729
|
columns: DataTableColumn<T>[];
|
|
@@ -784,79 +758,6 @@ export interface DataTableProps<T extends { id: string }> {
|
|
|
784
758
|
id?: string;
|
|
785
759
|
className?: string;
|
|
786
760
|
}
|
|
787
|
-
const collator = new Intl.Collator(undefined, {
|
|
788
|
-
numeric: true,
|
|
789
|
-
sensitivity: "base",
|
|
790
|
-
});
|
|
791
|
-
const isEmpty = (v: unknown) => v === null || v === undefined || v === "";
|
|
792
|
-
function compareValues(a: unknown, b: unknown) {
|
|
793
|
-
if (isEmpty(a) || isEmpty(b))
|
|
794
|
-
return isEmpty(a) === isEmpty(b) ? 0 : isEmpty(a) ? 1 : -1;
|
|
795
|
-
if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();
|
|
796
|
-
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
797
|
-
return collator.compare(String(a), String(b));
|
|
798
|
-
}
|
|
799
|
-
/** Stable sort; empty values always sort last regardless of direction. */
|
|
800
|
-
export function sortRows<T>(
|
|
801
|
-
rows: T[],
|
|
802
|
-
column: Pick<DataTableColumn<T>, "key" | "sortValue">,
|
|
803
|
-
direction: SortDirection,
|
|
804
|
-
) {
|
|
805
|
-
const value =
|
|
806
|
-
column.sortValue ||
|
|
807
|
-
((row: T) => (row as Record<string, unknown>)[column.key] as string);
|
|
808
|
-
const sign = direction === "ascending" ? 1 : -1;
|
|
809
|
-
return rows
|
|
810
|
-
.map((row, index) => ({ row, index, v: value(row) }))
|
|
811
|
-
.sort(
|
|
812
|
-
(a, b) =>
|
|
813
|
-
// Empty values sort last in both directions, so only real values flip.
|
|
814
|
-
(isEmpty(a.v) || isEmpty(b.v) ? 1 : sign) * compareValues(a.v, b.v) ||
|
|
815
|
-
a.index - b.index,
|
|
816
|
-
)
|
|
817
|
-
.map((entry) => entry.row);
|
|
818
|
-
}
|
|
819
|
-
function SelectAll({
|
|
820
|
-
checked,
|
|
821
|
-
partial,
|
|
822
|
-
onChange,
|
|
823
|
-
}: {
|
|
824
|
-
checked: boolean;
|
|
825
|
-
partial: boolean;
|
|
826
|
-
onChange: () => void;
|
|
827
|
-
}) {
|
|
828
|
-
const ref = useRef<HTMLInputElement>(null);
|
|
829
|
-
useEffect(() => {
|
|
830
|
-
if (ref.current) ref.current.indeterminate = partial;
|
|
831
|
-
}, [partial]);
|
|
832
|
-
return (
|
|
833
|
-
<input
|
|
834
|
-
ref={ref}
|
|
835
|
-
type="checkbox"
|
|
836
|
-
aria-label="Select all rows"
|
|
837
|
-
checked={checked}
|
|
838
|
-
onChange={onChange}
|
|
839
|
-
/>
|
|
840
|
-
);
|
|
841
|
-
}
|
|
842
|
-
/** Buckets ordered rows by group; groups keep their first-appearance order in the unsorted rows. */
|
|
843
|
-
function groupRows<T>(rows: T[], ordered: T[], groupBy: (row: T) => string) {
|
|
844
|
-
const groups = new Map<string, T[]>(rows.map((row) => [groupBy(row), []]));
|
|
845
|
-
ordered.forEach((row) => groups.get(groupBy(row))!.push(row));
|
|
846
|
-
return [...groups];
|
|
847
|
-
}
|
|
848
|
-
/** Full-width header row that labels the rows of its tbody. */
|
|
849
|
-
function TableGroupRow({ label, span }: { label: string; span: number }) {
|
|
850
|
-
return (
|
|
851
|
-
<tr className="m-table-group">
|
|
852
|
-
<th colSpan={span} scope="rowgroup">
|
|
853
|
-
{label}
|
|
854
|
-
</th>
|
|
855
|
-
</tr>
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
const columnAlign = (align?: "start" | "end") =>
|
|
859
|
-
align === "end" ? "end" : undefined;
|
|
860
761
|
export function DataTable<T extends { id: string }>({
|
|
861
762
|
caption,
|
|
862
763
|
columns,
|
package/src/data-grid.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* @tonycodes-ui/mortar/data-grid: DataGrid for large and server-driven data,
|
|
2
|
+
built on the optional peer dependencies @tanstack/react-table and
|
|
3
|
+
@tanstack/react-virtual. Install both to use this entry point. */
|
|
4
|
+
|
|
5
|
+
export { DataGrid } from "./grid.js";
|
|
6
|
+
export type {
|
|
7
|
+
DataGridColumn,
|
|
8
|
+
DataGridFilters,
|
|
9
|
+
DataGridPagination,
|
|
10
|
+
DataGridProps,
|
|
11
|
+
SortDirection,
|
|
12
|
+
TableSort,
|
|
13
|
+
} from "./grid.js";
|
package/src/data.css
CHANGED
|
@@ -171,7 +171,8 @@
|
|
|
171
171
|
--m-cell-pad-y: 6px;
|
|
172
172
|
--m-cell-pad-x: 10px;
|
|
173
173
|
}
|
|
174
|
-
:
|
|
174
|
+
/* Cells only: a Stack or Grid in the toolbar also carries data-align. */
|
|
175
|
+
:is(.m-data-table, .m-table) :is(th, td)[data-align="end"] {
|
|
175
176
|
text-align: right;
|
|
176
177
|
font-variant-numeric: tabular-nums;
|
|
177
178
|
}
|
|
@@ -293,6 +294,68 @@
|
|
|
293
294
|
:where(.m-data-table) tr[data-selected] > [data-pin] {
|
|
294
295
|
background-color: var(--m-selected);
|
|
295
296
|
}
|
|
297
|
+
/* DataGrid pins columns to the start too; the inline inset comes from the
|
|
298
|
+
measured widths of the pinned columns before it. */
|
|
299
|
+
/* Zero specificity, like the end pin above, so stripes and selection win. */
|
|
300
|
+
:where(.m-data-grid) :where(th, td)[data-pin="start"] {
|
|
301
|
+
position: sticky;
|
|
302
|
+
inset-inline-start: 0;
|
|
303
|
+
z-index: 2;
|
|
304
|
+
background-color: var(--m-surface);
|
|
305
|
+
box-shadow: inset -1px 0 0 var(--m-line);
|
|
306
|
+
}
|
|
307
|
+
:where(.m-data-grid:dir(rtl)) :where(th, td)[data-pin="start"] {
|
|
308
|
+
box-shadow: inset 1px 0 0 var(--m-line);
|
|
309
|
+
}
|
|
310
|
+
/* Bottom-align labelled filter controls; the selection bar stays centred. */
|
|
311
|
+
.m-data-grid .m-table-toolbar:has(> .m-data-grid-controls) {
|
|
312
|
+
align-items: flex-end;
|
|
313
|
+
}
|
|
314
|
+
.m-data-grid-controls {
|
|
315
|
+
display: flex;
|
|
316
|
+
flex-wrap: wrap;
|
|
317
|
+
align-items: flex-end;
|
|
318
|
+
gap: 12px;
|
|
319
|
+
min-width: 0;
|
|
320
|
+
}
|
|
321
|
+
.m-sort-order {
|
|
322
|
+
display: inline-grid;
|
|
323
|
+
place-items: center;
|
|
324
|
+
min-width: 16px;
|
|
325
|
+
height: 16px;
|
|
326
|
+
border-radius: var(--m-radius-full);
|
|
327
|
+
background: var(--m-sunken);
|
|
328
|
+
color: var(--m-muted);
|
|
329
|
+
font-size: 11px;
|
|
330
|
+
font-variant-numeric: tabular-nums;
|
|
331
|
+
}
|
|
332
|
+
.m-data-grid-columns-panel {
|
|
333
|
+
z-index: 30;
|
|
334
|
+
min-width: 200px;
|
|
335
|
+
margin-top: 4px;
|
|
336
|
+
padding: 12px;
|
|
337
|
+
border: 1px solid var(--m-line);
|
|
338
|
+
border-radius: var(--m-radius);
|
|
339
|
+
background: var(--m-surface);
|
|
340
|
+
box-shadow: var(--m-float);
|
|
341
|
+
}
|
|
342
|
+
.m-data-grid-columns-panel fieldset {
|
|
343
|
+
display: grid;
|
|
344
|
+
gap: 8px;
|
|
345
|
+
margin: 0;
|
|
346
|
+
padding: 0;
|
|
347
|
+
border: 0;
|
|
348
|
+
}
|
|
349
|
+
.m-data-grid-columns-panel legend {
|
|
350
|
+
margin-bottom: 8px;
|
|
351
|
+
color: var(--m-muted);
|
|
352
|
+
font-size: 12px;
|
|
353
|
+
font-weight: var(--m-weight-semibold);
|
|
354
|
+
}
|
|
355
|
+
.m-data-grid-spacer > td {
|
|
356
|
+
padding: 0;
|
|
357
|
+
border: 0;
|
|
358
|
+
}
|
|
296
359
|
/* Column priority follows the table's own width, so a table in a narrow
|
|
297
360
|
panel collapses as it would on a phone. */
|
|
298
361
|
@container m-data-table (max-width: 767px) {
|
package/src/foundation.css
CHANGED
|
@@ -552,10 +552,12 @@
|
|
|
552
552
|
background: var(--m-surface);
|
|
553
553
|
overflow: hidden;
|
|
554
554
|
}
|
|
555
|
+
/* The group draws the 1px border, so the whole field matches --m-control
|
|
556
|
+
like Select and Button beside it. */
|
|
555
557
|
.m-input-group input {
|
|
556
558
|
min-width: 0;
|
|
557
559
|
width: 100%;
|
|
558
|
-
min-height: var(--m-control);
|
|
560
|
+
min-height: calc(var(--m-control) - 2px);
|
|
559
561
|
padding: 4px var(--m-pad);
|
|
560
562
|
border: 0;
|
|
561
563
|
background: transparent;
|