@redis-ui/table 2.23.2 → 3.3.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.
Files changed (85) hide show
  1. package/dist/Table/Table.cjs +34 -5
  2. package/dist/Table/Table.context.d.ts +0 -1
  3. package/dist/Table/Table.d.ts +22 -18
  4. package/dist/Table/Table.js +34 -5
  5. package/dist/Table/Table.style.cjs +65 -39
  6. package/dist/Table/Table.style.d.ts +10 -7
  7. package/dist/Table/Table.style.js +65 -39
  8. package/dist/Table/Table.types.d.ts +8 -20
  9. package/dist/Table/components/Compose/Compose.cjs +4 -6
  10. package/dist/Table/components/Compose/Compose.d.ts +10 -9
  11. package/dist/Table/components/Compose/Compose.js +5 -7
  12. package/dist/Table/components/ExpandRowButton/useExpanderColumn.cjs +0 -1
  13. package/dist/Table/components/ExpandRowButton/useExpanderColumn.js +0 -1
  14. package/dist/Table/components/PluggableTable/PluggableTable.cjs +7 -1
  15. package/dist/Table/components/PluggableTable/PluggableTable.d.ts +3 -1
  16. package/dist/Table/components/PluggableTable/PluggableTable.js +7 -1
  17. package/dist/Table/components/PluggableTable/compositionComponents.cjs +4 -0
  18. package/dist/Table/components/PluggableTable/compositionComponents.d.ts +8 -6
  19. package/dist/Table/components/PluggableTable/compositionComponents.js +4 -0
  20. package/dist/Table/components/RowSelection/useRowSelectionColumn.cjs +0 -1
  21. package/dist/Table/components/RowSelection/useRowSelectionColumn.js +0 -1
  22. package/dist/Table/components/TableBody/TableBody.d.ts +2 -2
  23. package/dist/Table/components/TableBodyCell/TableBodyCell.d.ts +1 -1
  24. package/dist/Table/components/TableBodyCell/components/Compose/Compose.d.ts +1 -1
  25. package/dist/Table/components/TableBodyRow/TableBodyRow.d.ts +1 -1
  26. package/dist/Table/components/TableBodyRow/components/Compose/Compose.d.ts +1 -1
  27. package/dist/Table/components/TableBottomBar/TableBottomBar.cjs +12 -0
  28. package/dist/Table/components/TableBottomBar/TableBottomBar.d.ts +2 -0
  29. package/dist/Table/components/TableBottomBar/TableBottomBar.js +12 -0
  30. package/dist/Table/components/TableBottomBar/TableBottomBar.test.d.ts +1 -0
  31. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.cjs +8 -1
  32. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.d.ts +1 -1
  33. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.js +9 -2
  34. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.style.cjs +11 -1
  35. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.style.d.ts +3 -2
  36. package/dist/Table/components/TableExpandedRow/TableAnimatedExpandedRow.style.js +11 -1
  37. package/dist/Table/components/TableExpandedRow/TableExpandedRow.cjs +2 -1
  38. package/dist/Table/components/TableExpandedRow/TableExpandedRow.d.ts +1 -1
  39. package/dist/Table/components/TableExpandedRow/TableExpandedRow.js +2 -1
  40. package/dist/Table/components/TableExpandedRow/TableExpandedRow.style.cjs +2 -2
  41. package/dist/Table/components/TableExpandedRow/TableExpandedRow.style.js +2 -2
  42. package/dist/Table/components/TableExpandedRow/TableExpandedRow.types.d.ts +3 -2
  43. package/dist/Table/components/TableHeader/TableHeader.d.ts +1 -1
  44. package/dist/Table/components/TableHeaderCell/TableHeaderCell.d.ts +1 -1
  45. package/dist/Table/components/TableHeaderCell/components/Compose/Compose.cjs +1 -1
  46. package/dist/Table/components/TableHeaderCell/components/Compose/Compose.d.ts +1 -1
  47. package/dist/Table/components/TableHeaderCell/components/Compose/Compose.js +2 -2
  48. package/dist/Table/components/TableHeaderCell/components/Heading/Heading.d.ts +2 -3
  49. package/dist/Table/components/TablePagination/TablePagination.d.ts +3 -2
  50. package/dist/Table/components/TablePagination/TablePagination.style.cjs +1 -1
  51. package/dist/Table/components/TablePagination/TablePagination.style.d.ts +3 -2
  52. package/dist/Table/components/TablePagination/TablePagination.style.js +1 -1
  53. package/dist/Table/components/TableRoot/TableRoot.cjs +6 -3
  54. package/dist/Table/components/TableRoot/TableRoot.js +7 -4
  55. package/dist/Table/components/TableTopBar/TableTopBar.cjs +12 -0
  56. package/dist/Table/components/TableTopBar/TableTopBar.d.ts +2 -0
  57. package/dist/Table/components/TableTopBar/TableTopBar.js +12 -0
  58. package/dist/Table/components/TableTopBar/TableTopBar.test.d.ts +1 -0
  59. package/dist/Table/index.d.ts +1 -0
  60. package/dist/Table/plugins/ColumnVisibilityPlugin.cjs +14 -0
  61. package/dist/Table/plugins/ColumnVisibilityPlugin.d.ts +10 -0
  62. package/dist/Table/plugins/ColumnVisibilityPlugin.js +14 -0
  63. package/dist/Table/plugins/ColumnVisibilityPlugin.test.d.ts +1 -0
  64. package/dist/Table/plugins/ExpandableRowPlugin.cjs +16 -3
  65. package/dist/Table/plugins/ExpandableRowPlugin.d.ts +3 -1
  66. package/dist/Table/plugins/ExpandableRowPlugin.js +14 -1
  67. package/dist/Table/plugins/FilteringPlugin.cjs +25 -0
  68. package/dist/Table/plugins/FilteringPlugin.d.ts +20 -0
  69. package/dist/Table/plugins/FilteringPlugin.js +25 -0
  70. package/dist/Table/plugins/FilteringPlugin.test.d.ts +1 -0
  71. package/dist/Table/plugins/PaginationPlugin.d.ts +1 -1
  72. package/dist/Table/plugins/RowNavigationPlugin.d.ts +1 -1
  73. package/dist/Table/plugins/RowSelectionPlugin.cjs +11 -1
  74. package/dist/Table/plugins/RowSelectionPlugin.d.ts +3 -1
  75. package/dist/Table/plugins/RowSelectionPlugin.js +11 -1
  76. package/dist/Table/tanStackExtendedTypes.d.ts +3 -3
  77. package/dist/Table/utils/plugin.utils.cjs +17 -2
  78. package/dist/Table/utils/plugin.utils.d.ts +5 -2
  79. package/dist/Table/utils/plugin.utils.js +18 -3
  80. package/dist/Table/utils/table.utils.cjs +13 -0
  81. package/dist/Table/utils/table.utils.d.ts +12 -0
  82. package/dist/Table/utils/table.utils.js +13 -0
  83. package/dist/index.cjs +2 -0
  84. package/dist/index.js +2 -0
  85. package/package.json +4 -4
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const index = require("../../node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs");
4
+ const ClickableRowPlugin = require("./ClickableRowPlugin.cjs");
4
5
  const DEFAULT_ROW_SELECTION = {};
