@kopexa/data-grid 18.1.0 → 18.3.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,7 +1,14 @@
1
1
  "use client";
2
+ import {
3
+ dataGridMessages
4
+ } from "./chunk-M6DRKGKE.mjs";
2
5
 
3
6
  // src/data-grid.tsx
7
+ import { Button, IconButton } from "@kopexa/button";
4
8
  import { Checkbox } from "@kopexa/checkbox";
9
+ import { DropdownMenu } from "@kopexa/dropdown-menu";
10
+ import { useSafeIntl } from "@kopexa/i18n";
11
+ import { TableHeaderColumnIcon } from "@kopexa/icons";
5
12
  import { createContext } from "@kopexa/react-utils";
6
13
  import { cn } from "@kopexa/shared-utils";
7
14
  import { datagrid } from "@kopexa/theme";
@@ -36,6 +43,7 @@ function DataGrid(props) {
36
43
  isLoading = false,
37
44
  pageSize = 20,
38
45
  cellBorder,
46
+ columnVisibilityToggle,
39
47
  onRowClick,
40
48
  ...rest
41
49
  } = props;
@@ -80,9 +88,11 @@ function DataGrid(props) {
80
88
  rowBorder,
81
89
  cellBorder,
82
90
  loadingMode,
91
+ width,
83
92
  emptyMessage,
84
93
  isLoading,
85
94
  pageSize,
95
+ columnVisibilityToggle,
86
96
  onRowClick
87
97
  }),
88
98
  [
@@ -95,9 +105,11 @@ function DataGrid(props) {
95
105
  rowBorder,
96
106
  cellBorder,
97
107
  loadingMode,
108
+ width,
98
109
  emptyMessage,
99
110
  isLoading,
100
111
  pageSize,
112
+ columnVisibilityToggle,
101
113
  onRowClick
102
114
  ]
103
115
  );
