@vendure-io/ui 3.0.0-next.0 → 3.0.0-next.2
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/package.json +2 -2
- package/src/components/atoms/alert.tsx +13 -6
- package/src/components/atoms/avatar.tsx +11 -3
- package/src/components/atoms/breadcrumb.tsx +467 -53
- package/src/components/atoms/button.tsx +1 -1
- package/src/components/atoms/calendar.tsx +11 -2
- package/src/components/atoms/combobox.tsx +220 -17
- package/src/components/atoms/command.tsx +51 -130
- package/src/components/atoms/dialog.tsx +23 -1
- package/src/components/atoms/empty.tsx +1 -1
- package/src/components/atoms/field.tsx +4 -1
- package/src/components/atoms/input-group.tsx +2 -2
- package/src/components/atoms/label-swap.tsx +59 -3
- package/src/components/atoms/popover.tsx +6 -1
- package/src/components/atoms/sheet.tsx +18 -1
- package/src/components/atoms/sidebar.tsx +73 -1
- package/src/components/atoms/sonner.tsx +1 -1
- package/src/components/atoms/table.tsx +133 -10
- package/src/components/atoms/tooltip.tsx +3 -3
- package/src/components/molecules/chip.tsx +43 -4
- package/src/components/molecules/confirm-dialog.tsx +9 -0
- package/src/components/molecules/count-badge.tsx +115 -0
- package/src/components/molecules/data-table/data-table-filters.tsx +61 -21
- package/src/components/molecules/data-table/data-table-helpers.tsx +26 -1
- package/src/components/molecules/data-table/data-table-types.tsx +66 -2
- package/src/components/molecules/data-table/data-table.tsx +190 -35
- package/src/components/molecules/direction-link.tsx +1 -1
- package/src/components/molecules/format-provider.tsx +12 -2
- package/src/components/molecules/page-header.tsx +1 -1
- package/src/components/molecules/search-trigger.tsx +2 -18
- package/src/components/molecules/secret-value.tsx +6 -3
- package/src/components/molecules/state-views/loading-state.tsx +37 -7
- package/src/components/molecules/state-views/skeleton-parts.tsx +245 -0
- package/src/components/molecules/status-badge.tsx +2 -2
- package/src/components/molecules/timeline.tsx +1 -1
- package/src/hooks/use-active-label-size.ts +39 -5
- package/src/hooks/use-apple-platform.ts +26 -0
- package/src/lib/utils.ts +0 -7
|
@@ -21,6 +21,19 @@ interface ChipProps extends React.ComponentProps<'span'> {
|
|
|
21
21
|
* whenever `onRemove` is set — the × has no text otherwise.
|
|
22
22
|
*/
|
|
23
23
|
removeLabel?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Presence of this handler makes the label a button that runs it, e.g. to
|
|
26
|
+
* open an editor for the chip's value. The remove button stays a separate
|
|
27
|
+
* button after it. Absent → the label is plain text.
|
|
28
|
+
*/
|
|
29
|
+
onEdit?: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Accessible label for the edit button. Optional: without it the button is
|
|
32
|
+
* named by the chip's text.
|
|
33
|
+
*/
|
|
34
|
+
editLabel?: string;
|
|
35
|
+
/** `aria-expanded` of the edit button, while the editor it opens is open. */
|
|
36
|
+
editExpanded?: boolean;
|
|
24
37
|
/** Dims the chip and disables removal (e.g. a pending un-assign mutation). */
|
|
25
38
|
disabled?: boolean;
|
|
26
39
|
}
|
|
@@ -42,6 +55,9 @@ function Chip({
|
|
|
42
55
|
icon,
|
|
43
56
|
onRemove,
|
|
44
57
|
removeLabel,
|
|
58
|
+
onEdit,
|
|
59
|
+
editLabel,
|
|
60
|
+
editExpanded,
|
|
45
61
|
disabled,
|
|
46
62
|
children,
|
|
47
63
|
...props
|
|
@@ -61,15 +77,36 @@ function Chip({
|
|
|
61
77
|
// exempts from the contrast minimum.
|
|
62
78
|
aria-disabled={disabled || undefined}
|
|
63
79
|
className={cn(
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
// The StatusBadge shape: 24px high, the 6px corner (`rounded-lg`), the
|
|
81
|
+
// label 10px from the edge (9px of padding and the 1px border).
|
|
82
|
+
'h-6 max-w-full gap-1 rounded-lg px-2.25 [--content-inset:calc(var(--spacing)*2.5)]',
|
|
83
|
+
// The remove button sits 4px from the top, bottom and end edges: the
|
|
84
|
+
// 1px border and 3px of padding.
|
|
85
|
+
onRemove && 'pe-0.75',
|
|
66
86
|
disabled && 'pointer-events-none opacity-60',
|
|
67
87
|
className,
|
|
68
88
|
)}
|
|
69
89
|
{...props}
|
|
70
90
|
>
|
|
71
91
|
{icon}
|
|
72
|
-
|
|
92
|
+
{onEdit ? (
|
|
93
|
+
<button
|
|
94
|
+
type="button"
|
|
95
|
+
data-slot="chip-edit"
|
|
96
|
+
disabled={disabled}
|
|
97
|
+
aria-label={editLabel}
|
|
98
|
+
aria-expanded={editExpanded}
|
|
99
|
+
onClick={onEdit}
|
|
100
|
+
// The label stays text: no padding of its own, so an editable chip
|
|
101
|
+
// has the same size as a static one. The ring is drawn outside the
|
|
102
|
+
// label, 2px from its text.
|
|
103
|
+
className="min-w-0 cursor-pointer truncate rounded-sm hover:underline hover:underline-offset-2 disabled:pointer-events-none outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
|
|
104
|
+
>
|
|
105
|
+
{children}
|
|
106
|
+
</button>
|
|
107
|
+
) : (
|
|
108
|
+
<span className="truncate">{children}</span>
|
|
109
|
+
)}
|
|
73
110
|
{onRemove ? (
|
|
74
111
|
<button
|
|
75
112
|
type="button"
|
|
@@ -77,7 +114,9 @@ function Chip({
|
|
|
77
114
|
disabled={disabled}
|
|
78
115
|
aria-label={removeLabel}
|
|
79
116
|
onClick={onRemove}
|
|
80
|
-
|
|
117
|
+
// Nested in the chip's 6px corner, 4px from each edge: the concentric
|
|
118
|
+
// radius is 6px - 4px = 2px (`rounded-sm`).
|
|
119
|
+
className="ms-0.5 inline-flex size-4 shrink-0 items-center justify-center rounded-sm text-current/70 hover:bg-current/10 hover:text-current disabled:pointer-events-none outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
|
|
81
120
|
>
|
|
82
121
|
<XIcon className="size-3" />
|
|
83
122
|
</button>
|
|
@@ -92,6 +92,13 @@ interface ConfirmDialogProps {
|
|
|
92
92
|
* once, also when a mouse click opened the dialog.
|
|
93
93
|
*/
|
|
94
94
|
initialFocus?: ComponentProps<typeof AlertDialogContent>['initialFocus'];
|
|
95
|
+
/**
|
|
96
|
+
* The element that takes focus when the dialog closes. By default focus goes
|
|
97
|
+
* back to the element that opened it. Set it when that element is gone after
|
|
98
|
+
* a confirm, e.g. the row of a deleted item: return the next row, or the
|
|
99
|
+
* list's main action. Same type as Base UI's `Dialog.Popup` `finalFocus`.
|
|
100
|
+
*/
|
|
101
|
+
finalFocus?: ComponentProps<typeof AlertDialogContent>['finalFocus'];
|
|
95
102
|
/** Uncontrolled mode — the element that opens the dialog. */
|
|
96
103
|
children?: ReactElement;
|
|
97
104
|
/** Controlled mode — supply with `onOpenChange`. */
|
|
@@ -111,6 +118,7 @@ function ConfirmDialog({
|
|
|
111
118
|
confirmDisabled = false,
|
|
112
119
|
confirmDisabledReason,
|
|
113
120
|
initialFocus,
|
|
121
|
+
finalFocus,
|
|
114
122
|
children,
|
|
115
123
|
open,
|
|
116
124
|
onOpenChange,
|
|
@@ -168,6 +176,7 @@ function ConfirmDialog({
|
|
|
168
176
|
<AlertDialogContent
|
|
169
177
|
data-slot="confirm-dialog"
|
|
170
178
|
initialFocus={initialFocus ?? defaultInitialFocus}
|
|
179
|
+
finalFocus={finalFocus}
|
|
171
180
|
>
|
|
172
181
|
<AlertDialogHeader>
|
|
173
182
|
{icon ? (
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Tone } from '@vendure-io/ui/lib/state-dictionary';
|
|
2
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import type * as React from 'react';
|
|
5
|
+
|
|
6
|
+
type CountBadgeTone = Tone | 'brand';
|
|
7
|
+
type CountBadgePlacement = 'inline' | 'corner';
|
|
8
|
+
|
|
9
|
+
// A small solid count: unread notifications or alerts on an icon button, the
|
|
10
|
+
// number of active filters inside a button. The number is the whole content,
|
|
11
|
+
// so the fill is solid, not a tint: a tint at 11px does not read.
|
|
12
|
+
//
|
|
13
|
+
// `tone` takes every shared tone, so a `maxTone()` result passes in as it is,
|
|
14
|
+
// plus `brand`. `critical` takes the `destructive` slots and `progress` the
|
|
15
|
+
// `info` slots, as on StatusBadge. `neutral` is the `primary` ink (near black
|
|
16
|
+
// in light mode, light grey in dark mode): every hand-built count in the apps
|
|
17
|
+
// used it. `brand` follows accent rationing: an opt-in, not the default for
|
|
18
|
+
// unread items. Each pair is held to 4.5:1 by the tokens' contrast test.
|
|
19
|
+
//
|
|
20
|
+
// `corner` sits on the top end corner of an icon button, 16px high. Its start
|
|
21
|
+
// edge is pinned to the middle of the button, so a wider count ("99+") grows
|
|
22
|
+
// away from the icon, not over it, and mirrors in RTL. The button must be the
|
|
23
|
+
// containing block: add `relative` to it. A 2px ring in the
|
|
24
|
+
// page background cuts the count out of the icon under it. `inline` sits in
|
|
25
|
+
// the flow of a button label, 20px high, the button's gap spacing it.
|
|
26
|
+
const countBadgeVariants = cva(
|
|
27
|
+
[
|
|
28
|
+
'inline-flex shrink-0 items-center justify-center rounded-full font-medium tabular-nums whitespace-nowrap',
|
|
29
|
+
// Forced colours drop the fill; an outline keeps the pill visible.
|
|
30
|
+
'outline-1 outline-transparent -outline-offset-1',
|
|
31
|
+
],
|
|
32
|
+
{
|
|
33
|
+
variants: {
|
|
34
|
+
tone: {
|
|
35
|
+
neutral: 'bg-primary text-primary-foreground',
|
|
36
|
+
brand: 'bg-brand text-brand-foreground',
|
|
37
|
+
info: 'bg-info text-info-foreground',
|
|
38
|
+
success: 'bg-success text-success-foreground',
|
|
39
|
+
warning: 'bg-warning text-warning-foreground',
|
|
40
|
+
critical: 'bg-destructive text-destructive-foreground',
|
|
41
|
+
progress: 'bg-info text-info-foreground',
|
|
42
|
+
} satisfies Record<CountBadgeTone, string>,
|
|
43
|
+
placement: {
|
|
44
|
+
inline: 'h-5 min-w-5 px-1.5 text-xs/none',
|
|
45
|
+
corner:
|
|
46
|
+
'pointer-events-none absolute start-1/2 -top-1 h-4 min-w-4 px-1 text-2xs/none ring-2 ring-background',
|
|
47
|
+
} satisfies Record<CountBadgePlacement, string>,
|
|
48
|
+
},
|
|
49
|
+
defaultVariants: {
|
|
50
|
+
tone: 'neutral',
|
|
51
|
+
placement: 'inline',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/** The visible text: the count, or `${max}+` above the cap. */
|
|
57
|
+
function formatCount(count: number, max: number) {
|
|
58
|
+
return count > max ? `${max}+` : String(count);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface CountBadgeProps extends Omit<React.ComponentProps<'span'>, 'children'> {
|
|
62
|
+
/** The number to show. Nothing renders at 0, below 0 or for a non-finite value. */
|
|
63
|
+
count: number;
|
|
64
|
+
/** The highest number shown as is. Above it the badge reads "99+". Default 99. */
|
|
65
|
+
max?: number;
|
|
66
|
+
tone?: CountBadgeTone;
|
|
67
|
+
placement?: CountBadgePlacement;
|
|
68
|
+
/**
|
|
69
|
+
* What the count means to a screen reader, with the real number: "3 unread",
|
|
70
|
+
* "120 unread". The visible number is then hidden from it. The design system
|
|
71
|
+
* does not know the noun, so the caller writes (and translates) it. Leave it
|
|
72
|
+
* out where the text around the count already names it ("Active filters").
|
|
73
|
+
* An `aria-label` on the button replaces its content: put the count in that
|
|
74
|
+
* label instead.
|
|
75
|
+
*/
|
|
76
|
+
label?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function CountBadge({
|
|
80
|
+
count,
|
|
81
|
+
max = 99,
|
|
82
|
+
tone = 'neutral',
|
|
83
|
+
placement = 'inline',
|
|
84
|
+
label,
|
|
85
|
+
className,
|
|
86
|
+
...props
|
|
87
|
+
}: CountBadgeProps) {
|
|
88
|
+
if (!Number.isFinite(count) || count <= 0) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const text = formatCount(Math.floor(count), max);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<span
|
|
96
|
+
data-slot="count-badge"
|
|
97
|
+
data-tone={tone}
|
|
98
|
+
data-placement={placement}
|
|
99
|
+
className={cn(countBadgeVariants({ tone, placement }), className)}
|
|
100
|
+
{...props}
|
|
101
|
+
>
|
|
102
|
+
{label ? (
|
|
103
|
+
<>
|
|
104
|
+
<span aria-hidden="true">{text}</span>
|
|
105
|
+
<span className="sr-only">{label}</span>
|
|
106
|
+
</>
|
|
107
|
+
) : (
|
|
108
|
+
text
|
|
109
|
+
)}
|
|
110
|
+
</span>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { CountBadge, countBadgeVariants, formatCount };
|
|
115
|
+
export type { CountBadgePlacement, CountBadgeProps, CountBadgeTone };
|
|
@@ -129,6 +129,57 @@ function labelText(label: React.ReactNode, fallback: string): string {
|
|
|
129
129
|
return typeof label === 'string' ? label : fallback;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/** One applied filter. With `renderEditor`, its label opens the consumer's editor. */
|
|
133
|
+
function AppliedFilterChip<TData>({
|
|
134
|
+
table,
|
|
135
|
+
filterId,
|
|
136
|
+
value,
|
|
137
|
+
column,
|
|
138
|
+
removeLabel,
|
|
139
|
+
}: {
|
|
140
|
+
table: Table<TData>;
|
|
141
|
+
filterId: string;
|
|
142
|
+
value: DataTableFilterValue;
|
|
143
|
+
column: DataTableFilterColumn<TData> | undefined;
|
|
144
|
+
removeLabel: (columnLabel: string) => string;
|
|
145
|
+
}) {
|
|
146
|
+
const [editing, setEditing] = React.useState(false);
|
|
147
|
+
const anchor = React.useRef<HTMLSpanElement>(null);
|
|
148
|
+
const text = labelText(column?.label, filterId);
|
|
149
|
+
const content = column?.formatChip ? (
|
|
150
|
+
column.formatChip(value)
|
|
151
|
+
) : (
|
|
152
|
+
<>
|
|
153
|
+
{column?.label ?? filterId}: {JSON.stringify(value)}
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
const editor = column?.renderEditor;
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<>
|
|
160
|
+
<Chip
|
|
161
|
+
ref={anchor}
|
|
162
|
+
onEdit={editor ? () => setEditing((open) => !open) : undefined}
|
|
163
|
+
editExpanded={editor ? editing : undefined}
|
|
164
|
+
onRemove={() => table.getColumn(filterId)?.setFilterValue(undefined)}
|
|
165
|
+
removeLabel={removeLabel(text)}
|
|
166
|
+
>
|
|
167
|
+
{content}
|
|
168
|
+
</Chip>
|
|
169
|
+
{editor && column
|
|
170
|
+
? editor({
|
|
171
|
+
open: editing,
|
|
172
|
+
onOpenChange: setEditing,
|
|
173
|
+
anchor,
|
|
174
|
+
value,
|
|
175
|
+
onChange: (next) => table.getColumn(filterId)?.setFilterValue(next),
|
|
176
|
+
column,
|
|
177
|
+
})
|
|
178
|
+
: null}
|
|
179
|
+
</>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
132
183
|
interface DataTableAppliedFiltersProps<TData> {
|
|
133
184
|
table: Table<TData>;
|
|
134
185
|
columns?: DataTableFilterColumn<TData>[];
|
|
@@ -149,27 +200,16 @@ function DataTableAppliedFilters<TData>({
|
|
|
149
200
|
|
|
150
201
|
const columnMap = new Map((columns ?? []).map((column) => [column.id, column]));
|
|
151
202
|
|
|
152
|
-
const chipFor = (filter: (typeof applied)[number]) =>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
<Chip
|
|
165
|
-
key={filter.id}
|
|
166
|
-
onRemove={() => table.getColumn(filter.id)?.setFilterValue(undefined)}
|
|
167
|
-
removeLabel={removeLabel(text)}
|
|
168
|
-
>
|
|
169
|
-
{content}
|
|
170
|
-
</Chip>
|
|
171
|
-
);
|
|
172
|
-
};
|
|
203
|
+
const chipFor = (filter: (typeof applied)[number]) => (
|
|
204
|
+
<AppliedFilterChip
|
|
205
|
+
key={filter.id}
|
|
206
|
+
table={table}
|
|
207
|
+
filterId={filter.id}
|
|
208
|
+
value={filter.value as DataTableFilterValue}
|
|
209
|
+
column={columnMap.get(filter.id)}
|
|
210
|
+
removeLabel={removeLabel}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
173
213
|
|
|
174
214
|
const inline = applied.slice(0, inlineChipLimit);
|
|
175
215
|
const overflow = applied.slice(inlineChipLimit);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Column, ColumnDef, RowSelectionState, Table } from '@tanstack/react-table';
|
|
2
2
|
import type {
|
|
3
3
|
ControlledState,
|
|
4
|
+
DataTableClearFilters,
|
|
4
5
|
DataTableColumnMeta,
|
|
5
6
|
} from '@vendure-io/ui/components/molecules/data-table/data-table-types';
|
|
6
7
|
|
|
@@ -46,6 +47,25 @@ export function getHideableLeafColumns<TData>(table: Table<TData>): Column<TData
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/** Resolve a render-prop-or-node slot against the live table instance. */
|
|
50
|
+
/**
|
|
51
|
+
* The "Clear filters" button after the chips, or undefined when it is off.
|
|
52
|
+
* `emptyCell`: the table shows its empty state (no rows, not loading). The
|
|
53
|
+
* button hides there unless the consumer sets `hidden`. Default click: remove
|
|
54
|
+
* every applied filter.
|
|
55
|
+
*/
|
|
56
|
+
export function resolveClearFilters<TData>(
|
|
57
|
+
option: boolean | DataTableClearFilters | undefined,
|
|
58
|
+
table: Pick<Table<TData>, 'setColumnFilters'>,
|
|
59
|
+
emptyCell: boolean,
|
|
60
|
+
): { hidden: boolean; onClear: () => void } | undefined {
|
|
61
|
+
if (!option) return undefined;
|
|
62
|
+
const config = option === true ? {} : option;
|
|
63
|
+
return {
|
|
64
|
+
hidden: config.hidden ?? emptyCell,
|
|
65
|
+
onClear: config.onClear ?? (() => table.setColumnFilters([])),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
49
69
|
export function resolveSlot<TData, TSlot>(
|
|
50
70
|
slot: TSlot | ((table: Table<TData>) => TSlot) | undefined,
|
|
51
71
|
table: Table<TData>,
|
|
@@ -103,7 +123,12 @@ export function measureColumnIndents(table: HTMLTableElement): Record<string, nu
|
|
|
103
123
|
for (const cell of cells) {
|
|
104
124
|
const id = cell.dataset.columnId;
|
|
105
125
|
const first = cell.firstElementChild;
|
|
106
|
-
|
|
126
|
+
// A pinned table's row-link overlay host comes after the content, so it is
|
|
127
|
+
// first only in a cell without content elements. It is not content: its
|
|
128
|
+
// overlay spans the whole row.
|
|
129
|
+
const host =
|
|
130
|
+
(first as HTMLElement | null)?.dataset?.slot === 'data-table-row-link-overlay-host';
|
|
131
|
+
if (id == null || first == null || host) continue;
|
|
107
132
|
const style = getComputedStyle(cell);
|
|
108
133
|
const rtl = style.direction === 'rtl';
|
|
109
134
|
const start = (rect: DOMRect) => (rtl ? -rect.right : rect.left);
|
|
@@ -122,6 +122,24 @@ export interface DataTableFilterColumn<TData = unknown> {
|
|
|
122
122
|
* passes its human-readable-operator formatter here.
|
|
123
123
|
*/
|
|
124
124
|
formatChip?: (value: DataTableFilterValue) => React.ReactNode;
|
|
125
|
+
/**
|
|
126
|
+
* Makes the column's applied-filter chip editable. Present → the chip label
|
|
127
|
+
* is a button that opens this editor, and the consumer renders the whole
|
|
128
|
+
* popup (a Popover, a Combobox, a Dialog) controlled by `open`. Anchor a
|
|
129
|
+
* positioned popup to `anchor`, the chip. Absent → the chip only removes.
|
|
130
|
+
*/
|
|
131
|
+
renderEditor?: (ctx: DataTableFilterEditorContext<TData>) => React.ReactNode;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface DataTableFilterEditorContext<TData = unknown> {
|
|
135
|
+
/** Whether the editor is open. The chip label opens it. */
|
|
136
|
+
open: boolean;
|
|
137
|
+
onOpenChange: (open: boolean) => void;
|
|
138
|
+
/** The applied-filter chip, to anchor a positioned popup to. */
|
|
139
|
+
anchor: React.RefObject<HTMLElement | null>;
|
|
140
|
+
value: DataTableFilterValue | undefined;
|
|
141
|
+
onChange: (next: DataTableFilterValue | undefined) => void;
|
|
142
|
+
column: DataTableFilterColumn<TData>;
|
|
125
143
|
}
|
|
126
144
|
|
|
127
145
|
export type DataTableFilters<TData> = ControlledState<ColumnFiltersState> & {
|
|
@@ -141,8 +159,28 @@ export type DataTableFilters<TData> = ControlledState<ColumnFiltersState> & {
|
|
|
141
159
|
showAddFilter?: boolean;
|
|
142
160
|
/** Defaults to true. Set false when a consumer renders its own applied-filter UI. */
|
|
143
161
|
showAppliedFilters?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* A "Clear filters" button after the applied-filter chips. Off by default.
|
|
164
|
+
* `true` or an object turns it on. It shows only with a chip: a search has
|
|
165
|
+
* the clear of its own field. While the table shows its empty state (no
|
|
166
|
+
* rows, not loading), the empty state holds the only "Clear filters", so the
|
|
167
|
+
* button hides. The chip line keeps the button's height either way, so the
|
|
168
|
+
* table does not move when it shows or hides.
|
|
169
|
+
*/
|
|
170
|
+
clearFilters?: boolean | DataTableClearFilters;
|
|
144
171
|
};
|
|
145
172
|
|
|
173
|
+
export interface DataTableClearFilters {
|
|
174
|
+
/** Runs on click. Default: removes every applied filter. */
|
|
175
|
+
onClear?: () => void;
|
|
176
|
+
/**
|
|
177
|
+
* Hides the button while a chip applies. Default: true while the table
|
|
178
|
+
* shows its empty state (no rows, not loading). Set it when the consumer
|
|
179
|
+
* knows better, e.g. loading passed through `emptyState`.
|
|
180
|
+
*/
|
|
181
|
+
hidden?: boolean;
|
|
182
|
+
}
|
|
183
|
+
|
|
146
184
|
export interface DataTableBulkActionContext<TData> {
|
|
147
185
|
/**
|
|
148
186
|
* `row.original` of the selected rows the table has loaded, from the core's
|
|
@@ -187,11 +225,14 @@ export interface DataTableRowRipple {
|
|
|
187
225
|
* (`<TableCell {...cellProps(cell.column.id)}>`) and the cell matches the
|
|
188
226
|
* built-in row: the select cell is the zero-width cell the checkbox floats
|
|
189
227
|
* over, the leading data cell carries the checkbox gutter, and every cell
|
|
190
|
-
* lines its content up with the header.
|
|
228
|
+
* lines its content up with the header. With `pinFirstColumn`, the leading
|
|
229
|
+
* data cell carries `data-pinned`, so it stays at the edge with the select
|
|
230
|
+
* cell. Merge your own classes with `cn`.
|
|
191
231
|
*/
|
|
192
232
|
export interface DataTableRowCellProps {
|
|
193
233
|
'data-column-id': string;
|
|
194
234
|
'data-content-inset-cell': string;
|
|
235
|
+
'data-pinned': '' | undefined;
|
|
195
236
|
className: string;
|
|
196
237
|
style: React.CSSProperties | undefined;
|
|
197
238
|
}
|
|
@@ -227,6 +268,7 @@ export interface DataTableLabels {
|
|
|
227
268
|
columnsTrigger?: string; // 'Columns'
|
|
228
269
|
columnsHeading?: string; // 'Toggle columns'
|
|
229
270
|
addFilter?: string; // 'Add filter'
|
|
271
|
+
clearFilters?: string; // 'Clear filters'
|
|
230
272
|
removeFilter?: (columnLabel: string) => string; // (l) => `Remove ${l} filter`
|
|
231
273
|
sortLabel?: (columnLabel: string) => string; // (c) => `Sort by ${c}`
|
|
232
274
|
filtersCollapsed?: (count: number) => string; // (n) => `${n} filters`
|
|
@@ -342,7 +384,9 @@ export interface DataTableProps<TData> {
|
|
|
342
384
|
* are selected; a row without it keeps opening the item from anywhere on it.
|
|
343
385
|
* A row with a `DataTableRowLink` needs nothing more: the table raises its
|
|
344
386
|
* buttons, links, inputs and copy chips above the stretched link, as it does
|
|
345
|
-
* on a built-in row.
|
|
387
|
+
* on a built-in row. With `pinFirstColumn`, render `ctx.rowLinkHost(columnId)`
|
|
388
|
+
* at the end of every cell too, so the whole row opens the item (see
|
|
389
|
+
* `pinFirstColumn`).
|
|
346
390
|
*/
|
|
347
391
|
renderRow?: (
|
|
348
392
|
row: Row<TData>,
|
|
@@ -352,6 +396,13 @@ export interface DataTableProps<TData> {
|
|
|
352
396
|
defaultRow: React.ReactNode;
|
|
353
397
|
ripple: DataTableRowRipple;
|
|
354
398
|
cellProps: (columnId: string) => DataTableRowCellProps;
|
|
399
|
+
/**
|
|
400
|
+
* Where a `DataTableRowLink` draws the anchor that opens the item from
|
|
401
|
+
* the cells on the other side of the pinned edge. Render it as the last
|
|
402
|
+
* child of every cell: `{ctx.rowLinkHost(cell.column.id)}`. It is `null`
|
|
403
|
+
* without `pinFirstColumn`, and in the cells that need no host.
|
|
404
|
+
*/
|
|
405
|
+
rowLinkHost: (columnId: string) => React.ReactNode;
|
|
355
406
|
selectProps: DataTableRowSelectProps;
|
|
356
407
|
},
|
|
357
408
|
) => React.ReactNode;
|
|
@@ -396,6 +447,19 @@ export interface DataTableProps<TData> {
|
|
|
396
447
|
* edge-cell alignment — the host card is the frame.
|
|
397
448
|
*/
|
|
398
449
|
frame?: 'card' | 'plain';
|
|
450
|
+
/**
|
|
451
|
+
* Keeps the first column in place while the others scroll sideways (Table's
|
|
452
|
+
* `pinFirstColumn`). The select checkbox is pinned with it, and a selected
|
|
453
|
+
* row's bar stays on the pinned edge. A `DataTableRowLink` still opens the
|
|
454
|
+
* item from every cell: the name stays the row's one link, and the cells
|
|
455
|
+
* that scroll under the pinned column open it through a second anchor with
|
|
456
|
+
* the same href, hidden from assistive technology and the tab order. A row
|
|
457
|
+
* from `renderRow` that renders its own cells gets that anchor when it
|
|
458
|
+
* renders `ctx.rowLinkHost(cell.column.id)` after the content of every cell;
|
|
459
|
+
* without it, only the cells on the link's side of the pinned edge open the
|
|
460
|
+
* item.
|
|
461
|
+
*/
|
|
462
|
+
pinFirstColumn?: boolean;
|
|
399
463
|
/**
|
|
400
464
|
* Extra `<TableRow>`s appended inside `TableBody` after the data rows — e.g.
|
|
401
465
|
* an order table's subtotal/shipping/total rows. Rendered only alongside
|