@umriss-ui/table 0.7.5 → 0.8.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/docs/llms-full.md CHANGED
@@ -1,4 +1,4 @@
1
- # @umriss-ui/table 0.7.5
1
+ # @umriss-ui/table 0.8.0
2
2
 
3
3
  > React data table for data-dense applications - sorting, filtering, grouping, aggregates, virtualisation. Declared the way it reads: columns as JSX, typed against their rows.
4
4
 
@@ -707,6 +707,10 @@ export default function FirstTable() {
707
707
  | `toggleFold` (required) | `(path: string) => void` | — | Folds a group or unfolds it. A group of one row does not fold. |
708
708
  | `foldAll` (required) | `() => void` | — | Folds every group that has more than one row. |
709
709
  | `unfoldAll` (required) | `() => void` | — | Unfolds every group. |
710
+ | `branches` (required) | `readonly string[]` | — | Tree rows: the keys of the open branches. |
711
+ | `toggleBranch` (required) | `(key: string) => void` | — | Tree rows: opens a branch or closes it. |
712
+ | `unfoldAllBranches` (required) | `() => void` | — | Tree rows: opens every branch that has children. |
713
+ | `foldAllBranches` (required) | `() => void` | — | Tree rows: closes every branch. |
710
714
  | `view` (required) | `TableView` | — | The part of the state an application can keep; whatever is at its default is absent. |
711
715
  | `asCsv` (required) | `() => string` | — | The filtered set in the visible columns as text for a spreadsheet - in manual mode the page. |
712
716
  | `virtual` (required) | `boolean` | — | Whether it virtualises. |
@@ -3115,6 +3119,466 @@ It imports `logistics.ts` from beside itself; the file stands once, under "Files
3115
3119
 
3116
3120
  What umriss deliberately does not build, and why: [ADR-0032](https://github.com/romanhaendler/umriss-ui/blob/main/docs/adr/0032-what-umriss-is-not.md).
3117
3121
 
3122
+ ### Tree rows
3123
+
3124
+ Rows that hold rows: a hierarchy of any number of levels whose every level carries the same figures (also called tree data). Reach for it to drill down an organisation, regions and places or cost centres - levels the application holds, uneven as they are.
3125
+
3126
+ ```ts
3127
+ import { useTable } from "@umriss-ui/table";
3128
+ ```
3129
+
3130
+ Demo page: https://romanhaendler.github.io/umriss-ui/table/tree-rows/
3131
+
3132
+ `childRows` names the children of a row; the rows passed in are the roots. Every row with children gets a fold in the first column, and the next level stands beneath it, indented.
3133
+
3134
+ The figures of a row are the application's: the table sums nothing for a branch. The footer sums the top level only, since a parent already holds its children.
3135
+
3136
+ Every level sorts on its own, and a child never leaves its parent. A search or a filter shows a match with the rows above it, muted, and leaves the open branches as they were.
3137
+
3138
+ The export writes every row of the filtered tree, open or not, with its level first.
3139
+
3140
+ #### Examples
3141
+
3142
+ ##### A small tree
3143
+
3144
+ Name the children of a row with `childRows`: the table shows the roots, and every row with children gets a fold in the first column that opens the next level beneath it.
3145
+
3146
+ ```tsx
3147
+ import { useTable } from "@umriss-ui/table";
3148
+
3149
+ interface Unit {
3150
+ id: string;
3151
+ name: string;
3152
+ headcount: number;
3153
+ children?: Unit[];
3154
+ }
3155
+
3156
+ const UNITS: Unit[] = [
3157
+ {
3158
+ id: "sales",
3159
+ name: "Sales",
3160
+ headcount: 42,
3161
+ children: [
3162
+ { id: "sales-north", name: "Sales North", headcount: 18 },
3163
+ { id: "sales-south", name: "Sales South", headcount: 24 },
3164
+ ],
3165
+ },
3166
+ { id: "finance", name: "Finance", headcount: 11 },
3167
+ {
3168
+ id: "operations",
3169
+ name: "Operations",
3170
+ headcount: 96,
3171
+ children: [
3172
+ { id: "site", name: "Site Ashcombe", headcount: 81 },
3173
+ { id: "logistics", name: "Logistics", headcount: 15 },
3174
+ ],
3175
+ },
3176
+ ];
3177
+
3178
+ export default function ASmallTree() {
3179
+ const { Table, Column } = useTable(UNITS, { rowKey: (u) => u.id, childRows: (u) => u.children });
3180
+ return (
3181
+ <Table ariaLabel="Organisation">
3182
+ <Column value="name" label="Unit" rowHeader />
3183
+ <Column value="headcount" label="Headcount" />
3184
+ </Table>
3185
+ );
3186
+ }
3187
+ ```
3188
+
3189
+ ##### An uneven organisation
3190
+
3191
+ Five levels in one division, one in the staff unit - each unit with figures of its own. The table opens the first level, sorts every level on its own, and the footer sums the top level only: a parent already holds its children. Search for “line” and the matches come with the rows above them, muted.
3192
+
3193
+ ```tsx
3194
+ import { Search, Toolbar, ColumnMenu, useTable } from "@umriss-ui/table";
3195
+
3196
+ interface Unit {
3197
+ id: string;
3198
+ name: string;
3199
+ budget: number;
3200
+ spent: number;
3201
+ children?: Unit[];
3202
+ }
3203
+
3204
+ const UNITS: Unit[] = [
3205
+ {
3206
+ id: "ops",
3207
+ name: "Operations",
3208
+ budget: 4_800,
3209
+ spent: 4_950,
3210
+ children: [
3211
+ {
3212
+ id: "ops-ash",
3213
+ name: "Site Ashcombe",
3214
+ budget: 3_100,
3215
+ spent: 3_320,
3216
+ children: [
3217
+ {
3218
+ id: "ops-ash-a",
3219
+ name: "Hall A",
3220
+ budget: 1_700,
3221
+ spent: 1_910,
3222
+ children: [
3223
+ {
3224
+ id: "ops-ash-a-1",
3225
+ name: "Line 1",
3226
+ budget: 900,
3227
+ spent: 1_080,
3228
+ children: [
3229
+ { id: "ops-ash-a-1-press", name: "Press cell", budget: 520, spent: 690 },
3230
+ { id: "ops-ash-a-1-weld", name: "Welding cell", budget: 380, spent: 390 },
3231
+ ],
3232
+ },
3233
+ { id: "ops-ash-a-2", name: "Line 2", budget: 800, spent: 830 },
3234
+ ],
3235
+ },
3236
+ { id: "ops-ash-b", name: "Hall B", budget: 1_400, spent: 1_410 },
3237
+ ],
3238
+ },
3239
+ { id: "ops-log", name: "Logistics", budget: 1_700, spent: 1_630 },
3240
+ ],
3241
+ },
3242
+ {
3243
+ id: "sales",
3244
+ name: "Sales",
3245
+ budget: 2_200,
3246
+ spent: 2_050,
3247
+ children: [
3248
+ { id: "sales-n", name: "Region North", budget: 1_200, spent: 1_150 },
3249
+ { id: "sales-s", name: "Region South", budget: 1_000, spent: 900 },
3250
+ ],
3251
+ },
3252
+ { id: "staff", name: "Staff unit", budget: 600, spent: 610 },
3253
+ ];
3254
+
3255
+ export default function AnUnevenOrganisation() {
3256
+ const { Table, Column } = useTable(UNITS, { rowKey: (u) => u.id, childRows: (u) => u.children, defaultBranches: 1 });
3257
+ return (
3258
+ <Table ariaLabel="Budget by unit">
3259
+ <Toolbar>
3260
+ <Search />
3261
+ <ColumnMenu />
3262
+ </Toolbar>
3263
+ <Column value="name" label="Unit" rowHeader searchable />
3264
+ <Column value="budget" label="Budget (k€)" aggregate="sum" />
3265
+ <Column value="spent" label="Spent (k€)" aggregate="sum" />
3266
+ <Column value={(u) => u.spent - u.budget} id="delta" label="Δ (k€)" />
3267
+ </Table>
3268
+ );
3269
+ }
3270
+ ```
3271
+
3272
+ ##### Regions and places
3273
+
3274
+ One country has states, another goes straight to its cities: the tree stands as deep as each branch is. A column only places carry stays empty on a country - one column set for every level, absent where a level has no value.
3275
+
3276
+ ```tsx
3277
+ import { useTable } from "@umriss-ui/table";
3278
+
3279
+ interface Place {
3280
+ id: string;
3281
+ name: string;
3282
+ sites: number;
3283
+ /** Only places have a postcode. */
3284
+ postcode?: string;
3285
+ children?: Place[];
3286
+ }
3287
+
3288
+ const PLACES: Place[] = [
3289
+ {
3290
+ id: "de",
3291
+ name: "Germany",
3292
+ sites: 5,
3293
+ children: [
3294
+ {
3295
+ id: "de-by",
3296
+ name: "Bavaria",
3297
+ sites: 3,
3298
+ children: [
3299
+ { id: "de-by-muc", name: "Munich", sites: 2, postcode: "80331" },
3300
+ { id: "de-by-nue", name: "Nuremberg", sites: 1, postcode: "90402" },
3301
+ ],
3302
+ },
3303
+ { id: "de-hh", name: "Hamburg", sites: 2, postcode: "20095" },
3304
+ ],
3305
+ },
3306
+ {
3307
+ id: "nl",
3308
+ name: "Netherlands",
3309
+ sites: 2,
3310
+ children: [
3311
+ { id: "nl-ams", name: "Amsterdam", sites: 1, postcode: "1012" },
3312
+ { id: "nl-rtm", name: "Rotterdam", sites: 1, postcode: "3011" },
3313
+ ],
3314
+ },
3315
+ { id: "lu", name: "Luxembourg", sites: 1, postcode: "1009" },
3316
+ ];
3317
+
3318
+ export default function RegionsAndPlaces() {
3319
+ const { Table, Column } = useTable(PLACES, { rowKey: (p) => p.id, childRows: (p) => p.children, defaultBranches: 2 });
3320
+ return (
3321
+ <Table ariaLabel="Sites by region">
3322
+ <Column value="name" label="Region" rowHeader />
3323
+ <Column value="sites" label="Sites" />
3324
+ <Column value="postcode" label="Postcode" />
3325
+ </Table>
3326
+ );
3327
+ }
3328
+ ```
3329
+
3330
+ ##### Employees in the detail
3331
+
3332
+ When the bottom of the hierarchy is records of another kind, the tree carries the summarising columns and a team's `RowDetail` holds its employees - a table of their own, with every field they have and their own sort. In a tree the team's fold opens them: they hang from it a level deeper, on the table's surface, without a box.
3333
+
3334
+ ```tsx
3335
+ import { useTable } from "@umriss-ui/table";
3336
+
3337
+ interface Employee {
3338
+ id: string;
3339
+ name: string;
3340
+ role: string;
3341
+ since: string;
3342
+ hours: number;
3343
+ }
3344
+
3345
+ interface Team {
3346
+ id: string;
3347
+ name: string;
3348
+ headcount: number;
3349
+ hours: number;
3350
+ employees?: Employee[];
3351
+ children?: Team[];
3352
+ }
3353
+
3354
+ const TEAMS: Team[] = [
3355
+ {
3356
+ id: "it",
3357
+ name: "IT",
3358
+ headcount: 5,
3359
+ hours: 196,
3360
+ children: [
3361
+ {
3362
+ id: "it-ops",
3363
+ name: "IT Operations",
3364
+ headcount: 3,
3365
+ hours: 118,
3366
+ employees: [
3367
+ { id: "e1", name: "Ada Brenner", role: "Lead", since: "2016", hours: 40 },
3368
+ { id: "e2", name: "Jonas Kessler", role: "Administrator", since: "2021", hours: 40 },
3369
+ { id: "e3", name: "Mira Otto", role: "Administrator", since: "2024", hours: 38 },
3370
+ ],
3371
+ },
3372
+ {
3373
+ id: "it-dev",
3374
+ name: "Development",
3375
+ headcount: 2,
3376
+ hours: 78,
3377
+ employees: [
3378
+ { id: "e4", name: "Lena Vogt", role: "Developer", since: "2019", hours: 40 },
3379
+ { id: "e5", name: "Tom Weiss", role: "Developer", since: "2023", hours: 38 },
3380
+ ],
3381
+ },
3382
+ ],
3383
+ },
3384
+ ];
3385
+
3386
+ function Employees({ team }: { team: Team }) {
3387
+ const { Table, Column } = useTable(team.employees ?? [], { rowKey: (e) => e.id, defaultSort: { column: "name", direction: "asc" } });
3388
+ return (
3389
+ <Table ariaLabel={`Employees of ${team.name}`} density="compact">
3390
+ <Column value="name" label="Employee" rowHeader />
3391
+ <Column value="role" label="Role" />
3392
+ <Column value="since" label="Since" />
3393
+ <Column value="hours" label="Hours" />
3394
+ </Table>
3395
+ );
3396
+ }
3397
+
3398
+ export default function EmployeesInTheDetail() {
3399
+ const { Table, Column, RowDetail } = useTable(TEAMS, { rowKey: (t) => t.id, childRows: (t) => t.children, defaultBranches: 1 });
3400
+ return (
3401
+ <Table ariaLabel="Teams">
3402
+ <Column value="name" label="Team" rowHeader />
3403
+ <Column value="headcount" label="Headcount" />
3404
+ <Column value="hours" label="Hours a week" />
3405
+ <RowDetail>{(team) => (team.employees ? <Employees team={team} /> : null)}</RowDetail>
3406
+ </Table>
3407
+ );
3408
+ }
3409
+ ```
3410
+
3411
+ ##### Own staff and teams
3412
+
3413
+ A unit can have people of its own and teams beneath it. Its fold opens both: first its own staff on the rail, then its teams a level deeper - one chevron for everything that stands under the row. A unit without staff of its own opens only its teams; a team without teams only its staff.
3414
+
3415
+ ```tsx
3416
+ import { useTable } from "@umriss-ui/table";
3417
+
3418
+ interface Employee {
3419
+ id: string;
3420
+ name: string;
3421
+ role: string;
3422
+ hours: number;
3423
+ }
3424
+
3425
+ interface Unit {
3426
+ id: string;
3427
+ name: string;
3428
+ headcount: number;
3429
+ hours: number;
3430
+ /** The people the unit has itself - not those of its teams. */
3431
+ staff?: Employee[];
3432
+ children?: Unit[];
3433
+ }
3434
+
3435
+ const UNITS: Unit[] = [
3436
+ {
3437
+ id: "it",
3438
+ name: "IT",
3439
+ headcount: 6,
3440
+ hours: 236,
3441
+ staff: [{ id: "e0", name: "Nora Albers", role: "Head of IT", hours: 40 }],
3442
+ children: [
3443
+ {
3444
+ id: "it-ops",
3445
+ name: "IT Operations",
3446
+ headcount: 3,
3447
+ hours: 118,
3448
+ staff: [
3449
+ { id: "e1", name: "Ada Brenner", role: "Lead", hours: 40 },
3450
+ { id: "e2", name: "Jonas Kessler", role: "Administrator", hours: 40 },
3451
+ { id: "e3", name: "Mira Otto", role: "Administrator", hours: 38 },
3452
+ ],
3453
+ },
3454
+ {
3455
+ id: "it-dev",
3456
+ name: "Development",
3457
+ headcount: 2,
3458
+ hours: 78,
3459
+ staff: [
3460
+ { id: "e4", name: "Lena Vogt", role: "Developer", hours: 40 },
3461
+ { id: "e5", name: "Tom Weiss", role: "Developer", hours: 38 },
3462
+ ],
3463
+ },
3464
+ ],
3465
+ },
3466
+ {
3467
+ id: "fin",
3468
+ name: "Finance",
3469
+ headcount: 2,
3470
+ hours: 72,
3471
+ children: [
3472
+ {
3473
+ id: "fin-ctl",
3474
+ name: "Controlling",
3475
+ headcount: 2,
3476
+ hours: 72,
3477
+ staff: [
3478
+ { id: "e6", name: "Paula Hartmann", role: "Controller", hours: 40 },
3479
+ { id: "e7", name: "Ben Lindner", role: "Analyst", hours: 32 },
3480
+ ],
3481
+ },
3482
+ ],
3483
+ },
3484
+ ];
3485
+
3486
+ function Staff({ unit }: { unit: Unit }) {
3487
+ const { Table, Column } = useTable(unit.staff ?? [], { rowKey: (e) => e.id });
3488
+ return (
3489
+ <Table ariaLabel={`Staff of ${unit.name}`} density="compact">
3490
+ <Column value="name" label="Employee" rowHeader />
3491
+ <Column value="role" label="Role" />
3492
+ <Column value="hours" label="Hours" />
3493
+ </Table>
3494
+ );
3495
+ }
3496
+
3497
+ export default function OwnStaffAndTeams() {
3498
+ const { Table, Column, RowDetail } = useTable(UNITS, { rowKey: (u) => u.id, childRows: (u) => u.children, defaultBranches: ["it"] });
3499
+ return (
3500
+ <Table ariaLabel="Units with their staff">
3501
+ <Column value="name" label="Unit" rowHeader />
3502
+ <Column value="headcount" label="Headcount" />
3503
+ <Column value="hours" label="Hours a week" />
3504
+ <RowDetail>{(unit) => (unit.staff ? <Staff unit={unit} /> : null)}</RowDetail>
3505
+ </Table>
3506
+ );
3507
+ }
3508
+ ```
3509
+
3510
+ ##### From a flat list
3511
+
3512
+ Data from a database often comes flat, each record with its parent's id. A few lines nest it; the table takes the nested rows.
3513
+
3514
+ ```tsx
3515
+ import { useMemo } from "react";
3516
+ import { useTable } from "@umriss-ui/table";
3517
+
3518
+ interface CostCentre {
3519
+ id: string;
3520
+ parent: string | null;
3521
+ name: string;
3522
+ amount: number;
3523
+ }
3524
+
3525
+ const FLAT: CostCentre[] = [
3526
+ { id: "1000", parent: null, name: "Administration", amount: 820 },
3527
+ { id: "1100", parent: "1000", name: "Accounting", amount: 310 },
3528
+ { id: "1110", parent: "1100", name: "Payroll", amount: 120 },
3529
+ { id: "1200", parent: "1000", name: "Legal", amount: 190 },
3530
+ { id: "2000", parent: null, name: "Production", amount: 4_300 },
3531
+ { id: "2100", parent: "2000", name: "Assembly", amount: 2_600 },
3532
+ ];
3533
+
3534
+ type Nested = CostCentre & { children?: Nested[] };
3535
+
3536
+ /** Nests a flat list by its parent ids - the roots are those without one. */
3537
+ function nest(flat: readonly CostCentre[]): Nested[] {
3538
+ const byId = new Map<string, Nested>(flat.map((c) => [c.id, { ...c }]));
3539
+ const roots: Nested[] = [];
3540
+ for (const c of byId.values()) {
3541
+ const parent = c.parent === null ? undefined : byId.get(c.parent);
3542
+ if (parent) (parent.children ??= []).push(c);
3543
+ else roots.push(c);
3544
+ }
3545
+ return roots;
3546
+ }
3547
+
3548
+ export default function FromAFlatList() {
3549
+ const rows = useMemo(() => nest(FLAT), []);
3550
+ const { Table, Column } = useTable(rows, { rowKey: (c) => c.id, childRows: (c) => c.children, defaultBranches: 1 });
3551
+ return (
3552
+ <Table ariaLabel="Cost centres">
3553
+ <Column value="name" label="Name" rowHeader />
3554
+ <Column value="id" label="Cost centre" />
3555
+ <Column value="amount" label="Amount (k€)" />
3556
+ </Table>
3557
+ );
3558
+ }
3559
+ ```
3560
+
3561
+ #### When to use something else
3562
+
3563
+ - Rows that share a value - a customer, a month → Grouping
3564
+ - A hierarchy without figures → `TreeView` from @umriss-ui/core
3565
+ - Records of another kind beneath the bottom level → RowDetail
3566
+
3567
+ #### Keyboard
3568
+
3569
+ | Key | Action |
3570
+ |---|---|
3571
+ | `→ / ←` | On a fold: opens or closes its branch; ← on a closed one goes to the parent's fold. |
3572
+ | `Alt + → / Alt + ←` | On a fold: opens or closes the branch and all its siblings. |
3573
+
3574
+ #### Known limits
3575
+
3576
+ - Not with grouping or pagination: both would build or cut levels a second way. A large tree uses virtualisation.
3577
+ - Not in [manual mode](#/manual-mode), and no branches loaded on demand yet.
3578
+ - One column set for every level; a level without a value shows it as absent.
3579
+
3580
+ What umriss deliberately does not build, and why: [ADR-0032](https://github.com/romanhaendler/umriss-ui/blob/main/docs/adr/0032-what-umriss-is-not.md).
3581
+
3118
3582
  ### Aggregate
3119
3583
 
3120
3584
  What a column's values come to: a sum, an average, the extremes, a count. It stands in the footer over the filtered rows and in each group header over the group's rows.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umriss-ui/table",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
4
4
  "description": "React data table for data-dense applications - sorting, filtering, grouping, aggregates, virtualisation. Declared the way it reads: columns as JSX, typed against their rows.",
5
5
  "license": "MIT",
6
6
  "author": "Roman Händler",
@@ -51,7 +51,7 @@
51
51
  "peerDependencies": {
52
52
  "react": ">=18",
53
53
  "react-dom": ">=18",
54
- "@umriss-ui/core": "^0.18.0"
54
+ "@umriss-ui/core": "^0.19.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@fontsource/geist-mono": "^5.3.0",
@@ -66,7 +66,7 @@
66
66
  "vite": "^6.0.0",
67
67
  "vite-plugin-dts": "^4.3.0",
68
68
  "@umriss-ui/demo": "0.0.0",
69
- "@umriss-ui/core": "0.18.0"
69
+ "@umriss-ui/core": "0.19.0"
70
70
  },
71
71
  "scripts": {
72
72
  "props": "node --disable-warning=ExperimentalWarning --experimental-strip-types demo/props.ts",