@gntik-ai/blocks 0.9.0 → 0.11.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/dist/index.d.ts +426 -55
- package/dist/index.js +2275 -639
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.labels.test.tsx +179 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +59 -24
- package/src/auth/ForgotPasswordForm/block.meta.ts +22 -1
- package/src/auth/ForgotPasswordForm/examples/Labels.tsx +29 -0
- package/src/auth/MfaChallenge/MfaChallenge.labels.test.tsx +139 -0
- package/src/auth/MfaChallenge/MfaChallenge.tsx +69 -23
- package/src/auth/MfaChallenge/block.meta.ts +29 -1
- package/src/auth/MfaChallenge/examples/Labels.tsx +28 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.labels.test.tsx +104 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +42 -15
- package/src/auth/ResetPasswordForm/block.meta.ts +17 -1
- package/src/auth/ResetPasswordForm/examples/Labels.tsx +28 -0
- package/src/auth/SignInForm/SignInForm.labels.test.tsx +137 -0
- package/src/auth/SignInForm/SignInForm.tsx +43 -16
- package/src/auth/SignInForm/block.meta.ts +22 -1
- package/src/auth/SignInForm/examples/Labels.tsx +29 -0
- package/src/auth/SignUpForm/SignUpForm.labels.test.tsx +217 -0
- package/src/auth/SignUpForm/SignUpForm.tsx +65 -26
- package/src/auth/SignUpForm/block.meta.ts +27 -1
- package/src/auth/SignUpForm/examples/Labels.tsx +29 -0
- package/src/auth/SsoButtons/SsoButtons.labels.test.tsx +30 -0
- package/src/auth/SsoButtons/SsoButtons.tsx +10 -2
- package/src/auth/SsoButtons/block.meta.ts +8 -1
- package/src/auth/SsoButtons/examples/Labels.tsx +24 -0
- package/src/auth/shared.i18n.test.tsx +71 -0
- package/src/auth/shared.tsx +48 -11
- package/src/billing/CostBreakdown/CostBreakdown.test.tsx +10 -0
- package/src/billing/CostBreakdown/CostBreakdown.tsx +50 -43
- package/src/billing/SpendVsBudget/SpendVsBudget.test.tsx +10 -0
- package/src/billing/SpendVsBudget/SpendVsBudget.tsx +35 -31
- package/src/builders/FlowBuilder/FlowBuilder.test.tsx +237 -2
- package/src/builders/FlowBuilder/FlowBuilder.tsx +101 -29
- package/src/builders/FlowBuilder/block.meta.ts +1 -1
- package/src/builders/FlowBuilder/connections.ts +30 -12
- package/src/builders/FlowBuilder/examples/ControlledGraph.tsx +8 -0
- package/src/builders/FlowBuilder/graph-state.ts +78 -0
- package/src/builders/LogViewer/LogViewer.labels.test.tsx +90 -0
- package/src/builders/LogViewer/LogViewer.levels.test.tsx +49 -0
- package/src/builders/LogViewer/LogViewer.tsx +72 -18
- package/src/builders/LogViewer/LogViewer.wrap.test.tsx +181 -0
- package/src/builders/LogViewer/block.meta.ts +19 -1
- package/src/builders/LogViewer/examples/Spanish.tsx +30 -0
- package/src/builders/LogViewer/examples/Wrap.tsx +62 -0
- package/src/builders/LogViewer/use-wrapped-log-rows.ts +42 -0
- package/src/data-display/ChartCard/ChartCard.locale.test.tsx +15 -0
- package/src/data-display/ChartCard/ChartCard.test.tsx +9 -0
- package/src/data-display/ChartCard/ChartCard.tsx +81 -67
- package/src/data-display/ChartCard/block.meta.ts +1 -1
- package/src/data-display/DescriptionListCard/DescriptionListCard.labels.test.tsx +73 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.options.test.tsx +64 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +74 -23
- package/src/data-display/DescriptionListCard/block.meta.ts +11 -1
- package/src/data-display/DescriptionListCard/examples/Spanish.tsx +29 -0
- package/src/feedback/EmptyStates/EmptyStates.labels.test.tsx +185 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +101 -30
- package/src/feedback/EmptyStates/NoAccessEmpty.options.test.tsx +38 -0
- package/src/feedback/EmptyStates/block.meta.ts +73 -1
- package/src/feedback/EmptyStates/examples/Spanish.tsx +48 -0
- package/src/feedback/ErrorPanel/ErrorPanel.labels.test.tsx +99 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +38 -9
- package/src/feedback/ErrorPanel/block.meta.ts +19 -1
- package/src/feedback/ErrorPanel/examples/Spanish.tsx +30 -0
- package/src/feedback/InlineCallout/InlineCallout.labels.test.tsx +62 -0
- package/src/feedback/InlineCallout/InlineCallout.tsx +22 -9
- package/src/feedback/InlineCallout/block.meta.ts +9 -1
- package/src/feedback/InlineCallout/examples/Spanish.tsx +19 -0
- package/src/feedback/Skeletons/Skeletons.labels.test.tsx +24 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.labels.test.tsx +115 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +63 -21
- package/src/forms/CreateApiKeyDialog/block.meta.ts +22 -1
- package/src/forms/CreateApiKeyDialog/examples/Labels.tsx +29 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.labels.test.tsx +165 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.tsx +31 -8
- package/src/forms/CredentialDisclosureDialog/SecretCopy.tsx +16 -8
- package/src/forms/CredentialDisclosureDialog/block.meta.ts +19 -1
- package/src/forms/CredentialDisclosureDialog/examples/Labels.tsx +38 -0
- package/src/forms/DangerZone/ConfirmDestructiveDialog.tsx +17 -3
- package/src/forms/DangerZone/DangerZone.labels.test.tsx +87 -0
- package/src/forms/DangerZone/DangerZone.tsx +20 -5
- package/src/forms/DangerZone/block.meta.ts +10 -1
- package/src/forms/DangerZone/examples/Labels.tsx +29 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.labels.test.tsx +52 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.tsx +11 -3
- package/src/forms/DateRangeFilter/block.meta.ts +8 -1
- package/src/forms/DateRangeFilter/examples/Labels.tsx +28 -0
- package/src/forms/DialogWizard/DialogWizard.labels.test.tsx +37 -0
- package/src/forms/DialogWizard/DialogWizard.tsx +13 -2
- package/src/forms/DialogWizard/block.meta.ts +7 -1
- package/src/forms/DialogWizard/examples/Labels.tsx +39 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.labels.test.tsx +126 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.test.tsx +22 -1
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +85 -22
- package/src/forms/FileUploadPanel/block.meta.ts +22 -1
- package/src/forms/FileUploadPanel/examples/Labels.tsx +29 -0
- package/src/forms/FileUploadPanel/fixtures.ts +0 -12
- package/src/forms/FileUploadPanel/format-bytes.test.ts +8 -0
- package/src/forms/FormSection/FormSection.labels.test.tsx +37 -0
- package/src/forms/FormSection/FormSection.tsx +14 -3
- package/src/forms/FormSection/block.meta.ts +7 -1
- package/src/forms/FormSection/examples/Labels.tsx +27 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.labels.test.tsx +87 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +51 -16
- package/src/forms/InviteMembersDialog/block.meta.ts +20 -1
- package/src/forms/InviteMembersDialog/examples/Labels.tsx +28 -0
- package/src/forms/SettingsRow/SettingsRow.labels.test.tsx +33 -0
- package/src/forms/SettingsRow/SettingsRow.tsx +14 -3
- package/src/forms/SettingsRow/block.meta.ts +7 -1
- package/src/forms/SettingsRow/examples/Labels.tsx +27 -0
- package/src/forms/ValidationSummary/ValidationSummary.labels.test.tsx +47 -0
- package/src/forms/ValidationSummary/ValidationSummary.tsx +9 -3
- package/src/forms/ValidationSummary/block.meta.ts +6 -1
- package/src/forms/ValidationSummary/examples/Labels.tsx +24 -0
- package/src/forms/index.ts +5 -1
- package/src/forms/translated-content.tsx +12 -0
- package/src/page-chrome/PageHeader/PageHeader.labels.test.tsx +56 -0
- package/src/page-chrome/PageHeader/PageHeader.options.test.tsx +34 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +26 -5
- package/src/page-chrome/PageHeader/block.meta.ts +8 -1
- package/src/page-chrome/PageHeader/examples/Labels.tsx +16 -0
- package/src/page-chrome/PageHeader/examples/Spanish.tsx +11 -0
- package/src/scheduling/AgendaList/AgendaList.test.tsx +25 -0
- package/src/scheduling/AgendaList/AgendaList.tsx +7 -2
- package/src/scheduling/AgendaList/AgendaListLocale.test.tsx +11 -0
- package/src/scheduling/AgendaList/block.meta.ts +1 -1
- package/src/scheduling/AgendaList/examples/Locale.tsx +29 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.test.tsx +111 -1
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +19 -9
- package/src/scheduling/MonthCalendar/block.meta.ts +1 -1
- package/src/scheduling/MonthCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.test.tsx +73 -2
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +26 -12
- package/src/scheduling/WeekCalendar/block.meta.ts +1 -1
- package/src/scheduling/WeekCalendar/examples/Locale.tsx +19 -0
- package/src/scheduling/shared/dates.test.ts +75 -0
- package/src/scheduling/shared/dates.ts +46 -22
- package/src/scheduling/shared/useSchedulingClock.ts +13 -0
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +12 -0
- package/src/shell/GlobalSearch/fixtures.ts +2 -2
- package/src/tables/DataTable/DataTable.cross-page-selection.test.tsx +322 -0
- package/src/tables/DataTable/DataTable.labels.test.tsx +74 -0
- package/src/tables/DataTable/DataTable.server-pagination.test.tsx +1 -1
- package/src/tables/DataTable/DataTable.single-select.test.tsx +47 -7
- package/src/tables/DataTable/DataTable.test.tsx +55 -0
- package/src/tables/DataTable/DataTable.tsx +134 -67
- package/src/tables/DataTable/block.meta.ts +21 -3
- package/src/tables/DataTable/data-table-props.ts +14 -5
- package/src/tables/DataTable/data-table-row.tsx +7 -3
- package/src/tables/DataTable/data-table-utils.ts +2 -0
- package/src/tables/DataTable/examples/client-selection.tsx +33 -0
- package/src/tables/DataTable/examples/paginated-single-selection.tsx +46 -0
- package/src/tables/DataTable/examples/server-pagination.tsx +55 -15
- package/src/tables/DataTable/labels.ts +4 -0
- package/src/tables/DataTable/selection-strip.tsx +31 -0
- package/src/tables/DataTable/single-selection.tsx +0 -7
- package/src/tables/DataTable/use-multiple-selection.ts +86 -0
- package/src/tables/PaginationFooter/PaginationFooter.i18n.test.tsx +26 -0
- package/src/test/OptInDefaults.test.tsx +27 -0
- package/src/test/fixtures/opt-in-defaults.json +10 -0
|
@@ -44,7 +44,9 @@ import { DensityToggle } from './density-toggle';
|
|
|
44
44
|
import { DEPLOYMENT_COLUMNS, DEPLOYMENT_ROWS } from './fixtures';
|
|
45
45
|
import { DataTableHeadCell } from './header-cell';
|
|
46
46
|
import { SelectionGroup, useSingleSelection, useSingleSelectionWarnings } from './single-selection';
|
|
47
|
+
import { SelectionStrip } from './selection-strip';
|
|
47
48
|
import { useControllable, useTableViews } from './use-table-views';
|
|
49
|
+
import { useMultipleSelection } from './use-multiple-selection';
|
|
48
50
|
import { useVirtualRows } from './use-virtual-rows';
|
|
49
51
|
import { ViewSwitcher, type DataTableViewState } from './views';
|
|
50
52
|
|
|
@@ -85,6 +87,11 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
85
87
|
selectedIds,
|
|
86
88
|
defaultSelectedIds = [],
|
|
87
89
|
onSelectionChange,
|
|
90
|
+
preserveSelection,
|
|
91
|
+
selectAllMatching = false,
|
|
92
|
+
hideSelectAll = false,
|
|
93
|
+
selectionModel,
|
|
94
|
+
onSelectionModelChange,
|
|
88
95
|
bulkActions,
|
|
89
96
|
selectionSummary = true,
|
|
90
97
|
rowActions,
|
|
@@ -144,14 +151,15 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
144
151
|
className,
|
|
145
152
|
labels,
|
|
146
153
|
}: DataTableProps<T>) {
|
|
147
|
-
const { t } = useI18n();
|
|
154
|
+
const { t, formatNumber } = useI18n();
|
|
148
155
|
const singleMode = selectionMode === 'single';
|
|
149
156
|
const serverMode = paginationMode === 'server';
|
|
150
157
|
const selectable = selectionMode === undefined ? selectableProp : selectionMode === 'multiple';
|
|
151
158
|
const selectionColumn = selectable || singleMode;
|
|
152
|
-
const paginated =
|
|
159
|
+
const paginated = paginatedProp ?? (serverMode || !singleMode);
|
|
153
160
|
const editHintId = useId();
|
|
154
161
|
const tableRef = useRef<HTMLTableElement>(null);
|
|
162
|
+
const pageCheckboxRef = useRef<HTMLElement>(null);
|
|
155
163
|
// A view active at mount seeds the initial state.
|
|
156
164
|
const [initialView] = useState(() =>
|
|
157
165
|
(viewsProp ?? defaultViews ?? []).find((v) => v.id === (activeViewId ?? defaultActiveViewId)),
|
|
@@ -161,7 +169,6 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
161
169
|
const defaultHidden = columns.filter((c) => c.defaultHidden).map((c) => c.id);
|
|
162
170
|
|
|
163
171
|
const [innerSort, setInnerSort] = useState<SortState | null>(seed.sort !== undefined ? seed.sort : defaultSort);
|
|
164
|
-
const [innerSelected, setInnerSelected] = useState<ReadonlySet<string>>(() => new Set(defaultSelectedIds));
|
|
165
172
|
const [innerDensity, setInnerDensity] = useState<TableDensity | null>(defaultDensity ?? null);
|
|
166
173
|
const contextDensity = useDensity();
|
|
167
174
|
const [hiddenList, setHiddenList] = useControllable<readonly string[]>(
|
|
@@ -188,7 +195,30 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
188
195
|
const effectiveGroupBy: DataTableGroupBy<T> | undefined =
|
|
189
196
|
groupOverride === undefined ? groupBy : ((groupOverride ?? undefined) as DataTableGroupBy<T> | undefined);
|
|
190
197
|
const sort = sortProp === undefined ? innerSort : sortProp;
|
|
191
|
-
const
|
|
198
|
+
const enabledIds = rows.filter((row) => !isRowDisabled?.(row)).map(getRowId);
|
|
199
|
+
const {
|
|
200
|
+
selected,
|
|
201
|
+
selectedList,
|
|
202
|
+
setSelected,
|
|
203
|
+
model,
|
|
204
|
+
selectedCount,
|
|
205
|
+
allMatchingSelected,
|
|
206
|
+
selectAllMatching: selectMatching,
|
|
207
|
+
clear,
|
|
208
|
+
} = useMultipleSelection({
|
|
209
|
+
rowIds: rows.map(getRowId),
|
|
210
|
+
selectedIds,
|
|
211
|
+
defaultSelectedIds,
|
|
212
|
+
onSelectionChange,
|
|
213
|
+
preserveSelection: preserveSelection ?? serverMode,
|
|
214
|
+
enabledIds,
|
|
215
|
+
selectionModel,
|
|
216
|
+
onSelectionModelChange,
|
|
217
|
+
serverMode,
|
|
218
|
+
selectAllMatching: selectable && selectAllMatching,
|
|
219
|
+
total: rowCount ?? rows.length,
|
|
220
|
+
filters,
|
|
221
|
+
});
|
|
192
222
|
const density = densityProp ?? innerDensity ?? contextDensity;
|
|
193
223
|
const visibleColumns = orderColumns(
|
|
194
224
|
columns.filter((c) => !hidden.has(c.id)),
|
|
@@ -212,14 +242,10 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
212
242
|
// Rows in collapsed groups are hidden, so select-all leaves them alone.
|
|
213
243
|
const pageIds = (
|
|
214
244
|
effectiveGroupBy ? pageRows.filter((row) => !collapsed.has(groupKeyOf(row, effectiveGroupBy))) : pageRows
|
|
215
|
-
)
|
|
245
|
+
)
|
|
246
|
+
.filter((row) => !isRowDisabled?.(row))
|
|
247
|
+
.map(getRowId);
|
|
216
248
|
const header = selectionState(pageIds, selected);
|
|
217
|
-
const selectedList = rows.map(getRowId).filter((id) => selected.has(id));
|
|
218
|
-
|
|
219
|
-
const setSelected = (next: Set<string>) => {
|
|
220
|
-
setInnerSelected(next);
|
|
221
|
-
onSelectionChange?.(rows.map(getRowId).filter((id) => next.has(id)));
|
|
222
|
-
};
|
|
223
249
|
const changeSort = (columnId: string, direction: SortState['direction']) => {
|
|
224
250
|
if (serverMode) return;
|
|
225
251
|
const next: SortState = { columnId, direction: sort?.columnId === columnId ? direction : 'ascending' };
|
|
@@ -244,6 +270,7 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
244
270
|
name: nameOf(g.key),
|
|
245
271
|
rows: pageRows.filter((row) => groupKeyOf(row, effectiveGroupBy) === g.key),
|
|
246
272
|
ids: g.rows.map(getRowId),
|
|
273
|
+
selectableIds: g.rows.filter((row) => !isRowDisabled?.(row)).map(getRowId),
|
|
247
274
|
}))
|
|
248
275
|
.filter((g) => g.rows.length > 0)
|
|
249
276
|
: undefined;
|
|
@@ -264,7 +291,6 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
264
291
|
useSingleSelectionWarnings({
|
|
265
292
|
single: singleMode,
|
|
266
293
|
selectionName,
|
|
267
|
-
paginated: paginatedProp,
|
|
268
294
|
hasLabel:
|
|
269
295
|
Boolean(legend || ariaLabel?.trim() || ariaLabelledBy?.trim()) ||
|
|
270
296
|
typeof legend === 'number' ||
|
|
@@ -341,66 +367,101 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
341
367
|
const rowHeight = rowHeightProp ?? ROW_HEIGHT[density];
|
|
342
368
|
const virtual = useVirtualRows({ enabled: virtualOn, count: items, rowHeight, tableRef, viewportHeight: 512 });
|
|
343
369
|
|
|
344
|
-
const hasSelection = selectable &&
|
|
370
|
+
const hasSelection = selectable && selectedCount > 0 && (selectionSummary || bulkActions != null);
|
|
345
371
|
const showToolbar = toolbar != null || showDensityToggle || showColumnMenu || showViews || hasSelection;
|
|
346
372
|
const anyEditable = onCellEdit != null && columns.some((c) => c.editable);
|
|
373
|
+
const showSelectionStrip =
|
|
374
|
+
selectable &&
|
|
375
|
+
selectAllMatching &&
|
|
376
|
+
(!serverMode || !!onSelectionModelChange) &&
|
|
377
|
+
(header.checked || model.type === 'exclude' || (!serverMode && allMatchingSelected)) &&
|
|
378
|
+
(serverMode ? (rowCount ?? 0) > rows.length : enabledIds.length > pageIds.length);
|
|
379
|
+
const allMatching = serverMode ? model.type === 'exclude' : allMatchingSelected;
|
|
380
|
+
const matchingCount = serverMode ? selectedCount : enabledIds.length;
|
|
381
|
+
const stripMessage = allMatching
|
|
382
|
+
? (labels?.allMatchingSelected?.(matchingCount) ??
|
|
383
|
+
t('table.allMatchingSelected', { count: formatNumber(matchingCount) }))
|
|
384
|
+
: (labels?.pageSelected?.(pageIds.length) ?? t('table.pageSelected', { count: formatNumber(pageIds.length) }));
|
|
385
|
+
const selectionCount = labels?.selectionCount ? labels.selectionCount(selectedCount) : <>{selectedCount} selected</>;
|
|
347
386
|
|
|
348
387
|
return (
|
|
349
388
|
<div className={cn('overflow-hidden rounded-xl border border-border bg-card shadow-sm', className)}>
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
389
|
+
<div
|
|
390
|
+
className={cn(
|
|
391
|
+
!showToolbar && 'sr-only',
|
|
392
|
+
'flex min-h-12 flex-wrap items-center gap-2 border-b border-border px-3 py-2 transition-colors motion-reduce:transition-none',
|
|
393
|
+
hasSelection ? 'bg-primary/8' : 'bg-secondary/30',
|
|
394
|
+
)}
|
|
395
|
+
>
|
|
396
|
+
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
|
|
397
|
+
{/* Matching selection needs a mounted announcer; default tables retain their published surface. */}
|
|
398
|
+
{selectable && (selectAllMatching || (hasSelection && selectionSummary)) && (
|
|
399
|
+
<span
|
|
400
|
+
className={
|
|
401
|
+
hasSelection && selectionSummary && !showSelectionStrip
|
|
402
|
+
? 'text-[12.5px] font-semibold text-foreground'
|
|
403
|
+
: 'sr-only'
|
|
404
|
+
}
|
|
405
|
+
aria-live="polite"
|
|
406
|
+
aria-atomic="true"
|
|
407
|
+
>
|
|
408
|
+
{showSelectionStrip ? stripMessage : hasSelection && selectionSummary ? selectionCount : null}
|
|
409
|
+
</span>
|
|
410
|
+
)}
|
|
411
|
+
{hasSelection ? (
|
|
412
|
+
<>
|
|
413
|
+
{selectionSummary && showSelectionStrip && (
|
|
414
|
+
<span className="text-[12.5px] font-semibold text-foreground">{selectionCount}</span>
|
|
415
|
+
)}
|
|
416
|
+
{selectionSummary && bulkActions && <span aria-hidden className="h-4 w-px bg-border" />}
|
|
417
|
+
{bulkActions?.(selectedList, model)}
|
|
418
|
+
</>
|
|
419
|
+
) : (
|
|
420
|
+
toolbar
|
|
355
421
|
)}
|
|
356
|
-
>
|
|
357
|
-
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
|
|
358
|
-
{hasSelection ? (
|
|
359
|
-
<>
|
|
360
|
-
{selectionSummary && (
|
|
361
|
-
<span className="text-[12.5px] font-semibold text-foreground" aria-live="polite">
|
|
362
|
-
{labels?.selectionCount ? (
|
|
363
|
-
labels.selectionCount(selectedList.length)
|
|
364
|
-
) : (
|
|
365
|
-
<>{selectedList.length} selected</>
|
|
366
|
-
)}
|
|
367
|
-
</span>
|
|
368
|
-
)}
|
|
369
|
-
{selectionSummary && bulkActions && <span aria-hidden className="h-4 w-px bg-border" />}
|
|
370
|
-
{bulkActions?.(selectedList)}
|
|
371
|
-
</>
|
|
372
|
-
) : (
|
|
373
|
-
toolbar
|
|
374
|
-
)}
|
|
375
|
-
</div>
|
|
376
|
-
<div className="flex items-center gap-2">
|
|
377
|
-
{showViews && (
|
|
378
|
-
<ViewSwitcher
|
|
379
|
-
labels={labels}
|
|
380
|
-
views={viewsApi.views}
|
|
381
|
-
activeId={viewsApi.activeId}
|
|
382
|
-
dirty={viewsApi.dirty}
|
|
383
|
-
onSelect={viewsApi.select}
|
|
384
|
-
onSaveAs={viewsApi.saveAs}
|
|
385
|
-
onSave={viewsApi.save}
|
|
386
|
-
onRename={viewsApi.rename}
|
|
387
|
-
onDelete={viewsApi.remove}
|
|
388
|
-
onReset={viewsApi.reset}
|
|
389
|
-
/>
|
|
390
|
-
)}
|
|
391
|
-
{showDensityToggle && <DensityToggle labels={labels} value={density} onChange={changeDensity} />}
|
|
392
|
-
{showColumnMenu && (
|
|
393
|
-
<ColumnVisibilityMenu
|
|
394
|
-
labels={labels}
|
|
395
|
-
columns={columns}
|
|
396
|
-
hidden={hidden}
|
|
397
|
-
onToggle={toggleColumn}
|
|
398
|
-
pinOf={pinning ? (id) => pinSideOf(id, pinned) : undefined}
|
|
399
|
-
onPin={pinning ? (id, side) => setPinned(setColumnPin(pinned, id, side)) : undefined}
|
|
400
|
-
/>
|
|
401
|
-
)}
|
|
402
|
-
</div>
|
|
403
422
|
</div>
|
|
423
|
+
<div className="flex items-center gap-2">
|
|
424
|
+
{showViews && (
|
|
425
|
+
<ViewSwitcher
|
|
426
|
+
labels={labels}
|
|
427
|
+
views={viewsApi.views}
|
|
428
|
+
activeId={viewsApi.activeId}
|
|
429
|
+
dirty={viewsApi.dirty}
|
|
430
|
+
onSelect={viewsApi.select}
|
|
431
|
+
onSaveAs={viewsApi.saveAs}
|
|
432
|
+
onSave={viewsApi.save}
|
|
433
|
+
onRename={viewsApi.rename}
|
|
434
|
+
onDelete={viewsApi.remove}
|
|
435
|
+
onReset={viewsApi.reset}
|
|
436
|
+
/>
|
|
437
|
+
)}
|
|
438
|
+
{showDensityToggle && <DensityToggle labels={labels} value={density} onChange={changeDensity} />}
|
|
439
|
+
{showColumnMenu && (
|
|
440
|
+
<ColumnVisibilityMenu
|
|
441
|
+
labels={labels}
|
|
442
|
+
columns={columns}
|
|
443
|
+
hidden={hidden}
|
|
444
|
+
onToggle={toggleColumn}
|
|
445
|
+
pinOf={pinning ? (id) => pinSideOf(id, pinned) : undefined}
|
|
446
|
+
onPin={pinning ? (id, side) => setPinned(setColumnPin(pinned, id, side)) : undefined}
|
|
447
|
+
/>
|
|
448
|
+
)}
|
|
449
|
+
</div>
|
|
450
|
+
</div>
|
|
451
|
+
{showSelectionStrip && (
|
|
452
|
+
<SelectionStrip
|
|
453
|
+
labels={labels}
|
|
454
|
+
all={allMatching}
|
|
455
|
+
message={stripMessage}
|
|
456
|
+
total={serverMode ? (rowCount ?? 0) : enabledIds.length}
|
|
457
|
+
onSelectAll={selectMatching}
|
|
458
|
+
onClear={() => {
|
|
459
|
+
// Restore focus before clearing removes the strip and its focused button.
|
|
460
|
+
const target = hideSelectAll || loading || pageIds.length === 0 ? tableRef : pageCheckboxRef;
|
|
461
|
+
target.current?.focus();
|
|
462
|
+
clear();
|
|
463
|
+
}}
|
|
464
|
+
/>
|
|
404
465
|
)}
|
|
405
466
|
{anyEditable && (
|
|
406
467
|
<span id={editHintId} className="sr-only">
|
|
@@ -412,6 +473,7 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
412
473
|
<DensityProvider density={density}>
|
|
413
474
|
<Table
|
|
414
475
|
ref={tableRef}
|
|
476
|
+
tabIndex={selectable && selectAllMatching ? -1 : undefined}
|
|
415
477
|
aria-busy={loading || undefined}
|
|
416
478
|
aria-rowcount={virtual ? items + 1 : undefined}
|
|
417
479
|
stickyHeader={virtualOn}
|
|
@@ -421,6 +483,7 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
421
483
|
// final column would add a scroll-container stop before the header.
|
|
422
484
|
className={cn(
|
|
423
485
|
layout.tableClassName,
|
|
486
|
+
selectable && selectAllMatching && 'focus-visible:outline-2 focus-visible:outline-focus-ring',
|
|
424
487
|
singleMode && '[&_[data-column-resizer]]:end-0 [&_[data-column-resizer]]:justify-end',
|
|
425
488
|
)}
|
|
426
489
|
style={layout.tableStyle}
|
|
@@ -439,9 +502,12 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
439
502
|
)}
|
|
440
503
|
style={layout.lead.style}
|
|
441
504
|
>
|
|
442
|
-
{singleMode
|
|
443
|
-
|
|
505
|
+
{(singleMode || hideSelectAll) && (
|
|
506
|
+
<span className="sr-only">{labels?.selection ?? t('table.selection')}</span>
|
|
507
|
+
)}
|
|
508
|
+
{selectable && !hideSelectAll && (
|
|
444
509
|
<Checkbox
|
|
510
|
+
ref={pageCheckboxRef}
|
|
445
511
|
aria-label={labels?.selectAll ?? t('table.selectAllPage')}
|
|
446
512
|
checked={header.checked}
|
|
447
513
|
indeterminate={header.indeterminate}
|
|
@@ -496,6 +562,7 @@ export function DataTable<T = (typeof DEPLOYMENT_ROWS)[number]>({
|
|
|
496
562
|
getRowId={getRowId}
|
|
497
563
|
getRowLabel={labelOf}
|
|
498
564
|
selectable={selectable}
|
|
565
|
+
isRowDisabled={isRowDisabled}
|
|
499
566
|
selected={selected}
|
|
500
567
|
singleSelection={singleMode ? singleSelection : undefined}
|
|
501
568
|
onToggleRow={(id) => setSelected(toggleOne(id, selected))}
|
|
@@ -7,9 +7,11 @@ export const meta: BlockMeta = {
|
|
|
7
7
|
status: 'beta',
|
|
8
8
|
description:
|
|
9
9
|
'Generic typed table: sortable headers with aria-sort, row selection with select-all and indeterminate by default (selectionMode="multiple"), selectionMode="none" to hide selection, column visibility menu, density toggle, row actions, loading and empty states, client-side sort and pagination, optional row groups (groupBy) with rowgroup header rows, counts, keyboard-accessible collapse buttons and group selection; column resize (pointer drag or a focusable role="separator" handle with arrow keys, min/max widths, controlled columnWidths), column pinning to either edge with sticky cells (column menu or pinnedColumns), row virtualization for large datasets (aria-rowcount/aria-rowindex, works with selection and grouping), inline cell editing (text, number and select editors; Enter/F2 to edit, Enter/Tab to commit, Escape to cancel, onCellEdit can reject with an inline error) and saved views (filters, sort, visible columns, widths, pinning and grouping) with a view switcher to save as, rename, delete and reset. ' +
|
|
10
|
-
'Opt-in selectionMode="single" uses native radios in a labelled fieldset (never
|
|
10
|
+
'Opt-in selectionMode="single" uses native radios in a labelled fieldset (never virtualized; client pagination defaults to false, and paginated=true or paginationMode="server" enables pagination). Single mode uses selectedId/onSelectedIdChange or defaultSelectedId; isRowDisabled skips unavailable rows and preserves a checked disabled choice without callbacks. Supply legend, aria-label or aria-labelledby for the group and getRowLabel for each radio (otherwise the first column labels it). selectionName is used verbatim and must be unique per page; omitted names use an instance-unique useId name, and duplicate supplied names or missing group labels warn in development. Tab enters once on the checked enabled row or first enabled row; arrows wrap and skip disabled rows, Space selects, Shift+Tab exits, and all-disabled groups have no tab stop. No select-all, group checkboxes, bulk actions or selection summary appear in single mode. ' +
|
|
11
11
|
'Examples in examples/single-selection.tsx: an uncontrolled non-paginated list with legend="Available items" and a controlled versions table with legend="Available versions", selectedId="v2" and a checked disabled version. ' +
|
|
12
|
-
'Opt-in paginationMode="server" accepts a controlled 1-based page, pageSize and required rowCount (known total), with onPageChange/onPageSizeChange requests. Supplied rows render in order without client sorting or slicing, and headers have no sort affordance. Single selection
|
|
12
|
+
'Opt-in paginationMode="server" accepts a controlled 1-based page, pageSize and required rowCount (known total), with onPageChange/onPageSizeChange requests. Supplied rows render in order without client sorting or slicing, and headers have no sort affordance. Single selection keeps its chosen id across pages. Off-page choices leave every visible radio unchecked and the first enabled radio is the tab stop; name the current choice in the legend. See examples/paginated-single-selection.tsx for client and server pagination. The footer stays visible for empty results, clamps stale pages for display without callbacks, and hides during loading. Page-size changes may also request a page to keep the first visible row on screen. The consumer owns fetching and reconciles stale pages. See examples/server-pagination.tsx for an items/total/page/pageSize envelope consumer that handles both callbacks. ' +
|
|
13
|
+
'Multiple selection preserves ids from other server pages by default; preserveSelection=false restores page-only reporting, and client tables can opt in with preserveSelection=true. selectedIds remains supported. A controlled selectionModel takes precedence and uses { type: "include", ids: string[] } for selected ids or { type: "exclude", ids: string[] } for every match except those ids. bulkActions(ids, model) receives the full include list; in exclude mode ids contains enabled selections in the current rows and the model is authoritative. One-argument actions remain compatible. ' +
|
|
14
|
+
'selectAllMatching defaults to false and offers a strip after the page is fully selected: client mode includes every enabled row, while server mode requires onSelectionModelChange and reports an exclude model. The same button becomes Clear selection without moving focus; clearing returns focus to the page checkbox, or to the table when the checkbox is hidden or unavailable. An exclude model resets through both callbacks when filters changes by JSON value; filters must include every narrowing input, including search text. Paging, page size and sorting preserve selection. An exclude action covers the matching result set at action time, including later-created rows; the consumer executes it. isRowDisabled disables multiple-selection checkboxes and page/group/all-matching toggles skip known disabled rows. Server counts use rowCount minus explicit excluded ids, including disabled ids on the page where Select all is activated. isRowDisabled cannot evaluate unloaded rows, so the server must enforce eligibility for the complete matching result set; return only eligible matches and their rowCount when counts must exclude all unavailable rows. hideSelectAll defaults to false and hides just the header checkbox, retaining an accessible Selection heading. See examples/client-selection.tsx for client preservation, disabled rows and select-all-matching, and examples/server-pagination.tsx for controlled models, cross-page actions and the preservation/header options.',
|
|
13
15
|
|
|
14
16
|
labels: [
|
|
15
17
|
{ key: 'booleanTrue', type: 'string', state: 'Default cell text for a true boolean value' },
|
|
@@ -24,6 +26,22 @@ export const meta: BlockMeta = {
|
|
|
24
26
|
type: '(count: number) => string',
|
|
25
27
|
state: 'Multiple selection: toolbar count and polite live region',
|
|
26
28
|
},
|
|
29
|
+
{
|
|
30
|
+
key: 'pageSelected',
|
|
31
|
+
type: '(count: number) => string',
|
|
32
|
+
state: 'Matching-selection strip: selected page announcement',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: 'selectAllMatching',
|
|
36
|
+
type: '(count: number) => string',
|
|
37
|
+
state: 'Matching-selection strip: select every enabled match',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: 'allMatchingSelected',
|
|
41
|
+
type: '(count: number) => string',
|
|
42
|
+
state: 'Matching-selection strip: all-matching announcement',
|
|
43
|
+
},
|
|
44
|
+
{ key: 'clearSelection', type: 'string', state: 'Matching-selection strip: clear action' },
|
|
27
45
|
{ key: 'columns', type: 'string', state: 'Column visibility trigger text and name' },
|
|
28
46
|
{ key: 'visibleColumns', type: 'string', state: 'Open column menu: visibility heading' },
|
|
29
47
|
{ key: 'pinColumns', type: 'string', state: 'Open column menu with pinning: pin heading' },
|
|
@@ -61,7 +79,7 @@ export const meta: BlockMeta = {
|
|
|
61
79
|
{ key: 'saveView', type: 'string', state: 'Save as dialog: submit button' },
|
|
62
80
|
{ key: 'rename', type: 'string', state: 'Rename dialog: submit button' },
|
|
63
81
|
{ key: 'closeDialog', type: 'string', state: 'Save as and Rename dialogs: close button name' },
|
|
64
|
-
{ key: 'selection', type: 'string', state: 'Single selection: screen reader column heading' },
|
|
82
|
+
{ key: 'selection', type: 'string', state: 'Single selection or hideSelectAll: screen reader column heading' },
|
|
65
83
|
{ key: 'selectAll', type: 'string', state: 'Multiple selection: header checkbox name' },
|
|
66
84
|
{
|
|
67
85
|
key: 'selectRow',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MoreMenuAction, TableDensity } from '@gntik-ai/ui';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
3
|
import type { ColumnWidths, PinnedColumns } from './column-sizing';
|
|
4
|
-
import type { DataTableColumn, DataTableGroupBy, SortState } from './data-table-utils';
|
|
4
|
+
import type { DataTableColumn, DataTableGroupBy, DataTableSelectionModel, SortState } from './data-table-utils';
|
|
5
5
|
import type { DataTableCellEditHandler } from './editable-cell';
|
|
6
6
|
import type { DataTableLabels } from './labels';
|
|
7
7
|
import type { DataTableView } from './views';
|
|
@@ -30,8 +30,18 @@ interface DataTableCommonProps<T> {
|
|
|
30
30
|
selectedIds?: readonly string[];
|
|
31
31
|
defaultSelectedIds?: readonly string[];
|
|
32
32
|
onSelectionChange?: (ids: string[]) => void;
|
|
33
|
+
/** Keep ids absent from rows. Defaults to true for server pagination, false for client pagination. */
|
|
34
|
+
preserveSelection?: boolean;
|
|
35
|
+
/** Offer to extend a selected page to all matching rows (default false). */
|
|
36
|
+
selectAllMatching?: boolean;
|
|
37
|
+
/** Hide the page select-all checkbox, retaining row controls and the column heading. */
|
|
38
|
+
hideSelectAll?: boolean;
|
|
39
|
+
/** Controlled model; takes precedence over selectedIds. */
|
|
40
|
+
selectionModel?: DataTableSelectionModel;
|
|
41
|
+
/** Required to offer select-all-matching with server pagination. */
|
|
42
|
+
onSelectionModelChange?: (model: DataTableSelectionModel) => void;
|
|
33
43
|
/** Rendered in the toolbar while rows are selected. */
|
|
34
|
-
bulkActions?: (selectedIds: string[]) => ReactNode;
|
|
44
|
+
bulkActions?: (selectedIds: string[], selection: DataTableSelectionModel) => ReactNode;
|
|
35
45
|
/**
|
|
36
46
|
* Shows the "N selected" text in the toolbar while rows are selected (default true). Turn it
|
|
37
47
|
* off when the page renders its own count, e.g. a BulkActionBar.
|
|
@@ -165,13 +175,12 @@ export type DataTableProps<T> = DataTableCommonProps<T> &
|
|
|
165
175
|
(
|
|
166
176
|
| ({
|
|
167
177
|
selectionMode: 'single';
|
|
168
|
-
paginated?:
|
|
178
|
+
paginated?: boolean;
|
|
169
179
|
/** Consumer-supplied accessible group label; the kit adds no default. */
|
|
170
180
|
legend?: ReactNode;
|
|
171
181
|
'aria-label'?: string;
|
|
172
182
|
'aria-labelledby'?: string;
|
|
173
|
-
|
|
174
|
-
} & ClientPaginationProps)
|
|
183
|
+
} & (ClientPaginationProps | ServerPaginationProps))
|
|
175
184
|
| ({
|
|
176
185
|
selectionMode?: 'none' | 'multiple';
|
|
177
186
|
paginated?: boolean;
|
|
@@ -34,6 +34,7 @@ export interface DataTableBodyGroup<T> {
|
|
|
34
34
|
rows: readonly T[];
|
|
35
35
|
/** Ids of every row in the group (all pages): the count and the group checkbox use them. */
|
|
36
36
|
ids: readonly string[];
|
|
37
|
+
selectableIds: readonly string[];
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/** Row rendering shared by the plain, grouped and virtualized bodies. */
|
|
@@ -43,6 +44,7 @@ export interface RowContext<T> {
|
|
|
43
44
|
getRowId: (row: T) => string;
|
|
44
45
|
getRowLabel: (row: T) => string;
|
|
45
46
|
selectable: boolean;
|
|
47
|
+
isRowDisabled?: (row: T) => boolean;
|
|
46
48
|
selected: ReadonlySet<string>;
|
|
47
49
|
singleSelection?: SingleSelection<T>;
|
|
48
50
|
onToggleRow: (id: string) => void;
|
|
@@ -67,6 +69,7 @@ export function DataTableRow<T>({
|
|
|
67
69
|
getRowId,
|
|
68
70
|
getRowLabel,
|
|
69
71
|
selectable,
|
|
72
|
+
isRowDisabled,
|
|
70
73
|
selected,
|
|
71
74
|
singleSelection,
|
|
72
75
|
onToggleRow,
|
|
@@ -99,6 +102,7 @@ export function DataTableRow<T>({
|
|
|
99
102
|
<Checkbox
|
|
100
103
|
aria-label={labels?.selectRow?.(label) ?? t('table.selectRow', { label })}
|
|
101
104
|
checked={isSelected}
|
|
105
|
+
disabled={isRowDisabled?.(row)}
|
|
102
106
|
onCheckedChange={() => onToggleRow(id)}
|
|
103
107
|
/>
|
|
104
108
|
)}
|
|
@@ -196,7 +200,7 @@ export function GroupHeaderRow<T>({
|
|
|
196
200
|
style,
|
|
197
201
|
}: GroupHeaderRowProps<T>) {
|
|
198
202
|
const { t } = useI18n();
|
|
199
|
-
const state = selectionState(group.
|
|
203
|
+
const state = selectionState(group.selectableIds, selected);
|
|
200
204
|
const count = group.ids.length;
|
|
201
205
|
const heading = (
|
|
202
206
|
<>
|
|
@@ -215,8 +219,8 @@ export function GroupHeaderRow<T>({
|
|
|
215
219
|
aria-label={labels?.selectGroup?.(group.name) ?? t('table.selectRow', { label: `all in ${group.name}` })}
|
|
216
220
|
checked={state.checked}
|
|
217
221
|
indeterminate={state.indeterminate}
|
|
218
|
-
disabled={
|
|
219
|
-
onCheckedChange={() => onToggleRows?.(group.
|
|
222
|
+
disabled={group.selectableIds.length === 0}
|
|
223
|
+
onCheckedChange={() => onToggleRows?.(group.selectableIds)}
|
|
220
224
|
/>
|
|
221
225
|
</TableCell>
|
|
222
226
|
)}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
export type SortDirectionValue = 'ascending' | 'descending';
|
|
4
|
+
/** Include lists selected ids; exclude selects every match except the listed ids. */
|
|
5
|
+
export type DataTableSelectionModel = { type: 'include'; ids: string[] } | { type: 'exclude'; ids: string[] };
|
|
4
6
|
export type CellValue = string | number | boolean | Date | null | undefined;
|
|
5
7
|
|
|
6
8
|
export type DataTableColumnVariant = 'default' | 'mono' | 'muted' | 'numeric';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Checkbox } from '@gntik-ai/ui';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { DataTable } from '../DataTable';
|
|
4
|
+
|
|
5
|
+
const rows = Array.from({ length: 95 }, (_, index) => ({
|
|
6
|
+
id: String(index + 1),
|
|
7
|
+
name: `Item ${index + 1}`,
|
|
8
|
+
locked: index === 3,
|
|
9
|
+
}));
|
|
10
|
+
const columns = [{ id: 'name', header: 'Name', accessor: (row: (typeof rows)[number]) => row.name }];
|
|
11
|
+
|
|
12
|
+
/** Client preservation retains a selected row even when the consumer removes it from rows. */
|
|
13
|
+
export default function ClientSelectionExample() {
|
|
14
|
+
const [showFirst, setShowFirst] = useState(true);
|
|
15
|
+
const [ids, setIds] = useState<string[]>([]);
|
|
16
|
+
return (
|
|
17
|
+
<div className="space-y-3">
|
|
18
|
+
<Checkbox label="Show first item" checked={showFirst} onCheckedChange={setShowFirst} />
|
|
19
|
+
<DataTable
|
|
20
|
+
caption="Items"
|
|
21
|
+
rows={showFirst ? rows : rows.slice(1)}
|
|
22
|
+
columns={columns}
|
|
23
|
+
preserveSelection
|
|
24
|
+
selectAllMatching
|
|
25
|
+
isRowDisabled={(row) => row.locked}
|
|
26
|
+
onSelectionChange={setIds}
|
|
27
|
+
/>
|
|
28
|
+
<p role="status" className="text-sm text-muted-foreground">
|
|
29
|
+
Selected ids: {ids.join(', ') || 'none'}
|
|
30
|
+
</p>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { DataTable } from '../DataTable';
|
|
3
|
+
|
|
4
|
+
const rows = Array.from({ length: 60 }, (_, i) => ({ id: String(i + 1), name: `Item ${i + 1}` }));
|
|
5
|
+
const columns = [{ id: 'name', header: 'Name', accessor: (row: (typeof rows)[number]) => row.name }];
|
|
6
|
+
|
|
7
|
+
/** Include the current choice in the legend because its checked radio may be on another page. */
|
|
8
|
+
export default function PaginatedSingleSelectionExample() {
|
|
9
|
+
const [selectedId, setSelectedId] = useState('42');
|
|
10
|
+
const [page, setPage] = useState(1);
|
|
11
|
+
const [pageSize, setPageSize] = useState(20);
|
|
12
|
+
return (
|
|
13
|
+
<div className="space-y-4">
|
|
14
|
+
<DataTable
|
|
15
|
+
caption="Client items"
|
|
16
|
+
rows={rows}
|
|
17
|
+
columns={columns}
|
|
18
|
+
selectionMode="single"
|
|
19
|
+
paginated
|
|
20
|
+
defaultPageSize={20}
|
|
21
|
+
defaultSelectedId="42"
|
|
22
|
+
legend="Client items; initial choice Item 42"
|
|
23
|
+
showColumnMenu={false}
|
|
24
|
+
showDensityToggle={false}
|
|
25
|
+
/>
|
|
26
|
+
<DataTable
|
|
27
|
+
caption="Server items"
|
|
28
|
+
rows={rows.slice((page - 1) * pageSize, page * pageSize)}
|
|
29
|
+
columns={columns}
|
|
30
|
+
selectionMode="single"
|
|
31
|
+
paginationMode="server"
|
|
32
|
+
page={page}
|
|
33
|
+
pageSize={pageSize}
|
|
34
|
+
rowCount={rows.length}
|
|
35
|
+
onPageChange={setPage}
|
|
36
|
+
onPageSizeChange={setPageSize}
|
|
37
|
+
pageSizeOptions={[10, 20, 50]}
|
|
38
|
+
selectedId={selectedId}
|
|
39
|
+
onSelectedIdChange={setSelectedId}
|
|
40
|
+
legend={`Server items; current choice Item ${selectedId}`}
|
|
41
|
+
showColumnMenu={false}
|
|
42
|
+
showDensityToggle={false}
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { Button, Checkbox } from '@gntik-ai/ui';
|
|
1
2
|
import { useEffect, useState } from 'react';
|
|
2
3
|
import { DataTable } from '../DataTable';
|
|
4
|
+
import type { DataTableSelectionModel } from '../data-table-utils';
|
|
3
5
|
|
|
4
6
|
interface Item {
|
|
5
7
|
id: number;
|
|
6
8
|
name: string;
|
|
9
|
+
locked: boolean;
|
|
7
10
|
}
|
|
8
11
|
interface Envelope {
|
|
9
12
|
items: Item[];
|
|
@@ -23,6 +26,7 @@ function readPage(page: number, pageSize: number): Envelope {
|
|
|
23
26
|
return {
|
|
24
27
|
items: Array.from({ length: Math.max(0, Math.min(pageSize, total - from)) }, (_, i) => ({
|
|
25
28
|
id: from + i + 1,
|
|
29
|
+
locked: (from + i + 1) % 10 === 4,
|
|
26
30
|
name: `Item ${from + i + 1}`,
|
|
27
31
|
})),
|
|
28
32
|
total,
|
|
@@ -36,6 +40,10 @@ async function requestPage(page: number, pageSize: number): Promise<Envelope> {
|
|
|
36
40
|
|
|
37
41
|
/** Known-total, 1-based pages. The consumer owns requests and keeps the old envelope until they resolve. */
|
|
38
42
|
export default function ServerPaginationExample() {
|
|
43
|
+
const [selection, setSelection] = useState<DataTableSelectionModel>({ type: 'include', ids: [] });
|
|
44
|
+
const [preserveSelection, setPreserveSelection] = useState(true);
|
|
45
|
+
const [hideSelectAll, setHideSelectAll] = useState(false);
|
|
46
|
+
const [review, setReview] = useState('');
|
|
39
47
|
const [envelope, setEnvelope] = useState(() => readPage(2, 20));
|
|
40
48
|
const [request, setRequest] = useState({ page: 2, pageSize: 20 });
|
|
41
49
|
useEffect(() => {
|
|
@@ -49,20 +57,52 @@ export default function ServerPaginationExample() {
|
|
|
49
57
|
}, [request]);
|
|
50
58
|
|
|
51
59
|
return (
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
<div className="space-y-3">
|
|
61
|
+
<Checkbox
|
|
62
|
+
label="Keep selections across pages"
|
|
63
|
+
checked={preserveSelection}
|
|
64
|
+
onCheckedChange={setPreserveSelection}
|
|
65
|
+
/>
|
|
66
|
+
<Checkbox label="Hide page select-all" checked={hideSelectAll} onCheckedChange={setHideSelectAll} />
|
|
67
|
+
<DataTable
|
|
68
|
+
caption="Items"
|
|
69
|
+
selectionMode="multiple"
|
|
70
|
+
selectionModel={selection}
|
|
71
|
+
onSelectionModelChange={setSelection}
|
|
72
|
+
preserveSelection={preserveSelection}
|
|
73
|
+
hideSelectAll={hideSelectAll}
|
|
74
|
+
selectAllMatching
|
|
75
|
+
isRowDisabled={(row) => row.locked}
|
|
76
|
+
bulkActions={(ids, model) => (
|
|
77
|
+
<Button
|
|
78
|
+
variant="soft"
|
|
79
|
+
size="sm"
|
|
80
|
+
onClick={() =>
|
|
81
|
+
setReview(
|
|
82
|
+
model.type === 'exclude'
|
|
83
|
+
? `Review all matching items except: ${model.ids.join(', ') || 'none'}`
|
|
84
|
+
: `Review items: ${ids.join(', ')}`,
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
>
|
|
88
|
+
Review selection
|
|
89
|
+
</Button>
|
|
90
|
+
)}
|
|
91
|
+
columns={columns}
|
|
92
|
+
rows={envelope.items}
|
|
93
|
+
paginationMode="server"
|
|
94
|
+
rowCount={envelope.total}
|
|
95
|
+
page={envelope.page}
|
|
96
|
+
pageSize={envelope.pageSize}
|
|
97
|
+
pageSizeOptions={[10, 20, 50]}
|
|
98
|
+
onPageChange={(page) => setRequest((previous) => ({ ...previous, page }))}
|
|
99
|
+
// The footer can also call onPageChange to keep the first row visible (20 to 50 at page 2 requests page 1).
|
|
100
|
+
// Functional updates batch both callbacks into one request with the new size and page.
|
|
101
|
+
onPageSizeChange={(pageSize) => setRequest((previous) => ({ ...previous, pageSize }))}
|
|
102
|
+
/>
|
|
103
|
+
<p role="status" className="text-sm text-muted-foreground">
|
|
104
|
+
{review}
|
|
105
|
+
</p>
|
|
106
|
+
</div>
|
|
67
107
|
);
|
|
68
108
|
}
|
|
@@ -7,6 +7,10 @@ export interface DataTableLabels extends PaginationFooterLabels {
|
|
|
7
7
|
/** Non-virtual table overflow region; virtualized regions keep the caller caption. */
|
|
8
8
|
scrollRegion: string;
|
|
9
9
|
selectionCount: (count: number) => string;
|
|
10
|
+
pageSelected: (count: number) => string;
|
|
11
|
+
selectAllMatching: (count: number) => string;
|
|
12
|
+
allMatchingSelected: (count: number) => string;
|
|
13
|
+
clearSelection: string;
|
|
10
14
|
columns: string;
|
|
11
15
|
visibleColumns: string;
|
|
12
16
|
pinColumns: string;
|