@dbcdk/react-components 0.0.135 → 0.0.137

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 (33) hide show
  1. package/dist/components/forms/file-upload/FileUpload.cjs +13 -3
  2. package/dist/components/forms/file-upload/FileUpload.d.ts +4 -1
  3. package/dist/components/forms/file-upload/FileUpload.js +14 -4
  4. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +12 -10
  5. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +12 -10
  6. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +18 -14
  7. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +12 -0
  8. package/dist/components/table/Table.cjs +3 -4
  9. package/dist/components/table/Table.d.ts +1 -1
  10. package/dist/components/table/Table.js +4 -5
  11. package/dist/components/table/Table.module.css +52 -21
  12. package/dist/components/table/Table.types.d.ts +9 -1
  13. package/dist/components/table/components/TableBody.cjs +2 -0
  14. package/dist/components/table/components/TableBody.d.ts +2 -1
  15. package/dist/components/table/components/TableBody.js +2 -0
  16. package/dist/components/table/components/TableHeader.cjs +1 -10
  17. package/dist/components/table/components/TableHeader.d.ts +1 -2
  18. package/dist/components/table/components/TableHeader.js +1 -10
  19. package/dist/components/table/components/TableRow.cjs +89 -68
  20. package/dist/components/table/components/TableRow.d.ts +2 -1
  21. package/dist/components/table/components/TableRow.js +89 -68
  22. package/dist/components/table/table.utils.cjs +0 -2
  23. package/dist/components/table/table.utils.d.ts +0 -1
  24. package/dist/components/table/table.utils.js +1 -2
  25. package/dist/components/table/tanstackTable.utils.cjs +2 -2
  26. package/dist/components/table/tanstackTable.utils.js +3 -3
  27. package/dist/hooks/useSorting.cjs +1 -0
  28. package/dist/hooks/useSorting.d.ts +6 -5
  29. package/dist/hooks/useSorting.js +1 -1
  30. package/dist/hooks/useTableData.cjs +29 -7
  31. package/dist/hooks/useTableData.d.ts +3 -1
  32. package/dist/hooks/useTableData.js +31 -9
  33. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import type { ColumnDef } from '@tanstack/react-table';
1
2
  import type { PageChangeEvent } from '../components/pagination/Pagination';
2
3
  import { type PaginationState } from './usePagination';
3
4
  import { type SortDirection, type SortState, type ColumnComparators } from './useSorting';
@@ -10,13 +11,14 @@ export interface UseTableDataProps<T> {
10
11
  onStateChange?: (next: PaginationState) => void;
11
12
  };
12
13
  sorting?: {
13
- sortBy?: keyof T | null;
14
+ sortBy?: string | null;
14
15
  direction?: SortDirection;
15
16
  state?: SortState<T>;
16
17
  onStateChange?: (next: SortState<T>) => void;
17
18
  columnComparators?: ColumnComparators<T>;
18
19
  nulls?: 'first' | 'last';
19
20
  allowUnsort?: boolean;
21
+ columns?: ReadonlyArray<ColumnDef<T, any>>;
20
22
  };
21
23
  /**
22
24
  * Resets to page 1 whenever sorting changes (typical UX).
@@ -1,7 +1,7 @@
1
1
  'use client';
2
- import { useEffect, useMemo } from 'react';
2
+ import { useMemo, useEffect } from 'react';
3
3
  import { usePagination } from './usePagination';
4
- import { useSorting } from './useSorting';
4
+ import { useSorting, defaultCompare } from './useSorting';
5
5
 
6
6
  function useTableData({
7
7
  data = [],
@@ -10,28 +10,50 @@ function useTableData({
10
10
  resetPageOnSortChange = true
11
11
  }) {
12
12
  var _a, _b, _c, _d, _e, _f;
13
+ const hasPagination = pagination != null;
14
+ const nullsMode = (_a = sorting == null ? void 0 : sorting.nulls) != null ? _a : "last";
15
+ const mergedComparators = useMemo(() => {
16
+ var _a2, _b2;
17
+ const derived = {};
18
+ for (const col of (_a2 = sorting == null ? void 0 : sorting.columns) != null ? _a2 : []) {
19
+ const colId = (_b2 = col.id) != null ? _b2 : col.accessorKey;
20
+ if (!colId) continue;
21
+ const accessorFn = col.accessorFn;
22
+ const accessorKey = col.accessorKey;
23
+ if (accessorFn) {
24
+ derived[colId] = (a, b, dir) => defaultCompare(accessorFn(a, 0), accessorFn(b, 0), dir, nullsMode);
25
+ } else if (accessorKey) {
26
+ derived[colId] = (a, b, dir) => defaultCompare(a[accessorKey], b[accessorKey], dir, nullsMode);
27
+ }
28
+ }
29
+ return { ...derived, ...sorting == null ? void 0 : sorting.columnComparators };
30
+ }, [sorting == null ? void 0 : sorting.columns, sorting == null ? void 0 : sorting.columnComparators, nullsMode]);
13
31
  const s = useSorting({
14
32
  data,
15
- sortBy: (_a = sorting == null ? void 0 : sorting.sortBy) != null ? _a : null,
16
- sortDirection: (_b = sorting == null ? void 0 : sorting.direction) != null ? _b : null,
33
+ sortBy: (_b = sorting == null ? void 0 : sorting.sortBy) != null ? _b : null,
34
+ sortDirection: (_c = sorting == null ? void 0 : sorting.direction) != null ? _c : null,
17
35
  state: sorting == null ? void 0 : sorting.state,
18
36
  onStateChange: sorting == null ? void 0 : sorting.onStateChange,
19
- columnComparators: sorting == null ? void 0 : sorting.columnComparators,
20
- nulls: (_c = sorting == null ? void 0 : sorting.nulls) != null ? _c : "last",
37
+ columnComparators: mergedComparators,
38
+ nulls: nullsMode,
21
39
  allowUnsort: (_d = sorting == null ? void 0 : sorting.allowUnsort) != null ? _d : true
22
40
  });
23
41
  const p = usePagination({
24
42
  data: s.sortedData,
25
43
  skip: (_e = pagination == null ? void 0 : pagination.skip) != null ? _e : 0,
26
- take: (_f = pagination == null ? void 0 : pagination.take) != null ? _f : 10,
44
+ take: (_f = pagination == null ? void 0 : pagination.take) != null ? _f : Math.max(s.sortedData.length, 1),
27
45
  state: pagination == null ? void 0 : pagination.state,
28
46
  onStateChange: pagination == null ? void 0 : pagination.onStateChange
29
47
  });
30
48
  useEffect(() => {
49
+ if (!hasPagination) return;
31
50
  if (!resetPageOnSortChange) return;
32
51
  p.resetPage();
33
- }, [resetPageOnSortChange, s.sortState.sortBy, s.sortState.sortDirection]);
34
- const rows = useMemo(() => p.paginatedData, [p.paginatedData]);
52
+ }, [hasPagination, resetPageOnSortChange, s.sortState.sortBy, s.sortState.sortDirection]);
53
+ const rows = useMemo(
54
+ () => hasPagination ? p.paginatedData : s.sortedData,
55
+ [hasPagination, p.paginatedData, s.sortedData]
56
+ );
35
57
  return {
36
58
  rows,
37
59
  totalCount: s.sortedData.length,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.135",
3
+ "version": "0.0.137",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",