@umriss-ui/table 0.6.2 → 0.7.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 +45 -0
- package/README.md +7 -5
- package/dist/index.d.ts +37 -0
- package/dist/table.css +1 -1
- package/dist/table.js +2210 -1987
- package/docs/llms-full.md +167 -2
- package/package.json +4 -4
package/docs/llms-full.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @umriss-ui/table 0.
|
|
1
|
+
# @umriss-ui/table 0.7.0
|
|
2
2
|
|
|
3
3
|
> The umriss table for data-dense applications - declared the way it reads: columns as JSX, typed against their rows.
|
|
4
4
|
|
|
@@ -651,6 +651,11 @@ export default function FirstTable() {
|
|
|
651
651
|
| `groupable` | `boolean` | — | `false`: the user cannot group this table - the column menu offers no grouping, and a grouping handed in is passed over. |
|
|
652
652
|
| `grid` | `boolean` | — | Grid mode: the table is one tab stop, and the arrows walk its cells - Home and End in the row, Ctrl+Home and Ctrl+End to the table's ends, PageUp and PageDown by the rows in view. A cell's own controls are reached with Enter or F2 and left with Escape; a column with `edit` is edited in place. Without it the table stays a native table. |
|
|
653
653
|
| `onCellEdit` | `(edit: CellEdit<Z>) => void` | — | Grid mode: an edit the user committed. The table applies nothing; the cell shows the new value when the rows passed in carry it. |
|
|
654
|
+
| `editMode` | `"cell" \| "row"` | — | Grid mode (ADR-0036): `"cell"` reports every cell as it is left (`onCellEdit`); `"row"` opens every cell of a row that edits at once, as one **Row draft**, and reports it only when the row is saved on purpose (`onRowSave`) - by its Save button or Enter; Escape or Discard drops it. A row with a draft is left only by saving or discarding it. |
|
|
655
|
+
| `onRowSave` | `(save: RowSave<Z>) => void` | — | `editMode="row"`: a saved Row draft, with the columns it changed. |
|
|
656
|
+
| `onRowAdd` | `(add: RowAdd) => void` | — | Grid mode: puts up a "New row" button - in the table toolbar, or beneath the table without one. It opens an empty Row draft above the rows; saved, it is reported whole. The row appears when the rows passed in carry it. |
|
|
657
|
+
| `newRow` | `() => Partial<Z>` | — | What a new row starts with - the values the columns read before anything is typed. Without it, nothing. |
|
|
658
|
+
| `onRowDelete` | `(remove: RowDelete<Z>) => void` | — | Grid mode: a Delete button on every row, which asks inside its row before the delete is reported. The table removes nothing. |
|
|
654
659
|
| `children` | `ReactNode` | — | Columns, `RowDetail`, `RowActions` and the unbound parts. |
|
|
655
660
|
|
|
656
661
|
##### `TableOptions<Z>`
|
|
@@ -5115,6 +5120,7 @@ export default function TheWholeGrid() {
|
|
|
5115
5120
|
| `Home / End` | The first or last cell of the row. |
|
|
5116
5121
|
| `Ctrl + Home / Ctrl + End` | The first cell of the head, the last cell of the footer. |
|
|
5117
5122
|
| `Page Up / Page Down` | Moves by the rows in view. |
|
|
5123
|
+
| `Click` | Opens the editor of a cell that edits; a select shows its list, a day its calendar. |
|
|
5118
5124
|
| `Enter / F2` | Starts an edit, or reaches the cell's own controls. |
|
|
5119
5125
|
| `Escape` | Cancels an edit, or goes back from a control to its cell. |
|
|
5120
5126
|
| `Space` | Selects the row of the active cell. |
|
|
@@ -5131,6 +5137,10 @@ Demo page: https://romanhaendler.github.io/umriss-ui/table/#/edits
|
|
|
5131
5137
|
|
|
5132
5138
|
An edit is reported, never applied: the application owns the rows. `validate` keeps the editor open with its message until the draft passes.
|
|
5133
5139
|
|
|
5140
|
+
By default each cell is reported as it is left (`onCellEdit`) - for another cell, or by a click outside the table. `editMode="row"` opens a whole row as one draft and reports it only when it is saved (`onRowSave`); a row with a draft is left only by saving or discarding it (ADR-0036).
|
|
5141
|
+
|
|
5142
|
+
`onRowAdd` puts up "New row" - in the toolbar, or beneath the table without one - and `onRowDelete` a Delete that asks inside its row. Both work in either mode.
|
|
5143
|
+
|
|
5134
5144
|
#### Examples
|
|
5135
5145
|
|
|
5136
5146
|
##### Edit a comments column
|
|
@@ -5235,11 +5245,166 @@ export default function ValidatedEdits() {
|
|
|
5235
5245
|
}
|
|
5236
5246
|
```
|
|
5237
5247
|
|
|
5248
|
+
##### Save a row on purpose
|
|
5249
|
+
|
|
5250
|
+
`editMode="row"` opens every cell of a row that edits at once. Nothing is reported until Save or Enter; `onRowSave` hands over only the columns that changed.
|
|
5251
|
+
|
|
5252
|
+
```tsx
|
|
5253
|
+
import { useState } from "react";
|
|
5254
|
+
import { Stack, Text } from "@umriss-ui/core";
|
|
5255
|
+
import { useTable } from "@umriss-ui/table";
|
|
5256
|
+
import type { RowSave } from "@umriss-ui/table";
|
|
5257
|
+
|
|
5258
|
+
interface Project {
|
|
5259
|
+
id: string;
|
|
5260
|
+
name: string;
|
|
5261
|
+
phase: string;
|
|
5262
|
+
owner: string;
|
|
5263
|
+
days: number;
|
|
5264
|
+
}
|
|
5265
|
+
|
|
5266
|
+
const PROJECTS: Project[] = [
|
|
5267
|
+
{ id: "P-1", name: "Checkout redesign", phase: "Build", owner: "Ines Duarte", days: 40 },
|
|
5268
|
+
{ id: "P-2", name: "Mobile app", phase: "Discovery", owner: "Tomasz Wrona", days: 15 },
|
|
5269
|
+
{ id: "P-3", name: "Data warehouse", phase: "Launch", owner: "Amira Haddad", days: 60 },
|
|
5270
|
+
];
|
|
5271
|
+
|
|
5272
|
+
export default function SaveARowOnPurpose() {
|
|
5273
|
+
const [projects, setProjects] = useState(PROJECTS);
|
|
5274
|
+
const [last, setLast] = useState<RowSave<Project> | null>(null);
|
|
5275
|
+
const { Table, Column } = useTable(projects, { rowKey: (p) => p.id });
|
|
5276
|
+
|
|
5277
|
+
const save = (saved: RowSave<Project>) => {
|
|
5278
|
+
setProjects((all) => all.map((p) => (p.id === saved.rowKey ? { ...p, ...saved.changes } : p)));
|
|
5279
|
+
setLast(saved);
|
|
5280
|
+
};
|
|
5281
|
+
|
|
5282
|
+
return (
|
|
5283
|
+
<Stack gap={2}>
|
|
5284
|
+
<Table grid editMode="row" ariaLabel="Projects" onRowSave={save}>
|
|
5285
|
+
<Column value="name" label="Project" rowHeader />
|
|
5286
|
+
<Column value="phase" label="Phase" edit="select" editOptions={["Discovery", "Build", "Launch"]} width={140} />
|
|
5287
|
+
<Column value="owner" label="Owner" edit="text" />
|
|
5288
|
+
<Column value="days" label="Budget (days)" edit="number" width={130} />
|
|
5289
|
+
</Table>
|
|
5290
|
+
<Text size="xs" tone="muted">
|
|
5291
|
+
{last ? `Saved ${last.row.name}: ${Object.keys(last.changes).join(", ")}` : "Nothing saved yet."}
|
|
5292
|
+
</Text>
|
|
5293
|
+
</Stack>
|
|
5294
|
+
);
|
|
5295
|
+
}
|
|
5296
|
+
```
|
|
5297
|
+
|
|
5298
|
+
##### Check a whole row before it is saved
|
|
5299
|
+
|
|
5300
|
+
On Save every open cell runs its `validate`; each message stands beneath its field, and the row stays open until all of them pass. A click into another row is refused while the draft is open.
|
|
5301
|
+
|
|
5302
|
+
```tsx
|
|
5303
|
+
import { useState } from "react";
|
|
5304
|
+
import { useTable } from "@umriss-ui/table";
|
|
5305
|
+
|
|
5306
|
+
interface Offer {
|
|
5307
|
+
id: string;
|
|
5308
|
+
product: string;
|
|
5309
|
+
unit: string;
|
|
5310
|
+
price: number | null;
|
|
5311
|
+
minimum: number | null;
|
|
5312
|
+
maximum: number | null;
|
|
5313
|
+
}
|
|
5314
|
+
|
|
5315
|
+
const OFFERS: Offer[] = [
|
|
5316
|
+
{ id: "o1", product: "Printer paper A4", unit: "box", price: 24.5, minimum: 5, maximum: 200 },
|
|
5317
|
+
{ id: "o2", product: "Toner cartridge", unit: "piece", price: 68, minimum: 1, maximum: 40 },
|
|
5318
|
+
{ id: "o3", product: "Desk lamp", unit: "piece", price: 39.9, minimum: 2, maximum: 25 },
|
|
5319
|
+
];
|
|
5320
|
+
|
|
5321
|
+
const required = (label: string) => (value: number | null) => (value === null ? `${label} is required` : undefined);
|
|
5322
|
+
|
|
5323
|
+
export default function CheckAWholeRow() {
|
|
5324
|
+
const [offers, setOffers] = useState(OFFERS);
|
|
5325
|
+
const { Table, Column } = useTable(offers, { rowKey: (o) => o.id });
|
|
5326
|
+
return (
|
|
5327
|
+
<Table
|
|
5328
|
+
grid
|
|
5329
|
+
editMode="row"
|
|
5330
|
+
ariaLabel="Price list"
|
|
5331
|
+
onRowSave={({ rowKey, changes }) => setOffers((all) => all.map((o) => (o.id === rowKey ? { ...o, ...changes } : o)))}
|
|
5332
|
+
>
|
|
5333
|
+
<Column value="product" label="Product" rowHeader />
|
|
5334
|
+
<Column value="unit" label="Unit" width={80} />
|
|
5335
|
+
<Column
|
|
5336
|
+
value="price"
|
|
5337
|
+
label="Price"
|
|
5338
|
+
edit="number"
|
|
5339
|
+
width={130}
|
|
5340
|
+
validate={(value) => (value === null ? "A price is required" : value < 0 ? "Not below 0" : undefined)}
|
|
5341
|
+
/>
|
|
5342
|
+
<Column value="minimum" label="Minimum order" edit="number" width={150} validate={required("A minimum order")} />
|
|
5343
|
+
<Column value="maximum" label="Maximum order" edit="number" width={150} validate={required("A maximum order")} />
|
|
5344
|
+
</Table>
|
|
5345
|
+
);
|
|
5346
|
+
}
|
|
5347
|
+
```
|
|
5348
|
+
|
|
5349
|
+
##### Keep a list: add, change and delete rows
|
|
5350
|
+
|
|
5351
|
+
`onRowAdd` puts up "New row" in the toolbar - an empty row draft above the rows, whatever the sort; `newRow` gives its first values. `onRowDelete` adds a Delete that asks inside its row. The application owns the rows: it inserts, changes and removes them itself.
|
|
5352
|
+
|
|
5353
|
+
```tsx
|
|
5354
|
+
import { useState } from "react";
|
|
5355
|
+
import { Search, Toolbar, useTable } from "@umriss-ui/table";
|
|
5356
|
+
|
|
5357
|
+
type Kind = "Spare part" | "Consumable" | "Tool";
|
|
5358
|
+
|
|
5359
|
+
interface Item {
|
|
5360
|
+
id: string;
|
|
5361
|
+
name: string;
|
|
5362
|
+
kind: Kind;
|
|
5363
|
+
stock: number | null;
|
|
5364
|
+
location: string;
|
|
5365
|
+
}
|
|
5366
|
+
|
|
5367
|
+
const ITEMS: Item[] = [
|
|
5368
|
+
{ id: "i1", name: "Burner nozzle 4 mm", kind: "Spare part", stock: 6, location: "Store A-3" },
|
|
5369
|
+
{ id: "i2", name: "Refractory mortar", kind: "Consumable", stock: 14, location: "Yard" },
|
|
5370
|
+
{ id: "i3", name: "Thermocouple type K", kind: "Spare part", stock: 3, location: "Store A-1" },
|
|
5371
|
+
{ id: "i4", name: "Torque wrench 40-200 Nm", kind: "Tool", stock: 2, location: "Workshop" },
|
|
5372
|
+
];
|
|
5373
|
+
|
|
5374
|
+
let next = ITEMS.length;
|
|
5375
|
+
|
|
5376
|
+
export default function KeepAList() {
|
|
5377
|
+
const [items, setItems] = useState(ITEMS);
|
|
5378
|
+
const { Table, Column } = useTable(items, { rowKey: (i) => i.id });
|
|
5379
|
+
return (
|
|
5380
|
+
<Table
|
|
5381
|
+
grid
|
|
5382
|
+
editMode="row"
|
|
5383
|
+
ariaLabel="Stores"
|
|
5384
|
+
newRow={() => ({ kind: "Spare part", stock: 0 })}
|
|
5385
|
+
onRowSave={({ rowKey, changes }) => setItems((all) => all.map((i) => (i.id === rowKey ? { ...i, ...changes } : i)))}
|
|
5386
|
+
onRowAdd={({ values }) => setItems((all) => [...all, { id: `i${++next}`, ...(values as Omit<Item, "id">) }])}
|
|
5387
|
+
onRowDelete={({ rowKey }) => setItems((all) => all.filter((i) => i.id !== rowKey))}
|
|
5388
|
+
>
|
|
5389
|
+
<Toolbar>
|
|
5390
|
+
<Search />
|
|
5391
|
+
</Toolbar>
|
|
5392
|
+
<Column value="name" label="Item" rowHeader edit="text" validate={(value) => (value ? undefined : "An item needs a name")} />
|
|
5393
|
+
<Column value="kind" label="Kind" edit="select" editOptions={["Spare part", "Consumable", "Tool"]} width={150} />
|
|
5394
|
+
<Column value="stock" label="In stock" edit="number" width={110} validate={(value) => (value === null || value < 0 ? "0 or more" : undefined)} />
|
|
5395
|
+
<Column value="location" label="Location" edit="text" width={150} />
|
|
5396
|
+
</Table>
|
|
5397
|
+
);
|
|
5398
|
+
}
|
|
5399
|
+
```
|
|
5400
|
+
|
|
5238
5401
|
#### Keyboard
|
|
5239
5402
|
|
|
5240
5403
|
| Key | Action |
|
|
5241
5404
|
|---|---|
|
|
5242
|
-
| `Tab (while editing)` | Commits the edit and moves to the next cell that edits. |
|
|
5405
|
+
| `Tab (while editing)` | Commits the edit and moves to the next cell that edits; in a row draft, walks its fields and buttons. |
|
|
5406
|
+
| `Enter (row draft)` | Saves the row. |
|
|
5407
|
+
| `Escape (row draft)` | Discards the row's changes. |
|
|
5243
5408
|
|
|
5244
5409
|
#### Known limits
|
|
5245
5410
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umriss-ui/table",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The umriss table for data-dense applications - declared the way it reads: columns as JSX, typed against their rows.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Roman Händler",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=18",
|
|
47
47
|
"react-dom": ">=18",
|
|
48
|
-
"@umriss-ui/core": "^0.
|
|
48
|
+
"@umriss-ui/core": "^0.14.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@fontsource/geist-mono": "^5.3.0",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"typescript": "^5.6.3",
|
|
60
60
|
"vite": "^6.0.0",
|
|
61
61
|
"vite-plugin-dts": "^4.3.0",
|
|
62
|
-
"@umriss-ui/
|
|
63
|
-
"@umriss-ui/
|
|
62
|
+
"@umriss-ui/core": "0.14.0",
|
|
63
|
+
"@umriss-ui/demo": "0.0.0"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"props": "node --disable-warning=ExperimentalWarning --experimental-strip-types demo/props.ts",
|