@umriss-ui/table 0.8.0 → 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/docs/llms-full.md CHANGED
@@ -1,4 +1,4 @@
1
- # @umriss-ui/table 0.8.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 per column, in the order in which they were set. Whatever fits no column is absent. |
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. |
@@ -1778,6 +1780,7 @@ export default function SearchFromACardHeader() {
1778
1780
  | `placeholder` | `string` | — | The placeholder in the field; without it "Search …" from the wording. |
1779
1781
  | `aria-label` | `string` | — | Accessible name; without it "Search table" from the wording. |
1780
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. |
1781
1784
  | `of` | `TableRef` | — | The table, when the part does not stand inside it: the return value of `useTable`. |
1782
1785
 
1783
1786
  #### Known limits
@@ -1791,7 +1794,7 @@ What umriss deliberately does not build, and why: [ADR-0032](https://github.com/
1791
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.
1792
1795
 
1793
1796
  ```ts
1794
- import { columnFilter } from "@umriss-ui/table";
1797
+ import { columnFilter, rowFilter } from "@umriss-ui/table";
1795
1798
  ```
1796
1799
 
1797
1800
  Demo page: https://romanhaendler.github.io/umriss-ui/table/filter/
@@ -2001,6 +2004,14 @@ const SHIPMENTS: Shipment[] = [
2001
2004
 
2002
2005
  const QUICK_FILTERS: readonly Status[] = ["out for delivery", "failed attempt"];
2003
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). */
2004
2015
  export default function ConditionsFromOutside() {
2005
2016
  const t = useTable(SHIPMENTS, { rowKey: (s) => s.id });
2006
2017
  const { Table, Column } = t;
@@ -2042,6 +2053,209 @@ export default function ConditionsFromOutside() {
2042
2053
  }
2043
2054
  ```
2044
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
+
2045
2259
  #### When to use something else
2046
2260
 
2047
2261
  - Free text across the columns → Search
@@ -2066,6 +2280,15 @@ export default function ConditionsFromOutside() {
2066
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. |
2067
2281
  | `column` (required) | `{ id: string; label: string }` | — | The column whose filter this is. |
2068
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
+
2069
2292
  #### Known limits
2070
2293
 
2071
2294
  - No text filter per column: the search covers text.
@@ -4646,8 +4869,272 @@ export default function PlaceItOutside() {
4646
4869
  |---|---|---|---|
4647
4870
  | `children` | `ReactNode` | — | Search, column menu, export – on the left in the table toolbar, before the conditions. |
4648
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. |
4649
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. |
4650
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. |
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. |
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
+
4651
5138
  ### ColumnMenu
4652
5139
 
4653
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.
@@ -4757,6 +5244,7 @@ export default function PinAColumn() {
4757
5244
 
4758
5245
  | Prop | Type | Default | Description |
4759
5246
  |---|---|---|---|
5247
+ | `size` | `ToolbarSize` | — | `sm` or `md`; without it the size of the toolbar it stands in, `sm` outside one. |
4760
5248
  | `of` | `TableRef` | — | The table, when the part does not stand inside it: the return value of `useTable`. |
4761
5249
 
4762
5250
  ### Export
@@ -4866,6 +5354,7 @@ export default function TakeTheText() {
4866
5354
  |---|---|---|---|
4867
5355
  | `filename` | `string` | — | File name of the download. Without it the one from the wording ("table.csv"). |
4868
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. |
4869
5358
  | `of` | `TableRef` | — | The table, when the part does not stand inside it: the return value of `useTable`. |
4870
5359
 
4871
5360
  #### Known limits
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umriss-ui/table",
3
- "version": "0.8.0",
3
+ "version": "0.9.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.19.0"
54
+ "@umriss-ui/core": "^0.20.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.19.0"
69
+ "@umriss-ui/core": "0.20.0"
70
70
  },
71
71
  "scripts": {
72
72
  "props": "node --disable-warning=ExperimentalWarning --experimental-strip-types demo/props.ts",