@dbcdk/react-components 0.0.3 → 0.0.5

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 (223) hide show
  1. package/dist/assets/logo.cjs +10 -10
  2. package/dist/assets/logo.js +10 -10
  3. package/dist/components/__stories__/story-components/Colors.cjs +159 -0
  4. package/dist/components/__stories__/story-components/Colors.d.ts +10 -0
  5. package/dist/components/__stories__/story-components/Colors.js +151 -0
  6. package/dist/components/__stories__/story-components/Colors.module.css +27 -0
  7. package/dist/components/__stories__/story-components/Spacing.cjs +190 -0
  8. package/dist/components/__stories__/story-components/Spacing.d.ts +1 -0
  9. package/dist/components/__stories__/story-components/Spacing.js +184 -0
  10. package/dist/components/__stories__/story-components/Spacing.module.css +154 -0
  11. package/dist/components/app-header/AppHeader.module.css +10 -15
  12. package/dist/components/attribute-chip/AttributeChip.cjs +22 -0
  13. package/dist/components/attribute-chip/AttributeChip.d.ts +8 -0
  14. package/dist/components/attribute-chip/AttributeChip.js +16 -0
  15. package/dist/components/attribute-chip/AttributeChip.module.css +65 -0
  16. package/dist/components/avatar/Avatar.cjs +38 -4
  17. package/dist/components/avatar/Avatar.d.ts +4 -2
  18. package/dist/components/avatar/Avatar.js +39 -5
  19. package/dist/components/avatar/Avatar.module.css +27 -0
  20. package/dist/components/breadcrumbs/Breadcrumbs.cjs +1 -2
  21. package/dist/components/breadcrumbs/Breadcrumbs.js +1 -2
  22. package/dist/components/breadcrumbs/Breadcrumbs.module.css +19 -22
  23. package/dist/components/button/Button.cjs +20 -12
  24. package/dist/components/button/Button.d.ts +4 -1
  25. package/dist/components/button/Button.js +20 -12
  26. package/dist/components/button/Button.module.css +118 -55
  27. package/dist/components/card/Card.cjs +53 -13
  28. package/dist/components/card/Card.d.ts +21 -6
  29. package/dist/components/card/Card.js +54 -14
  30. package/dist/components/card/Card.module.css +148 -44
  31. package/dist/components/card-container/CardContainer.cjs +6 -5
  32. package/dist/components/card-container/CardContainer.d.ts +5 -2
  33. package/dist/components/card-container/CardContainer.js +6 -5
  34. package/dist/components/card-container/CardContainer.module.css +40 -0
  35. package/dist/components/checkbox/Checkbox.cjs +3 -4
  36. package/dist/components/checkbox/Checkbox.d.ts +1 -1
  37. package/dist/components/checkbox/Checkbox.js +3 -4
  38. package/dist/components/checkbox/Checkbox.module.css +10 -10
  39. package/dist/components/chip/Chip.cjs +2 -1
  40. package/dist/components/chip/Chip.d.ts +2 -1
  41. package/dist/components/chip/Chip.js +2 -1
  42. package/dist/components/chip/Chip.module.css +42 -27
  43. package/dist/components/circle/Circle.module.css +11 -11
  44. package/dist/components/clear-button/ClearButton.cjs +3 -3
  45. package/dist/components/clear-button/ClearButton.js +3 -3
  46. package/dist/components/clear-button/ClearButton.module.css +8 -7
  47. package/dist/components/code-block/CodeBlock.cjs +18 -0
  48. package/dist/components/code-block/CodeBlock.d.ts +6 -0
  49. package/dist/components/code-block/CodeBlock.js +12 -0
  50. package/dist/components/code-block/CodeBlock.module.css +60 -0
  51. package/dist/components/copy-button/CopyButton.cjs +35 -0
  52. package/dist/components/copy-button/CopyButton.d.ts +9 -0
  53. package/dist/components/copy-button/CopyButton.js +29 -0
  54. package/dist/components/copy-button/CopyButton.module.css +6 -0
  55. package/dist/components/datetime-picker/DateTimePicker.cjs +504 -0
  56. package/dist/components/datetime-picker/DateTimePicker.d.ts +39 -0
  57. package/dist/components/datetime-picker/DateTimePicker.js +498 -0
  58. package/dist/components/datetime-picker/DateTimePicker.module.css +144 -0
  59. package/dist/components/filter-field/FilterField.cjs +34 -19
  60. package/dist/components/filter-field/FilterField.d.ts +2 -2
  61. package/dist/components/filter-field/FilterField.js +35 -20
  62. package/dist/components/filter-field/FilterField.module.css +14 -20
  63. package/dist/components/headline/Headline.cjs +10 -4
  64. package/dist/components/headline/Headline.d.ts +9 -1
  65. package/dist/components/headline/Headline.js +10 -4
  66. package/dist/components/headline/Headline.module.css +32 -7
  67. package/dist/components/icon/Icon.module.css +10 -9
  68. package/dist/components/input/Input.cjs +60 -19
  69. package/dist/components/input/Input.d.ts +7 -2
  70. package/dist/components/input/Input.js +60 -19
  71. package/dist/components/input/Input.module.css +90 -43
  72. package/dist/components/link/Link.cjs +46 -0
  73. package/dist/components/link/Link.d.ts +9 -0
  74. package/dist/components/link/Link.js +21 -0
  75. package/dist/components/link/Link.module.css +32 -0
  76. package/dist/components/menu/Menu.module.css +10 -32
  77. package/dist/components/meta-bar/MetaBar.cjs +29 -0
  78. package/dist/components/meta-bar/MetaBar.d.ts +11 -0
  79. package/dist/components/meta-bar/MetaBar.js +22 -0
  80. package/dist/components/meta-bar/MetaBar.module.css +12 -0
  81. package/dist/components/modal/Modal.cjs +134 -0
  82. package/dist/components/modal/Modal.d.ts +21 -0
  83. package/dist/components/modal/Modal.js +128 -0
  84. package/dist/components/modal/Modal.module.css +66 -0
  85. package/dist/components/modal/provider/ModalProvider.cjs +80 -0
  86. package/dist/components/modal/provider/ModalProvider.d.ts +21 -0
  87. package/dist/components/modal/provider/ModalProvider.js +77 -0
  88. package/dist/components/multi-select/MultiSelect.cjs +12 -1
  89. package/dist/components/multi-select/MultiSelect.js +12 -1
  90. package/dist/components/nav-bar/NavBar.module.css +11 -16
  91. package/dist/components/page/Page.module.css +2 -2
  92. package/dist/components/page-layout/PageLayout.cjs +5 -22
  93. package/dist/components/page-layout/PageLayout.d.ts +1 -8
  94. package/dist/components/page-layout/PageLayout.js +5 -22
  95. package/dist/components/page-layout/PageLayout.module.css +4 -80
  96. package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.cjs +32 -0
  97. package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.d.ts +11 -0
  98. package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.js +25 -0
  99. package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.module.css +84 -0
  100. package/dist/components/pagination/Pagination.cjs +83 -67
  101. package/dist/components/pagination/Pagination.d.ts +3 -1
  102. package/dist/components/pagination/Pagination.js +84 -68
  103. package/dist/components/pagination/Pagination.module.css +11 -3
  104. package/dist/components/panel/Panel.module.css +5 -7
  105. package/dist/components/popover/Popover.cjs +25 -8
  106. package/dist/components/popover/Popover.d.ts +2 -1
  107. package/dist/components/popover/Popover.js +25 -8
  108. package/dist/components/popover/Popover.module.css +4 -6
  109. package/dist/components/search-box/SearchBox.cjs +50 -37
  110. package/dist/components/search-box/SearchBox.d.ts +10 -7
  111. package/dist/components/search-box/SearchBox.js +50 -37
  112. package/dist/components/search-box/SearchBox.module.css +0 -1
  113. package/dist/components/segmented-progress-bar/SegmentedProgressBar.cjs +12 -6
  114. package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +12 -6
  115. package/dist/components/segmented-progress-bar/SegmentedProgressBar.module.css +5 -1
  116. package/dist/components/select/Select.cjs +82 -13
  117. package/dist/components/select/Select.d.ts +2 -1
  118. package/dist/components/select/Select.js +83 -14
  119. package/dist/components/sidebar/Sidebar.cjs +3 -30
  120. package/dist/components/sidebar/Sidebar.d.ts +2 -1
  121. package/dist/components/sidebar/Sidebar.js +4 -26
  122. package/dist/components/sidebar/components/SidebarItem.cjs +3 -1
  123. package/dist/components/sidebar/components/SidebarItem.js +3 -1
  124. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +40 -14
  125. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.d.ts +3 -1
  126. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +40 -14
  127. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +9 -38
  128. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.cjs +50 -0
  129. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.d.ts +8 -0
  130. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +43 -0
  131. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +155 -0
  132. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.cjs +16 -9
  133. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.d.ts +2 -1
  134. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +16 -9
  135. package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +25 -12
  136. package/dist/components/sidebar/components/sidebar-items/SidebarItems.cjs +2 -1
  137. package/dist/components/sidebar/components/sidebar-items/SidebarItems.d.ts +1 -1
  138. package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +2 -1
  139. package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.cjs +29 -2
  140. package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.js +25 -2
  141. package/dist/components/sidebar/providers/SidebarProvider.cjs +108 -10
  142. package/dist/components/sidebar/providers/SidebarProvider.d.ts +7 -3
  143. package/dist/components/sidebar/providers/SidebarProvider.js +109 -11
  144. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.cjs +1 -1
  145. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +1 -1
  146. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +0 -12
  147. package/dist/components/split-pane/SplitPane.cjs +123 -0
  148. package/dist/components/split-pane/SplitPane.d.ts +34 -0
  149. package/dist/components/split-pane/SplitPane.js +114 -0
  150. package/dist/components/split-pane/SplitPane.module.css +106 -0
  151. package/dist/components/split-pane/provider/SplitPaneContext.cjs +87 -0
  152. package/dist/components/split-pane/provider/SplitPaneContext.d.ts +23 -0
  153. package/dist/components/split-pane/provider/SplitPaneContext.js +79 -0
  154. package/dist/components/table/Table.cjs +180 -112
  155. package/dist/components/table/Table.d.ts +22 -6
  156. package/dist/components/table/Table.js +181 -113
  157. package/dist/components/table/Table.module.css +74 -47
  158. package/dist/components/table/components/empty-state/EmptyState.cjs +52 -0
  159. package/dist/components/table/components/empty-state/EmptyState.d.ts +40 -0
  160. package/dist/components/table/components/empty-state/EmptyState.js +46 -0
  161. package/dist/components/table/components/empty-state/EmptyState.module.css +16 -0
  162. package/dist/components/table/components/table-settings/TableSettings.cjs +32 -0
  163. package/dist/components/table/components/table-settings/TableSettings.d.ts +7 -0
  164. package/dist/components/table/components/table-settings/TableSettings.js +30 -0
  165. package/dist/{tanstack.cjs → components/table/tanstack.cjs} +61 -99
  166. package/dist/components/table/tanstack.d.ts +14 -0
  167. package/dist/{tanstack.js → components/table/tanstack.js} +61 -99
  168. package/dist/components/tabs/Tabs.cjs +33 -17
  169. package/dist/components/tabs/Tabs.d.ts +6 -3
  170. package/dist/components/tabs/Tabs.js +33 -17
  171. package/dist/components/tabs/Tabs.module.css +9 -9
  172. package/dist/components/toast/Toast.cjs +47 -0
  173. package/dist/components/toast/Toast.d.ts +14 -0
  174. package/dist/components/toast/Toast.js +41 -0
  175. package/dist/components/toast/Toast.module.css +101 -0
  176. package/dist/components/toast/provider/ToastProvider.cjs +98 -0
  177. package/dist/components/toast/provider/ToastProvider.d.ts +23 -0
  178. package/dist/components/toast/provider/ToastProvider.js +91 -0
  179. package/dist/components/tooltip/Tooltip.cjs +134 -29
  180. package/dist/components/tooltip/Tooltip.js +135 -30
  181. package/dist/components/tooltip/Tooltip.module.css +25 -43
  182. package/dist/components/user-display/UserDisplay.module.css +2 -2
  183. package/dist/constants/severity.cjs +12 -12
  184. package/dist/constants/severity.js +12 -12
  185. package/dist/constants/sizes.cjs +1 -0
  186. package/dist/constants/sizes.d.ts +1 -1
  187. package/dist/constants/sizes.js +1 -0
  188. package/dist/hooks/usePagination.cjs +88 -0
  189. package/dist/hooks/usePagination.d.ts +33 -0
  190. package/dist/hooks/usePagination.js +86 -0
  191. package/dist/hooks/useSorting.cjs +118 -0
  192. package/dist/hooks/useSorting.d.ts +49 -0
  193. package/dist/hooks/useSorting.js +116 -0
  194. package/dist/hooks/useTableData.cjs +52 -0
  195. package/dist/hooks/useTableData.d.ts +40 -0
  196. package/dist/hooks/useTableData.js +50 -0
  197. package/dist/hooks/useTableSelection.cjs +130 -0
  198. package/dist/hooks/useTableSelection.d.ts +25 -0
  199. package/dist/hooks/useTableSelection.js +128 -0
  200. package/dist/hooks/useTableSettings.cjs +28 -0
  201. package/dist/hooks/useTableSettings.d.ts +7 -0
  202. package/dist/hooks/useTableSettings.js +26 -0
  203. package/dist/hooks/useTimeDuration.cjs +39 -0
  204. package/dist/hooks/useTimeDuration.d.ts +22 -0
  205. package/dist/hooks/useTimeDuration.js +37 -0
  206. package/dist/hooks/useViewportFill.js +1 -1
  207. package/dist/index.cjs +119 -0
  208. package/dist/index.d.ts +17 -0
  209. package/dist/index.js +17 -0
  210. package/dist/src/styles/styles.css +101 -8
  211. package/dist/styles/css-helper-classes/flex.css +97 -0
  212. package/dist/styles/css-helper-classes/typography.css +7 -0
  213. package/dist/styles/styles.css +101 -8
  214. package/dist/styles/themes/dbc/dark.css +206 -99
  215. package/dist/styles/themes/dbc/light.css +183 -89
  216. package/dist/types/sizes.types.d.ts +2 -2
  217. package/package.json +17 -11
  218. package/dist/components/data-summary/DataSummary.cjs +0 -49
  219. package/dist/components/data-summary/DataSummary.d.ts +0 -19
  220. package/dist/components/data-summary/DataSummary.js +0 -43
  221. package/dist/components/data-summary/DataSummary.module.css +0 -51
  222. package/dist/components/sidebar/Sidebar.module.css +0 -66
  223. package/dist/tanstack.d.ts +0 -25
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const sizes = {
4
+ xs: "var(--component-size-xs)",
4
5
  sm: "var(--component-size-sm)",
5
6
  md: "var(--component-size-md)",
6
7
  lg: "var(--component-size-lg)",
@@ -1,2 +1,2 @@
1
- import type { Size, SizeVariable } from "../types/sizes.types";
1
+ import type { Size, SizeVariable } from '../types/sizes.types';
2
2
  export declare const sizes: Record<Size, SizeVariable>;
@@ -1,4 +1,5 @@
1
1
  const sizes = {
2
+ xs: "var(--component-size-xs)",
2
3
  sm: "var(--component-size-sm)",
3
4
  md: "var(--component-size-md)",
4
5
  lg: "var(--component-size-lg)",
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ function clamp(n, min, max) {
6
+ return Math.max(min, Math.min(max, n));
7
+ }
8
+ function usePagination({
9
+ data = [],
10
+ skip = 0,
11
+ take = 10,
12
+ state,
13
+ onStateChange,
14
+ resetOnDataChange = false
15
+ }) {
16
+ const isControlled = state != null;
17
+ const [uncontrolled, setUncontrolled] = react.useState(() => ({
18
+ skip: Math.max(0, skip),
19
+ take: Math.max(1, take)
20
+ }));
21
+ const didInitRef = react.useRef(false);
22
+ react.useEffect(() => {
23
+ if (isControlled) return;
24
+ if (!didInitRef.current) {
25
+ didInitRef.current = true;
26
+ return;
27
+ }
28
+ setUncontrolled((prev) => ({
29
+ skip: prev.skip,
30
+ take: Math.max(1, take)
31
+ }));
32
+ }, [isControlled, take]);
33
+ const paginationState = isControlled ? state : uncontrolled;
34
+ const totalCount = data.length;
35
+ const safeTake = Math.max(1, paginationState.take);
36
+ const maxSkip = Math.max(
37
+ 0,
38
+ totalCount === 0 ? 0 : Math.floor((totalCount - 1) / safeTake) * safeTake
39
+ );
40
+ const safeSkip = clamp(Math.max(0, paginationState.skip), 0, maxSkip);
41
+ const setPagination = react.useCallback(
42
+ (next) => {
43
+ const normalized = {
44
+ take: Math.max(1, next.take),
45
+ skip: Math.max(0, next.skip)
46
+ };
47
+ if (isControlled) onStateChange == null ? void 0 : onStateChange(normalized);
48
+ else setUncontrolled(normalized);
49
+ },
50
+ [isControlled, onStateChange]
51
+ );
52
+ const onPageChange = react.useCallback(
53
+ (pageEvent) => {
54
+ const nextTake = Math.max(1, pageEvent.take);
55
+ const nextSkip = Math.max(0, (pageEvent.page - 1) * nextTake);
56
+ setPagination({ skip: nextSkip, take: nextTake });
57
+ },
58
+ [setPagination]
59
+ );
60
+ const resetPage = react.useCallback(() => {
61
+ setPagination({ skip: 0, take: safeTake });
62
+ }, [setPagination, safeTake]);
63
+ react.useEffect(() => {
64
+ if (!resetOnDataChange) return;
65
+ resetPage();
66
+ }, [resetOnDataChange, data]);
67
+ const paginatedData = react.useMemo(() => {
68
+ return data.slice(safeSkip, safeSkip + safeTake);
69
+ }, [data, safeSkip, safeTake]);
70
+ const page = react.useMemo(() => Math.floor(safeSkip / safeTake) + 1, [safeSkip, safeTake]);
71
+ react.useEffect(() => {
72
+ if (isControlled) return;
73
+ if (safeSkip !== paginationState.skip) {
74
+ setUncontrolled((prev) => ({ ...prev, skip: safeSkip }));
75
+ }
76
+ }, [isControlled, safeSkip, paginationState.skip]);
77
+ return {
78
+ paginatedData,
79
+ paginationState: { skip: safeSkip, take: safeTake },
80
+ onPageChange,
81
+ setPagination,
82
+ resetPage,
83
+ page,
84
+ totalCount
85
+ };
86
+ }
87
+
88
+ exports.usePagination = usePagination;
@@ -0,0 +1,33 @@
1
+ import type { PageChangeEvent } from '@/components/pagination/Pagination';
2
+ export type PaginationState = {
3
+ skip: number;
4
+ take: number;
5
+ };
6
+ export interface UsePaginationProps<T> {
7
+ data?: readonly T[];
8
+ /**
9
+ * Default/initial state. If you pass `state`, these are ignored.
10
+ */
11
+ skip?: number;
12
+ take?: number;
13
+ /**
14
+ * Controlled mode: if provided, the hook will not keep its own state.
15
+ */
16
+ state?: PaginationState;
17
+ onStateChange?: (next: PaginationState) => void;
18
+ /**
19
+ * When true, page index resets to 0 whenever `data` reference changes.
20
+ * Useful after filtering/sorting changes upstream.
21
+ */
22
+ resetOnDataChange?: boolean;
23
+ }
24
+ export interface UsePaginationResult<T> {
25
+ paginatedData: T[];
26
+ paginationState: PaginationState;
27
+ onPageChange: (pageEvent: PageChangeEvent) => void;
28
+ setPagination: (next: PaginationState) => void;
29
+ resetPage: () => void;
30
+ page: number;
31
+ totalCount: number;
32
+ }
33
+ export declare function usePagination<T>({ data, skip, take, state, onStateChange, resetOnDataChange, }: UsePaginationProps<T>): UsePaginationResult<T>;
@@ -0,0 +1,86 @@
1
+ import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
2
+
3
+ function clamp(n, min, max) {
4
+ return Math.max(min, Math.min(max, n));
5
+ }
6
+ function usePagination({
7
+ data = [],
8
+ skip = 0,
9
+ take = 10,
10
+ state,
11
+ onStateChange,
12
+ resetOnDataChange = false
13
+ }) {
14
+ const isControlled = state != null;
15
+ const [uncontrolled, setUncontrolled] = useState(() => ({
16
+ skip: Math.max(0, skip),
17
+ take: Math.max(1, take)
18
+ }));
19
+ const didInitRef = useRef(false);
20
+ useEffect(() => {
21
+ if (isControlled) return;
22
+ if (!didInitRef.current) {
23
+ didInitRef.current = true;
24
+ return;
25
+ }
26
+ setUncontrolled((prev) => ({
27
+ skip: prev.skip,
28
+ take: Math.max(1, take)
29
+ }));
30
+ }, [isControlled, take]);
31
+ const paginationState = isControlled ? state : uncontrolled;
32
+ const totalCount = data.length;
33
+ const safeTake = Math.max(1, paginationState.take);
34
+ const maxSkip = Math.max(
35
+ 0,
36
+ totalCount === 0 ? 0 : Math.floor((totalCount - 1) / safeTake) * safeTake
37
+ );
38
+ const safeSkip = clamp(Math.max(0, paginationState.skip), 0, maxSkip);
39
+ const setPagination = useCallback(
40
+ (next) => {
41
+ const normalized = {
42
+ take: Math.max(1, next.take),
43
+ skip: Math.max(0, next.skip)
44
+ };
45
+ if (isControlled) onStateChange == null ? void 0 : onStateChange(normalized);
46
+ else setUncontrolled(normalized);
47
+ },
48
+ [isControlled, onStateChange]
49
+ );
50
+ const onPageChange = useCallback(
51
+ (pageEvent) => {
52
+ const nextTake = Math.max(1, pageEvent.take);
53
+ const nextSkip = Math.max(0, (pageEvent.page - 1) * nextTake);
54
+ setPagination({ skip: nextSkip, take: nextTake });
55
+ },
56
+ [setPagination]
57
+ );
58
+ const resetPage = useCallback(() => {
59
+ setPagination({ skip: 0, take: safeTake });
60
+ }, [setPagination, safeTake]);
61
+ useEffect(() => {
62
+ if (!resetOnDataChange) return;
63
+ resetPage();
64
+ }, [resetOnDataChange, data]);
65
+ const paginatedData = useMemo(() => {
66
+ return data.slice(safeSkip, safeSkip + safeTake);
67
+ }, [data, safeSkip, safeTake]);
68
+ const page = useMemo(() => Math.floor(safeSkip / safeTake) + 1, [safeSkip, safeTake]);
69
+ useEffect(() => {
70
+ if (isControlled) return;
71
+ if (safeSkip !== paginationState.skip) {
72
+ setUncontrolled((prev) => ({ ...prev, skip: safeSkip }));
73
+ }
74
+ }, [isControlled, safeSkip, paginationState.skip]);
75
+ return {
76
+ paginatedData,
77
+ paginationState: { skip: safeSkip, take: safeTake },
78
+ onPageChange,
79
+ setPagination,
80
+ resetPage,
81
+ page,
82
+ totalCount
83
+ };
84
+ }
85
+
86
+ export { usePagination };
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ function defaultCompare(a, b, dir, nulls) {
6
+ const aNull = a == null;
7
+ const bNull = b == null;
8
+ if (aNull || bNull) {
9
+ if (aNull && bNull) return 0;
10
+ const order = nulls === "first" ? -1 : 1;
11
+ return aNull ? order : -order;
12
+ }
13
+ if (a instanceof Date && b instanceof Date) {
14
+ const diff2 = a.getTime() - b.getTime();
15
+ return dir === "asc" ? diff2 : -diff2;
16
+ }
17
+ if (typeof a === "number" && typeof b === "number") {
18
+ const diff2 = a - b;
19
+ return dir === "asc" ? diff2 : -diff2;
20
+ }
21
+ if (typeof a === "boolean" && typeof b === "boolean") {
22
+ const diff2 = Number(a) - Number(b);
23
+ return dir === "asc" ? diff2 : -diff2;
24
+ }
25
+ const aStr = String(a);
26
+ const bStr = String(b);
27
+ const diff = aStr.localeCompare(bStr, void 0, { numeric: true, sensitivity: "base" });
28
+ return dir === "asc" ? diff : -diff;
29
+ }
30
+ function stableSort(arr, cmp) {
31
+ return arr.map((item, idx) => ({ item, idx })).sort((x, y) => {
32
+ const c = cmp(x.item, y.item);
33
+ return c !== 0 ? c : x.idx - y.idx;
34
+ }).map((x) => x.item);
35
+ }
36
+ function useSorting({
37
+ data = [],
38
+ sortBy = null,
39
+ sortDirection = "asc",
40
+ state,
41
+ onStateChange,
42
+ columnComparators = {},
43
+ nulls = "last",
44
+ allowUnsort = true,
45
+ resetOnDataChange = false
46
+ }) {
47
+ const isControlled = state != null;
48
+ const [uncontrolled, setUncontrolled] = react.useState(() => ({
49
+ sortBy,
50
+ sortDirection
51
+ }));
52
+ const sortState = isControlled ? state : uncontrolled;
53
+ const setSort = react.useCallback(
54
+ (next) => {
55
+ var _a, _b;
56
+ const normalized = {
57
+ sortBy: (_a = next.sortBy) != null ? _a : null,
58
+ sortDirection: (_b = next.sortDirection) != null ? _b : null
59
+ };
60
+ if (isControlled) onStateChange == null ? void 0 : onStateChange(normalized);
61
+ else setUncontrolled(normalized);
62
+ },
63
+ [isControlled, onStateChange]
64
+ );
65
+ const clearSort = react.useCallback(() => setSort({ sortBy: null, sortDirection: null }), [setSort]);
66
+ const onSortChange = react.useCallback(
67
+ (e) => {
68
+ var _a, _b;
69
+ const nextSortBy = (_a = e.sortBy) != null ? _a : null;
70
+ setSort(sortState);
71
+ const current = sortState;
72
+ if (nextSortBy == null) {
73
+ return clearSort();
74
+ }
75
+ if (current.sortBy === nextSortBy) {
76
+ const nextDir = current.sortDirection === "asc" ? "desc" : allowUnsort ? null : "asc";
77
+ return setSort({ sortBy: nextSortBy, sortDirection: nextDir });
78
+ }
79
+ return setSort({
80
+ sortBy: nextSortBy,
81
+ sortDirection: (_b = e.sortDirection) != null ? _b : "asc"
82
+ });
83
+ },
84
+ [allowUnsort, clearSort, setSort, sortState]
85
+ );
86
+ const didInitRef = react.useRef(false);
87
+ react.useEffect(() => {
88
+ if (!resetOnDataChange) return;
89
+ if (!didInitRef.current) {
90
+ didInitRef.current = true;
91
+ return;
92
+ }
93
+ clearSort();
94
+ }, [resetOnDataChange, data]);
95
+ const sortedData = react.useMemo(() => {
96
+ const { sortBy: sb, sortDirection: dir } = sortState;
97
+ if (!sb || !dir) return data;
98
+ const custom = columnComparators[sb];
99
+ const cmp = (a, b) => {
100
+ if (custom) return custom(a, b, dir);
101
+ const av = a[sb];
102
+ const bv = b[sb];
103
+ return defaultCompare(av, bv, dir, nulls);
104
+ };
105
+ return stableSort(data, cmp);
106
+ }, [data, sortState, columnComparators, nulls]);
107
+ const setSortRef = react.useRef(setSort);
108
+ setSortRef.current = setSort;
109
+ return {
110
+ sortedData,
111
+ sortState,
112
+ onSortChange,
113
+ setSort,
114
+ clearSort
115
+ };
116
+ }
117
+
118
+ exports.useSorting = useSorting;
@@ -0,0 +1,49 @@
1
+ export type SortDirection = 'asc' | 'desc' | null;
2
+ export type SortState<T> = {
3
+ sortBy: keyof T | null;
4
+ sortDirection: SortDirection;
5
+ };
6
+ export type SortEvent<T> = Partial<SortState<T>>;
7
+ export type ColumnComparators<T> = Partial<Record<keyof T, (a: T, b: T, direction: Exclude<SortDirection, null>) => number>>;
8
+ export interface UseSortingProps<T> {
9
+ data?: readonly T[];
10
+ /**
11
+ * Default/initial state. If you pass `state`, these are ignored.
12
+ */
13
+ sortBy?: keyof T | null;
14
+ sortDirection?: SortDirection;
15
+ /**
16
+ * Controlled mode: if provided, hook will not keep its own state.
17
+ */
18
+ state?: SortState<T>;
19
+ onStateChange?: (next: SortState<T>) => void;
20
+ /**
21
+ * Optional per-column comparator.
22
+ * If absent, falls back to default compare on the field value.
23
+ */
24
+ columnComparators?: ColumnComparators<T>;
25
+ /**
26
+ * How to handle null/undefined values when using the default comparator:
27
+ * - "first": nulls come first
28
+ * - "last": nulls come last
29
+ */
30
+ nulls?: 'first' | 'last';
31
+ /**
32
+ * If true, toggling a column cycles: asc -> desc -> null
33
+ * If false, cycles: asc -> desc -> asc ...
34
+ */
35
+ allowUnsort?: boolean;
36
+ /**
37
+ * When true, resets sorting when data reference changes.
38
+ * (Most people want to keep sort; default false.)
39
+ */
40
+ resetOnDataChange?: boolean;
41
+ }
42
+ export interface UseSortingResult<T> {
43
+ sortedData: T[];
44
+ sortState: SortState<T>;
45
+ onSortChange: (e: SortEvent<T>) => void;
46
+ setSort: (next: SortState<T>) => void;
47
+ clearSort: () => void;
48
+ }
49
+ export declare function useSorting<T extends Record<string, any>>({ data, sortBy, sortDirection, state, onStateChange, columnComparators, nulls, allowUnsort, resetOnDataChange, }: UseSortingProps<T>): UseSortingResult<T>;
@@ -0,0 +1,116 @@
1
+ import { useState, useCallback, useRef, useEffect, useMemo } from 'react';
2
+
3
+ function defaultCompare(a, b, dir, nulls) {
4
+ const aNull = a == null;
5
+ const bNull = b == null;
6
+ if (aNull || bNull) {
7
+ if (aNull && bNull) return 0;
8
+ const order = nulls === "first" ? -1 : 1;
9
+ return aNull ? order : -order;
10
+ }
11
+ if (a instanceof Date && b instanceof Date) {
12
+ const diff2 = a.getTime() - b.getTime();
13
+ return dir === "asc" ? diff2 : -diff2;
14
+ }
15
+ if (typeof a === "number" && typeof b === "number") {
16
+ const diff2 = a - b;
17
+ return dir === "asc" ? diff2 : -diff2;
18
+ }
19
+ if (typeof a === "boolean" && typeof b === "boolean") {
20
+ const diff2 = Number(a) - Number(b);
21
+ return dir === "asc" ? diff2 : -diff2;
22
+ }
23
+ const aStr = String(a);
24
+ const bStr = String(b);
25
+ const diff = aStr.localeCompare(bStr, void 0, { numeric: true, sensitivity: "base" });
26
+ return dir === "asc" ? diff : -diff;
27
+ }
28
+ function stableSort(arr, cmp) {
29
+ return arr.map((item, idx) => ({ item, idx })).sort((x, y) => {
30
+ const c = cmp(x.item, y.item);
31
+ return c !== 0 ? c : x.idx - y.idx;
32
+ }).map((x) => x.item);
33
+ }
34
+ function useSorting({
35
+ data = [],
36
+ sortBy = null,
37
+ sortDirection = "asc",
38
+ state,
39
+ onStateChange,
40
+ columnComparators = {},
41
+ nulls = "last",
42
+ allowUnsort = true,
43
+ resetOnDataChange = false
44
+ }) {
45
+ const isControlled = state != null;
46
+ const [uncontrolled, setUncontrolled] = useState(() => ({
47
+ sortBy,
48
+ sortDirection
49
+ }));
50
+ const sortState = isControlled ? state : uncontrolled;
51
+ const setSort = useCallback(
52
+ (next) => {
53
+ var _a, _b;
54
+ const normalized = {
55
+ sortBy: (_a = next.sortBy) != null ? _a : null,
56
+ sortDirection: (_b = next.sortDirection) != null ? _b : null
57
+ };
58
+ if (isControlled) onStateChange == null ? void 0 : onStateChange(normalized);
59
+ else setUncontrolled(normalized);
60
+ },
61
+ [isControlled, onStateChange]
62
+ );
63
+ const clearSort = useCallback(() => setSort({ sortBy: null, sortDirection: null }), [setSort]);
64
+ const onSortChange = useCallback(
65
+ (e) => {
66
+ var _a, _b;
67
+ const nextSortBy = (_a = e.sortBy) != null ? _a : null;
68
+ setSort(sortState);
69
+ const current = sortState;
70
+ if (nextSortBy == null) {
71
+ return clearSort();
72
+ }
73
+ if (current.sortBy === nextSortBy) {
74
+ const nextDir = current.sortDirection === "asc" ? "desc" : allowUnsort ? null : "asc";
75
+ return setSort({ sortBy: nextSortBy, sortDirection: nextDir });
76
+ }
77
+ return setSort({
78
+ sortBy: nextSortBy,
79
+ sortDirection: (_b = e.sortDirection) != null ? _b : "asc"
80
+ });
81
+ },
82
+ [allowUnsort, clearSort, setSort, sortState]
83
+ );
84
+ const didInitRef = useRef(false);
85
+ useEffect(() => {
86
+ if (!resetOnDataChange) return;
87
+ if (!didInitRef.current) {
88
+ didInitRef.current = true;
89
+ return;
90
+ }
91
+ clearSort();
92
+ }, [resetOnDataChange, data]);
93
+ const sortedData = useMemo(() => {
94
+ const { sortBy: sb, sortDirection: dir } = sortState;
95
+ if (!sb || !dir) return data;
96
+ const custom = columnComparators[sb];
97
+ const cmp = (a, b) => {
98
+ if (custom) return custom(a, b, dir);
99
+ const av = a[sb];
100
+ const bv = b[sb];
101
+ return defaultCompare(av, bv, dir, nulls);
102
+ };
103
+ return stableSort(data, cmp);
104
+ }, [data, sortState, columnComparators, nulls]);
105
+ const setSortRef = useRef(setSort);
106
+ setSortRef.current = setSort;
107
+ return {
108
+ sortedData,
109
+ sortState,
110
+ onSortChange,
111
+ setSort,
112
+ clearSort
113
+ };
114
+ }
115
+
116
+ export { useSorting };
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var usePagination = require('./usePagination');
5
+ var useSorting = require('./useSorting');
6
+
7
+ function useTableData({
8
+ data = [],
9
+ pagination,
10
+ sorting,
11
+ resetPageOnSortChange = true
12
+ }) {
13
+ var _a, _b, _c, _d, _e, _f;
14
+ const s = useSorting.useSorting({
15
+ data,
16
+ sortBy: (_a = sorting == null ? void 0 : sorting.sortBy) != null ? _a : null,
17
+ sortDirection: (_b = sorting == null ? void 0 : sorting.direction) != null ? _b : null,
18
+ state: sorting == null ? void 0 : sorting.state,
19
+ onStateChange: sorting == null ? void 0 : sorting.onStateChange,
20
+ columnComparators: sorting == null ? void 0 : sorting.columnComparators,
21
+ nulls: (_c = sorting == null ? void 0 : sorting.nulls) != null ? _c : "last",
22
+ allowUnsort: (_d = sorting == null ? void 0 : sorting.allowUnsort) != null ? _d : true
23
+ });
24
+ const p = usePagination.usePagination({
25
+ data: s.sortedData,
26
+ skip: (_e = pagination == null ? void 0 : pagination.skip) != null ? _e : 0,
27
+ take: (_f = pagination == null ? void 0 : pagination.take) != null ? _f : 10,
28
+ state: pagination == null ? void 0 : pagination.state,
29
+ onStateChange: pagination == null ? void 0 : pagination.onStateChange
30
+ });
31
+ react.useEffect(() => {
32
+ if (!resetPageOnSortChange) return;
33
+ p.resetPage();
34
+ }, [resetPageOnSortChange, s.sortState.sortBy, s.sortState.sortDirection]);
35
+ const rows = react.useMemo(() => p.paginatedData, [p.paginatedData]);
36
+ return {
37
+ rows,
38
+ totalCount: s.sortedData.length,
39
+ pagination: {
40
+ state: p.paginationState,
41
+ onPageChange: p.onPageChange,
42
+ resetPage: p.resetPage
43
+ },
44
+ sorting: {
45
+ state: s.sortState,
46
+ onSortChange: s.onSortChange,
47
+ clearSort: s.clearSort
48
+ }
49
+ };
50
+ }
51
+
52
+ exports.useTableData = useTableData;
@@ -0,0 +1,40 @@
1
+ import type { PageChangeEvent } from '@/components/pagination/Pagination';
2
+ import { type PaginationState } from './usePagination';
3
+ import { type SortDirection, type SortState, type ColumnComparators } from './useSorting';
4
+ export interface UseTableDataProps<T> {
5
+ data?: readonly T[];
6
+ pagination?: {
7
+ skip?: number;
8
+ take?: number;
9
+ state?: PaginationState;
10
+ onStateChange?: (next: PaginationState) => void;
11
+ };
12
+ sorting?: {
13
+ sortBy?: keyof T | null;
14
+ direction?: SortDirection;
15
+ state?: SortState<T>;
16
+ onStateChange?: (next: SortState<T>) => void;
17
+ columnComparators?: ColumnComparators<T>;
18
+ nulls?: 'first' | 'last';
19
+ allowUnsort?: boolean;
20
+ };
21
+ /**
22
+ * Resets to page 1 whenever sorting changes (typical UX).
23
+ */
24
+ resetPageOnSortChange?: boolean;
25
+ }
26
+ export interface UseTableDataResult<T> {
27
+ rows: T[];
28
+ totalCount: number;
29
+ pagination: {
30
+ state: PaginationState;
31
+ onPageChange: (e: PageChangeEvent) => void;
32
+ resetPage: () => void;
33
+ };
34
+ sorting: {
35
+ state: SortState<T>;
36
+ onSortChange: (next: Partial<SortState<T>>) => void;
37
+ clearSort: () => void;
38
+ };
39
+ }
40
+ export declare function useTableData<T extends Record<string, any>>({ data, pagination, sorting, resetPageOnSortChange, }: UseTableDataProps<T>): UseTableDataResult<T>;
@@ -0,0 +1,50 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { usePagination } from './usePagination';
3
+ import { useSorting } from './useSorting';
4
+
5
+ function useTableData({
6
+ data = [],
7
+ pagination,
8
+ sorting,
9
+ resetPageOnSortChange = true
10
+ }) {
11
+ var _a, _b, _c, _d, _e, _f;
12
+ const s = useSorting({
13
+ data,
14
+ sortBy: (_a = sorting == null ? void 0 : sorting.sortBy) != null ? _a : null,
15
+ sortDirection: (_b = sorting == null ? void 0 : sorting.direction) != null ? _b : null,
16
+ state: sorting == null ? void 0 : sorting.state,
17
+ onStateChange: sorting == null ? void 0 : sorting.onStateChange,
18
+ columnComparators: sorting == null ? void 0 : sorting.columnComparators,
19
+ nulls: (_c = sorting == null ? void 0 : sorting.nulls) != null ? _c : "last",
20
+ allowUnsort: (_d = sorting == null ? void 0 : sorting.allowUnsort) != null ? _d : true
21
+ });
22
+ const p = usePagination({
23
+ data: s.sortedData,
24
+ skip: (_e = pagination == null ? void 0 : pagination.skip) != null ? _e : 0,
25
+ take: (_f = pagination == null ? void 0 : pagination.take) != null ? _f : 10,
26
+ state: pagination == null ? void 0 : pagination.state,
27
+ onStateChange: pagination == null ? void 0 : pagination.onStateChange
28
+ });
29
+ useEffect(() => {
30
+ if (!resetPageOnSortChange) return;
31
+ p.resetPage();
32
+ }, [resetPageOnSortChange, s.sortState.sortBy, s.sortState.sortDirection]);
33
+ const rows = useMemo(() => p.paginatedData, [p.paginatedData]);
34
+ return {
35
+ rows,
36
+ totalCount: s.sortedData.length,
37
+ pagination: {
38
+ state: p.paginationState,
39
+ onPageChange: p.onPageChange,
40
+ resetPage: p.resetPage
41
+ },
42
+ sorting: {
43
+ state: s.sortState,
44
+ onSortChange: s.onSortChange,
45
+ clearSort: s.clearSort
46
+ }
47
+ };
48
+ }
49
+
50
+ export { useTableData };