@dbcdk/react-components 0.0.4 → 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
@@ -2,7 +2,7 @@ import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { useMemo, useCallback } from 'react';
3
3
  import styles from './Pagination.module.css';
4
4
  import { Button } from '../button/Button';
5
- import { ArrowLeft, ArrowRight } from 'lucide-react';
5
+ import { ChevronsLeft, ArrowLeft, ArrowRight, ChevronsRight, ChevronDown } from 'lucide-react';
6
6
  import { Popover } from '../popover/Popover';
7
7
  import { Menu } from '../menu/Menu';
8
8
 
@@ -12,97 +12,113 @@ function Pagination({
12
12
  skip = 0,
13
13
  take = DEFAULT_PAGE_SIZE_OPTIONS[1],
14
14
  onPageChange,
15
- pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS
15
+ pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
16
+ showFirstLast = true,
17
+ showGoToPage = true
16
18
  }) {
17
- const totalPages = useMemo(() => {
18
- const pages = Math.max(1, Math.ceil(itemsCount / Math.max(1, take)));
19
- return pages;
20
- }, [itemsCount, take]);
19
+ const totalPages = useMemo(
20
+ () => Math.max(1, Math.ceil(itemsCount / Math.max(1, take))),
21
+ [itemsCount, take]
22
+ );
21
23
  const currentPage = useMemo(() => {
22
24
  const p = Math.floor(skip / Math.max(1, take)) + 1;
23
25
  return Math.min(Math.max(1, p), totalPages);
24
26
  }, [skip, take, totalPages]);
25
27
  const emit = useCallback(
26
- (page) => {
27
- const clampedPage = Math.min(Math.max(1, page), totalPages);
28
- const nextSkip = (clampedPage - 1) * take;
28
+ (page, nextTake = take) => {
29
+ const nextTotalPages = Math.max(1, Math.ceil(itemsCount / Math.max(1, nextTake)));
30
+ const clampedPage = Math.min(Math.max(1, page), nextTotalPages);
31
+ const nextSkip = (clampedPage - 1) * nextTake;
29
32
  onPageChange == null ? void 0 : onPageChange({
30
33
  page: clampedPage,
31
- take,
34
+ take: nextTake,
32
35
  skip: nextSkip,
33
- totalPages
36
+ totalPages: nextTotalPages
34
37
  });
35
38
  },
36
- [onPageChange, take, totalPages]
39
+ [onPageChange, take, itemsCount]
37
40
  );
41
+ const firstPage = useCallback(() => emit(1), [emit]);
42
+ const lastPage = useCallback(() => emit(totalPages), [emit, totalPages]);
38
43
  const prevPage = useCallback(() => emit(currentPage - 1), [emit, currentPage]);
39
44
  const nextPage = useCallback(() => emit(currentPage + 1), [emit, currentPage]);
40
45
  const goToPage = useCallback((page) => emit(page), [emit]);
41
- const pageList = useMemo(() => {
42
- const visiblePages = 3;
43
- const pages = Array.from({ length: totalPages }, (_, i) => i + 1);
44
- let startIndex = Math.max(currentPage - Math.floor(visiblePages / 2) - 1, 0);
45
- let endIndex = startIndex + visiblePages;
46
- if (endIndex > totalPages) {
47
- endIndex = totalPages;
48
- startIndex = Math.max(endIndex - visiblePages, 0);
49
- }
50
- return {
51
- first: startIndex > 0 ? 1 : void 0,
52
- items: pages.slice(startIndex, endIndex),
53
- last: endIndex < totalPages ? totalPages : void 0
54
- };
55
- }, [totalPages, currentPage]);
56
- const handlePageSizeChange = useCallback(
57
- (size) => {
58
- onPageChange == null ? void 0 : onPageChange({
59
- page: 1,
60
- take: size,
61
- skip: 0,
62
- totalPages: Math.max(1, Math.ceil(itemsCount / Math.max(1, size)))
63
- });
64
- },
65
- [onPageChange, itemsCount]
66
- );
46
+ const canPrev = currentPage > 1;
47
+ const canNext = currentPage < totalPages;
48
+ const rangeLabel = useMemo(() => {
49
+ if (itemsCount <= 0) return "0 af 0";
50
+ const first = skip + 1;
51
+ const last = Math.min(skip + take, itemsCount);
52
+ return `${first.toLocaleString("da-DK")}\u2013${last.toLocaleString("da-DK")} af ${itemsCount.toLocaleString("da-DK")}`;
53
+ }, [itemsCount, skip, take]);
54
+ const pages = useMemo(() => Array.from({ length: totalPages }, (_, i) => i + 1), [totalPages]);
55
+ const handlePageSizeChange = useCallback((size) => emit(1, size), [emit]);
67
56
  return /* @__PURE__ */ jsxs("div", { className: styles.container, children: [
68
- /* @__PURE__ */ jsx(Button, { disabled: currentPage === 1, icon: /* @__PURE__ */ jsx(ArrowLeft, {}), onClick: prevPage }),
69
- pageList.first && /* @__PURE__ */ jsxs("span", { className: styles.ellipsisButton, children: [
70
- /* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: () => goToPage(1), children: pageList.first }),
71
- "\u2026"
72
- ] }),
73
- pageList.items.map((page) => /* @__PURE__ */ jsx(
57
+ showFirstLast && /* @__PURE__ */ jsx(
74
58
  Button,
75
59
  {
76
- "aria-current": page === currentPage ? "page" : void 0,
77
- variant: "outlined",
78
- onClick: () => goToPage(page),
79
- active: page === currentPage,
80
- children: page
81
- },
82
- page
83
- )),
84
- pageList.last !== void 0 && /* @__PURE__ */ jsxs("span", { className: styles.ellipsisButton, children: [
85
- "\u2026",
86
- /* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: () => goToPage(pageList.last), children: pageList.last })
87
- ] }),
88
- /* @__PURE__ */ jsx(Button, { disabled: currentPage === totalPages, icon: /* @__PURE__ */ jsx(ArrowRight, {}), onClick: nextPage }),
60
+ size: "sm",
61
+ icon: /* @__PURE__ */ jsx(ChevronsLeft, {}),
62
+ disabled: !canPrev,
63
+ onClick: firstPage,
64
+ "aria-label": "First page"
65
+ }
66
+ ),
67
+ /* @__PURE__ */ jsx(
68
+ Button,
69
+ {
70
+ size: "sm",
71
+ icon: /* @__PURE__ */ jsx(ArrowLeft, {}),
72
+ disabled: !canPrev,
73
+ onClick: prevPage,
74
+ "aria-label": "Previous page"
75
+ }
76
+ ),
77
+ /* @__PURE__ */ jsx("div", { className: styles.range, "aria-live": "polite", children: rangeLabel }),
78
+ /* @__PURE__ */ jsx(
79
+ Button,
80
+ {
81
+ size: "sm",
82
+ icon: /* @__PURE__ */ jsx(ArrowRight, {}),
83
+ disabled: !canNext,
84
+ onClick: nextPage,
85
+ "aria-label": "Next page"
86
+ }
87
+ ),
88
+ showFirstLast && /* @__PURE__ */ jsx(
89
+ Button,
90
+ {
91
+ size: "sm",
92
+ icon: /* @__PURE__ */ jsx(ChevronsRight, {}),
93
+ disabled: !canNext,
94
+ onClick: lastPage,
95
+ "aria-label": "Last page"
96
+ }
97
+ ),
98
+ showGoToPage && /* @__PURE__ */ jsx(
99
+ Popover,
100
+ {
101
+ trigger: (open) => /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "outlined", onClick: open, children: [
102
+ "Side ",
103
+ currentPage,
104
+ "/",
105
+ totalPages,
106
+ " ",
107
+ /* @__PURE__ */ jsx(ChevronDown, { size: 16 })
108
+ ] }),
109
+ children: /* @__PURE__ */ jsx(Menu, { children: pages.map((page) => /* @__PURE__ */ jsx(Menu.Item, { active: page === currentPage, children: /* @__PURE__ */ jsx("button", { onClick: () => goToPage(page), children: page }) }, page)) })
110
+ }
111
+ ),
89
112
  /* @__PURE__ */ jsx(
90
113
  Popover,
91
114
  {
92
- trigger: (event, icon) => /* @__PURE__ */ jsxs(Button, { variant: "outlined", onClick: event, children: [
115
+ trigger: (open) => /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "outlined", onClick: open, children: [
93
116
  "Vis ",
94
117
  take,
95
- icon
118
+ " ",
119
+ /* @__PURE__ */ jsx(ChevronDown, { size: 16 })
96
120
  ] }),
97
- children: /* @__PURE__ */ jsx(Menu, { children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx(Menu.Item, { active: size === take, children: /* @__PURE__ */ jsx(
98
- "button",
99
- {
100
- onClick: () => {
101
- handlePageSizeChange(size);
102
- },
103
- children: size
104
- }
105
- ) }, size)) })
121
+ children: /* @__PURE__ */ jsx(Menu, { children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx(Menu.Item, { active: size === take, children: /* @__PURE__ */ jsx("button", { onClick: () => handlePageSizeChange(size), children: size }) }, size)) })
106
122
  }
107
123
  )
108
124
  ] });
@@ -1,17 +1,25 @@
1
1
  .container {
2
2
  display: flex;
3
- gap: 5px;
4
- align-items: flex-end;
3
+ gap: var(--spacing-xxs);
4
+ align-items: center;
5
5
  justify-content: center;
6
6
  margin: 0 auto;
7
+ max-width: 100%;
8
+ overflow-x: auto;
7
9
  }
8
10
 
9
11
  .ellipsisButton {
10
12
  display: none;
11
13
  }
12
14
 
13
- @media (min-width: 480px) {
15
+ @media (min-width: var(--bp-xs)) {
14
16
  .ellipsisButton {
15
17
  display: contents;
16
18
  }
17
19
  }
20
+ .range {
21
+ min-width: 110px;
22
+ text-align: center;
23
+ font-size: var(--font-size-xs);
24
+ padding: 0 var(--spacing-xxs);
25
+ }
@@ -1,7 +1,7 @@
1
1
  .container {
2
2
  border: 1px solid var(--color-border-strong);
3
3
  border-radius: var(--border-radius-default);
4
- background-color: var(--color-bg);
4
+ background-color: var(--color-bg-surface);
5
5
  box-sizing: border-box;
6
6
  display: flex;
7
7
  flex-direction: column;
@@ -11,19 +11,17 @@
11
11
  border-bottom: 1px solid var(--color-border-strong);
12
12
  }
13
13
 
14
-
15
14
  .content {
16
15
  padding: var(--spacing-md);
17
16
  }
18
17
 
19
- .header
20
- {
18
+ .header {
21
19
  padding: var(--spacing-sm) var(--spacing-md);
22
20
  }
23
21
 
24
-
25
22
  .container.sm {
26
- .header,.content {
23
+ .header,
24
+ .content {
27
25
  padding: var(--spacing-sm) var(--spacing-md);
28
26
  }
29
- }
27
+ }
@@ -9,8 +9,15 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
10
10
  var styles__default = /*#__PURE__*/_interopDefault(styles);
11
11
 
12
- const Popover = react.forwardRef(function Popover2({ trigger: Trigger, children, minWidth = "200px", viewportPadding = 8, edgeBuffer = 100 }, ref) {
13
- const [pos, setPos] = react.useState({ top: 0, left: 0, visible: false });
12
+ const Popover = react.forwardRef(function Popover2({
13
+ trigger: Trigger,
14
+ children,
15
+ minWidth = "200px",
16
+ matchTriggerWidth = true,
17
+ viewportPadding = 8,
18
+ edgeBuffer = 100
19
+ }, ref) {
20
+ const [pos, setPos] = react.useState({ top: 0, left: 0, width: 0, visible: false });
14
21
  const containerRef = react.useRef(null);
15
22
  const contentRef = react.useRef(null);
16
23
  const computeAndSetPosition = react.useCallback(
@@ -18,15 +25,25 @@ const Popover = react.forwardRef(function Popover2({ trigger: Trigger, children,
18
25
  const container = containerRef.current;
19
26
  const content = contentRef.current;
20
27
  if (!container || !content) return;
28
+ const triggerRect = container.getBoundingClientRect();
21
29
  const prevVis = content.style.visibility;
22
30
  const prevDisp = content.style.display;
31
+ const prevMinWidth = content.style.minWidth;
32
+ const prevWidth = content.style.width;
23
33
  content.style.visibility = "hidden";
24
34
  content.style.display = "block";
25
- const triggerRect = container.getBoundingClientRect();
35
+ content.style.minWidth = minWidth;
36
+ content.style.width = "auto";
37
+ const minWidthPx = content.offsetWidth;
38
+ const desiredWidthPx = Math.max(matchTriggerWidth ? triggerRect.width : 0, minWidthPx);
39
+ content.style.minWidth = `${desiredWidthPx}px`;
40
+ content.style.width = `${desiredWidthPx}px`;
26
41
  const contentWidth = content.offsetWidth;
27
42
  const contentHeight = content.offsetHeight;
28
43
  content.style.visibility = prevVis;
29
44
  content.style.display = prevDisp;
45
+ content.style.minWidth = prevMinWidth;
46
+ content.style.width = prevWidth;
30
47
  const vw = window.innerWidth;
31
48
  const vh = window.innerHeight;
32
49
  const spaceAbove = Math.max(0, triggerRect.top);
@@ -54,9 +71,9 @@ const Popover = react.forwardRef(function Popover2({ trigger: Trigger, children,
54
71
  viewportPadding,
55
72
  Math.min(rawTop, vh - contentHeight - viewportPadding)
56
73
  );
57
- setPos({ top: clampedTop, left: clampedLeft, visible: show });
74
+ setPos({ top: clampedTop, left: clampedLeft, width: desiredWidthPx, visible: show });
58
75
  },
59
- [edgeBuffer, viewportPadding]
76
+ [edgeBuffer, viewportPadding, minWidth, matchTriggerWidth]
60
77
  );
61
78
  const openPopover = react.useCallback(
62
79
  (e) => {
@@ -111,18 +128,18 @@ const Popover = react.forwardRef(function Popover2({ trigger: Trigger, children,
111
128
  ref: contentRef,
112
129
  className: styles__default.default.content,
113
130
  style: {
114
- position: "fixed",
115
131
  top: pos.top,
116
132
  left: pos.left,
117
133
  visibility: pos.visible ? "visible" : "hidden",
118
- minWidth,
134
+ minWidth: pos.width ? `${pos.width}px` : minWidth,
135
+ width: pos.width ? `${pos.width}px` : void 0,
119
136
  maxWidth: `calc(100vw - ${viewportPadding * 2}px)`,
120
137
  maxHeight: `calc(100vh - ${viewportPadding * 2}px)`,
121
138
  overflow: "auto"
122
139
  },
123
140
  role: "dialog",
124
141
  "aria-hidden": !pos.visible,
125
- children
142
+ children: typeof children === "function" ? children(closePopover) : children
126
143
  }
127
144
  )
128
145
  ] });
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
2
  interface PopoverProps {
3
3
  trigger: (event: (e: React.MouseEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => void, icon: React.ReactNode) => React.ReactNode;
4
- children: React.ReactNode;
4
+ children: ((close?: () => void) => React.ReactNode) | React.ReactNode;
5
5
  minWidth?: string;
6
+ matchTriggerWidth?: boolean;
6
7
  viewportPadding?: number;
7
8
  edgeBuffer?: number;
8
9
  }
@@ -3,8 +3,15 @@ import { forwardRef, useState, useRef, useCallback, useImperativeHandle, useEffe
3
3
  import styles from './Popover.module.css';
4
4
  import { ChevronUp, ChevronDown } from 'lucide-react';
5
5
 
6
- const Popover = forwardRef(function Popover2({ trigger: Trigger, children, minWidth = "200px", viewportPadding = 8, edgeBuffer = 100 }, ref) {
7
- const [pos, setPos] = useState({ top: 0, left: 0, visible: false });
6
+ const Popover = forwardRef(function Popover2({
7
+ trigger: Trigger,
8
+ children,
9
+ minWidth = "200px",
10
+ matchTriggerWidth = true,
11
+ viewportPadding = 8,
12
+ edgeBuffer = 100
13
+ }, ref) {
14
+ const [pos, setPos] = useState({ top: 0, left: 0, width: 0, visible: false });
8
15
  const containerRef = useRef(null);
9
16
  const contentRef = useRef(null);
10
17
  const computeAndSetPosition = useCallback(
@@ -12,15 +19,25 @@ const Popover = forwardRef(function Popover2({ trigger: Trigger, children, minWi
12
19
  const container = containerRef.current;
13
20
  const content = contentRef.current;
14
21
  if (!container || !content) return;
22
+ const triggerRect = container.getBoundingClientRect();
15
23
  const prevVis = content.style.visibility;
16
24
  const prevDisp = content.style.display;
25
+ const prevMinWidth = content.style.minWidth;
26
+ const prevWidth = content.style.width;
17
27
  content.style.visibility = "hidden";
18
28
  content.style.display = "block";
19
- const triggerRect = container.getBoundingClientRect();
29
+ content.style.minWidth = minWidth;
30
+ content.style.width = "auto";
31
+ const minWidthPx = content.offsetWidth;
32
+ const desiredWidthPx = Math.max(matchTriggerWidth ? triggerRect.width : 0, minWidthPx);
33
+ content.style.minWidth = `${desiredWidthPx}px`;
34
+ content.style.width = `${desiredWidthPx}px`;
20
35
  const contentWidth = content.offsetWidth;
21
36
  const contentHeight = content.offsetHeight;
22
37
  content.style.visibility = prevVis;
23
38
  content.style.display = prevDisp;
39
+ content.style.minWidth = prevMinWidth;
40
+ content.style.width = prevWidth;
24
41
  const vw = window.innerWidth;
25
42
  const vh = window.innerHeight;
26
43
  const spaceAbove = Math.max(0, triggerRect.top);
@@ -48,9 +65,9 @@ const Popover = forwardRef(function Popover2({ trigger: Trigger, children, minWi
48
65
  viewportPadding,
49
66
  Math.min(rawTop, vh - contentHeight - viewportPadding)
50
67
  );
51
- setPos({ top: clampedTop, left: clampedLeft, visible: show });
68
+ setPos({ top: clampedTop, left: clampedLeft, width: desiredWidthPx, visible: show });
52
69
  },
53
- [edgeBuffer, viewportPadding]
70
+ [edgeBuffer, viewportPadding, minWidth, matchTriggerWidth]
54
71
  );
55
72
  const openPopover = useCallback(
56
73
  (e) => {
@@ -105,18 +122,18 @@ const Popover = forwardRef(function Popover2({ trigger: Trigger, children, minWi
105
122
  ref: contentRef,
106
123
  className: styles.content,
107
124
  style: {
108
- position: "fixed",
109
125
  top: pos.top,
110
126
  left: pos.left,
111
127
  visibility: pos.visible ? "visible" : "hidden",
112
- minWidth,
128
+ minWidth: pos.width ? `${pos.width}px` : minWidth,
129
+ width: pos.width ? `${pos.width}px` : void 0,
113
130
  maxWidth: `calc(100vw - ${viewportPadding * 2}px)`,
114
131
  maxHeight: `calc(100vh - ${viewportPadding * 2}px)`,
115
132
  overflow: "auto"
116
133
  },
117
134
  role: "dialog",
118
135
  "aria-hidden": !pos.visible,
119
- children
136
+ children: typeof children === "function" ? children(closePopover) : children
120
137
  }
121
138
  )
122
139
  ] });
@@ -1,22 +1,20 @@
1
1
  .container {
2
2
  position: relative;
3
- display: inline-flex;
4
3
  }
5
4
 
6
5
  .content {
7
- position: absolute;
8
- border: 1px solid var(--color-border);
6
+ position: fixed;
9
7
  top: 100%;
10
8
  left: 0;
11
- background-color: var(--color-surface);
9
+ border: 1px solid var(--color-border-default);
10
+ background-color: var(--color-bg-surface);
12
11
  border-radius: var(--border-radius-default);
13
12
  padding: var(--spacing-sm) 0;
14
13
  z-index: var(--z-popover);
15
- background-color: var(--color-background);
16
14
  max-width: 80vw;
17
15
  max-height: 80vh;
18
16
  overflow: auto;
19
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
17
+ box-shadow: var(--shadow-md);
20
18
  }
21
19
 
22
20
  .content svg {
@@ -3,19 +3,19 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var react = require('react');
5
5
  var lucideReact = require('lucide-react');
6
- var Input = require('../input/Input');
7
- var Menu = require('../menu/Menu');
8
- var Popover = require('../popover/Popover');
9
- var Button = require('../button/Button');
10
- var SkeletonLoaderItem = require('../skeleton-loader/skeleton-loader-item/SkeletonLoaderItem');
6
+ var Input = require('@/components/input/Input');
7
+ var Menu = require('@/components/menu/Menu');
8
+ var Popover = require('@/components/popover/Popover');
9
+ var Button = require('@/components/button/Button');
10
+ var SkeletonLoaderItem = require('@/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem');
11
11
  var styles = require('./SearchBox.module.css');
12
12
 
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var styles__default = /*#__PURE__*/_interopDefault(styles);
16
16
 
17
- const SearchBox = react.forwardRef(function SearchBox2({
18
- width,
17
+ const SearchBox = react.forwardRef(function SearchBoxInner({
18
+ inputWidth,
19
19
  inputSize,
20
20
  variant,
21
21
  result,
@@ -32,9 +32,12 @@ const SearchBox = react.forwardRef(function SearchBox2({
32
32
  loading,
33
33
  enableHotkey = true,
34
34
  onButtonClick,
35
+ value,
36
+ onChange,
35
37
  ...rest
36
38
  }, ref) {
37
- const [query, setQuery] = react.useState("");
39
+ const isControlled = value !== void 0;
40
+ const [draft, setDraft] = react.useState(() => isControlled ? String(value != null ? value : "") : "");
38
41
  const [searchQuery, setSearchQuery] = react.useState("");
39
42
  const popoverRef = react.useRef(null);
40
43
  const internalInputRef = react.useRef(null);
@@ -45,18 +48,24 @@ const SearchBox = react.forwardRef(function SearchBox2({
45
48
  ref.current = internalInputRef.current;
46
49
  }
47
50
  }, [ref]);
51
+ react.useEffect(() => {
52
+ if (!isControlled) return;
53
+ const next = String(value != null ? value : "");
54
+ if (next !== draft) setDraft(next);
55
+ }, [value]);
48
56
  react.useEffect(() => {
49
57
  if (!onSearch) return;
50
- if (debounce) {
51
- const handler = setTimeout(() => {
52
- setSearchQuery(query);
53
- onSearch(query);
54
- }, debounceMs);
55
- return () => clearTimeout(handler);
56
- } else {
57
- onSearch(query);
58
+ if (!debounce) {
59
+ setSearchQuery(draft);
60
+ onSearch(draft);
61
+ return;
58
62
  }
59
- }, [query, onSearch, debounce]);
63
+ const handler = setTimeout(() => {
64
+ setSearchQuery(draft);
65
+ onSearch(draft);
66
+ }, debounceMs);
67
+ return () => clearTimeout(handler);
68
+ }, [draft, onSearch, debounce, debounceMs]);
60
69
  react.useEffect(() => {
61
70
  function handleKeyDown(event) {
62
71
  var _a;
@@ -71,7 +80,8 @@ const SearchBox = react.forwardRef(function SearchBox2({
71
80
  }
72
81
  }, [enableHotkey]);
73
82
  const handleChange = (e) => {
74
- setQuery(e.target.value);
83
+ setDraft(e.target.value);
84
+ onChange == null ? void 0 : onChange(e);
75
85
  };
76
86
  function handleSelect(item) {
77
87
  onSelect == null ? void 0 : onSelect(item);
@@ -79,12 +89,15 @@ const SearchBox = react.forwardRef(function SearchBox2({
79
89
  }
80
90
  function reset() {
81
91
  var _a;
82
- setQuery("");
92
+ setDraft("");
83
93
  setSearchQuery("");
84
94
  (_a = popoverRef.current) == null ? void 0 : _a.close();
85
95
  }
86
- rest.value = query;
87
- rest.onChange = handleChange;
96
+ const inputProps = {
97
+ ...rest,
98
+ value: draft,
99
+ onChange: handleChange
100
+ };
88
101
  const inputField = react.useMemo(() => {
89
102
  var _a;
90
103
  if (displayPopover) {
@@ -99,30 +112,30 @@ const SearchBox = react.forwardRef(function SearchBox2({
99
112
  Input.Input,
100
113
  {
101
114
  ref: internalInputRef,
102
- onInput: handleChange,
103
115
  onFocusCapture: event,
104
116
  onClick: event,
105
- minWidth: width != null ? width : "300px",
117
+ minWidth: inputWidth != null ? inputWidth : "300px",
118
+ width: inputWidth != null ? inputWidth : "300px",
106
119
  icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, {}),
107
120
  inputSize,
108
- ...rest,
121
+ variant,
122
+ ...inputProps,
109
123
  placeholder: (_a2 = rest.placeholder) != null ? _a2 : "Indtast s\xF8geord"
110
124
  }
111
125
  );
112
126
  },
113
- children: (result == null ? void 0 : result.length) ? /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: /* @__PURE__ */ jsxRuntime.jsx("table", { children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: result.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx("tr", { onClick: () => handleSelect(item), role: "button", tabIndex: 0, children: resultKeys == null ? void 0 : resultKeys.map((key) => {
114
- const value = item[key] ? String(item[key]) : "";
127
+ children: resultTemplate ? resultTemplate : (result == null ? void 0 : result.length) ? /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: /* @__PURE__ */ jsxRuntime.jsx("table", { children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: result.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx("tr", { onClick: () => handleSelect(item), role: "button", tabIndex: 0, children: resultKeys == null ? void 0 : resultKeys.map((key) => {
128
+ const raw = item[key];
129
+ const cell = raw != null ? String(raw) : "";
115
130
  return /* @__PURE__ */ jsxRuntime.jsx(
116
131
  "td",
117
132
  {
118
- style: {
119
- whiteSpace: String(value.length < 10 ? "nowrap" : "")
120
- },
121
- children: String(item[key])
133
+ style: { whiteSpace: cell.length < 10 ? "nowrap" : void 0 },
134
+ children: cell
122
135
  },
123
- String(key)
136
+ key
124
137
  );
125
- }) }, index)) }) }) }) : !searchQuery && !loading ? initialTemplate || /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.resultContainer, children: "Indtast s\xF8geord" }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("table", { style: { width: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: Array.from({ length: 5 }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: resultKeys == null ? void 0 : resultKeys.map((key) => /* @__PURE__ */ jsxRuntime.jsx("td", { style: { padding: "8px" }, children: /* @__PURE__ */ jsxRuntime.jsx(SkeletonLoaderItem.SkeletonLoaderItem, { height: 20, width: "100%" }) }, String(key))) }, index)) }) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.resultContainer, children: noResultText })
138
+ }) }, index)) }) }) }) : !searchQuery && !loading ? initialTemplate || /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.resultContainer, children: "Indtast s\xF8geord" }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("table", { style: { width: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: Array.from({ length: 5 }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: resultKeys == null ? void 0 : resultKeys.map((key) => /* @__PURE__ */ jsxRuntime.jsx("td", { style: { padding: "8px" }, children: /* @__PURE__ */ jsxRuntime.jsx(SkeletonLoaderItem.SkeletonLoaderItem, { height: 20, width: "100%" }) }, key)) }, index)) }) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.resultContainer, children: noResultText })
126
139
  }
127
140
  );
128
141
  }
@@ -130,12 +143,11 @@ const SearchBox = react.forwardRef(function SearchBox2({
130
143
  Input.Input,
131
144
  {
132
145
  ref: internalInputRef,
133
- onInput: handleChange,
134
146
  icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, {}),
135
- minWidth: width != null ? width : "300px",
147
+ minWidth: inputWidth != null ? inputWidth : "300px",
136
148
  inputSize,
137
149
  variant,
138
- ...rest,
150
+ ...inputProps,
139
151
  placeholder: (_a = rest.placeholder) != null ? _a : "Indtast s\xF8geord"
140
152
  }
141
153
  );
@@ -148,10 +160,11 @@ const SearchBox = react.forwardRef(function SearchBox2({
148
160
  initialTemplate,
149
161
  searchQuery,
150
162
  loading,
151
- width,
163
+ inputWidth,
152
164
  inputSize,
153
165
  variant,
154
- rest
166
+ inputProps,
167
+ rest.placeholder
155
168
  ]);
156
169
  return onButtonClick ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles__default.default.withButton, children: [
157
170
  inputField,
@@ -1,17 +1,17 @@
1
1
  import React from 'react';
2
- import { InputVariant } from '../input/Input';
2
+ import { InputVariant } from '@/components/input/Input';
3
3
  import { Size } from '@/types/sizes.types';
4
- export declare const SearchBox: React.ForwardRefExoticComponent<{
5
- width?: string;
4
+ type SearchBoxProps<T extends Record<string, unknown>> = {
5
+ inputWidth?: string | number;
6
6
  inputSize?: Size;
7
7
  variant?: InputVariant;
8
- result?: unknown[] | undefined;
9
- resultKeys?: never[] | undefined;
8
+ result?: T[];
9
+ resultKeys?: Array<Extract<keyof T, string>>;
10
10
  resultTemplate?: React.ReactNode;
11
11
  debounce?: boolean;
12
12
  debounceMs?: number;
13
13
  onSearch?: (query: string) => void;
14
- onSelect?: ((item: unknown) => void) | undefined;
14
+ onSelect?: (item: T) => void;
15
15
  displayPopover?: boolean;
16
16
  initialTemplate?: React.ReactNode;
17
17
  noResultText?: string;
@@ -19,4 +19,7 @@ export declare const SearchBox: React.ForwardRefExoticComponent<{
19
19
  loading?: boolean;
20
20
  enableHotkey?: boolean;
21
21
  onButtonClick?: () => void;
22
- } & React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
22
+ } & React.InputHTMLAttributes<HTMLInputElement>;
23
+ type SearchBoxComponent = <T extends Record<string, unknown>>(props: SearchBoxProps<T> & React.RefAttributes<HTMLInputElement>) => React.ReactElement | null;
24
+ export declare const SearchBox: SearchBoxComponent;
25
+ export {};