@umriss-ui/table 0.7.5 → 0.9.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 +91 -0
- package/README.md +13 -3
- package/dist/index.d.ts +103 -13
- package/dist/table.css +1 -1
- package/dist/table.js +2378 -2068
- package/docs/llms-full.md +957 -4
- package/package.json +3 -3
package/docs/llms-full.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @umriss-ui/table 0.
|
|
1
|
+
# @umriss-ui/table 0.9.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
|
|
|
@@ -668,6 +668,7 @@ export default function FirstTable() {
|
|
|
668
668
|
| `defaultGrouping` | `GroupingId<Z> \| readonly GroupingId<Z>[]` | — | The application's grouping: a column or group key, or up to three, the outermost first. It is the default that `view` leaves out; without it the table is ungrouped until the user groups it. |
|
|
669
669
|
| `preFilter` | `(row: Z) => boolean` | — | Which rows the table has at all – by permission, by tenant, by anything the user is not meant to undo. It is invisible: never a condition, never reset, never part of the view, and "43 of 1,204" counts only the rows it admits. It may stand in the call; a change leaves the page standing, and the model clamps it. |
|
|
670
670
|
| `filter` | `(row: Z) => boolean` | — | The old name of `preFilter` – the same filter, the same meaning. |
|
|
671
|
+
| `rowFilters` | `readonly RowFilter<Z, any>[]` | — | The row filters the table has: conditions the application defines over the whole row and sets with `t.setFilter(filter, condition)` from a control of its own. Named here so that a condition from `initialView`, which arrives by id, is known in the first render. |
|
|
671
672
|
| `initialView` | `TableView` | — | The view on the first render. The table remembers none: where a view is kept is the application's decision. Names no column carries fall out. |
|
|
672
673
|
| `virtual` | `{ rowHeight: number; overscan?: number }` | — | Renders only what stands in the scroll area; paging is then off. |
|
|
673
674
|
| `selection` | `TableSelection<string>` | — | A selection from outside instead of its own – when the application holds it. |
|
|
@@ -698,8 +699,9 @@ export default function FirstTable() {
|
|
|
698
699
|
| `setWidth` (required) | `(column: string, width: number \| undefined) => void` | — | Sets the width of a column; `undefined` takes it back. |
|
|
699
700
|
| `expanded` (required) | `readonly string[]` | — | The keys of the expanded rows. |
|
|
700
701
|
| `toggleRow` (required) | `(key: string) => void` | — | Expands a row or collapses it. |
|
|
701
|
-
| `filter` (required) | `Readonly<Record<string, unknown>>` | — | The conditions of the column filters
|
|
702
|
-
| `setFilter` (required) | `SetFilter<Z>` | — | Sets the condition of a column filter; `null` clears it. Back to page one. A condition that does not fit the kind of the filter – a range on a list filter, a column without a filter – is passed over with a warning in development. |
|
|
702
|
+
| `filter` (required) | `Readonly<Record<string, unknown>>` | — | The conditions of the column filters and row filters by id, in the order in which they were set. Whatever fits no column and no row filter is absent. |
|
|
703
|
+
| `setFilter` (required) | `SetFilter<Z>` | — | Sets the condition of a column filter or a row filter; `null` clears it. Back to page one. A condition that does not fit the kind of the filter – a range on a list filter, a column without a filter, a row filter not in `rowFilters` – is passed over with a warning in development. |
|
|
704
|
+
| `conditionOf` (required) | `<B>(filter: RowFilter<Z, B>) => B \| null` | — | The condition of a row filter, as its type - `null` while it is lifted. |
|
|
703
705
|
| `selection` (required) | `TableSelection<string>` | — | The selection – its own or the one handed in through `selection`. |
|
|
704
706
|
| `grouping` (required) | `readonly string[]` | — | The ids the table is grouped by, the outermost first – only those a groupable column or a group key carries, at most three. |
|
|
705
707
|
| `setGrouping` (required) | `(grouping: readonly string[]) => void` | — | Groups by these columns or group keys; `[]` ungroups. Back to page one. |
|
|
@@ -707,6 +709,10 @@ export default function FirstTable() {
|
|
|
707
709
|
| `toggleFold` (required) | `(path: string) => void` | — | Folds a group or unfolds it. A group of one row does not fold. |
|
|
708
710
|
| `foldAll` (required) | `() => void` | — | Folds every group that has more than one row. |
|
|
709
711
|
| `unfoldAll` (required) | `() => void` | — | Unfolds every group. |
|
|
712
|
+
| `branches` (required) | `readonly string[]` | — | Tree rows: the keys of the open branches. |
|
|
713
|
+
| `toggleBranch` (required) | `(key: string) => void` | — | Tree rows: opens a branch or closes it. |
|
|
714
|
+
| `unfoldAllBranches` (required) | `() => void` | — | Tree rows: opens every branch that has children. |
|
|
715
|
+
| `foldAllBranches` (required) | `() => void` | — | Tree rows: closes every branch. |
|
|
710
716
|
| `view` (required) | `TableView` | — | The part of the state an application can keep; whatever is at its default is absent. |
|
|
711
717
|
| `asCsv` (required) | `() => string` | — | The filtered set in the visible columns as text for a spreadsheet - in manual mode the page. |
|
|
712
718
|
| `virtual` (required) | `boolean` | — | Whether it virtualises. |
|
|
@@ -1774,6 +1780,7 @@ export default function SearchFromACardHeader() {
|
|
|
1774
1780
|
| `placeholder` | `string` | — | The placeholder in the field; without it "Search …" from the wording. |
|
|
1775
1781
|
| `aria-label` | `string` | — | Accessible name; without it "Search table" from the wording. |
|
|
1776
1782
|
| `className` | `string` | — | Classes on the field. |
|
|
1783
|
+
| `size` | `ToolbarSize` | — | `sm` or `md`; without it the size of the toolbar it stands in, `sm` outside one. |
|
|
1777
1784
|
| `of` | `TableRef` | — | The table, when the part does not stand inside it: the return value of `useTable`. |
|
|
1778
1785
|
|
|
1779
1786
|
#### Known limits
|
|
@@ -1787,7 +1794,7 @@ What umriss deliberately does not build, and why: [ADR-0032](https://github.com/
|
|
|
1787
1794
|
Narrow a column to some of its values: those that occur, a range between two bounds, or a condition the application defines. Reach for it when people look for records by a field rather than by free text.
|
|
1788
1795
|
|
|
1789
1796
|
```ts
|
|
1790
|
-
import { columnFilter } from "@umriss-ui/table";
|
|
1797
|
+
import { columnFilter, rowFilter } from "@umriss-ui/table";
|
|
1791
1798
|
```
|
|
1792
1799
|
|
|
1793
1800
|
Demo page: https://romanhaendler.github.io/umriss-ui/table/filter/
|
|
@@ -1997,6 +2004,14 @@ const SHIPMENTS: Shipment[] = [
|
|
|
1997
2004
|
|
|
1998
2005
|
const QUICK_FILTERS: readonly Status[] = ["out for delivery", "failed attempt"];
|
|
1999
2006
|
|
|
2007
|
+
/* The table holds the condition; the buttons only ask it to change. That is
|
|
2008
|
+
why the column's funnel, the chip in the toolbar, "Reset" and `t.view` all
|
|
2009
|
+
agree with them without a line of synchronisation. `setFilter` takes the
|
|
2010
|
+
condition of the column's filter - for `filter="list"` the chosen values -
|
|
2011
|
+
and passes over a column that has none, with a warning in development.
|
|
2012
|
+
Something the user may lift belongs here; `preFilter` is for rows the user
|
|
2013
|
+
may not see at all. A restriction by no column, or by several fields at
|
|
2014
|
+
once, is a row filter (the examples below). */
|
|
2000
2015
|
export default function ConditionsFromOutside() {
|
|
2001
2016
|
const t = useTable(SHIPMENTS, { rowKey: (s) => s.id });
|
|
2002
2017
|
const { Table, Column } = t;
|
|
@@ -2038,6 +2053,209 @@ export default function ConditionsFromOutside() {
|
|
|
2038
2053
|
}
|
|
2039
2054
|
```
|
|
2040
2055
|
|
|
2056
|
+
##### Filter by a field no column shows
|
|
2057
|
+
|
|
2058
|
+
A row filter asks the whole row; a control of one's own sets it with `t.setFilter` and reads it with `t.conditionOf`. The table holds the choice, counts it and resets it - no column needed.
|
|
2059
|
+
|
|
2060
|
+
```tsx
|
|
2061
|
+
import { MultiSelect } from "@umriss-ui/core";
|
|
2062
|
+
import { SHIPMENTS } from "./logistics";
|
|
2063
|
+
import type { Shipment } from "./logistics";
|
|
2064
|
+
import { Pagination, Search, Toolbar, rowFilter, useTable } from "@umriss-ui/table";
|
|
2065
|
+
|
|
2066
|
+
/* Defined once, outside the component. The object is the key from here on:
|
|
2067
|
+
the id is only its name in the view. */
|
|
2068
|
+
const tours = rowFilter({
|
|
2069
|
+
id: "tours",
|
|
2070
|
+
label: "Tours",
|
|
2071
|
+
matches: (shipment: Shipment, chosen: readonly string[]) => chosen.includes(shipment.tour),
|
|
2072
|
+
});
|
|
2073
|
+
|
|
2074
|
+
const TOURS = [...new Set(SHIPMENTS.map((s) => s.tour))].map((tour) => ({ value: tour, label: tour }));
|
|
2075
|
+
|
|
2076
|
+
export default function FieldNoColumnShows() {
|
|
2077
|
+
const t = useTable(SHIPMENTS, { rowKey: (s) => s.id, rowFilters: [tours] });
|
|
2078
|
+
const { Table, Column } = t;
|
|
2079
|
+
|
|
2080
|
+
return (
|
|
2081
|
+
<Table ariaLabel="Shipments by tour">
|
|
2082
|
+
<Toolbar>
|
|
2083
|
+
<Search placeholder="Shipment or customer" />
|
|
2084
|
+
<MultiSelect
|
|
2085
|
+
aria-label="Tours"
|
|
2086
|
+
placeholder="All tours"
|
|
2087
|
+
options={TOURS}
|
|
2088
|
+
size="sm"
|
|
2089
|
+
style={{ width: 240 }}
|
|
2090
|
+
/* Typed as the filter's condition - no cast. */
|
|
2091
|
+
value={t.conditionOf(tours) ?? []}
|
|
2092
|
+
/* The whole new choice, every time; an empty one lifts the condition. */
|
|
2093
|
+
onChange={(next) => t.setFilter(tours, next.length > 0 ? next : null)}
|
|
2094
|
+
/>
|
|
2095
|
+
</Toolbar>
|
|
2096
|
+
<Column value="id" label="Shipment" rowHeader />
|
|
2097
|
+
<Column value="customer" label="Customer" />
|
|
2098
|
+
<Column value="weight" label="Weight (kg)" />
|
|
2099
|
+
<Pagination />
|
|
2100
|
+
</Table>
|
|
2101
|
+
);
|
|
2102
|
+
}
|
|
2103
|
+
```
|
|
2104
|
+
|
|
2105
|
+
It imports `logistics.ts` from beside itself; the file stands once, under "Files the examples show" at the end.
|
|
2106
|
+
|
|
2107
|
+
##### Rows from a request
|
|
2108
|
+
|
|
2109
|
+
Hand the table the rows a query answers, as they come - with a fallback that is the same array on every render and `loading` while nothing has arrived. The filters stay the table's.
|
|
2110
|
+
|
|
2111
|
+
```tsx
|
|
2112
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2113
|
+
import { Button, MultiSelect } from "@umriss-ui/core";
|
|
2114
|
+
import { SHIPMENTS } from "./logistics";
|
|
2115
|
+
import type { Shipment } from "./logistics";
|
|
2116
|
+
import { Pagination, Toolbar, rowFilter, useTable } from "@umriss-ui/table";
|
|
2117
|
+
|
|
2118
|
+
/* Stands in for any query hook: `data` stays the same array until an answer
|
|
2119
|
+
brings new rows, `isPending` holds until the first one. The first answer
|
|
2120
|
+
comes at once, so that the example stands still; "Reload" takes 800 ms. */
|
|
2121
|
+
function useShipmentsQuery() {
|
|
2122
|
+
const [data, setData] = useState<readonly Shipment[] | undefined>(undefined);
|
|
2123
|
+
const [fetching, setFetching] = useState(0);
|
|
2124
|
+
useEffect(() => {
|
|
2125
|
+
const timer = setTimeout(() => setData([...SHIPMENTS]), fetching === 0 ? 0 : 800);
|
|
2126
|
+
return () => clearTimeout(timer);
|
|
2127
|
+
}, [fetching]);
|
|
2128
|
+
const refetch = useCallback(() => {
|
|
2129
|
+
setData(undefined);
|
|
2130
|
+
setFetching((n) => n + 1);
|
|
2131
|
+
}, []);
|
|
2132
|
+
return { data, isPending: data === undefined, refetch };
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
type Status = Shipment["status"];
|
|
2136
|
+
|
|
2137
|
+
const STATUSES: { value: Status; label: string }[] = [
|
|
2138
|
+
{ value: "out for delivery", label: "Out for delivery" },
|
|
2139
|
+
{ value: "failed attempt", label: "Failed attempt" },
|
|
2140
|
+
{ value: "delivered", label: "Delivered" },
|
|
2141
|
+
];
|
|
2142
|
+
|
|
2143
|
+
const statuses = rowFilter({
|
|
2144
|
+
id: "statuses",
|
|
2145
|
+
label: "Status",
|
|
2146
|
+
matches: (shipment: Shipment, chosen: readonly Status[]) => chosen.includes(shipment.status),
|
|
2147
|
+
});
|
|
2148
|
+
|
|
2149
|
+
/* Outside the component: `data ?? []` would be a new array on every render,
|
|
2150
|
+
and the table would calculate everything anew each time while it waits. */
|
|
2151
|
+
const NO_SHIPMENTS: readonly Shipment[] = [];
|
|
2152
|
+
|
|
2153
|
+
export default function RowsFromARequest() {
|
|
2154
|
+
const { data, isPending, refetch } = useShipmentsQuery();
|
|
2155
|
+
|
|
2156
|
+
/* The answer goes in as it is - not copied into a state of one's own, which
|
|
2157
|
+
would lag a render behind and could go stale. Rows derived from it (mapped,
|
|
2158
|
+
joined) belong in a `useMemo` over `data`. The condition survives a reload:
|
|
2159
|
+
the table holds it, not the rows. */
|
|
2160
|
+
const t = useTable(data ?? NO_SHIPMENTS, { rowKey: (s) => s.id, rowFilters: [statuses] });
|
|
2161
|
+
const { Table, Column } = t;
|
|
2162
|
+
|
|
2163
|
+
return (
|
|
2164
|
+
<Table ariaLabel="Shipments from a request" loading={isPending}>
|
|
2165
|
+
<Toolbar>
|
|
2166
|
+
<MultiSelect<Status>
|
|
2167
|
+
aria-label="Status"
|
|
2168
|
+
placeholder="Every status"
|
|
2169
|
+
options={STATUSES}
|
|
2170
|
+
size="sm"
|
|
2171
|
+
style={{ width: 240 }}
|
|
2172
|
+
value={t.conditionOf(statuses) ?? []}
|
|
2173
|
+
onChange={(next) => t.setFilter(statuses, next.length > 0 ? next : null)}
|
|
2174
|
+
/>
|
|
2175
|
+
<Button size="sm" variant="ghost" onClick={refetch}>
|
|
2176
|
+
Reload
|
|
2177
|
+
</Button>
|
|
2178
|
+
</Toolbar>
|
|
2179
|
+
<Column value="id" label="Shipment" rowHeader />
|
|
2180
|
+
<Column value="customer" label="Customer" />
|
|
2181
|
+
<Column value="status" label="Status" />
|
|
2182
|
+
<Pagination />
|
|
2183
|
+
</Table>
|
|
2184
|
+
);
|
|
2185
|
+
}
|
|
2186
|
+
```
|
|
2187
|
+
|
|
2188
|
+
It imports `logistics.ts` from beside itself; the file stands once, under "Files the examples show" at the end.
|
|
2189
|
+
|
|
2190
|
+
##### Ask a question over several fields
|
|
2191
|
+
|
|
2192
|
+
"Overdue" is a window that has closed on a shipment not yet delivered - two fields and a moment. The condition carries what varies; `describe` puts it in the toolbar, where its cross lifts it.
|
|
2193
|
+
|
|
2194
|
+
```tsx
|
|
2195
|
+
import { Checkbox, Stack, Switch } from "@umriss-ui/core";
|
|
2196
|
+
import { NOW, SHIPMENTS } from "./logistics";
|
|
2197
|
+
import type { Shipment } from "./logistics";
|
|
2198
|
+
import { Pagination, Toolbar, rowFilter, useTable } from "@umriss-ui/table";
|
|
2199
|
+
|
|
2200
|
+
interface Overdue {
|
|
2201
|
+
/** The moment the windows are read against. */
|
|
2202
|
+
at: number;
|
|
2203
|
+
/** Count a failed attempt as overdue too. */
|
|
2204
|
+
failed: boolean;
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
/* What varies - the moment, the choice about failed attempts - stands in the
|
|
2208
|
+
condition, never in a closure over the component's state: the table sees a
|
|
2209
|
+
new condition, it cannot see a closure change. */
|
|
2210
|
+
const overdue = rowFilter({
|
|
2211
|
+
id: "overdue",
|
|
2212
|
+
label: "Overdue",
|
|
2213
|
+
matches: (shipment: Shipment, o: Overdue) =>
|
|
2214
|
+
shipment.window[1] < o.at &&
|
|
2215
|
+
(shipment.status === "out for delivery" || (o.failed && shipment.status === "failed attempt")),
|
|
2216
|
+
describe: (o) => (o.failed ? "with failed attempts" : "not delivered"),
|
|
2217
|
+
});
|
|
2218
|
+
|
|
2219
|
+
export default function QuestionOverSeveralFields() {
|
|
2220
|
+
const t = useTable(SHIPMENTS, {
|
|
2221
|
+
rowKey: (s) => s.id,
|
|
2222
|
+
rowFilters: [overdue],
|
|
2223
|
+
pageSize: 5,
|
|
2224
|
+
/* A view can start with it set, like any condition. */
|
|
2225
|
+
initialView: { conditions: { overdue: { at: NOW, failed: false } } },
|
|
2226
|
+
});
|
|
2227
|
+
const { Table, Column } = t;
|
|
2228
|
+
const condition = t.conditionOf(overdue);
|
|
2229
|
+
|
|
2230
|
+
/* The demo reads its windows at a fixed "now"; an application takes Date.now(). */
|
|
2231
|
+
const set = (on: boolean, failed: boolean) => t.setFilter(overdue, on ? { at: NOW, failed } : null);
|
|
2232
|
+
|
|
2233
|
+
return (
|
|
2234
|
+
<Stack gap={3}>
|
|
2235
|
+
<Stack direction="row" gap={4} wrap>
|
|
2236
|
+
<Switch label="Overdue only" checked={condition !== null} onChange={(e) => set(e.target.checked, condition?.failed ?? false)} />
|
|
2237
|
+
<Checkbox
|
|
2238
|
+
label="Count failed attempts"
|
|
2239
|
+
disabled={condition === null}
|
|
2240
|
+
checked={condition?.failed ?? false}
|
|
2241
|
+
onChange={(e) => set(true, e.target.checked)}
|
|
2242
|
+
/>
|
|
2243
|
+
</Stack>
|
|
2244
|
+
|
|
2245
|
+
<Table ariaLabel="Shipments and their windows">
|
|
2246
|
+
<Toolbar />
|
|
2247
|
+
<Column value="id" label="Shipment" rowHeader />
|
|
2248
|
+
<Column value="customer" label="Customer" />
|
|
2249
|
+
<Column value="status" label="Status" filter="list" />
|
|
2250
|
+
<Pagination />
|
|
2251
|
+
</Table>
|
|
2252
|
+
</Stack>
|
|
2253
|
+
);
|
|
2254
|
+
}
|
|
2255
|
+
```
|
|
2256
|
+
|
|
2257
|
+
It imports `logistics.ts` from beside itself; the file stands once, under "Files the examples show" at the end.
|
|
2258
|
+
|
|
2041
2259
|
#### When to use something else
|
|
2042
2260
|
|
|
2043
2261
|
- Free text across the columns → Search
|
|
@@ -2062,6 +2280,15 @@ export default function ConditionsFromOutside() {
|
|
|
2062
2280
|
| `values` (required) | `readonly Present<W>[]` | — | The values that occur in the rows the pre-filter admits – each one once, ordered, without the absent one. |
|
|
2063
2281
|
| `column` (required) | `{ id: string; label: string }` | — | The column whose filter this is. |
|
|
2064
2282
|
|
|
2283
|
+
##### `RowFilter<Z, B>`
|
|
2284
|
+
|
|
2285
|
+
| Prop | Type | Default | Description |
|
|
2286
|
+
|---|---|---|---|
|
|
2287
|
+
| `id` (required) | `string` | — | Its name in `t.view.conditions` and in what manual mode reports - the one place the filter is spelled. Not the id of a column of the same table. |
|
|
2288
|
+
| `label` (required) | `string` | — | What it is called: before the text of its chip, and in the chip's accessible names. |
|
|
2289
|
+
| `matches` (required) | `(row: Z, condition: B) => boolean` | — | Whether the row satisfies the condition. Any question over the whole row; whatever varies belongs in the condition - the table cannot see a change in a closure. |
|
|
2290
|
+
| `describe` | `(condition: B) => string` | — | The text of the condition in the table toolbar, behind the label. Without it the condition has no chip: the application's control shows it. |
|
|
2291
|
+
|
|
2065
2292
|
#### Known limits
|
|
2066
2293
|
|
|
2067
2294
|
- No text filter per column: the search covers text.
|
|
@@ -3115,6 +3342,466 @@ It imports `logistics.ts` from beside itself; the file stands once, under "Files
|
|
|
3115
3342
|
|
|
3116
3343
|
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
3344
|
|
|
3345
|
+
### Tree rows
|
|
3346
|
+
|
|
3347
|
+
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.
|
|
3348
|
+
|
|
3349
|
+
```ts
|
|
3350
|
+
import { useTable } from "@umriss-ui/table";
|
|
3351
|
+
```
|
|
3352
|
+
|
|
3353
|
+
Demo page: https://romanhaendler.github.io/umriss-ui/table/tree-rows/
|
|
3354
|
+
|
|
3355
|
+
`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.
|
|
3356
|
+
|
|
3357
|
+
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.
|
|
3358
|
+
|
|
3359
|
+
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.
|
|
3360
|
+
|
|
3361
|
+
The export writes every row of the filtered tree, open or not, with its level first.
|
|
3362
|
+
|
|
3363
|
+
#### Examples
|
|
3364
|
+
|
|
3365
|
+
##### A small tree
|
|
3366
|
+
|
|
3367
|
+
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.
|
|
3368
|
+
|
|
3369
|
+
```tsx
|
|
3370
|
+
import { useTable } from "@umriss-ui/table";
|
|
3371
|
+
|
|
3372
|
+
interface Unit {
|
|
3373
|
+
id: string;
|
|
3374
|
+
name: string;
|
|
3375
|
+
headcount: number;
|
|
3376
|
+
children?: Unit[];
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
const UNITS: Unit[] = [
|
|
3380
|
+
{
|
|
3381
|
+
id: "sales",
|
|
3382
|
+
name: "Sales",
|
|
3383
|
+
headcount: 42,
|
|
3384
|
+
children: [
|
|
3385
|
+
{ id: "sales-north", name: "Sales North", headcount: 18 },
|
|
3386
|
+
{ id: "sales-south", name: "Sales South", headcount: 24 },
|
|
3387
|
+
],
|
|
3388
|
+
},
|
|
3389
|
+
{ id: "finance", name: "Finance", headcount: 11 },
|
|
3390
|
+
{
|
|
3391
|
+
id: "operations",
|
|
3392
|
+
name: "Operations",
|
|
3393
|
+
headcount: 96,
|
|
3394
|
+
children: [
|
|
3395
|
+
{ id: "site", name: "Site Ashcombe", headcount: 81 },
|
|
3396
|
+
{ id: "logistics", name: "Logistics", headcount: 15 },
|
|
3397
|
+
],
|
|
3398
|
+
},
|
|
3399
|
+
];
|
|
3400
|
+
|
|
3401
|
+
export default function ASmallTree() {
|
|
3402
|
+
const { Table, Column } = useTable(UNITS, { rowKey: (u) => u.id, childRows: (u) => u.children });
|
|
3403
|
+
return (
|
|
3404
|
+
<Table ariaLabel="Organisation">
|
|
3405
|
+
<Column value="name" label="Unit" rowHeader />
|
|
3406
|
+
<Column value="headcount" label="Headcount" />
|
|
3407
|
+
</Table>
|
|
3408
|
+
);
|
|
3409
|
+
}
|
|
3410
|
+
```
|
|
3411
|
+
|
|
3412
|
+
##### An uneven organisation
|
|
3413
|
+
|
|
3414
|
+
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.
|
|
3415
|
+
|
|
3416
|
+
```tsx
|
|
3417
|
+
import { Search, Toolbar, ColumnMenu, useTable } from "@umriss-ui/table";
|
|
3418
|
+
|
|
3419
|
+
interface Unit {
|
|
3420
|
+
id: string;
|
|
3421
|
+
name: string;
|
|
3422
|
+
budget: number;
|
|
3423
|
+
spent: number;
|
|
3424
|
+
children?: Unit[];
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
const UNITS: Unit[] = [
|
|
3428
|
+
{
|
|
3429
|
+
id: "ops",
|
|
3430
|
+
name: "Operations",
|
|
3431
|
+
budget: 4_800,
|
|
3432
|
+
spent: 4_950,
|
|
3433
|
+
children: [
|
|
3434
|
+
{
|
|
3435
|
+
id: "ops-ash",
|
|
3436
|
+
name: "Site Ashcombe",
|
|
3437
|
+
budget: 3_100,
|
|
3438
|
+
spent: 3_320,
|
|
3439
|
+
children: [
|
|
3440
|
+
{
|
|
3441
|
+
id: "ops-ash-a",
|
|
3442
|
+
name: "Hall A",
|
|
3443
|
+
budget: 1_700,
|
|
3444
|
+
spent: 1_910,
|
|
3445
|
+
children: [
|
|
3446
|
+
{
|
|
3447
|
+
id: "ops-ash-a-1",
|
|
3448
|
+
name: "Line 1",
|
|
3449
|
+
budget: 900,
|
|
3450
|
+
spent: 1_080,
|
|
3451
|
+
children: [
|
|
3452
|
+
{ id: "ops-ash-a-1-press", name: "Press cell", budget: 520, spent: 690 },
|
|
3453
|
+
{ id: "ops-ash-a-1-weld", name: "Welding cell", budget: 380, spent: 390 },
|
|
3454
|
+
],
|
|
3455
|
+
},
|
|
3456
|
+
{ id: "ops-ash-a-2", name: "Line 2", budget: 800, spent: 830 },
|
|
3457
|
+
],
|
|
3458
|
+
},
|
|
3459
|
+
{ id: "ops-ash-b", name: "Hall B", budget: 1_400, spent: 1_410 },
|
|
3460
|
+
],
|
|
3461
|
+
},
|
|
3462
|
+
{ id: "ops-log", name: "Logistics", budget: 1_700, spent: 1_630 },
|
|
3463
|
+
],
|
|
3464
|
+
},
|
|
3465
|
+
{
|
|
3466
|
+
id: "sales",
|
|
3467
|
+
name: "Sales",
|
|
3468
|
+
budget: 2_200,
|
|
3469
|
+
spent: 2_050,
|
|
3470
|
+
children: [
|
|
3471
|
+
{ id: "sales-n", name: "Region North", budget: 1_200, spent: 1_150 },
|
|
3472
|
+
{ id: "sales-s", name: "Region South", budget: 1_000, spent: 900 },
|
|
3473
|
+
],
|
|
3474
|
+
},
|
|
3475
|
+
{ id: "staff", name: "Staff unit", budget: 600, spent: 610 },
|
|
3476
|
+
];
|
|
3477
|
+
|
|
3478
|
+
export default function AnUnevenOrganisation() {
|
|
3479
|
+
const { Table, Column } = useTable(UNITS, { rowKey: (u) => u.id, childRows: (u) => u.children, defaultBranches: 1 });
|
|
3480
|
+
return (
|
|
3481
|
+
<Table ariaLabel="Budget by unit">
|
|
3482
|
+
<Toolbar>
|
|
3483
|
+
<Search />
|
|
3484
|
+
<ColumnMenu />
|
|
3485
|
+
</Toolbar>
|
|
3486
|
+
<Column value="name" label="Unit" rowHeader searchable />
|
|
3487
|
+
<Column value="budget" label="Budget (k€)" aggregate="sum" />
|
|
3488
|
+
<Column value="spent" label="Spent (k€)" aggregate="sum" />
|
|
3489
|
+
<Column value={(u) => u.spent - u.budget} id="delta" label="Δ (k€)" />
|
|
3490
|
+
</Table>
|
|
3491
|
+
);
|
|
3492
|
+
}
|
|
3493
|
+
```
|
|
3494
|
+
|
|
3495
|
+
##### Regions and places
|
|
3496
|
+
|
|
3497
|
+
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.
|
|
3498
|
+
|
|
3499
|
+
```tsx
|
|
3500
|
+
import { useTable } from "@umriss-ui/table";
|
|
3501
|
+
|
|
3502
|
+
interface Place {
|
|
3503
|
+
id: string;
|
|
3504
|
+
name: string;
|
|
3505
|
+
sites: number;
|
|
3506
|
+
/** Only places have a postcode. */
|
|
3507
|
+
postcode?: string;
|
|
3508
|
+
children?: Place[];
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
const PLACES: Place[] = [
|
|
3512
|
+
{
|
|
3513
|
+
id: "de",
|
|
3514
|
+
name: "Germany",
|
|
3515
|
+
sites: 5,
|
|
3516
|
+
children: [
|
|
3517
|
+
{
|
|
3518
|
+
id: "de-by",
|
|
3519
|
+
name: "Bavaria",
|
|
3520
|
+
sites: 3,
|
|
3521
|
+
children: [
|
|
3522
|
+
{ id: "de-by-muc", name: "Munich", sites: 2, postcode: "80331" },
|
|
3523
|
+
{ id: "de-by-nue", name: "Nuremberg", sites: 1, postcode: "90402" },
|
|
3524
|
+
],
|
|
3525
|
+
},
|
|
3526
|
+
{ id: "de-hh", name: "Hamburg", sites: 2, postcode: "20095" },
|
|
3527
|
+
],
|
|
3528
|
+
},
|
|
3529
|
+
{
|
|
3530
|
+
id: "nl",
|
|
3531
|
+
name: "Netherlands",
|
|
3532
|
+
sites: 2,
|
|
3533
|
+
children: [
|
|
3534
|
+
{ id: "nl-ams", name: "Amsterdam", sites: 1, postcode: "1012" },
|
|
3535
|
+
{ id: "nl-rtm", name: "Rotterdam", sites: 1, postcode: "3011" },
|
|
3536
|
+
],
|
|
3537
|
+
},
|
|
3538
|
+
{ id: "lu", name: "Luxembourg", sites: 1, postcode: "1009" },
|
|
3539
|
+
];
|
|
3540
|
+
|
|
3541
|
+
export default function RegionsAndPlaces() {
|
|
3542
|
+
const { Table, Column } = useTable(PLACES, { rowKey: (p) => p.id, childRows: (p) => p.children, defaultBranches: 2 });
|
|
3543
|
+
return (
|
|
3544
|
+
<Table ariaLabel="Sites by region">
|
|
3545
|
+
<Column value="name" label="Region" rowHeader />
|
|
3546
|
+
<Column value="sites" label="Sites" />
|
|
3547
|
+
<Column value="postcode" label="Postcode" />
|
|
3548
|
+
</Table>
|
|
3549
|
+
);
|
|
3550
|
+
}
|
|
3551
|
+
```
|
|
3552
|
+
|
|
3553
|
+
##### Employees in the detail
|
|
3554
|
+
|
|
3555
|
+
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.
|
|
3556
|
+
|
|
3557
|
+
```tsx
|
|
3558
|
+
import { useTable } from "@umriss-ui/table";
|
|
3559
|
+
|
|
3560
|
+
interface Employee {
|
|
3561
|
+
id: string;
|
|
3562
|
+
name: string;
|
|
3563
|
+
role: string;
|
|
3564
|
+
since: string;
|
|
3565
|
+
hours: number;
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
interface Team {
|
|
3569
|
+
id: string;
|
|
3570
|
+
name: string;
|
|
3571
|
+
headcount: number;
|
|
3572
|
+
hours: number;
|
|
3573
|
+
employees?: Employee[];
|
|
3574
|
+
children?: Team[];
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
const TEAMS: Team[] = [
|
|
3578
|
+
{
|
|
3579
|
+
id: "it",
|
|
3580
|
+
name: "IT",
|
|
3581
|
+
headcount: 5,
|
|
3582
|
+
hours: 196,
|
|
3583
|
+
children: [
|
|
3584
|
+
{
|
|
3585
|
+
id: "it-ops",
|
|
3586
|
+
name: "IT Operations",
|
|
3587
|
+
headcount: 3,
|
|
3588
|
+
hours: 118,
|
|
3589
|
+
employees: [
|
|
3590
|
+
{ id: "e1", name: "Ada Brenner", role: "Lead", since: "2016", hours: 40 },
|
|
3591
|
+
{ id: "e2", name: "Jonas Kessler", role: "Administrator", since: "2021", hours: 40 },
|
|
3592
|
+
{ id: "e3", name: "Mira Otto", role: "Administrator", since: "2024", hours: 38 },
|
|
3593
|
+
],
|
|
3594
|
+
},
|
|
3595
|
+
{
|
|
3596
|
+
id: "it-dev",
|
|
3597
|
+
name: "Development",
|
|
3598
|
+
headcount: 2,
|
|
3599
|
+
hours: 78,
|
|
3600
|
+
employees: [
|
|
3601
|
+
{ id: "e4", name: "Lena Vogt", role: "Developer", since: "2019", hours: 40 },
|
|
3602
|
+
{ id: "e5", name: "Tom Weiss", role: "Developer", since: "2023", hours: 38 },
|
|
3603
|
+
],
|
|
3604
|
+
},
|
|
3605
|
+
],
|
|
3606
|
+
},
|
|
3607
|
+
];
|
|
3608
|
+
|
|
3609
|
+
function Employees({ team }: { team: Team }) {
|
|
3610
|
+
const { Table, Column } = useTable(team.employees ?? [], { rowKey: (e) => e.id, defaultSort: { column: "name", direction: "asc" } });
|
|
3611
|
+
return (
|
|
3612
|
+
<Table ariaLabel={`Employees of ${team.name}`} density="compact">
|
|
3613
|
+
<Column value="name" label="Employee" rowHeader />
|
|
3614
|
+
<Column value="role" label="Role" />
|
|
3615
|
+
<Column value="since" label="Since" />
|
|
3616
|
+
<Column value="hours" label="Hours" />
|
|
3617
|
+
</Table>
|
|
3618
|
+
);
|
|
3619
|
+
}
|
|
3620
|
+
|
|
3621
|
+
export default function EmployeesInTheDetail() {
|
|
3622
|
+
const { Table, Column, RowDetail } = useTable(TEAMS, { rowKey: (t) => t.id, childRows: (t) => t.children, defaultBranches: 1 });
|
|
3623
|
+
return (
|
|
3624
|
+
<Table ariaLabel="Teams">
|
|
3625
|
+
<Column value="name" label="Team" rowHeader />
|
|
3626
|
+
<Column value="headcount" label="Headcount" />
|
|
3627
|
+
<Column value="hours" label="Hours a week" />
|
|
3628
|
+
<RowDetail>{(team) => (team.employees ? <Employees team={team} /> : null)}</RowDetail>
|
|
3629
|
+
</Table>
|
|
3630
|
+
);
|
|
3631
|
+
}
|
|
3632
|
+
```
|
|
3633
|
+
|
|
3634
|
+
##### Own staff and teams
|
|
3635
|
+
|
|
3636
|
+
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.
|
|
3637
|
+
|
|
3638
|
+
```tsx
|
|
3639
|
+
import { useTable } from "@umriss-ui/table";
|
|
3640
|
+
|
|
3641
|
+
interface Employee {
|
|
3642
|
+
id: string;
|
|
3643
|
+
name: string;
|
|
3644
|
+
role: string;
|
|
3645
|
+
hours: number;
|
|
3646
|
+
}
|
|
3647
|
+
|
|
3648
|
+
interface Unit {
|
|
3649
|
+
id: string;
|
|
3650
|
+
name: string;
|
|
3651
|
+
headcount: number;
|
|
3652
|
+
hours: number;
|
|
3653
|
+
/** The people the unit has itself - not those of its teams. */
|
|
3654
|
+
staff?: Employee[];
|
|
3655
|
+
children?: Unit[];
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
const UNITS: Unit[] = [
|
|
3659
|
+
{
|
|
3660
|
+
id: "it",
|
|
3661
|
+
name: "IT",
|
|
3662
|
+
headcount: 6,
|
|
3663
|
+
hours: 236,
|
|
3664
|
+
staff: [{ id: "e0", name: "Nora Albers", role: "Head of IT", hours: 40 }],
|
|
3665
|
+
children: [
|
|
3666
|
+
{
|
|
3667
|
+
id: "it-ops",
|
|
3668
|
+
name: "IT Operations",
|
|
3669
|
+
headcount: 3,
|
|
3670
|
+
hours: 118,
|
|
3671
|
+
staff: [
|
|
3672
|
+
{ id: "e1", name: "Ada Brenner", role: "Lead", hours: 40 },
|
|
3673
|
+
{ id: "e2", name: "Jonas Kessler", role: "Administrator", hours: 40 },
|
|
3674
|
+
{ id: "e3", name: "Mira Otto", role: "Administrator", hours: 38 },
|
|
3675
|
+
],
|
|
3676
|
+
},
|
|
3677
|
+
{
|
|
3678
|
+
id: "it-dev",
|
|
3679
|
+
name: "Development",
|
|
3680
|
+
headcount: 2,
|
|
3681
|
+
hours: 78,
|
|
3682
|
+
staff: [
|
|
3683
|
+
{ id: "e4", name: "Lena Vogt", role: "Developer", hours: 40 },
|
|
3684
|
+
{ id: "e5", name: "Tom Weiss", role: "Developer", hours: 38 },
|
|
3685
|
+
],
|
|
3686
|
+
},
|
|
3687
|
+
],
|
|
3688
|
+
},
|
|
3689
|
+
{
|
|
3690
|
+
id: "fin",
|
|
3691
|
+
name: "Finance",
|
|
3692
|
+
headcount: 2,
|
|
3693
|
+
hours: 72,
|
|
3694
|
+
children: [
|
|
3695
|
+
{
|
|
3696
|
+
id: "fin-ctl",
|
|
3697
|
+
name: "Controlling",
|
|
3698
|
+
headcount: 2,
|
|
3699
|
+
hours: 72,
|
|
3700
|
+
staff: [
|
|
3701
|
+
{ id: "e6", name: "Paula Hartmann", role: "Controller", hours: 40 },
|
|
3702
|
+
{ id: "e7", name: "Ben Lindner", role: "Analyst", hours: 32 },
|
|
3703
|
+
],
|
|
3704
|
+
},
|
|
3705
|
+
],
|
|
3706
|
+
},
|
|
3707
|
+
];
|
|
3708
|
+
|
|
3709
|
+
function Staff({ unit }: { unit: Unit }) {
|
|
3710
|
+
const { Table, Column } = useTable(unit.staff ?? [], { rowKey: (e) => e.id });
|
|
3711
|
+
return (
|
|
3712
|
+
<Table ariaLabel={`Staff of ${unit.name}`} density="compact">
|
|
3713
|
+
<Column value="name" label="Employee" rowHeader />
|
|
3714
|
+
<Column value="role" label="Role" />
|
|
3715
|
+
<Column value="hours" label="Hours" />
|
|
3716
|
+
</Table>
|
|
3717
|
+
);
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
export default function OwnStaffAndTeams() {
|
|
3721
|
+
const { Table, Column, RowDetail } = useTable(UNITS, { rowKey: (u) => u.id, childRows: (u) => u.children, defaultBranches: ["it"] });
|
|
3722
|
+
return (
|
|
3723
|
+
<Table ariaLabel="Units with their staff">
|
|
3724
|
+
<Column value="name" label="Unit" rowHeader />
|
|
3725
|
+
<Column value="headcount" label="Headcount" />
|
|
3726
|
+
<Column value="hours" label="Hours a week" />
|
|
3727
|
+
<RowDetail>{(unit) => (unit.staff ? <Staff unit={unit} /> : null)}</RowDetail>
|
|
3728
|
+
</Table>
|
|
3729
|
+
);
|
|
3730
|
+
}
|
|
3731
|
+
```
|
|
3732
|
+
|
|
3733
|
+
##### From a flat list
|
|
3734
|
+
|
|
3735
|
+
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.
|
|
3736
|
+
|
|
3737
|
+
```tsx
|
|
3738
|
+
import { useMemo } from "react";
|
|
3739
|
+
import { useTable } from "@umriss-ui/table";
|
|
3740
|
+
|
|
3741
|
+
interface CostCentre {
|
|
3742
|
+
id: string;
|
|
3743
|
+
parent: string | null;
|
|
3744
|
+
name: string;
|
|
3745
|
+
amount: number;
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
const FLAT: CostCentre[] = [
|
|
3749
|
+
{ id: "1000", parent: null, name: "Administration", amount: 820 },
|
|
3750
|
+
{ id: "1100", parent: "1000", name: "Accounting", amount: 310 },
|
|
3751
|
+
{ id: "1110", parent: "1100", name: "Payroll", amount: 120 },
|
|
3752
|
+
{ id: "1200", parent: "1000", name: "Legal", amount: 190 },
|
|
3753
|
+
{ id: "2000", parent: null, name: "Production", amount: 4_300 },
|
|
3754
|
+
{ id: "2100", parent: "2000", name: "Assembly", amount: 2_600 },
|
|
3755
|
+
];
|
|
3756
|
+
|
|
3757
|
+
type Nested = CostCentre & { children?: Nested[] };
|
|
3758
|
+
|
|
3759
|
+
/** Nests a flat list by its parent ids - the roots are those without one. */
|
|
3760
|
+
function nest(flat: readonly CostCentre[]): Nested[] {
|
|
3761
|
+
const byId = new Map<string, Nested>(flat.map((c) => [c.id, { ...c }]));
|
|
3762
|
+
const roots: Nested[] = [];
|
|
3763
|
+
for (const c of byId.values()) {
|
|
3764
|
+
const parent = c.parent === null ? undefined : byId.get(c.parent);
|
|
3765
|
+
if (parent) (parent.children ??= []).push(c);
|
|
3766
|
+
else roots.push(c);
|
|
3767
|
+
}
|
|
3768
|
+
return roots;
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3771
|
+
export default function FromAFlatList() {
|
|
3772
|
+
const rows = useMemo(() => nest(FLAT), []);
|
|
3773
|
+
const { Table, Column } = useTable(rows, { rowKey: (c) => c.id, childRows: (c) => c.children, defaultBranches: 1 });
|
|
3774
|
+
return (
|
|
3775
|
+
<Table ariaLabel="Cost centres">
|
|
3776
|
+
<Column value="name" label="Name" rowHeader />
|
|
3777
|
+
<Column value="id" label="Cost centre" />
|
|
3778
|
+
<Column value="amount" label="Amount (k€)" />
|
|
3779
|
+
</Table>
|
|
3780
|
+
);
|
|
3781
|
+
}
|
|
3782
|
+
```
|
|
3783
|
+
|
|
3784
|
+
#### When to use something else
|
|
3785
|
+
|
|
3786
|
+
- Rows that share a value - a customer, a month → Grouping
|
|
3787
|
+
- A hierarchy without figures → `TreeView` from @umriss-ui/core
|
|
3788
|
+
- Records of another kind beneath the bottom level → RowDetail
|
|
3789
|
+
|
|
3790
|
+
#### Keyboard
|
|
3791
|
+
|
|
3792
|
+
| Key | Action |
|
|
3793
|
+
|---|---|
|
|
3794
|
+
| `→ / ←` | On a fold: opens or closes its branch; ← on a closed one goes to the parent's fold. |
|
|
3795
|
+
| `Alt + → / Alt + ←` | On a fold: opens or closes the branch and all its siblings. |
|
|
3796
|
+
|
|
3797
|
+
#### Known limits
|
|
3798
|
+
|
|
3799
|
+
- Not with grouping or pagination: both would build or cut levels a second way. A large tree uses virtualisation.
|
|
3800
|
+
- Not in [manual mode](#/manual-mode), and no branches loaded on demand yet.
|
|
3801
|
+
- One column set for every level; a level without a value shows it as absent.
|
|
3802
|
+
|
|
3803
|
+
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).
|
|
3804
|
+
|
|
3118
3805
|
### Aggregate
|
|
3119
3806
|
|
|
3120
3807
|
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.
|
|
@@ -4182,8 +4869,272 @@ export default function PlaceItOutside() {
|
|
|
4182
4869
|
|---|---|---|---|
|
|
4183
4870
|
| `children` | `ReactNode` | — | Search, column menu, export – on the left in the table toolbar, before the conditions. |
|
|
4184
4871
|
| `className` | `string` | — | Classes on the table toolbar. |
|
|
4872
|
+
| `size` | `ToolbarSize` | `"sm"` | The size of every control the table puts into it - search, column menu, export, "reset", the bulk actions -: `sm` (the default) or `md`. A control of one's own takes the same size by its own prop. |
|
|
4873
|
+
| `of` | `TableRef` | — | The table, when the table toolbar does not stand inside it. If it then stands behind the table in the tree, it registers only after the first frame – until then a table with a search or a column filter shows its own toolbar. Placed before the table, there is no such change. |
|
|
4874
|
+
|
|
4875
|
+
### Toolbar controls
|
|
4876
|
+
|
|
4877
|
+
Put controls of your own into the toolbar - a multiselect, a select, a combobox - and let them stand level with the table's: one size for the whole bar, and a row filter behind each control.
|
|
4878
|
+
|
|
4879
|
+
```ts
|
|
4880
|
+
import { Toolbar, rowFilter } from "@umriss-ui/table";
|
|
4881
|
+
```
|
|
4882
|
+
|
|
4883
|
+
Demo page: https://romanhaendler.github.io/umriss-ui/table/toolbar-controls/
|
|
4884
|
+
|
|
4885
|
+
`Toolbar` takes `size`, `sm` or `md`, and the parts the table puts into it follow: search, column menu, export, “Reset” and the bulk actions. A part says its own size with its own `size`. A control from @umriss-ui/core takes the same size by its own prop - `size` on `Input`, `MultiSelect` and `Combobox`, `selectSize` on `Select`.
|
|
4886
|
+
|
|
4887
|
+
A control of your own restricts the table through a [row filter](#/filter): it sets the condition with `t.setFilter(filter, condition)` and reads it with `t.conditionOf(filter)`, so “Reset”, the count of matches and the view include it.
|
|
4888
|
+
|
|
4889
|
+
#### Examples
|
|
4890
|
+
|
|
4891
|
+
##### Controls of your own at the toolbar's size
|
|
4892
|
+
|
|
4893
|
+
The toolbar is `sm` unless it says otherwise; a control from @umriss-ui/core stands level with the search at its own small size. Behind each control a row filter.
|
|
4894
|
+
|
|
4895
|
+
```tsx
|
|
4896
|
+
import { MultiSelect, Select } from "@umriss-ui/core";
|
|
4897
|
+
import { SHIPMENTS } from "./logistics";
|
|
4898
|
+
import type { Shipment } from "./logistics";
|
|
4899
|
+
import { Pagination, Search, Toolbar, rowFilter, useTable } from "@umriss-ui/table";
|
|
4900
|
+
|
|
4901
|
+
type Status = Shipment["status"];
|
|
4902
|
+
|
|
4903
|
+
const tours = rowFilter({
|
|
4904
|
+
id: "tours",
|
|
4905
|
+
label: "Tours",
|
|
4906
|
+
matches: (shipment: Shipment, chosen: readonly string[]) => chosen.includes(shipment.tour),
|
|
4907
|
+
});
|
|
4908
|
+
|
|
4909
|
+
const status = rowFilter({
|
|
4910
|
+
id: "status",
|
|
4911
|
+
label: "Status",
|
|
4912
|
+
matches: (shipment: Shipment, wanted: Status) => shipment.status === wanted,
|
|
4913
|
+
});
|
|
4914
|
+
|
|
4915
|
+
const TOURS = [...new Set(SHIPMENTS.map((s) => s.tour))].map((tour) => ({ value: tour, label: tour }));
|
|
4916
|
+
|
|
4917
|
+
export default function ControlsAtTheToolbarsSize() {
|
|
4918
|
+
const t = useTable(SHIPMENTS, { rowKey: (s) => s.id, rowFilters: [tours, status] });
|
|
4919
|
+
const { Table, Column } = t;
|
|
4920
|
+
|
|
4921
|
+
return (
|
|
4922
|
+
<Table ariaLabel="Shipments">
|
|
4923
|
+
<Toolbar>
|
|
4924
|
+
<Search placeholder="Shipment or customer" />
|
|
4925
|
+
<MultiSelect
|
|
4926
|
+
size="sm"
|
|
4927
|
+
aria-label="Tours"
|
|
4928
|
+
placeholder="All tours"
|
|
4929
|
+
options={TOURS}
|
|
4930
|
+
style={{ width: 200 }}
|
|
4931
|
+
value={t.conditionOf(tours) ?? []}
|
|
4932
|
+
onChange={(next) => t.setFilter(tours, next.length > 0 ? next : null)}
|
|
4933
|
+
/>
|
|
4934
|
+
{/* `Select` is the native field: its size is `selectSize`, since `size` is the element's own. */}
|
|
4935
|
+
<Select
|
|
4936
|
+
selectSize="sm"
|
|
4937
|
+
aria-label="Status"
|
|
4938
|
+
value={t.conditionOf(status) ?? ""}
|
|
4939
|
+
onChange={(event) => t.setFilter(status, event.target.value === "" ? null : (event.target.value as Status))}
|
|
4940
|
+
>
|
|
4941
|
+
<option value="">Every status</option>
|
|
4942
|
+
<option value="out for delivery">Out for delivery</option>
|
|
4943
|
+
<option value="failed attempt">Failed attempt</option>
|
|
4944
|
+
<option value="delivered">Delivered</option>
|
|
4945
|
+
</Select>
|
|
4946
|
+
</Toolbar>
|
|
4947
|
+
<Column value="id" label="Shipment" rowHeader />
|
|
4948
|
+
<Column value="customer" label="Customer" />
|
|
4949
|
+
<Column value="tour" label="Tour" />
|
|
4950
|
+
<Column value="status" label="Status" />
|
|
4951
|
+
<Pagination />
|
|
4952
|
+
</Table>
|
|
4953
|
+
);
|
|
4954
|
+
}
|
|
4955
|
+
```
|
|
4956
|
+
|
|
4957
|
+
It imports `logistics.ts` from beside itself; the file stands once, under "Files the examples show" at the end.
|
|
4958
|
+
|
|
4959
|
+
##### A larger toolbar
|
|
4960
|
+
|
|
4961
|
+
`size="md"` on the toolbar, and search, column menu, export and “Reset” follow; the multiselect is `md` by default. One size for the whole bar, said once.
|
|
4962
|
+
|
|
4963
|
+
```tsx
|
|
4964
|
+
import { MultiSelect } from "@umriss-ui/core";
|
|
4965
|
+
import { SHIPMENTS } from "./logistics";
|
|
4966
|
+
import type { Shipment } from "./logistics";
|
|
4967
|
+
import { ColumnMenu, Export, Pagination, Search, Toolbar, rowFilter, useTable } from "@umriss-ui/table";
|
|
4968
|
+
|
|
4969
|
+
const tours = rowFilter({
|
|
4970
|
+
id: "tours",
|
|
4971
|
+
label: "Tours",
|
|
4972
|
+
matches: (shipment: Shipment, chosen: readonly string[]) => chosen.includes(shipment.tour),
|
|
4973
|
+
});
|
|
4974
|
+
|
|
4975
|
+
const TOURS = [...new Set(SHIPMENTS.map((s) => s.tour))].map((tour) => ({ value: tour, label: tour }));
|
|
4976
|
+
|
|
4977
|
+
export default function ALargerToolbar() {
|
|
4978
|
+
const t = useTable(SHIPMENTS, { rowKey: (s) => s.id, rowFilters: [tours] });
|
|
4979
|
+
const { Table, Column } = t;
|
|
4980
|
+
|
|
4981
|
+
return (
|
|
4982
|
+
<Table ariaLabel="Shipments">
|
|
4983
|
+
<Toolbar size="md">
|
|
4984
|
+
<Search placeholder="Shipment or customer" />
|
|
4985
|
+
<MultiSelect
|
|
4986
|
+
aria-label="Tours"
|
|
4987
|
+
placeholder="All tours"
|
|
4988
|
+
options={TOURS}
|
|
4989
|
+
style={{ width: 240 }}
|
|
4990
|
+
value={t.conditionOf(tours) ?? []}
|
|
4991
|
+
onChange={(next) => t.setFilter(tours, next.length > 0 ? next : null)}
|
|
4992
|
+
/>
|
|
4993
|
+
<ColumnMenu />
|
|
4994
|
+
<Export />
|
|
4995
|
+
</Toolbar>
|
|
4996
|
+
<Column value="id" label="Shipment" rowHeader />
|
|
4997
|
+
<Column value="customer" label="Customer" />
|
|
4998
|
+
<Column value="tour" label="Tour" />
|
|
4999
|
+
<Column value="weight" label="Weight (kg)" />
|
|
5000
|
+
<Pagination />
|
|
5001
|
+
</Table>
|
|
5002
|
+
);
|
|
5003
|
+
}
|
|
5004
|
+
```
|
|
5005
|
+
|
|
5006
|
+
It imports `logistics.ts` from beside itself; the file stands once, under "Files the examples show" at the end.
|
|
5007
|
+
|
|
5008
|
+
##### A dispatcher's bar
|
|
5009
|
+
|
|
5010
|
+
Three controls of one's own and the table's parts in one `md` bar, a quick filter beside the table - and every condition counted, reset and kept in the view alike. Only the one set from outside describes itself as a chip: the others show in their control.
|
|
5011
|
+
|
|
5012
|
+
```tsx
|
|
5013
|
+
import { Button, Combobox, MultiSelect, Select, Stack } from "@umriss-ui/core";
|
|
5014
|
+
import { SHIPMENTS } from "./logistics";
|
|
5015
|
+
import type { Shipment } from "./logistics";
|
|
5016
|
+
import { ColumnMenu, Export, Pagination, Search, Toolbar, rowFilter, useTable } from "@umriss-ui/table";
|
|
5017
|
+
|
|
5018
|
+
type Status = Shipment["status"];
|
|
5019
|
+
|
|
5020
|
+
const tours = rowFilter({
|
|
5021
|
+
id: "tours",
|
|
5022
|
+
label: "Tours",
|
|
5023
|
+
matches: (shipment: Shipment, chosen: readonly string[]) => chosen.includes(shipment.tour),
|
|
5024
|
+
});
|
|
5025
|
+
|
|
5026
|
+
const status = rowFilter({
|
|
5027
|
+
id: "status",
|
|
5028
|
+
label: "Status",
|
|
5029
|
+
matches: (shipment: Shipment, wanted: Status) => shipment.status === wanted,
|
|
5030
|
+
});
|
|
5031
|
+
|
|
5032
|
+
const customer = rowFilter({
|
|
5033
|
+
id: "customer",
|
|
5034
|
+
label: "Customer",
|
|
5035
|
+
matches: (shipment: Shipment, name: string) => shipment.customer === name,
|
|
5036
|
+
});
|
|
5037
|
+
|
|
5038
|
+
/* Set from a button beside the table, not from a control in the bar - so it
|
|
5039
|
+
says itself in the toolbar, where its cross lifts it. */
|
|
5040
|
+
const heavy = rowFilter({
|
|
5041
|
+
id: "heavy",
|
|
5042
|
+
label: "Weight",
|
|
5043
|
+
matches: (shipment: Shipment, atLeast: number) => shipment.weight >= atLeast,
|
|
5044
|
+
describe: (atLeast) => `from ${atLeast} kg`,
|
|
5045
|
+
});
|
|
5046
|
+
|
|
5047
|
+
const TOURS = [...new Set(SHIPMENTS.map((s) => s.tour))].map((tour) => ({ value: tour, label: tour }));
|
|
5048
|
+
const CUSTOMERS = [...new Set(SHIPMENTS.map((s) => s.customer))]
|
|
5049
|
+
.sort()
|
|
5050
|
+
.map((name) => ({ value: name, label: name }));
|
|
5051
|
+
|
|
5052
|
+
export default function ADispatchersBar() {
|
|
5053
|
+
const t = useTable(SHIPMENTS, {
|
|
5054
|
+
rowKey: (s) => s.id,
|
|
5055
|
+
rowFilters: [tours, status, customer, heavy],
|
|
5056
|
+
initialView: { conditions: { heavy: 20 } },
|
|
5057
|
+
});
|
|
5058
|
+
const { Table, Column } = t;
|
|
5059
|
+
|
|
5060
|
+
return (
|
|
5061
|
+
<Stack gap={3}>
|
|
5062
|
+
<Stack direction="row" gap={2}>
|
|
5063
|
+
<Button size="sm" onClick={() => t.setFilter(heavy, 20)}>
|
|
5064
|
+
Heavy parcels
|
|
5065
|
+
</Button>
|
|
5066
|
+
</Stack>
|
|
5067
|
+
|
|
5068
|
+
<Table ariaLabel="Shipments of the day">
|
|
5069
|
+
<Toolbar size="md">
|
|
5070
|
+
<Search placeholder="Shipment" />
|
|
5071
|
+
<MultiSelect
|
|
5072
|
+
aria-label="Tours"
|
|
5073
|
+
placeholder="All tours"
|
|
5074
|
+
options={TOURS}
|
|
5075
|
+
style={{ width: 200 }}
|
|
5076
|
+
value={t.conditionOf(tours) ?? []}
|
|
5077
|
+
onChange={(next) => t.setFilter(tours, next.length > 0 ? next : null)}
|
|
5078
|
+
/>
|
|
5079
|
+
<Select
|
|
5080
|
+
aria-label="Status"
|
|
5081
|
+
value={t.conditionOf(status) ?? ""}
|
|
5082
|
+
onChange={(event) => t.setFilter(status, event.target.value === "" ? null : (event.target.value as Status))}
|
|
5083
|
+
>
|
|
5084
|
+
<option value="">Every status</option>
|
|
5085
|
+
<option value="out for delivery">Out for delivery</option>
|
|
5086
|
+
<option value="failed attempt">Failed attempt</option>
|
|
5087
|
+
<option value="delivered">Delivered</option>
|
|
5088
|
+
</Select>
|
|
5089
|
+
<Combobox
|
|
5090
|
+
aria-label="Customer"
|
|
5091
|
+
placeholder="Any customer"
|
|
5092
|
+
options={CUSTOMERS}
|
|
5093
|
+
style={{ width: 220 }}
|
|
5094
|
+
value={t.conditionOf(customer)}
|
|
5095
|
+
onChange={(name) => t.setFilter(customer, name)}
|
|
5096
|
+
/>
|
|
5097
|
+
<ColumnMenu />
|
|
5098
|
+
<Export />
|
|
5099
|
+
</Toolbar>
|
|
5100
|
+
<Column value="id" label="Shipment" rowHeader />
|
|
5101
|
+
<Column value="customer" label="Customer" />
|
|
5102
|
+
<Column value="tour" label="Tour" />
|
|
5103
|
+
<Column value="status" label="Status" />
|
|
5104
|
+
<Column value="weight" label="Weight (kg)" />
|
|
5105
|
+
<Pagination />
|
|
5106
|
+
</Table>
|
|
5107
|
+
</Stack>
|
|
5108
|
+
);
|
|
5109
|
+
}
|
|
5110
|
+
```
|
|
5111
|
+
|
|
5112
|
+
It imports `logistics.ts` from beside itself; the file stands once, under "Files the examples show" at the end.
|
|
5113
|
+
|
|
5114
|
+
#### When to use something else
|
|
5115
|
+
|
|
5116
|
+
- A filter on a column the table offers itself, in its header → Filter
|
|
5117
|
+
|
|
5118
|
+
#### API
|
|
5119
|
+
|
|
5120
|
+
##### `ToolbarProps`
|
|
5121
|
+
|
|
5122
|
+
| Prop | Type | Default | Description |
|
|
5123
|
+
|---|---|---|---|
|
|
5124
|
+
| `children` | `ReactNode` | — | Search, column menu, export – on the left in the table toolbar, before the conditions. |
|
|
5125
|
+
| `className` | `string` | — | Classes on the table toolbar. |
|
|
5126
|
+
| `size` | `ToolbarSize` | `"sm"` | The size of every control the table puts into it - search, column menu, export, "reset", the bulk actions -: `sm` (the default) or `md`. A control of one's own takes the same size by its own prop. |
|
|
4185
5127
|
| `of` | `TableRef` | — | The table, when the table toolbar does not stand inside it. If it then stands behind the table in the tree, it registers only after the first frame – until then a table with a search or a column filter shows its own toolbar. Placed before the table, there is no such change. |
|
|
4186
5128
|
|
|
5129
|
+
##### `RowFilter<Z, B>`
|
|
5130
|
+
|
|
5131
|
+
| Prop | Type | Default | Description |
|
|
5132
|
+
|---|---|---|---|
|
|
5133
|
+
| `id` (required) | `string` | — | Its name in `t.view.conditions` and in what manual mode reports - the one place the filter is spelled. Not the id of a column of the same table. |
|
|
5134
|
+
| `label` (required) | `string` | — | What it is called: before the text of its chip, and in the chip's accessible names. |
|
|
5135
|
+
| `matches` (required) | `(row: Z, condition: B) => boolean` | — | Whether the row satisfies the condition. Any question over the whole row; whatever varies belongs in the condition - the table cannot see a change in a closure. |
|
|
5136
|
+
| `describe` | `(condition: B) => string` | — | The text of the condition in the table toolbar, behind the label. Without it the condition has no chip: the application's control shows it. |
|
|
5137
|
+
|
|
4187
5138
|
### ColumnMenu
|
|
4188
5139
|
|
|
4189
5140
|
A menu in which the user shows, hides, reorders and pins the table's columns and picks a grouping (also called a column chooser). Offer it where the table has more columns than everyone needs.
|
|
@@ -4293,6 +5244,7 @@ export default function PinAColumn() {
|
|
|
4293
5244
|
|
|
4294
5245
|
| Prop | Type | Default | Description |
|
|
4295
5246
|
|---|---|---|---|
|
|
5247
|
+
| `size` | `ToolbarSize` | — | `sm` or `md`; without it the size of the toolbar it stands in, `sm` outside one. |
|
|
4296
5248
|
| `of` | `TableRef` | — | The table, when the part does not stand inside it: the return value of `useTable`. |
|
|
4297
5249
|
|
|
4298
5250
|
### Export
|
|
@@ -4402,6 +5354,7 @@ export default function TakeTheText() {
|
|
|
4402
5354
|
|---|---|---|---|
|
|
4403
5355
|
| `filename` | `string` | — | File name of the download. Without it the one from the wording ("table.csv"). |
|
|
4404
5356
|
| `onExport` | `(text: string) => void` | — | Gets the text instead of triggering a file. |
|
|
5357
|
+
| `size` | `ToolbarSize` | — | `sm` or `md`; without it the size of the toolbar it stands in, `sm` outside one. |
|
|
4405
5358
|
| `of` | `TableRef` | — | The table, when the part does not stand inside it: the return value of `useTable`. |
|
|
4406
5359
|
|
|
4407
5360
|
#### Known limits
|