5
6
  const useRowSelectionPlugin = ({
6
7
  rowSelection,
7
8
  defaultRowSelection,
8
9
  onRowSelectionChange,
9
10
  rowSelectionMode,
10
- getRowCanSelect
11
+ getRowCanSelect,
12
+ selectRowOnClick
11
13
  }) => {
14
+ const clickablePluginData = ClickableRowPlugin.useClickableRowPlugin({
15
+ getCanRowClick: (row) => !!(selectRowOnClick && row.getCanSelect()),
16
+ onRowClick: (row) => row.toggleSelected(),
17
+ shouldClickOnEnter: true
18
+ });
12
19
  const [rowSelectionState = DEFAULT_ROW_SELECTION, setRowSelectionState] = index.useControllableState({
13
20
  prop: rowSelection,
14
21
  defaultProp: defaultRowSelection,
@@ -22,6 +29,9 @@ const useRowSelectionPlugin = ({
22
29
  enableRowSelection: getRowCanSelect ?? true,
23
30
  enableMultiRowSelection: rowSelectionMode === "multiple",
24
31
  onRowSelectionChange: setRowSelectionState
32
+ },
33
+ context: {
34
+ ...selectRowOnClick ? clickablePluginData == null ? void 0 : clickablePluginData.context : null
25
35
  }
26
36
  };
27
37
  };
@@ -8,5 +8,7 @@ export interface TableRowSelectionParams<T extends object> {
8
8
  rowSelectionMode?: 'single' | 'multiple';
9
9
  /** Allows individual rows to be selectable */
10
10
  getRowCanSelect?: (row: Row<T>) => boolean;
11
+ /** Allows selecting row by Click on whole row and by pressing Enter, when row is focused */
12
+ selectRowOnClick?: boolean;
11
13
  }
12
- export declare const useRowSelectionPlugin: <T extends object>({ rowSelection, defaultRowSelection, onRowSelectionChange, rowSelectionMode, getRowCanSelect }: TableRowSelectionParams<T>) => TablePluginData<T>;
14
+ export declare const useRowSelectionPlugin: <T extends object>({ rowSelection, defaultRowSelection, onRowSelectionChange, rowSelectionMode, getRowCanSelect, selectRowOnClick }: TableRowSelectionParams<T>) => TablePluginData<T>;
@@ -1,12 +1,19 @@
1
1
  import { useControllableState } from "../../node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
2
+ import { useClickableRowPlugin } from "./ClickableRowPlugin.js";
2
3
  const DEFAULT_ROW_SELECTION = {};
3
4
  const useRowSelectionPlugin = ({
4
5
  rowSelection,
5
6
  defaultRowSelection,
6
7
  onRowSelectionChange,
7
8
  rowSelectionMode,
8
- getRowCanSelect
9
+ getRowCanSelect,
10
+ selectRowOnClick
9
11
  }) => {
12
+ const clickablePluginData = useClickableRowPlugin({
13
+ getCanRowClick: (row) => !!(selectRowOnClick && row.getCanSelect()),
14
+ onRowClick: (row) => row.toggleSelected(),
15
+ shouldClickOnEnter: true
16
+ });
10
17
  const [rowSelectionState = DEFAULT_ROW_SELECTION, setRowSelectionState] = useControllableState({
11
18
  prop: rowSelection,
12
19
  defaultProp: defaultRowSelection,
@@ -20,6 +27,9 @@ const useRowSelectionPlugin = ({
20
27
  enableRowSelection: getRowCanSelect ?? true,
21
28
  enableMultiRowSelection: rowSelectionMode === "multiple",
22
29
  onRowSelectionChange: setRowSelectionState
30
+ },
31
+ context: {
32
+ ...selectRowOnClick ? clickablePluginData == null ? void 0 : clickablePluginData.context : null
23
33
  }
24
34
  };
25
35
  };
@@ -1,19 +1,19 @@
1
1
  import '@tanstack/table-core';
2
2
  import { Cell, Header } from '@tanstack/react-table';
3
3
  import { HTMLAttributes } from 'react';
4
+ import { ColumnSizeUnit } from './Table.types';
4
5
  declare module '@tanstack/table-core' {
5
- type CellSizingUnits = 'fraction' | 'px' | 'rem';
6
6
  interface StringHeaderIdentifier {
7
7
  isHeaderHidden?: boolean;
8
8
  isHeaderCustom?: boolean;
9
- sizeUnit?: CellSizingUnits;
9
+ sizeUnit?: ColumnSizeUnit;
10
10
  getHeaderCellProps?: VoidFunction;
11
11
  getCellProps?: VoidFunction;
12
12
  }
13
13
  interface IdIdentifier<TData, TValue> {
14
14
  isHeaderHidden?: boolean;
15
15
  isHeaderCustom?: boolean;
16
- sizeUnit?: CellSizingUnits;
16
+ sizeUnit?: ColumnSizeUnit;
17
17
  getHeaderCellProps?: (header: Header<TData, unknown>) => HTMLAttributes<HTMLTableCellElement> & Record<string, unknown>;
18
18
  getCellProps?: (data: TData, cell: Cell<TData, unknown>) => HTMLAttributes<HTMLTableCellElement> & Record<string, unknown>;
19
19
  }
@@ -17,9 +17,9 @@ const mergeObjects = (key, container1, container2) => {
17
17
  }
18
18
  } : null;
19
19
  };
20
- const mergePluginsData = (plugins) => {
20
+ const mergePluginsData = (plugins, tableOptions) => {
21
21
  const merged = {
22
- tableOptions: {},
22
+ tableOptions: tableOptions ?? {},
23
23
  context: {}
24
24
  };
25
25
  if (!(plugins == null ? void 0 : plugins.length)) {
@@ -45,5 +45,20 @@ const mergePluginsData = (plugins) => {
45
45
  const buildPluginContext = (key, context) => ({
46
46
  [key]: context
47
47
  });
48
+ const normalizeColumns = (columns) => columns.map((column) => {
49
+ const {
50
+ size,
51
+ minSize,
52
+ sizeUnit
53
+ } = column;
54
+ const sizeFix = !minSize && sizeUnit && sizeUnit !== "fraction" && typeof size === "number" && size < 20 ? {
55
+ minSize: size
56
+ } : {};
57
+ return {
58
+ ...column,
59
+ ...sizeFix
60
+ };
61
+ });
48
62
  exports.buildPluginContext = buildPluginContext;
49
63
  exports.mergePluginsData = mergePluginsData;
64
+ exports.normalizeColumns = normalizeColumns;
@@ -1,6 +1,8 @@
1
1
  import { TableOptions } from '@tanstack/table-core';
2
- import { RowData } from '@tanstack/react-table';
2
+ import { ColumnDef, RowData } from '@tanstack/react-table';
3
+ import { SetOptional } from 'type-fest';
3
4
  export type PartialTableOptions<T extends RowData> = Partial<Omit<TableOptions<T>, 'columns' | 'data' | 'getRowId' | 'onStateChange' | 'getCoreRowModel' | 'defaultColumn' | 'debugTable' | 'debugRows' | 'debugHeaders' | 'debugColumns' | 'debugCells' | 'debugAll' | 'autoResetAll' | 'meta'>>;
5
+ export type UserTableOptions<T extends RowData> = Omit<SetOptional<TableOptions<T>, 'getCoreRowModel'>, 'data' | 'columns'>;
4
6
  export type TablePluginData<T extends RowData> = {
5
7
  /** Partial table options that will be smartly merged with other table options */
6
8
  tableOptions: PartialTableOptions<T>;
@@ -13,5 +15,6 @@ export type TableMergedData<T extends RowData> = {
13
15
  tableOptions: PartialTableOptions<T>;
14
16
  context?: Record<string, Record<string, unknown>>;
15
17
  };
16
- export declare const mergePluginsData: <T extends unknown>(plugins?: TablePluginData<T>[] | undefined) => TableMergedData<T>;
18
+ export declare const mergePluginsData: <T extends unknown>(plugins?: TablePluginData<T>[] | undefined, tableOptions?: UserTableOptions<T> | undefined) => TableMergedData<T>;
17
19
  export declare const buildPluginContext: (key: string, context: Record<string, unknown>) => Record<string, Record<string, unknown>>;
20
+ export declare const normalizeColumns: <T extends object>(columns: ColumnDef<T, unknown>[]) => ColumnDef<T, unknown>[];
@@ -15,9 +15,9 @@ const mergeObjects = (key, container1, container2) => {
15
15
  }
16
16
  } : null;
17
17
  };
18
- const mergePluginsData = (plugins) => {
18
+ const mergePluginsData = (plugins, tableOptions) => {
19
19
  const merged = {
20
- tableOptions: {},
20
+ tableOptions: tableOptions ?? {},
21
21
  context: {}
22
22
  };
23
23
  if (!(plugins == null ? void 0 : plugins.length)) {
@@ -43,7 +43,22 @@ const mergePluginsData = (plugins) => {
43
43
  const buildPluginContext = (key, context) => ({
44
44
  [key]: context
45
45
  });
46
+ const normalizeColumns = (columns) => columns.map((column) => {
47
+ const {
48
+ size,
49
+ minSize,
50
+ sizeUnit
51
+ } = column;
52
+ const sizeFix = !minSize && sizeUnit && sizeUnit !== "fraction" && typeof size === "number" && size < 20 ? {
53
+ minSize: size
54
+ } : {};
55
+ return {
56
+ ...column,
57
+ ...sizeFix
58
+ };
59
+ });
46
60
  export {
47
61
  buildPluginContext,
48
- mergePluginsData
62
+ mergePluginsData,
63
+ normalizeColumns
49
64
  };
@@ -10,4 +10,17 @@ const getWidth = (column) => {
10
10
  const unit = !sizeUnit || sizeUnit === "fraction" ? "%" : sizeUnit;
11
11
  return `${size}${unit}`;
12
12
  };
13
+ const calcTableMinSize = (columns) => {
14
+ if (!(columns == null ? void 0 : columns.length)) return "0";
15
+ const sums = columns.reduce((acc, {
16
+ sizeUnit,
17
+ size = 150
18
+ }) => {
19
+ const unit = !sizeUnit || sizeUnit === "fraction" ? "px" : sizeUnit;
20
+ acc[unit] = (acc[unit] || 0) + size;
21
+ return acc;
22
+ }, {});
23
+ return `calc(${Object.entries(sums).map(([sizeUnit, size]) => `${size}${sizeUnit}`).join(" + ")})`;
24
+ };
25
+ exports.calcTableMinSize = calcTableMinSize;
13
26
  exports.getWidth = getWidth;
@@ -1,2 +1,14 @@
1
1
  import { Column } from '@tanstack/react-table';
2
+ import type { ColumnSizeUnit } from '../Table.types';
2
3
  export declare const getWidth: <T extends object>(column: Column<T, unknown>) => string | number;
4
+ export type SizeParams = {
5
+ size?: number;
6
+ sizeUnit?: ColumnSizeUnit;
7
+ };
8
+ /**
9
+ * Calculates expected minimal table size, using column definition size and sizeUnit fields.
10
+ * Fractional size is accepted as absolute value in pixels, other units as is.
11
+ * Summary string is CSS-only value (`calc(...)`),
12
+ * that can be used for styling or can be passed to the minWidth prop of the table
13
+ */
14
+ export declare const calcTableMinSize: (columns: SizeParams[]) => string;
@@ -8,6 +8,19 @@ const getWidth = (column) => {
8
8
  const unit = !sizeUnit || sizeUnit === "fraction" ? "%" : sizeUnit;
9
9
  return `${size}${unit}`;
10
10
  };
11
+ const calcTableMinSize = (columns) => {
12
+ if (!(columns == null ? void 0 : columns.length)) return "0";
13
+ const sums = columns.reduce((acc, {
14
+ sizeUnit,
15
+ size = 150
16
+ }) => {
17
+ const unit = !sizeUnit || sizeUnit === "fraction" ? "px" : sizeUnit;
18
+ acc[unit] = (acc[unit] || 0) + size;
19
+ return acc;
20
+ }, {});
21
+ return `calc(${Object.entries(sums).map(([sizeUnit, size]) => `${size}${sizeUnit}`).join(" + ")})`;
22
+ };
11
23
  export {
24
+ calcTableMinSize,
12
25
  getWidth
13
26
  };
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ const ShowOnRowHover_style = require("./Table/components/ShowOnRowHover/ShowOnRo
5
5
  const index = require("./node_modules/@tanstack/react-table/build/lib/index.cjs");
6
6
  const Table_context = require("./Table/Table.context.cjs");
7
7
  const plugin_utils = require("./Table/utils/plugin.utils.cjs");
8
+ const table_utils = require("./Table/utils/table.utils.cjs");
8
9
  const index$1 = require("./node_modules/@tanstack/table-core/build/lib/index.cjs");
9
10
  exports.Table = Table.default;
10
11
  exports.ShowOnRowHover = ShowOnRowHover_style.ShowOnRowHover;
@@ -15,6 +16,7 @@ exports.useComposeContext = Table_context.useComposeContext;
15
16
  exports.usePluginContext = Table_context.usePluginContext;
16
17
  exports.useTableContext = Table_context.useTableContext;
17
18
  exports.buildPluginContext = plugin_utils.buildPluginContext;
19
+ exports.calcTableMinSize = table_utils.calcTableMinSize;
18
20
  exports.ColumnFaceting = index$1.ColumnFaceting;
19
21
  exports.ColumnFiltering = index$1.ColumnFiltering;
20
22
  exports.ColumnGrouping = index$1.ColumnGrouping;
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { ShowOnRowHover } from "./Table/components/ShowOnRowHover/ShowOnRowHover
3
3
  import { flexRender, useReactTable } from "./node_modules/@tanstack/react-table/build/lib/index.js";
4
4
  import { TableContextProvider, useComposeContext, usePluginContext, useTableContext } from "./Table/Table.context.js";
5
5
  import { buildPluginContext } from "./Table/utils/plugin.utils.js";
6
+ import { calcTableMinSize } from "./Table/utils/table.utils.js";
6
7
  import { ColumnFaceting, ColumnFiltering, ColumnGrouping, ColumnOrdering, ColumnPinning, ColumnSizing, ColumnVisibility, GlobalFaceting, GlobalFiltering, Headers, RowExpanding, RowPagination, RowPinning, RowSelection, RowSorting, _getVisibleLeafColumns, aggregationFns, buildHeaderGroups, createCell, createColumn, createColumnHelper, createRow, createTable, defaultColumnSizing, expandRows, filterFns, flattenBy, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getMemoOptions, getPaginationRowModel, getSortedRowModel, isFunction, isNumberArray, isRowSelected, isSubRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, selectRowsFn, shouldAutoRemoveFilter, sortingFns } from "./node_modules/@tanstack/table-core/build/lib/index.js";
7
8
  export {
8
9
  ColumnFaceting,
@@ -27,6 +28,7 @@ export {
27
28
  aggregationFns,
28
29
  buildHeaderGroups,
29
30
  buildPluginContext,
31
+ calcTableMinSize,
30
32
  createCell,
31
33
  createColumn,
32
34
  createColumnHelper,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@redis-ui/table",
3
3
  "license": "UNLICENSED",
4
- "version": "2.23.2",
4
+ "version": "3.3.2",
5
5
  "type": "module",
6
6
  "publishConfig": {
7
7
  "registry": "https://npm.pkg.github.com/"
@@ -29,11 +29,11 @@
29
29
  "react": "^17.0.0 || ^18.0.0",
30
30
  "react-dom": "^17.0.0 || ^18.0.0",
31
31
  "styled-components": "^5.0.0",
32
- "@redis-ui/styles": "^13.1.10"
32
+ "@redis-ui/styles": "^14.4.2"
33
33
  },
34
34
  "dependencies": {
35
- "@redis-ui/components": "^41.2.9",
36
- "@redis-ui/icons": "^6.3.11",
35
+ "@redis-ui/components": "^41.5.0",
36
+ "@redis-ui/icons": "^6.6.0",
37
37
  "@tanstack/react-table": "^8.9.8",
38
38
  "type-fest": "^3.13.1"
39
39
  },