@@ -141,23 +153,33 @@ function DataGridTableHeadRow({
141
153
  function DataGridTableBase({
142
154
  children,
143
155
  className,
156
+ style,
144
157
  ...restProps
145
158
  }) {
146
- const { styles } = useDataGridContext();
159
+ const { styles, table, width } = useDataGridContext();
160
+ const minWidth = width === "fixed" ? table.getVisibleLeafColumns().reduce((acc, column) => acc + column.getSize(), 0) : void 0;
147
161
  return /* @__PURE__ */ jsx(
148
162
  "table",
149
163
  {
150
164
  "data-slot": "data-grid-table",
151
165
  className: styles.table({ className }),
166
+ style: minWidth ? { minWidth, ...style } : style,
152
167
  ...restProps,
153
168
  children
154
169
  }
155
170
  );
156
171
  }
172
+ var STICKY_RIGHT_CELL = "sticky end-0 bg-background border-s border-border shadow-[-2px_0_5px_-2px_rgba(0,0,0,0.1)]";
173
+ var stickyRightStyle = (z) => ({
174
+ position: "sticky",
175
+ right: 0,
176
+ zIndex: z
177
+ });
157
178
  function DataGridTableHeadRowCell({
158
179
  children,
159
180
  header,
160
- dndRef
181
+ dndRef,
182
+ stickyRight
161
183
  }) {
162
184
  var _a;
163
185
  const { styles, columnsPinnable } = useDataGridContext();
@@ -171,13 +193,15 @@ function DataGridTableHeadRowCell({
171
193
  ref: dndRef,
172
194
  style: {
173
195
  "--size": `${header.getSize()}px`,
174
- ...columnsPinnable && isPinned && getPinningStyles(column)
196
+ ...columnsPinnable && isPinned && getPinningStyles(column),
197
+ ...stickyRight && stickyRightStyle(30)
175
198
  },
176
199
  "data-pinned": isPinned || void 0,
177
200
  "data-last-col": isLastLeftPinned ? "left" : isFirstRightPinned ? "right" : void 0,
178
201
  className: cn(
179
202
  styles.headerRowCell(),
180
- (_a = header.column.columnDef.meta) == null ? void 0 : _a.headerClassName
203
+ (_a = header.column.columnDef.meta) == null ? void 0 : _a.headerClassName,
204
+ stickyRight && STICKY_RIGHT_CELL
181
205
  ),
182
206
  children
183
207
  },
@@ -214,8 +238,12 @@ function DataGridTableBody({
214
238
  return /* @__PURE__ */ jsx("tbody", { className: cn(styles.body({ className })), ...restProps, children });
215
239
  }
216
240
  function DataGridTableEmpty() {
217
- const { styles, table, emptyMessage } = useDataGridContext();
218
- const totalColumns = table.getAllColumns().length;
241
+ const { styles, table, emptyMessage, columnVisibilityToggle } = useDataGridContext();
242
+ const { append: hasSettingsColumn } = getSettingsPlacement(
243
+ table,
244
+ columnVisibilityToggle
245
+ );
246
+ const totalColumns = table.getVisibleLeafColumns().length + (hasSettingsColumn ? 1 : 0);
219
247
  return /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: totalColumns, className: styles.empty(), children: emptyMessage || "No data available." }) });
220
248
  }
221
249
  function DataGridTableBodyRowSkeleton({ children }) {
@@ -236,7 +264,8 @@ function DataGridTableBodyRowCell({
236
264
  children,
237
265
  cell,
238
266
  dndRef,
239
- dndStyle
267
+ dndStyle,
268
+ stickyRight
240
269
  }) {
241
270
  var _a;
242
271
  const { styles, columnsResizable, columnsDraggable, columnsPinnable } = useDataGridContext();
@@ -252,14 +281,16 @@ function DataGridTableBodyRowCell({
252
281
  style: {
253
282
  "--size": `${column.getSize()}px`,
254
283
  ...columnsPinnable && isPinned && getPinningStyles(column),
255
- ...dndStyle ? dndStyle : null
284
+ ...dndStyle ? dndStyle : null,
285
+ ...stickyRight && stickyRightStyle(10)
256
286
  },
257
287
  "data-pinned": isPinned || void 0,
258
288
  "data-last-col": isLastLeftPinned ? "left" : isFirstRightPinned ? "right" : void 0,
259
289
  className: cn(
260
290
  styles.bodyRowCell(),
261
291
  columnsResizable && column.getCanResize() && "truncate",
262
- (_a = cell.column.columnDef.meta) == null ? void 0 : _a.cellClassName
292
+ (_a = cell.column.columnDef.meta) == null ? void 0 : _a.cellClassName,
293
+ stickyRight && STICKY_RIGHT_CELL
263
294
  ),
264
295
  children
265
296
  },
@@ -268,7 +299,8 @@ function DataGridTableBodyRowCell({
268
299
  }
269
300
  function DataGridTableBodyRowSkeletonCell({
270
301
  children,
271
- column
302
+ column,
303
+ stickyRight
272
304
  }) {
273
305
  var _a;
274
306
  const { styles, columnsResizable, columnsPinnable } = useDataGridContext();
@@ -280,14 +312,16 @@ function DataGridTableBodyRowSkeletonCell({
280
312
  {
281
313
  style: {
282
314
  "--size": `${column.getSize()}px`,
283
- ...columnsPinnable && isPinned && getPinningStyles(column)
315
+ ...columnsPinnable && isPinned && getPinningStyles(column),
316
+ ...stickyRight && stickyRightStyle(10)
284
317
  },
285
318
  "data-pinned": isPinned || void 0,
286
319
  "data-last-col": isLastLeftPinned ? "left" : isFirstRightPinned ? "right" : void 0,
287
320
  className: cn(
288
321
  styles.bodyRowSkeletonCell(),
289
322
  columnsResizable && column.getCanResize() && "truncate",
290
- (_a = column.columnDef.meta) == null ? void 0 : _a.cellClassName
323
+ (_a = column.columnDef.meta) == null ? void 0 : _a.cellClassName,
324
+ stickyRight && STICKY_RIGHT_CELL
291
325
  ),
292
326
  children
293
327
  }
@@ -318,15 +352,33 @@ function DataGridTableBodyRow({
318
352
  }
319
353
  function DataGridTableBodyRowExpanded({ row }) {
320
354
  var _a, _b, _c;
321
- const { table, styles } = useDataGridContext();
322
- return /* @__PURE__ */ jsx("tr", { className: styles.bodyRowExpanded(), children: /* @__PURE__ */ jsx("td", { colSpan: row.getVisibleCells().length, children: (_c = (_b = (_a = table.getAllColumns().find((column) => {
355
+ const { table, styles, columnVisibilityToggle } = useDataGridContext();
356
+ const { append: hasSettingsColumn } = getSettingsPlacement(
357
+ table,
358
+ columnVisibilityToggle
359
+ );
360
+ return /* @__PURE__ */ jsx("tr", { className: styles.bodyRowExpanded(), children: /* @__PURE__ */ jsx("td", { colSpan: row.getVisibleCells().length + (hasSettingsColumn ? 1 : 0), children: (_c = (_b = (_a = table.getAllColumns().find((column) => {
323
361
  var _a2;
324
362
  return (_a2 = column.columnDef.meta) == null ? void 0 : _a2.expandedContent;
325
363
  })) == null ? void 0 : _a.columnDef.meta) == null ? void 0 : _b.expandedContent) == null ? void 0 : _c.call(_b, row.original) }) });
326
364
  }
365
+ var SETTINGS_COLUMN_WIDTH = 44;
366
+ function getSettingsPlacement(table, enabled) {
367
+ if (!enabled) return { append: false };
368
+ if (!table.getAllLeafColumns().some((column) => column.getCanHide())) {
369
+ return { append: false };
370
+ }
371
+ const leafColumns = table.getVisibleLeafColumns();
372
+ const lastColumn = leafColumns[leafColumns.length - 1];
373
+ if (lastColumn && lastColumn.accessorFn == null) {
374
+ return { reuseColumnId: lastColumn.id, append: false };
375
+ }
376
+ return { append: true };
377
+ }
327
378
  function DataGridTable() {
328
379
  const {
329
380
  table,
381
+ styles,
330
382
  columnsResizable,
331
383
  columnsPinnable,
332
384
  stripped,
@@ -334,38 +386,98 @@ function DataGridTable() {
334
386
  cellBorder,
335
387
  loadingMode,
336
388
  isLoading,
337
- pageSize
389
+ pageSize,
390
+ columnVisibilityToggle
338
391
  } = useDataGridContext();
392
+ const { reuseColumnId, append: showColumnSettings } = getSettingsPlacement(
393
+ table,
394
+ columnVisibilityToggle
395
+ );
396
+ const headerGroups = table.getHeaderGroups();
397
+ const settingsCellStyle = {
398
+ "--size": `${SETTINGS_COLUMN_WIDTH}px`
399
+ };
339
400
  return /* @__PURE__ */ jsxs(DataGridTableBase, { children: [
340
- /* @__PURE__ */ jsx(DataGridTableHead, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(DataGridTableHeadRow, { headerGroup, children: headerGroup.headers.map((header) => {
341
- const { column } = header;
342
- return /* @__PURE__ */ jsxs(DataGridTableHeadRowCell, { header, children: [
343
- header.isPlaceholder ? null : flexRender(
401
+ /* @__PURE__ */ jsx(DataGridTableHead, { children: headerGroups.map((headerGroup, groupIndex) => /* @__PURE__ */ jsxs(DataGridTableHeadRow, { headerGroup, children: [
402
+ headerGroup.headers.map((header) => {
403
+ const { column } = header;
404
+ const isReuseColumn = reuseColumnId != null && column.id === reuseColumnId;
405
+ const reuseToggleHere = isReuseColumn && groupIndex === headerGroups.length - 1;
406
+ const headerContent = header.isPlaceholder ? null : flexRender(
344
407
  header.column.columnDef.header,
345
408
  header.getContext()
346
- ),
347
- columnsResizable && column.getCanResize() && /* @__PURE__ */ jsx(DataGridTableHeadRowCellResize, { header })
348
- ] }, column.id);
349
- }) }, headerGroup.id)) }),
409
+ );
410
+ return /* @__PURE__ */ jsxs(
411
+ DataGridTableHeadRowCell,
412
+ {
413
+ header,
414
+ stickyRight: isReuseColumn,
415
+ children: [
416
+ reuseToggleHere ? /* @__PURE__ */ jsxs("span", { className: "flex w-full items-center justify-center gap-1.5", children: [
417
+ headerContent,
418
+ /* @__PURE__ */ jsx(DataGridHeaderColumnToggle, {})
419
+ ] }) : headerContent,
420
+ columnsResizable && column.getCanResize() && /* @__PURE__ */ jsx(DataGridTableHeadRowCellResize, { header })
421
+ ]
422
+ },
423
+ column.id
424
+ );
425
+ }),
426
+ showColumnSettings && /* @__PURE__ */ jsx(
427
+ "th",
428
+ {
429
+ className: cn(styles.headerRowCell(), STICKY_RIGHT_CELL),
430
+ style: { ...settingsCellStyle, ...stickyRightStyle(30) },
431
+ children: groupIndex === headerGroups.length - 1 && /* @__PURE__ */ jsx("span", { className: "flex justify-center", children: /* @__PURE__ */ jsx(DataGridHeaderColumnToggle, {}) })
432
+ }
433
+ )
434
+ ] }, headerGroup.id)) }),
350
435
  (stripped || !rowBorder) && !cellBorder && !columnsPinnable && /* @__PURE__ */ jsx(DataGridTableRowSpacer, {}),
351
- /* @__PURE__ */ jsx(DataGridTableBody, { children: loadingMode === "skeleton" && isLoading && pageSize ? Array.from({ length: pageSize }).map((_, rowIndex) => /* @__PURE__ */ jsx(DataGridTableBodyRowSkeleton, { children: table.getVisibleFlatColumns().map((column, colIndex) => {
352
- var _a;
353
- return /* @__PURE__ */ jsx(
354
- DataGridTableBodyRowSkeletonCell,
436
+ /* @__PURE__ */ jsx(DataGridTableBody, { children: loadingMode === "skeleton" && isLoading && pageSize ? Array.from({ length: pageSize }).map((_, rowIndex) => /* @__PURE__ */ jsxs(DataGridTableBodyRowSkeleton, { children: [
437
+ table.getVisibleFlatColumns().map((column, colIndex) => {
438
+ var _a;
439
+ return /* @__PURE__ */ jsx(
440
+ DataGridTableBodyRowSkeletonCell,
441
+ {
442
+ column,
443
+ stickyRight: reuseColumnId != null && column.id === reuseColumnId,
444
+ children: (_a = column.columnDef.meta) == null ? void 0 : _a.skeleton
445
+ },
446
+ colIndex.toString()
447
+ );
448
+ }),
449
+ showColumnSettings && /* @__PURE__ */ jsx(
450
+ "td",
355
451
  {
356
- column,
357
- children: (_a = column.columnDef.meta) == null ? void 0 : _a.skeleton
358
- },
359
- colIndex.toString()
360
- );
361
- }) }, rowIndex.toString())) : table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => {
452
+ className: cn(styles.bodyRowCell(), STICKY_RIGHT_CELL),
453
+ style: { ...settingsCellStyle, ...stickyRightStyle(10) }
454
+ }
455
+ )
456
+ ] }, rowIndex.toString())) : table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => {
362
457
  return /* @__PURE__ */ jsxs(Fragment, { children: [
363
- /* @__PURE__ */ jsx(DataGridTableBodyRow, { row, children: row.getVisibleCells().map((cell) => {
364
- return /* @__PURE__ */ jsx(DataGridTableBodyRowCell, { cell, children: flexRender(
365
- cell.column.columnDef.cell,
366
- cell.getContext()
367
- ) }, cell.id);
368
- }) }, row.id),
458
+ /* @__PURE__ */ jsxs(DataGridTableBodyRow, { row, children: [
459
+ row.getVisibleCells().map((cell) => {
460
+ return /* @__PURE__ */ jsx(
461
+ DataGridTableBodyRowCell,
462
+ {
463
+ cell,
464
+ stickyRight: reuseColumnId != null && cell.column.id === reuseColumnId,
465
+ children: flexRender(
466
+ cell.column.columnDef.cell,
467
+ cell.getContext()
468
+ )
469
+ },
470
+ cell.id
471
+ );
472
+ }),
473
+ showColumnSettings && /* @__PURE__ */ jsx(
474
+ "td",
475
+ {
476
+ className: cn(styles.bodyRowCell(), STICKY_RIGHT_CELL),
477
+ style: { ...settingsCellStyle, ...stickyRightStyle(10) }
478
+ }
479
+ )
480
+ ] }, row.id),
369
481
  row.getIsExpanded() && /* @__PURE__ */ jsx(DataGridTableBodyRowExpanded, { row })
370
482
  ] }, row.id);
371
483
  }) : /* @__PURE__ */ jsx(DataGridTableEmpty, {}) })
@@ -381,6 +493,52 @@ function getPinningStyles(column) {
381
493
  zIndex: isPinned ? 1 : 0
382
494
  };
383
495
  }
496
+ function DataGridColumnToggle({
497
+ label,
498
+ align = "end",
499
+ children
500
+ }) {
501
+ const { table } = useDataGridContext();
502
+ const t = useSafeIntl();
503
+ const columns = table.getAllLeafColumns().filter((column) => column.getCanHide());
504
+ if (columns.length === 0) {
505
+ return null;
506
+ }
507
+ return /* @__PURE__ */ jsxs(DropdownMenu.Root, { children: [
508
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: children != null ? children : /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", children: [
509
+ /* @__PURE__ */ jsx(TableHeaderColumnIcon, { className: "size-4" }),
510
+ label != null ? label : t.formatMessage(dataGridMessages.columns)
511
+ ] }) }),
512
+ /* @__PURE__ */ jsx(DropdownMenu.Content, { align, children: columns.map((column) => {
513
+ var _a, _b;
514
+ return /* @__PURE__ */ jsx(
515
+ DropdownMenu.CheckboxItem,
516
+ {
517
+ checked: column.getIsVisible(),
518
+ onCheckedChange: (value) => column.toggleVisibility(!!value),
519
+ onSelect: (event) => event.preventDefault(),
520
+ children: (_b = (_a = column.columnDef.meta) == null ? void 0 : _a.headerTitle) != null ? _b : column.id
521
+ },
522
+ column.id
523
+ );
524
+ }) })
525
+ ] });
526
+ }
527
+ function DataGridHeaderColumnToggle() {
528
+ const t = useSafeIntl();
529
+ const label = t.formatMessage(dataGridMessages.columns);
530
+ return /* @__PURE__ */ jsx(DataGridColumnToggle, { align: "end", children: /* @__PURE__ */ jsx(
531
+ IconButton,
532
+ {
533
+ "aria-label": label,
534
+ tooltip: label,
535
+ variant: "ghost",
536
+ size: "sm",
537
+ className: "shrink-0",
538
+ children: /* @__PURE__ */ jsx(TableHeaderColumnIcon, {})
539
+ }
540
+ ) });
541
+ }
384
542
  function DataGridTableRowSelectAll({
385
543
  size
386
544
  }) {
@@ -428,7 +586,9 @@ function DataGridTableRowSelect({
428
586
  export {
429
587
  DataGrid,
430
588
  DataGridContainer,
589
+ SETTINGS_COLUMN_WIDTH,
431
590
  DataGridTable,
591
+ DataGridColumnToggle,
432
592
  DataGridTableRowSelectAll,
433
593
  DataGridTableRowSelect
434
594
  };
@@ -0,0 +1,15 @@
1
+ "use client";
2
+
3
+ // src/data-grid-messages.ts
4
+ import { defineMessages } from "@kopexa/i18n";
5
+ var dataGridMessages = defineMessages({
6
+ columns: {
7
+ id: "data-grid.columns",
8
+ defaultMessage: "Columns",
9
+ description: "Label for the column visibility toggle button"
10
+ }
11
+ });
12
+
13
+ export {
14
+ dataGridMessages
15
+ };
@@ -0,0 +1,9 @@
1
+ declare const dataGridMessages: {
2
+ columns: {
3
+ id: string;
4
+ defaultMessage: string;
5
+ description: string;
6
+ };
7
+ };
8
+
9
+ export { dataGridMessages };
@@ -0,0 +1,9 @@
1
+ declare const dataGridMessages: {
2
+ columns: {
3
+ id: string;
4
+ defaultMessage: string;
5
+ description: string;
6
+ };
7
+ };
8
+
9
+ export { dataGridMessages };
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/data-grid-messages.ts
22
+ var data_grid_messages_exports = {};
23
+ __export(data_grid_messages_exports, {
24
+ dataGridMessages: () => dataGridMessages
25
+ });
26
+ module.exports = __toCommonJS(data_grid_messages_exports);
27
+ var import_i18n = require("@kopexa/i18n");
28
+ var dataGridMessages = (0, import_i18n.defineMessages)({
29
+ columns: {
30
+ id: "data-grid.columns",
31
+ defaultMessage: "Columns",
32
+ description: "Label for the column visibility toggle button"
33
+ }
34
+ });
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ dataGridMessages
38
+ });
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ dataGridMessages
4
+ } from "./chunk-M6DRKGKE.mjs";
5
+ export {
6
+ dataGridMessages
7
+ };
@@ -17,6 +17,14 @@ type BaseProps<TData extends object> = {
17
17
  emptyMessage?: string;
18
18
  isLoading?: boolean;
19
19
  pageSize?: number;
20
+ /**
21
+ * Render a column-visibility icon button in a trailing column header instead
22
+ * of relying on a standalone `<DataGrid.ColumnToggle />`. Reuses the last
23
+ * column's header when it's a display column (e.g. an actions column),
24
+ * otherwise appends a dedicated fixed-width settings column. No-op when no
25
+ * column is hideable.
26
+ */
27
+ columnVisibilityToggle?: boolean;
20
28
  onRowClick?: (row: TData) => void;
21
29
  };
22
30
  type DataGridProps<TData extends object> = BaseProps<TData> & DataGridVariants & {
@@ -28,7 +36,24 @@ declare function DataGridContainer({ children, className, }: {
28
36
  className?: string;
29
37
  border?: boolean;
30
38
  }): react_jsx_runtime.JSX.Element;
39
+ declare const SETTINGS_COLUMN_WIDTH = 44;
31
40
  declare function DataGridTable<TData>(): react_jsx_runtime.JSX.Element;
41
+ type DataGridColumnToggleProps = {
42
+ /**
43
+ * Trigger button label. Defaults to the translated "Columns" message;
44
+ * ignored when `children` is provided.
45
+ */
46
+ label?: string;
47
+ align?: "start" | "center" | "end";
48
+ /** Custom trigger; replaces the default button. */
49
+ children?: ReactNode;
50
+ };
51
+ /**
52
+ * Dropdown that toggles column visibility. Lists every hideable leaf column
53
+ * (`enableHiding !== false`) and reflects/sets `columnVisibility` on the table.
54
+ * Column labels come from `meta.headerTitle`, falling back to the column id.
55
+ */
56
+ declare function DataGridColumnToggle({ label, align, children, }: DataGridColumnToggleProps): react_jsx_runtime.JSX.Element | null;
32
57
  declare function DataGridTableRowSelectAll({ size, }: {
33
58
  size?: "sm" | "md" | "lg";
34
59
  }): react_jsx_runtime.JSX.Element;
@@ -37,4 +62,4 @@ declare function DataGridTableRowSelect<TData>({ row, size, }: {
37
62
  size?: "sm" | "md" | "lg";
38
63
  }): react_jsx_runtime.JSX.Element;
39
64
 
40
- export { DataGrid, DataGridContainer, type DataGridProps, DataGridTable, DataGridTableRowSelect, DataGridTableRowSelectAll };
65
+ export { DataGrid, DataGridColumnToggle, type DataGridColumnToggleProps, DataGridContainer, type DataGridProps, DataGridTable, DataGridTableRowSelect, DataGridTableRowSelectAll, SETTINGS_COLUMN_WIDTH };
@@ -17,6 +17,14 @@ type BaseProps<TData extends object> = {
17
17
  emptyMessage?: string;
18
18
  isLoading?: boolean;
19
19
  pageSize?: number;
20
+ /**
21
+ * Render a column-visibility icon button in a trailing column header instead
22
+ * of relying on a standalone `<DataGrid.ColumnToggle />`. Reuses the last
23
+ * column's header when it's a display column (e.g. an actions column),
24
+ * otherwise appends a dedicated fixed-width settings column. No-op when no
25
+ * column is hideable.
26
+ */
27
+ columnVisibilityToggle?: boolean;
20
28
  onRowClick?: (row: TData) => void;
21
29
  };
22
30
  type DataGridProps<TData extends object> = BaseProps<TData> & DataGridVariants & {
@@ -28,7 +36,24 @@ declare function DataGridContainer({ children, className, }: {
28
36
  className?: string;
29
37
  border?: boolean;
30
38
  }): react_jsx_runtime.JSX.Element;
39
+ declare const SETTINGS_COLUMN_WIDTH = 44;
31
40
  declare function DataGridTable<TData>(): react_jsx_runtime.JSX.Element;
41
+ type DataGridColumnToggleProps = {
42
+ /**
43
+ * Trigger button label. Defaults to the translated "Columns" message;
44
+ * ignored when `children` is provided.
45
+ */
46
+ label?: string;
47
+ align?: "start" | "center" | "end";
48
+ /** Custom trigger; replaces the default button. */
49
+ children?: ReactNode;
50
+ };
51
+ /**
52
+ * Dropdown that toggles column visibility. Lists every hideable leaf column
53
+ * (`enableHiding !== false`) and reflects/sets `columnVisibility` on the table.
54
+ * Column labels come from `meta.headerTitle`, falling back to the column id.
55
+ */
56
+ declare function DataGridColumnToggle({ label, align, children, }: DataGridColumnToggleProps): react_jsx_runtime.JSX.Element | null;
32
57
  declare function DataGridTableRowSelectAll({ size, }: {
33
58
  size?: "sm" | "md" | "lg";
34
59
  }): react_jsx_runtime.JSX.Element;
@@ -37,4 +62,4 @@ declare function DataGridTableRowSelect<TData>({ row, size, }: {
37
62
  size?: "sm" | "md" | "lg";
38
63
  }): react_jsx_runtime.JSX.Element;
39
64
 
40
- export { DataGrid, DataGridContainer, type DataGridProps, DataGridTable, DataGridTableRowSelect, DataGridTableRowSelectAll };
65
+ export { DataGrid, DataGridColumnToggle, type DataGridColumnToggleProps, DataGridContainer, type DataGridProps, DataGridTable, DataGridTableRowSelect, DataGridTableRowSelectAll, SETTINGS_COLUMN_WIDTH };