compote-ui 0.84.0 → 0.86.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.
@@ -1,181 +1,181 @@
1
- # Column Options
2
-
3
- Column helper:
4
-
5
- ```ts
6
- const col = DataTable.createDataTableColumnHelper<Row>();
7
- ```
8
-
9
- Accessors:
10
-
11
- ```ts
12
- col.accessor('fieldName', { header: 'Field' });
13
- col.accessorFn((row) => row.a + row.b, { id: 'sum', header: 'Sum' });
14
- col.group('Group', [col.accessor('name', { header: 'Name' })]);
15
- col.columns([col.accessor('id', { header: 'ID' })]);
16
- ```
17
-
18
- Common options:
19
-
20
- - `header: string`
21
- - `type?: 'text' | 'number' | 'currency' | 'percent' | 'boolean' | 'select' | 'url' | 'phone' | 'date' | 'time' | 'date-time' | 'action'`
22
- - `align?: 'left' | 'center' | 'right'`
23
- - `size?: number`
24
- - `minSize?: number`
25
- - `maxSize?: number`
26
- - `enableResizing?: boolean`
27
- - `enableHiding?: boolean`
28
- - `enableSorting?: boolean`
29
- - `enableColumnFilter?: boolean`
30
- - `filterFn?: FilterFn | string`
31
- - `formatOptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions`
32
- - `formatLocale?: string`
33
- - `cell?: (value, row) => string | number | boolean | null | undefined`
34
- - `cellComponent?: Component`
35
- - `cellProps?: (value, row) => Record<string, unknown>`
36
- - `cellSnippet?: Snippet`
37
- - `pinned?: 'left' | 'right'` — sticky during horizontal scroll. Inside a `col.group(...)`, pinning
38
- a member column also pins the group header fragment above it, so the label stays visible while
39
- the rest of that group scrolls.
40
- - `grow?: boolean`
41
- - `sum?: boolean`
42
- - `footer?: (values: unknown[]) => string | number | undefined`
43
- - `exportValue?: (value, row) => unknown` — the value `DataTable.Export` writes instead of the
44
- accessor value (e.g. a number out of an object a `cellComponent` renders). Without `cell`, its
45
- text is formatted by `type`; it is never passed to `cell`. See [Export](export.md).
46
- - `enableExport?: boolean` — defaults to `true`, `false` for `type: 'action'`.
47
-
48
- Type defaults:
49
-
50
- - `number`, `currency`: right aligned, size `120`
51
- - `percent`: right aligned, size `100`
52
- - `date`: center aligned, size `110`
53
- - `time`: center aligned, size `80`
54
- - `date-time`: center aligned, size `160`
55
- - `boolean`: center aligned, size `90`
56
- - `url`: center aligned, sorting disabled, size `60`
57
- - `phone`: left aligned, size `160`
58
- - `action`: center aligned, size `60`, sorting/hiding/column-filter all disabled — layout-only,
59
- carries no value to format or filter. Supply a `cellComponent`/`cellSnippet` for the row action
60
- buttons; the defaults keep the actions column out of the column-visibility menu and filter
61
- toolbar automatically.
62
-
63
- Use one `grow: true` column to absorb extra horizontal space.
64
-
65
- ## Date columns: display and filter
66
-
67
- `date`, `time` and `date-time` cells are read the same way for display and for the date filter,
68
- in the column's display zone — `formatOptions.timeZone` when set, otherwise the viewer's local
69
- zone:
70
-
71
- - `'2024-03-15'` (and a `CalendarDate`) is a calendar day. It always shows and filters as
72
- 15 March, also in zones west of UTC — it is never turned into a midnight-UTC instant.
73
- - `Date`, epoch milliseconds, strings with an offset (`Z`, `+02:00`, DB `+02`) and
74
- `ZonedDateTime` are instants, shown and filtered on the day they fall on in the display zone.
75
- - A datetime without an offset (`'2024-03-15T10:30'`) is wall-clock time in the display zone.
76
- - Unreadable values (e.g. `'2024-02-30'`) render as `-` and never match an active filter.
77
-
78
- `date` and `date-time` columns filter by calendar-day range. The filter value is
79
- `[from?, to?]`, each `YYYY-MM-DD` or empty (open-ended); both days are inclusive, a reversed
80
- range is swapped, and an empty range removes the filter. Instants are judged by their calendar
81
- day, so 23- and 25-hour DST days need no special handling. `time` columns keep the text filter.
82
-
83
- ```ts
84
- table.getColumn('createdAt')?.setFilterValue(['2024-03-01', '2024-03-31']); // March
85
- table.getColumn('createdAt')?.setFilterValue([undefined, '2024-03-31']); // up to 31 March
86
- ```
87
-
88
- ## Select columns with multiple values
89
-
90
- A `type: 'select'` column may return an array (tags, multi-select attributes). The Funnel then
91
- lists each item as its own option with a row count, a row matches when any of its items is
92
- selected, and the cell renders the items joined with `, `. A row counts once per option even
93
- when its array repeats an item. Missing values — `null`, `undefined`, `''` or an empty array —
94
- share one `(empty)` option.
95
-
96
- The filter value is an array of selected options: each is the `String()` of the cell value, and
97
- the empty option is `null` — so a real `'null'` string stays its own option:
98
-
99
- ```ts
100
- table.getColumn('tags')?.setFilterValue(['Battery', null]); // Battery or no tags
101
- ```
102
-
103
- ```ts
104
- col.accessorFn((row) => row.tags.map((tag) => tag.name), {
105
- id: 'tags',
106
- header: 'Tags',
107
- type: 'select'
108
- });
109
- ```
110
-
111
- ## Locale for number/currency/percent
112
-
113
- Priority: `formatLocale` prop → `useLocaleContext().locale` → browser default. Wrap the app in
114
- `<LocaleProvider locale="sr-RS">` to set the context locale for every formatted column.
115
-
116
- ## Custom cellComponent
117
-
118
- ```svelte
119
- <!-- PriceCell.svelte -->
120
- <script lang="ts">
121
- let { value, prices }: { value: number; prices: { vendor: string; price: number }[] } = $props();
122
- </script>
123
-
124
- <span>{value}</span>
125
- ```
126
-
127
- ```ts
128
- col.accessorFn((row) => Math.min(...row.prices.map((p) => p.price)), {
129
- id: 'minPrice',
130
- header: 'Best Price',
131
- type: 'currency',
132
- align: 'right',
133
- cellComponent: PriceCell,
134
- cellProps: (value, row) => ({ value, prices: row.prices })
135
- });
136
- ```
137
-
138
- ## Row height and cell alignment
139
-
140
- Body cells are fixed at `h-9` (36px), matching the header, with content vertically centered — any
141
- control up to 36px tall (every `Button` `icon-xs`/`icon-sm`/`icon`/`icon-lg` size) fits without
142
- changing row height. Do **not** add negative margins (e.g. `-my-1`) to cell components to
143
- compensate for row growth — in the virtualized table that fights the virtualizer's 37px row
144
- estimate. Cells are `truncate` (single-line, `overflow: hidden`), so give action columns a little
145
- extra `size` if a focus ring on a control near the edge gets clipped.
146
-
147
- ## DataTable.Search
148
-
149
- Global filter input searching across all text columns, debounced (default 300ms).
150
-
151
- - `table: DataTableInstance<T>` — required
152
- - `placeholder?: string` (default `'Search...'`)
153
- - `class?: ClassValue`
154
- - `debounceMs?: number` (default `300`)
155
-
156
- Text/number columns stay searchable even when the first row's value is `null`/`undefined`;
157
- booleans and object-valued columns are excluded from global search. Also available as
158
- `VirtualDataTable.Search` for the virtualized variant.
159
-
160
- ## DataTable.Root props
161
-
162
- `table: DataTableInstance<T>` (required), `caption?: string` (sr-only `<caption>`),
163
- `emptyMessage?: string` (default `'No rows found'`), `class?: ClassValue`,
164
- `headerFilters?: boolean` (default `false`; funnel filter popups in column headers — see
165
- "Filter from column headers" in SKILL.md),
166
- `onRowClick?: (details: { row: T; event: MouseEvent }) => void`,
167
- `onRowDoubleClick?: (details: { row: T; event: MouseEvent }) => void` — `row` is `row.original`.
168
- Clicks on the row-selection checkbox and url-cell buttons do **not** trigger either handler.
169
- `rowClass?: (row: T) => ClassValue` adds classes to the row's `<tr>` (e.g. a tint; also set
170
- `--row-bg` so pinned and selection cells match).
171
- `VirtualDataTable.Root` shares the same props.
172
-
173
- ```svelte
174
- <DataTable.Root
175
- {table}
176
- onRowDoubleClick={({ row, event }) => {
177
- if (event.ctrlKey || event.metaKey) openInNewTab(row.id);
178
- else navigateTo(row.id);
179
- }}
180
- />
181
- ```
1
+ # Column Options
2
+
3
+ Column helper:
4
+
5
+ ```ts
6
+ const col = DataTable.createDataTableColumnHelper<Row>();
7
+ ```
8
+
9
+ Accessors:
10
+
11
+ ```ts
12
+ col.accessor('fieldName', { header: 'Field' });
13
+ col.accessorFn((row) => row.a + row.b, { id: 'sum', header: 'Sum' });
14
+ col.group('Group', [col.accessor('name', { header: 'Name' })]);
15
+ col.columns([col.accessor('id', { header: 'ID' })]);
16
+ ```
17
+
18
+ Common options:
19
+
20
+ - `header: string`
21
+ - `type?: 'text' | 'number' | 'currency' | 'percent' | 'boolean' | 'select' | 'url' | 'phone' | 'date' | 'time' | 'date-time' | 'action'`
22
+ - `align?: 'left' | 'center' | 'right'`
23
+ - `size?: number`
24
+ - `minSize?: number`
25
+ - `maxSize?: number`
26
+ - `enableResizing?: boolean`
27
+ - `enableHiding?: boolean`
28
+ - `enableSorting?: boolean`
29
+ - `enableColumnFilter?: boolean`
30
+ - `filterFn?: FilterFn | string`
31
+ - `formatOptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions`
32
+ - `formatLocale?: string`
33
+ - `cell?: (value, row) => string | number | boolean | null | undefined`
34
+ - `cellComponent?: Component`
35
+ - `cellProps?: (value, row) => Record<string, unknown>`
36
+ - `cellSnippet?: Snippet`
37
+ - `pinned?: 'left' | 'right'` — sticky during horizontal scroll. Inside a `col.group(...)`, pinning
38
+ a member column also pins the group header fragment above it, so the label stays visible while
39
+ the rest of that group scrolls.
40
+ - `grow?: boolean`
41
+ - `sum?: boolean`
42
+ - `footer?: (values: unknown[]) => string | number | undefined`
43
+ - `exportValue?: (value, row) => unknown` — the value `DataTable.Export` writes instead of the
44
+ accessor value (e.g. a number out of an object a `cellComponent` renders). Without `cell`, its
45
+ text is formatted by `type`; it is never passed to `cell`. See [Export](export.md).
46
+ - `enableExport?: boolean` — defaults to `true`, `false` for `type: 'action'`.
47
+
48
+ Type defaults:
49
+
50
+ - `number`, `currency`: right aligned, size `120`
51
+ - `percent`: right aligned, size `100`
52
+ - `date`: center aligned, size `110`
53
+ - `time`: center aligned, size `80`
54
+ - `date-time`: center aligned, size `160`
55
+ - `boolean`: center aligned, size `90`
56
+ - `url`: center aligned, sorting disabled, size `60`
57
+ - `phone`: left aligned, size `160`
58
+ - `action`: center aligned, size `60`, sorting/hiding/column-filter all disabled — layout-only,
59
+ carries no value to format or filter. Supply a `cellComponent`/`cellSnippet` for the row action
60
+ buttons; the defaults keep the actions column out of the column-visibility menu and filter
61
+ toolbar automatically.
62
+
63
+ Use one `grow: true` column to absorb extra horizontal space.
64
+
65
+ ## Date columns: display and filter
66
+
67
+ `date`, `time` and `date-time` cells are read the same way for display and for the date filter,
68
+ in the column's display zone — `formatOptions.timeZone` when set, otherwise the viewer's local
69
+ zone:
70
+
71
+ - `'2024-03-15'` (and a `CalendarDate`) is a calendar day. It always shows and filters as
72
+ 15 March, also in zones west of UTC — it is never turned into a midnight-UTC instant.
73
+ - `Date`, epoch milliseconds, strings with an offset (`Z`, `+02:00`, DB `+02`) and
74
+ `ZonedDateTime` are instants, shown and filtered on the day they fall on in the display zone.
75
+ - A datetime without an offset (`'2024-03-15T10:30'`) is wall-clock time in the display zone.
76
+ - Unreadable values (e.g. `'2024-02-30'`) render as `-` and never match an active filter.
77
+
78
+ `date` and `date-time` columns filter by calendar-day range. The filter value is
79
+ `[from?, to?]`, each `YYYY-MM-DD` or empty (open-ended); both days are inclusive, a reversed
80
+ range is swapped, and an empty range removes the filter. Instants are judged by their calendar
81
+ day, so 23- and 25-hour DST days need no special handling. `time` columns keep the text filter.
82
+
83
+ ```ts
84
+ table.getColumn('createdAt')?.setFilterValue(['2024-03-01', '2024-03-31']); // March
85
+ table.getColumn('createdAt')?.setFilterValue([undefined, '2024-03-31']); // up to 31 March
86
+ ```
87
+
88
+ ## Select columns with multiple values
89
+
90
+ A `type: 'select'` column may return an array (tags, multi-select attributes). The Funnel then
91
+ lists each item as its own option with a row count, a row matches when any of its items is
92
+ selected, and the cell renders the items joined with `, `. A row counts once per option even
93
+ when its array repeats an item. Missing values — `null`, `undefined`, `''` or an empty array —
94
+ share one `(empty)` option.
95
+
96
+ The filter value is an array of selected options: each is the `String()` of the cell value, and
97
+ the empty option is `null` — so a real `'null'` string stays its own option:
98
+
99
+ ```ts
100
+ table.getColumn('tags')?.setFilterValue(['Battery', null]); // Battery or no tags
101
+ ```
102
+
103
+ ```ts
104
+ col.accessorFn((row) => row.tags.map((tag) => tag.name), {
105
+ id: 'tags',
106
+ header: 'Tags',
107
+ type: 'select'
108
+ });
109
+ ```
110
+
111
+ ## Locale for number/currency/percent
112
+
113
+ Priority: `formatLocale` prop → `useLocaleContext().locale` → browser default. Wrap the app in
114
+ `<LocaleProvider locale="sr-RS">` to set the context locale for every formatted column.
115
+
116
+ ## Custom cellComponent
117
+
118
+ ```svelte
119
+ <!-- PriceCell.svelte -->
120
+ <script lang="ts">
121
+ let { value, prices }: { value: number; prices: { vendor: string; price: number }[] } = $props();
122
+ </script>
123
+
124
+ <span>{value}</span>
125
+ ```
126
+
127
+ ```ts
128
+ col.accessorFn((row) => Math.min(...row.prices.map((p) => p.price)), {
129
+ id: 'minPrice',
130
+ header: 'Best Price',
131
+ type: 'currency',
132
+ align: 'right',
133
+ cellComponent: PriceCell,
134
+ cellProps: (value, row) => ({ value, prices: row.prices })
135
+ });
136
+ ```
137
+
138
+ ## Row height and cell alignment
139
+
140
+ Body cells are fixed at `h-9` (36px), matching the header, with content vertically centered — any
141
+ control up to 36px tall (every `Button` `icon-xs`/`icon-sm`/`icon`/`icon-lg` size) fits without
142
+ changing row height. Do **not** add negative margins (e.g. `-my-1`) to cell components to
143
+ compensate for row growth — in the virtualized table that fights the virtualizer's 37px row
144
+ estimate. Cells are `truncate` (single-line, `overflow: hidden`), so give action columns a little
145
+ extra `size` if a focus ring on a control near the edge gets clipped.
146
+
147
+ ## DataTable.Search
148
+
149
+ Global filter input searching across all text columns, debounced (default 300ms).
150
+
151
+ - `table: DataTableInstance<T>` — required
152
+ - `placeholder?: string` (default `'Search...'`)
153
+ - `class?: ClassValue`
154
+ - `debounceMs?: number` (default `300`)
155
+
156
+ Text/number columns stay searchable even when the first row's value is `null`/`undefined`;
157
+ booleans and object-valued columns are excluded from global search. Also available as
158
+ `VirtualDataTable.Search` for the virtualized variant.
159
+
160
+ ## DataTable.Root props
161
+
162
+ `table: DataTableInstance<T>` (required), `caption?: string` (sr-only `<caption>`),
163
+ `emptyMessage?: string` (default `'No rows found'`), `class?: ClassValue`,
164
+ `headerFilters?: boolean` (default `false`; funnel filter popups in column headers — see
165
+ "Filter from column headers" in SKILL.md),
166
+ `onRowClick?: (details: { row: T; event: MouseEvent }) => void`,
167
+ `onRowDoubleClick?: (details: { row: T; event: MouseEvent }) => void` — `row` is `row.original`.
168
+ Clicks on the row-selection checkbox and url-cell buttons do **not** trigger either handler.
169
+ `rowClass?: (row: T) => ClassValue` adds classes to the row's `<tr>` (e.g. a tint; also set
170
+ `--row-bg` so pinned and selection cells match).
171
+ `VirtualDataTable.Root` shares the same props.
172
+
173
+ ```svelte
174
+ <DataTable.Root
175
+ {table}
176
+ onRowDoubleClick={({ row, event }) => {
177
+ if (event.ctrlKey || event.metaKey) openInNewTab(row.id);
178
+ else navigateTo(row.id);
179
+ }}
180
+ />
181
+ ```