@bmsuisse/datagrid 0.37.0 → 0.38.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/README.md +24 -0
- package/dist/index.d.ts +110 -9
- package/dist/index.js +442 -354
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,30 @@ const columns: ColumnDef<Row>[] = [
|
|
|
27
27
|
<DataGrid columns={columns} dataSource={{ mode: "client", data: rows }} />;
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
### Translating the filter UI
|
|
31
|
+
|
|
32
|
+
Filter widgets ship with English strings. Pass `filterLabels` (a
|
|
33
|
+
`Partial<FilterLabels>`; anything omitted keeps its default from
|
|
34
|
+
`defaultFilterLabels`) to translate them:
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { de } from "date-fns/locale";
|
|
38
|
+
|
|
39
|
+
<DataGrid
|
|
40
|
+
columns={columns}
|
|
41
|
+
dataSource={{ mode: "client", data: rows }}
|
|
42
|
+
filterLabels={{
|
|
43
|
+
selectAll: "Alle auswählen",
|
|
44
|
+
searchPlaceholder: (header) => `${header} suchen…`,
|
|
45
|
+
filterAriaLabel: (header) => `${header} filtern`,
|
|
46
|
+
dateLocale: de,
|
|
47
|
+
}}
|
|
48
|
+
/>;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Widgets rendered outside a `<DataGrid>` read the same labels from a
|
|
52
|
+
`<FilterLabelsProvider labels={…}>`, or take a per-widget `labels` prop.
|
|
53
|
+
|
|
30
54
|
See [AGENTS.md](../../AGENTS.md) for the full design rationale, and
|
|
31
55
|
`packages/datagrid/demo` for a runnable example against both a SQL and a
|
|
32
56
|
Meilisearch backend.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Locale } from 'date-fns';
|
|
1
2
|
import { ReactNode, ReactElement, MouseEvent, ComponentType, RefObject } from 'react';
|
|
2
3
|
import { ColumnSizingState, RowData } from '@tanstack/react-table';
|
|
3
4
|
export { ColumnSizingState } from '@tanstack/react-table';
|
|
@@ -62,6 +63,92 @@ declare function fieldKey(field: string | string[]): string;
|
|
|
62
63
|
*/
|
|
63
64
|
declare function evaluateFilter<TRow>(row: TRow, filter: CompositeFilterDescriptor | FilterDescriptor | null | undefined): boolean;
|
|
64
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Every user-facing string the built-in filter widgets (and `<DataGrid>`'s
|
|
68
|
+
* own header filter trigger) render. This package has no translation/i18n
|
|
69
|
+
* layer — same convention as `EditingOptions.saveLabel`/`discardLabel`:
|
|
70
|
+
* you supply already-translated strings (or, for templated ones, a
|
|
71
|
+
* function) and the English defaults in `defaultFilterLabels` apply to
|
|
72
|
+
* anything you leave out. See #72.
|
|
73
|
+
*
|
|
74
|
+
* Supply them via `<DataGrid filterLabels>`, a `<FilterLabelsProvider>`
|
|
75
|
+
* around any widgets you render yourself (custom `renderFilter`,
|
|
76
|
+
* `renderHeader`, standalone use), or a single widget's own `labels` prop —
|
|
77
|
+
* innermost wins, each merged over the one outside it.
|
|
78
|
+
*/
|
|
79
|
+
interface FilterLabels {
|
|
80
|
+
/** Accessible name of every filter trigger button (the header funnel icon and each widget's own `bare={false}` trigger). */
|
|
81
|
+
filterAriaLabel: (header: string) => string;
|
|
82
|
+
/** EnumFilter search input placeholder. */
|
|
83
|
+
searchPlaceholder: (header: string) => string;
|
|
84
|
+
/** EnumFilter "Select all" checkbox label (acts on the currently visible options). */
|
|
85
|
+
selectAll: string;
|
|
86
|
+
/** Accessible name of an EnumFilter group header's tri-state checkbox. */
|
|
87
|
+
selectAllOfGroup: (group: string) => string;
|
|
88
|
+
/** EnumFilter empty-search message. */
|
|
89
|
+
noMatches: string;
|
|
90
|
+
/** EnumFilter `bare={false}` trigger summary once something is selected. */
|
|
91
|
+
selectedCount: (count: number) => string;
|
|
92
|
+
stringPlaceholder: (header: string) => string;
|
|
93
|
+
stringContains: string;
|
|
94
|
+
stringIs: string;
|
|
95
|
+
stringStartsWith: string;
|
|
96
|
+
stringEndsWith: string;
|
|
97
|
+
/** Accessible name of the StringFilter/NumberComparisonFilter operator dropdown. */
|
|
98
|
+
operatorAriaLabel: (header: string) => string;
|
|
99
|
+
booleanAll: string;
|
|
100
|
+
booleanYes: string;
|
|
101
|
+
booleanNo: string;
|
|
102
|
+
/** Accessible name of the BooleanFilter select. */
|
|
103
|
+
booleanAriaLabel: (header: string) => string;
|
|
104
|
+
minPlaceholder: string;
|
|
105
|
+
maxPlaceholder: string;
|
|
106
|
+
valuePlaceholder: string;
|
|
107
|
+
/** The small word between the min and max inputs. */
|
|
108
|
+
rangeSeparator: string;
|
|
109
|
+
minimumAriaLabel: (header: string) => string;
|
|
110
|
+
maximumAriaLabel: (header: string) => string;
|
|
111
|
+
minimumSliderAriaLabel: (header: string) => string;
|
|
112
|
+
maximumSliderAriaLabel: (header: string) => string;
|
|
113
|
+
numberGreaterThan: string;
|
|
114
|
+
numberGreaterThanOrEqual: string;
|
|
115
|
+
numberLessThan: string;
|
|
116
|
+
numberLessThanOrEqual: string;
|
|
117
|
+
numberEquals: string;
|
|
118
|
+
numberNotEquals: string;
|
|
119
|
+
numberBetween: string;
|
|
120
|
+
/** NumberHistogramFilter's clear button. */
|
|
121
|
+
clear: string;
|
|
122
|
+
/** NumberHistogramFilter's `loadValues` in-flight message. */
|
|
123
|
+
loading: string;
|
|
124
|
+
dateToday: string;
|
|
125
|
+
dateLast7Days: string;
|
|
126
|
+
dateThisMonth: string;
|
|
127
|
+
dateCustom: string;
|
|
128
|
+
/**
|
|
129
|
+
* date-fns locale for DateRangeFilter's calendar (month/weekday names,
|
|
130
|
+
* first day of week) and its trigger summary. Unset keeps date-fns'/
|
|
131
|
+
* react-day-picker's own default (en-US), exactly as before.
|
|
132
|
+
*/
|
|
133
|
+
dateLocale?: Locale;
|
|
134
|
+
}
|
|
135
|
+
/** English defaults — byte-for-byte the strings every widget rendered before `FilterLabels` existed. */
|
|
136
|
+
declare const defaultFilterLabels: FilterLabels;
|
|
137
|
+
/** Merges `overrides` over `base`, ignoring keys explicitly set to `undefined` (so `{ selectAll: maybeT }` never blanks a default). */
|
|
138
|
+
declare function mergeFilterLabels(base: FilterLabels, overrides: Partial<FilterLabels> | undefined): FilterLabels;
|
|
139
|
+
/**
|
|
140
|
+
* Supplies `labels` to every filter widget below it, merged over any
|
|
141
|
+
* enclosing provider's (or the English defaults). `<DataGrid filterLabels>`
|
|
142
|
+
* renders one of these itself; use it directly around widgets you render
|
|
143
|
+
* outside a `<DataGrid>`.
|
|
144
|
+
*/
|
|
145
|
+
declare function FilterLabelsProvider({ labels, children, }: {
|
|
146
|
+
labels: Partial<FilterLabels> | undefined;
|
|
147
|
+
children: ReactNode;
|
|
148
|
+
}): ReactElement;
|
|
149
|
+
/** The effective labels here: context (or defaults), with an optional per-widget `overrides` merged on top. */
|
|
150
|
+
declare function useFilterLabels(overrides?: Partial<FilterLabels>): FilterLabels;
|
|
151
|
+
|
|
65
152
|
/**
|
|
66
153
|
* Contract every built-in filter widget implements. `TColumn` is narrowed to
|
|
67
154
|
* the specific column shape the widget knows how to render (e.g. `EnumColumn`
|
|
@@ -70,11 +157,16 @@ declare function evaluateFilter<TRow>(row: TRow, filter: CompositeFilterDescript
|
|
|
70
157
|
*
|
|
71
158
|
* `value` is the current FilterDescriptor for this column, or undefined when
|
|
72
159
|
* no filter is applied. `onChange(undefined)` clears the filter entirely.
|
|
160
|
+
*
|
|
161
|
+
* `labels` overrides this one widget's user-facing strings, merged over
|
|
162
|
+
* whatever an enclosing `<FilterLabelsProvider>`/`<DataGrid filterLabels>`
|
|
163
|
+
* supplies (see `FilterLabels`).
|
|
73
164
|
*/
|
|
74
165
|
interface FilterWidgetProps<TColumn> {
|
|
75
166
|
column: TColumn;
|
|
76
167
|
value: FilterDescriptor | undefined;
|
|
77
168
|
onChange: (next: FilterDescriptor | undefined) => void;
|
|
169
|
+
labels?: Partial<FilterLabels>;
|
|
78
170
|
}
|
|
79
171
|
|
|
80
172
|
/** Horizontal alignment used for a column's cell content and header. */
|
|
@@ -293,7 +385,7 @@ declare function isEditable<TRow>(column: ColumnDef<TRow>, row: TRow): boolean;
|
|
|
293
385
|
* `bare` doc for why (`renderDefaultFilterWidget` passes this automatically
|
|
294
386
|
* outside `filterDisplay: "row"`).
|
|
295
387
|
*/
|
|
296
|
-
declare function BooleanFilter<TRow>({ column, value, onChange, bare, }: FilterWidgetProps<BooleanColumn<TRow>> & {
|
|
388
|
+
declare function BooleanFilter<TRow>({ column, value, onChange, bare, labels: labelOverrides, }: FilterWidgetProps<BooleanColumn<TRow>> & {
|
|
297
389
|
bare?: boolean;
|
|
298
390
|
}): ReactElement;
|
|
299
391
|
|
|
@@ -312,7 +404,7 @@ declare function BooleanFilter<TRow>({ column, value, onChange, bare, }: FilterW
|
|
|
312
404
|
* `EnumFilter`'s identical `bare` doc for why (`renderDefaultFilterWidget`
|
|
313
405
|
* passes this automatically outside `filterDisplay: "row"`).
|
|
314
406
|
*/
|
|
315
|
-
declare function DateRangeFilter<TRow>({ column, value, onChange, today, bare, }: FilterWidgetProps<DateColumn<TRow>> & {
|
|
407
|
+
declare function DateRangeFilter<TRow>({ column, value, onChange, today, bare, labels: labelOverrides, }: FilterWidgetProps<DateColumn<TRow>> & {
|
|
316
408
|
today?: Date;
|
|
317
409
|
bare?: boolean;
|
|
318
410
|
}): ReactElement;
|
|
@@ -354,7 +446,7 @@ declare function DateRangeFilter<TRow>({ column, value, onChange, today, bare, }
|
|
|
354
446
|
* "row"`, so `<DataGrid>`'s own header-icon popover isn't nested inside a
|
|
355
447
|
* second one of this component's own).
|
|
356
448
|
*/
|
|
357
|
-
declare function EnumFilter<TRow>({ column, value, onChange, bare, }: FilterWidgetProps<EnumColumn<TRow>> & {
|
|
449
|
+
declare function EnumFilter<TRow>({ column, value, onChange, bare, labels: labelOverrides, }: FilterWidgetProps<EnumColumn<TRow>> & {
|
|
358
450
|
bare?: boolean;
|
|
359
451
|
}): ReactElement;
|
|
360
452
|
|
|
@@ -387,7 +479,7 @@ declare function EnumFilter<TRow>({ column, value, onChange, bare, }: FilterWidg
|
|
|
387
479
|
* column also sets `filterDisplay: "row"`, where nothing else provides a
|
|
388
480
|
* trigger — see `NumberHistogramFilter`'s identical `bare` doc for why.
|
|
389
481
|
*/
|
|
390
|
-
declare function NumberComparisonFilter<TRow>({ column, value, onChange, bare, }: FilterWidgetProps<NumberColumn<TRow>> & {
|
|
482
|
+
declare function NumberComparisonFilter<TRow>({ column, value, onChange, bare, labels: labelOverrides, }: FilterWidgetProps<NumberColumn<TRow>> & {
|
|
391
483
|
bare?: boolean;
|
|
392
484
|
}): ReactElement;
|
|
393
485
|
|
|
@@ -418,7 +510,7 @@ declare function NumberComparisonFilter<TRow>({ column, value, onChange, bare, }
|
|
|
418
510
|
* (bare: false) is what keeps a plain numeric column from forcing its whole
|
|
419
511
|
* column wider than its data ever needs.
|
|
420
512
|
*/
|
|
421
|
-
declare function NumberRangeFilter<TRow>({ column, value, onChange, bare, }: FilterWidgetProps<NumberColumn<TRow>> & {
|
|
513
|
+
declare function NumberRangeFilter<TRow>({ column, value, onChange, bare, labels: labelOverrides, }: FilterWidgetProps<NumberColumn<TRow>> & {
|
|
422
514
|
bare?: boolean;
|
|
423
515
|
}): ReactElement;
|
|
424
516
|
|
|
@@ -498,7 +590,7 @@ type NumberHistogramFilterProps<TRow> = FilterWidgetProps<NumberColumn<TRow>> &
|
|
|
498
590
|
* `facetedNumberValues(data, column, filter)` in client mode, or supply
|
|
499
591
|
* `loadValues` to fetch the facet from the server in server mode.
|
|
500
592
|
*/
|
|
501
|
-
declare function NumberHistogramFilter<TRow>({ column, value, onChange, allValues, loadValues, format, buckets, bare, }: NumberHistogramFilterProps<TRow>): ReactElement;
|
|
593
|
+
declare function NumberHistogramFilter<TRow>({ column, value, onChange, allValues, loadValues, format, buckets, bare, labels: labelOverrides, }: NumberHistogramFilterProps<TRow>): ReactElement;
|
|
502
594
|
|
|
503
595
|
type FilterNode = FilterDescriptor | CompositeFilterDescriptor;
|
|
504
596
|
/**
|
|
@@ -531,7 +623,7 @@ declare function facetedNumberValues<TRow>(data: readonly TRow[], column: Column
|
|
|
531
623
|
* identical `bare` doc for why (`renderDefaultFilterWidget` passes this
|
|
532
624
|
* automatically outside `filterDisplay: "row"`).
|
|
533
625
|
*/
|
|
534
|
-
declare function StringFilter<TRow>({ column, value, onChange, bare, }: FilterWidgetProps<StringColumn<TRow>> & {
|
|
626
|
+
declare function StringFilter<TRow>({ column, value, onChange, bare, labels: labelOverrides, }: FilterWidgetProps<StringColumn<TRow>> & {
|
|
535
627
|
bare?: boolean;
|
|
536
628
|
}): ReactElement;
|
|
537
629
|
|
|
@@ -1690,6 +1782,15 @@ interface DataGridProps<TRow> {
|
|
|
1690
1782
|
* See `CellEditingOptions` for the full contract.
|
|
1691
1783
|
*/
|
|
1692
1784
|
cellEditing?: CellEditingOptions<TRow>;
|
|
1785
|
+
/**
|
|
1786
|
+
* Overrides the user-facing strings of every column-filter UI this grid
|
|
1787
|
+
* renders — the header filter trigger's accessible name and every
|
|
1788
|
+
* built-in filter widget (including ones a column's own `renderFilter`
|
|
1789
|
+
* renders, via context). Anything omitted keeps its English default from
|
|
1790
|
+
* `defaultFilterLabels`, so leaving this unset changes nothing. See
|
|
1791
|
+
* `FilterLabels` for every key (#72).
|
|
1792
|
+
*/
|
|
1793
|
+
filterLabels?: Partial<FilterLabels>;
|
|
1693
1794
|
}
|
|
1694
1795
|
|
|
1695
1796
|
/**
|
|
@@ -1700,7 +1801,7 @@ interface DataGridProps<TRow> {
|
|
|
1700
1801
|
* (`"server"`). Column filter UI defaults to the type-appropriate widget
|
|
1701
1802
|
* from `src/filter` unless a column supplies its own `cell` renderer.
|
|
1702
1803
|
*/
|
|
1703
|
-
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, onGridStateChange, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, showTotals, editing, cellEditing, }: DataGridProps<TRow>): ReactElement;
|
|
1804
|
+
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, onGridStateChange, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, showTotals, editing, cellEditing, filterLabels, }: DataGridProps<TRow>): ReactElement;
|
|
1704
1805
|
|
|
1705
1806
|
interface GridStateController {
|
|
1706
1807
|
state: GridState;
|
|
@@ -2171,4 +2272,4 @@ interface UseTreeStateOptions<TRow> extends TreeAccessors<TRow> {
|
|
|
2171
2272
|
*/
|
|
2172
2273
|
declare function useTreeState<TRow>({ data, getRowId, getChildren, hasChildren, onLoadChildren, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, }: UseTreeStateOptions<TRow>): TreeStateController<TRow>;
|
|
2173
2274
|
|
|
2174
|
-
export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanEditor, BooleanFilter, type CellAddress, type CellChange, type CellEditingCellContext, type CellEditingOptions, type CellEditingState, type CellRange, type CellSelectionController, type CellSelectionOptions, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateEditor, DateRangeFilter, type DebouncedCallback, EditFieldError, type EditWidgetProps, type EditedRow, EditingBar, type EditingBarProps, type EditingCellContext, type EditingOptions, type EditingState, type EnumColumn, EnumEditor, EnumFilter, type EnumOption, type FilterDescriptor, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type GroupExpansionController, type MenuItem, type MenuItemContext, MultilineStringEditor, type NavigationDirection, type NormalizedRange, type NumberColumn, NumberComparisonFilter, NumberEditor, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type PendingRowEdit, type ResolvedMenuItem, SelectionOverlay, type SortDescriptor, type StickyGroupHeaderTop, type StringColumn, StringEditor, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, applyColumnOrder, buildIndexMap, canHideColumn, canHideGroup, cellsInRange, coerceValueForColumn, computeFillChanges, countVisible, defaultAlign, defaultFormat, editErrorId, evaluateFilter, extendRangeForFill, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isCellInRange, isColumnVisible, isCompositeFilterDescriptor, isEditable, isFilterDescriptor, isFilterable, isSortable, moveColumnBefore, normalizeRange, orderStorageKeyFor, parseTsv, processClientData, rangeToTsv, renderCellModeCell, renderDefaultEditWidget, renderDefaultFilterWidget, renderEditableCell, resolveMenuItems, storageKeyFor, toDate, useCellEditingState, useCellSelection, useDebouncedCallback, useEditingState, useGridState, useGroupExpansion, useStickyGroupHeaderTop, useTreeState, useVisibleColumns };
|
|
2275
|
+
export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanEditor, BooleanFilter, type CellAddress, type CellChange, type CellEditingCellContext, type CellEditingOptions, type CellEditingState, type CellRange, type CellSelectionController, type CellSelectionOptions, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateEditor, DateRangeFilter, type DebouncedCallback, EditFieldError, type EditWidgetProps, type EditedRow, EditingBar, type EditingBarProps, type EditingCellContext, type EditingOptions, type EditingState, type EnumColumn, EnumEditor, EnumFilter, type EnumOption, type FilterDescriptor, type FilterLabels, FilterLabelsProvider, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type GroupExpansionController, type MenuItem, type MenuItemContext, MultilineStringEditor, type NavigationDirection, type NormalizedRange, type NumberColumn, NumberComparisonFilter, NumberEditor, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type PendingRowEdit, type ResolvedMenuItem, SelectionOverlay, type SortDescriptor, type StickyGroupHeaderTop, type StringColumn, StringEditor, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, applyColumnOrder, buildIndexMap, canHideColumn, canHideGroup, cellsInRange, coerceValueForColumn, computeFillChanges, countVisible, defaultAlign, defaultFilterLabels, defaultFormat, editErrorId, evaluateFilter, extendRangeForFill, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isCellInRange, isColumnVisible, isCompositeFilterDescriptor, isEditable, isFilterDescriptor, isFilterable, isSortable, mergeFilterLabels, moveColumnBefore, normalizeRange, orderStorageKeyFor, parseTsv, processClientData, rangeToTsv, renderCellModeCell, renderDefaultEditWidget, renderDefaultFilterWidget, renderEditableCell, resolveMenuItems, storageKeyFor, toDate, useCellEditingState, useCellSelection, useDebouncedCallback, useEditingState, useFilterLabels, useGridState, useGroupExpansion, useStickyGroupHeaderTop, useTreeState, useVisibleColumns };
|