@helpwave/hightide 0.0.15 → 0.0.16

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 (111) hide show
  1. package/dist/index.d.mts +86 -2
  2. package/dist/index.d.ts +86 -2
  3. package/dist/index.js +5714 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +5541 -0
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/util/news.d.mts +9 -9
  8. package/dist/util/news.d.ts +9 -9
  9. package/package.json +11 -7
  10. package/dist/components/Span.d.mts +0 -2
  11. package/dist/components/Span.d.ts +0 -2
  12. package/dist/components/Span.js +0 -2
  13. package/dist/components/Span.js.map +0 -1
  14. package/dist/components/Span.mjs +0 -1
  15. package/dist/components/Span.mjs.map +0 -1
  16. package/dist/components/examples/InputGroupExample.d.mts +0 -11
  17. package/dist/components/examples/InputGroupExample.d.ts +0 -11
  18. package/dist/components/examples/InputGroupExample.js +0 -466
  19. package/dist/components/examples/InputGroupExample.js.map +0 -1
  20. package/dist/components/examples/InputGroupExample.mjs +0 -436
  21. package/dist/components/examples/InputGroupExample.mjs.map +0 -1
  22. package/dist/components/examples/MultiSelectExample.d.mts +0 -14
  23. package/dist/components/examples/MultiSelectExample.d.ts +0 -14
  24. package/dist/components/examples/MultiSelectExample.js +0 -661
  25. package/dist/components/examples/MultiSelectExample.js.map +0 -1
  26. package/dist/components/examples/MultiSelectExample.mjs +0 -631
  27. package/dist/components/examples/MultiSelectExample.mjs.map +0 -1
  28. package/dist/components/examples/SearchableSelectExample.d.mts +0 -13
  29. package/dist/components/examples/SearchableSelectExample.d.ts +0 -13
  30. package/dist/components/examples/SearchableSelectExample.js +0 -365
  31. package/dist/components/examples/SearchableSelectExample.js.map +0 -1
  32. package/dist/components/examples/SearchableSelectExample.mjs +0 -335
  33. package/dist/components/examples/SearchableSelectExample.mjs.map +0 -1
  34. package/dist/components/examples/SelectExample.d.mts +0 -9
  35. package/dist/components/examples/SelectExample.d.ts +0 -9
  36. package/dist/components/examples/SelectExample.js +0 -180
  37. package/dist/components/examples/SelectExample.js.map +0 -1
  38. package/dist/components/examples/SelectExample.mjs +0 -145
  39. package/dist/components/examples/SelectExample.mjs.map +0 -1
  40. package/dist/components/examples/StackingModals.d.mts +0 -8
  41. package/dist/components/examples/StackingModals.d.ts +0 -8
  42. package/dist/components/examples/StackingModals.js +0 -498
  43. package/dist/components/examples/StackingModals.js.map +0 -1
  44. package/dist/components/examples/StackingModals.mjs +0 -463
  45. package/dist/components/examples/StackingModals.mjs.map +0 -1
  46. package/dist/components/examples/TableExample.d.mts +0 -13
  47. package/dist/components/examples/TableExample.d.ts +0 -13
  48. package/dist/components/examples/TableExample.js +0 -853
  49. package/dist/components/examples/TableExample.js.map +0 -1
  50. package/dist/components/examples/TableExample.mjs +0 -823
  51. package/dist/components/examples/TableExample.mjs.map +0 -1
  52. package/dist/components/examples/TextareaExample.d.mts +0 -12
  53. package/dist/components/examples/TextareaExample.d.ts +0 -12
  54. package/dist/components/examples/TextareaExample.js +0 -176
  55. package/dist/components/examples/TextareaExample.js.map +0 -1
  56. package/dist/components/examples/TextareaExample.mjs +0 -141
  57. package/dist/components/examples/TextareaExample.mjs.map +0 -1
  58. package/dist/components/examples/TileExample.d.mts +0 -14
  59. package/dist/components/examples/TileExample.d.ts +0 -14
  60. package/dist/components/examples/TileExample.js +0 -79
  61. package/dist/components/examples/TileExample.js.map +0 -1
  62. package/dist/components/examples/TileExample.mjs +0 -44
  63. package/dist/components/examples/TileExample.mjs.map +0 -1
  64. package/dist/components/examples/Title.d.mts +0 -2
  65. package/dist/components/examples/Title.d.ts +0 -2
  66. package/dist/components/examples/Title.js +0 -2
  67. package/dist/components/examples/Title.js.map +0 -1
  68. package/dist/components/examples/Title.mjs +0 -1
  69. package/dist/components/examples/Title.mjs.map +0 -1
  70. package/dist/components/examples/date/DateTimePickerExample.d.mts +0 -18
  71. package/dist/components/examples/date/DateTimePickerExample.d.ts +0 -18
  72. package/dist/components/examples/date/DateTimePickerExample.js +0 -879
  73. package/dist/components/examples/date/DateTimePickerExample.js.map +0 -1
  74. package/dist/components/examples/date/DateTimePickerExample.mjs +0 -844
  75. package/dist/components/examples/date/DateTimePickerExample.mjs.map +0 -1
  76. package/dist/components/examples/properties/CheckboxPropertyExample.d.mts +0 -16
  77. package/dist/components/examples/properties/CheckboxPropertyExample.d.ts +0 -16
  78. package/dist/components/examples/properties/CheckboxPropertyExample.js +0 -349
  79. package/dist/components/examples/properties/CheckboxPropertyExample.js.map +0 -1
  80. package/dist/components/examples/properties/CheckboxPropertyExample.mjs +0 -314
  81. package/dist/components/examples/properties/CheckboxPropertyExample.mjs.map +0 -1
  82. package/dist/components/examples/properties/DatePropertyExample.d.mts +0 -16
  83. package/dist/components/examples/properties/DatePropertyExample.d.ts +0 -16
  84. package/dist/components/examples/properties/DatePropertyExample.js +0 -460
  85. package/dist/components/examples/properties/DatePropertyExample.js.map +0 -1
  86. package/dist/components/examples/properties/DatePropertyExample.mjs +0 -430
  87. package/dist/components/examples/properties/DatePropertyExample.mjs.map +0 -1
  88. package/dist/components/examples/properties/MultiSelectPropertyExample.d.mts +0 -18
  89. package/dist/components/examples/properties/MultiSelectPropertyExample.d.ts +0 -18
  90. package/dist/components/examples/properties/MultiSelectPropertyExample.js +0 -848
  91. package/dist/components/examples/properties/MultiSelectPropertyExample.js.map +0 -1
  92. package/dist/components/examples/properties/MultiSelectPropertyExample.mjs +0 -818
  93. package/dist/components/examples/properties/MultiSelectPropertyExample.mjs.map +0 -1
  94. package/dist/components/examples/properties/NumberPropertyExample.d.mts +0 -14
  95. package/dist/components/examples/properties/NumberPropertyExample.d.ts +0 -14
  96. package/dist/components/examples/properties/NumberPropertyExample.js +0 -456
  97. package/dist/components/examples/properties/NumberPropertyExample.js.map +0 -1
  98. package/dist/components/examples/properties/NumberPropertyExample.mjs +0 -426
  99. package/dist/components/examples/properties/NumberPropertyExample.mjs.map +0 -1
  100. package/dist/components/examples/properties/SelectPropertyExample.d.mts +0 -17
  101. package/dist/components/examples/properties/SelectPropertyExample.d.ts +0 -17
  102. package/dist/components/examples/properties/SelectPropertyExample.js +0 -584
  103. package/dist/components/examples/properties/SelectPropertyExample.js.map +0 -1
  104. package/dist/components/examples/properties/SelectPropertyExample.mjs +0 -554
  105. package/dist/components/examples/properties/SelectPropertyExample.mjs.map +0 -1
  106. package/dist/components/examples/properties/TextPropertyExample.d.mts +0 -16
  107. package/dist/components/examples/properties/TextPropertyExample.d.ts +0 -16
  108. package/dist/components/examples/properties/TextPropertyExample.js +0 -405
  109. package/dist/components/examples/properties/TextPropertyExample.js.map +0 -1
  110. package/dist/components/examples/properties/TextPropertyExample.mjs +0 -370
  111. package/dist/components/examples/properties/TextPropertyExample.mjs.map +0 -1
@@ -1,823 +0,0 @@
1
- // src/components/examples/TableExample.tsx
2
- import { useEffect as useEffect6, useState as useState7 } from "react";
3
-
4
- // src/components/Table.tsx
5
- import { Scrollbars } from "react-custom-scrollbars-2";
6
- import { useEffect as useEffect3, useRef, useState as useState4 } from "react";
7
-
8
- // src/util/noop.ts
9
- var noop = () => void 0;
10
-
11
- // src/components/user-input/Checkbox.tsx
12
- import { useState } from "react";
13
- import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
14
- import { Check, Minus } from "lucide-react";
15
- import clsx from "clsx";
16
-
17
- // src/components/user-input/Label.tsx
18
- import { jsx } from "react/jsx-runtime";
19
- var styleMapping = {
20
- labelSmall: "textstyle-label-sm",
21
- labelMedium: "textstyle-label-md",
22
- labelBig: "textstyle-label-lg"
23
- };
24
- var Label = ({
25
- children,
26
- name,
27
- labelType = "labelSmall",
28
- ...props
29
- }) => {
30
- return /* @__PURE__ */ jsx("label", { ...props, children: children ? children : /* @__PURE__ */ jsx("span", { className: styleMapping[labelType], children: name }) });
31
- };
32
-
33
- // src/components/user-input/Checkbox.tsx
34
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
35
- var checkboxSizeMapping = {
36
- small: "size-4",
37
- medium: "size-6",
38
- large: "size-8"
39
- };
40
- var checkboxIconSizeMapping = {
41
- small: "size-3",
42
- medium: "size-5",
43
- large: "size-7"
44
- };
45
- var ControlledCheckbox = ({
46
- id,
47
- label,
48
- checked,
49
- disabled,
50
- onChange,
51
- onChangeTristate,
52
- size = "medium",
53
- className = "",
54
- containerClassName
55
- }) => {
56
- const usedSizeClass = checkboxSizeMapping[size];
57
- const innerIconSize = checkboxIconSizeMapping[size];
58
- const propagateChange = (checked2) => {
59
- if (onChangeTristate) {
60
- onChangeTristate(checked2);
61
- }
62
- if (onChange) {
63
- onChange(checked2 === "indeterminate" ? false : checked2);
64
- }
65
- };
66
- const changeValue = () => {
67
- const newValue = checked === "indeterminate" ? false : !checked;
68
- propagateChange(newValue);
69
- };
70
- return /* @__PURE__ */ jsxs("div", { className: clsx("row justify-center items-center", containerClassName), children: [
71
- /* @__PURE__ */ jsx2(
72
- CheckboxPrimitive.Root,
73
- {
74
- onCheckedChange: propagateChange,
75
- checked,
76
- disabled,
77
- id,
78
- className: clsx(usedSizeClass, `items-center border-2 rounded outline-none focus:border-primary`, {
79
- "text-disabled-text border-disabled-text": disabled,
80
- "border-on-background": !disabled,
81
- "bg-primary/30 border-primary text-primary": checked === true || checked === "indeterminate",
82
- "hover:border-gray-400 focus:hover:border-primary": !checked
83
- }, className),
84
- children: /* @__PURE__ */ jsxs(CheckboxPrimitive.Indicator, { children: [
85
- checked === true && /* @__PURE__ */ jsx2(Check, { className: innerIconSize }),
86
- checked === "indeterminate" && /* @__PURE__ */ jsx2(Minus, { className: innerIconSize })
87
- ] })
88
- }
89
- ),
90
- label && /* @__PURE__ */ jsx2(Label, { ...label, className: clsx("cursor-pointer", label.className), htmlFor: id, onClick: changeValue })
91
- ] });
92
- };
93
-
94
- // src/components/Pagination.tsx
95
- import { ChevronLast, ChevronLeft, ChevronFirst, ChevronRight } from "lucide-react";
96
- import clsx2 from "clsx";
97
-
98
- // src/hooks/useLanguage.tsx
99
- import { createContext, useContext, useEffect as useEffect2, useState as useState3 } from "react";
100
-
101
- // src/hooks/useLocalStorage.tsx
102
- import { useCallback, useEffect, useState as useState2 } from "react";
103
-
104
- // src/hooks/useLanguage.tsx
105
- import { jsx as jsx3 } from "react/jsx-runtime";
106
- var DEFAULT_LANGUAGE = "en";
107
- var LanguageContext = createContext({ language: DEFAULT_LANGUAGE, setLanguage: (v) => v });
108
- var useLanguage = () => useContext(LanguageContext);
109
-
110
- // src/hooks/useTranslation.ts
111
- var useTranslation = (defaults, translationOverwrite = {}) => {
112
- const { language: languageProp, translation: overwrite } = translationOverwrite;
113
- const { language: inferredLanguage } = useLanguage();
114
- const usedLanguage = languageProp ?? inferredLanguage;
115
- let defaultValues = defaults[usedLanguage];
116
- if (overwrite && overwrite[usedLanguage]) {
117
- defaultValues = { ...defaultValues, ...overwrite[usedLanguage] };
118
- }
119
- return defaultValues;
120
- };
121
-
122
- // src/components/Pagination.tsx
123
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
124
- var defaultPaginationTranslations = {
125
- en: {
126
- of: "of"
127
- },
128
- de: {
129
- of: "von"
130
- }
131
- };
132
- var Pagination = ({
133
- overwriteTranslation,
134
- page,
135
- numberOfPages,
136
- onPageChanged
137
- }) => {
138
- const translation = useTranslation(defaultPaginationTranslations, overwriteTranslation);
139
- const changePage = (page2) => {
140
- onPageChanged(page2);
141
- };
142
- const noPages = numberOfPages === 0;
143
- const onFirstPage = page === 0 && !noPages;
144
- const onLastPage = page === numberOfPages - 1;
145
- return /* @__PURE__ */ jsxs2("div", { className: clsx2("row", { "opacity-30": noPages }), children: [
146
- /* @__PURE__ */ jsx4("button", { onClick: () => changePage(0), disabled: onFirstPage, children: /* @__PURE__ */ jsx4(ChevronFirst, { className: clsx2({ "opacity-30": onFirstPage }) }) }),
147
- /* @__PURE__ */ jsx4("button", { onClick: () => changePage(page - 1), disabled: onFirstPage, children: /* @__PURE__ */ jsx4(ChevronLeft, { className: clsx2({ "opacity-30": onFirstPage }) }) }),
148
- /* @__PURE__ */ jsxs2("div", { className: "min-w-[80px] justify-center mx-2", children: [
149
- /* @__PURE__ */ jsx4("span", { className: "select-none text-right flex-1", children: noPages ? 0 : page + 1 }),
150
- /* @__PURE__ */ jsx4("span", { className: "select-none mx-2", children: translation.of }),
151
- /* @__PURE__ */ jsx4("span", { className: "select-none text-left flex-1", children: numberOfPages })
152
- ] }),
153
- /* @__PURE__ */ jsx4("button", { onClick: () => changePage(page + 1), disabled: onLastPage || noPages, children: /* @__PURE__ */ jsx4(ChevronRight, { className: clsx2({ "opacity-30": onLastPage }) }) }),
154
- /* @__PURE__ */ jsx4("button", { onClick: () => changePage(numberOfPages - 1), disabled: onLastPage || noPages, children: /* @__PURE__ */ jsx4(ChevronLast, { className: clsx2({ "opacity-30": onLastPage }) }) })
155
- ] });
156
- };
157
-
158
- // src/components/Table.tsx
159
- import clsx3 from "clsx";
160
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
161
- var defaultTableStatePagination = {
162
- currentPage: 0,
163
- entriesPerPage: 5
164
- };
165
- var defaultTableStateSelection = {
166
- currentSelection: [],
167
- hasSelectedAll: false,
168
- hasSelectedSome: false,
169
- hasSelectedNone: true
170
- };
171
- var isDataObjectSelected = (tableState, dataObject, identifierMapping) => {
172
- if (!tableState.selection) {
173
- return false;
174
- }
175
- return !!tableState.selection.currentSelection.find((value) => value.localeCompare(identifierMapping(dataObject)) === 0);
176
- };
177
- var pageForItem = (data, item, entriesPerPage, identifierMapping) => {
178
- const index = data.findIndex((value) => identifierMapping(value) === identifierMapping(item));
179
- if (index !== -1) {
180
- return Math.floor(index / entriesPerPage);
181
- }
182
- console.warn("item doesn't exist on data", item, data);
183
- return 0;
184
- };
185
- var updatePagination = (pagination, dataLength) => ({
186
- ...pagination,
187
- currentPage: Math.min(Math.max(Math.ceil(dataLength / pagination.entriesPerPage) - 1, 0), pagination.currentPage)
188
- });
189
- var addElementToTable = (tableState, data, dataObject, identifierMapping) => {
190
- return {
191
- ...tableState,
192
- pagination: tableState.pagination ? {
193
- ...tableState.pagination,
194
- currentPage: pageForItem(data, dataObject, tableState.pagination.entriesPerPage, identifierMapping)
195
- } : void 0,
196
- selection: tableState.selection ? {
197
- ...tableState.selection,
198
- hasSelectedAll: false,
199
- hasSelectedSome: tableState.selection.hasSelectedAll || tableState.selection.hasSelectedSome
200
- } : void 0
201
- };
202
- };
203
- var removeFromTableSelection = (tableState, deletedObjects, dataLength, identifierMapping) => {
204
- if (!tableState.selection) {
205
- return tableState;
206
- }
207
- const deletedObjectIds = deletedObjects.map(identifierMapping);
208
- const elementsBefore = tableState.selection.currentSelection.length;
209
- const currentSelection = tableState.selection.currentSelection.filter((value) => !deletedObjectIds.includes(value));
210
- dataLength -= elementsBefore - currentSelection.length;
211
- return {
212
- ...tableState,
213
- selection: {
214
- currentSelection,
215
- hasSelectedAll: currentSelection.length === dataLength && dataLength !== 0,
216
- hasSelectedSome: currentSelection.length > 0 && currentSelection.length !== dataLength,
217
- hasSelectedNone: currentSelection.length === 0
218
- },
219
- pagination: tableState.pagination ? updatePagination(tableState.pagination, dataLength) : void 0
220
- };
221
- };
222
- var changeTableSelectionSingle = (tableState, dataObject, dataLength, identifierMapping) => {
223
- if (!tableState.selection) {
224
- return tableState;
225
- }
226
- const hasSelectedObject = isDataObjectSelected(tableState, dataObject, identifierMapping);
227
- let currentSelection = [...tableState.selection.currentSelection, identifierMapping(dataObject)];
228
- if (hasSelectedObject) {
229
- currentSelection = tableState.selection.currentSelection.filter((value) => value.localeCompare(identifierMapping(dataObject)) !== 0);
230
- }
231
- return {
232
- ...tableState,
233
- selection: {
234
- currentSelection,
235
- hasSelectedAll: currentSelection.length === dataLength,
236
- hasSelectedSome: currentSelection.length > 0 && currentSelection.length !== dataLength,
237
- hasSelectedNone: currentSelection.length === 0
238
- }
239
- };
240
- };
241
- var changeTableSelectionAll = (tableState, data, identifierMapping) => {
242
- if (!tableState.selection) {
243
- return tableState;
244
- }
245
- if (data.length === 0) {
246
- return {
247
- ...tableState,
248
- selection: {
249
- currentSelection: [],
250
- hasSelectedAll: false,
251
- hasSelectedSome: false,
252
- hasSelectedNone: true
253
- }
254
- };
255
- }
256
- const hasSelectedAll = !(tableState.selection.hasSelectedSome || tableState.selection.hasSelectedAll);
257
- return {
258
- ...tableState,
259
- selection: {
260
- currentSelection: hasSelectedAll ? data.map(identifierMapping) : [],
261
- hasSelectedAll,
262
- hasSelectedSome: false,
263
- hasSelectedNone: !hasSelectedAll
264
- }
265
- };
266
- };
267
- var Table = ({
268
- data,
269
- stateManagement = [{}, noop],
270
- identifierMapping,
271
- header,
272
- rowMappingToCells,
273
- sorting,
274
- focusElement,
275
- className
276
- }) => {
277
- const sortedData = [...data];
278
- if (sorting) {
279
- const [sortingFunction, sortingType] = sorting;
280
- sortedData.sort((a, b) => sortingFunction(a, b) * (sortingType === "ascending" ? 1 : -1));
281
- }
282
- let currentPage = 0;
283
- let pageCount = 1;
284
- let entriesPerPage = 5;
285
- const [tableState, updateTableState] = stateManagement;
286
- let shownElements = sortedData;
287
- if (tableState?.pagination) {
288
- if (tableState.pagination.entriesPerPage < 1) {
289
- console.error("tableState.pagination.entriesPerPage must be >= 1", tableState.pagination.entriesPerPage);
290
- }
291
- entriesPerPage = Math.max(1, tableState.pagination.entriesPerPage);
292
- pageCount = Math.ceil(sortedData.length / entriesPerPage);
293
- if (tableState.pagination.currentPage < 0 || tableState.pagination.currentPage >= pageCount && pageCount !== 0) {
294
- console.error(
295
- "tableState.pagination.currentPage < 0 || (tableState.pagination.currentPage >= pageCount && pageCount !== 0) must be fullfilled",
296
- [`pageCount: ${pageCount}`, `tableState.pagination.currentPage: ${tableState.pagination.currentPage}`]
297
- );
298
- } else {
299
- currentPage = tableState.pagination.currentPage;
300
- }
301
- if (focusElement) {
302
- currentPage = pageForItem(sortedData, focusElement, entriesPerPage, identifierMapping);
303
- }
304
- shownElements = sortedData.slice(currentPage * entriesPerPage, Math.min(sortedData.length, (currentPage + 1) * entriesPerPage));
305
- } else {
306
- currentPage = 0;
307
- }
308
- const headerRow = "border-b-2 border-gray-300";
309
- const headerPaddingHead = "pb-2";
310
- const headerPaddingBody = "pt-2";
311
- const cellPadding = "py-1 px-2";
312
- const [scrollbarsAutoHeightMin, setScrollbarsAutoHeightMin] = useState4(0);
313
- const tableRef = useRef(null);
314
- const calculateHeight = () => {
315
- if (tableRef.current) {
316
- const tableHeight = tableRef.current.offsetHeight;
317
- const offset = 25;
318
- setScrollbarsAutoHeightMin(tableHeight + offset);
319
- }
320
- };
321
- useEffect3(() => {
322
- calculateHeight();
323
- const handleResize = () => {
324
- calculateHeight();
325
- };
326
- window.addEventListener("resize", handleResize);
327
- return () => {
328
- window.removeEventListener("resize", handleResize);
329
- };
330
- }, [data, currentPage]);
331
- return /* @__PURE__ */ jsxs3("div", { className: clsx3("col gap-y-4 overflow-hidden", className), children: [
332
- /* @__PURE__ */ jsx5("div", { children: /* @__PURE__ */ jsx5(Scrollbars, { autoHeight: true, autoHeightMin: scrollbarsAutoHeightMin, children: /* @__PURE__ */ jsxs3("table", { ref: tableRef, className: "w-full mb-[12px]", children: [
333
- /* @__PURE__ */ jsx5("thead", { children: /* @__PURE__ */ jsxs3("tr", { className: headerRow, children: [
334
- header && tableState.selection && /* @__PURE__ */ jsx5("th", { className: headerPaddingHead, children: /* @__PURE__ */ jsx5(
335
- ControlledCheckbox,
336
- {
337
- checked: tableState.selection.hasSelectedSome ? "indeterminate" : tableState.selection.hasSelectedAll,
338
- onChange: () => updateTableState(changeTableSelectionAll(tableState, data, identifierMapping))
339
- }
340
- ) }),
341
- header && header.map((value, index) => /* @__PURE__ */ jsx5("th", { className: headerPaddingHead, children: /* @__PURE__ */ jsx5("div", { className: "row justify-start px-2", children: value }) }, `tableHeader${index}`))
342
- ] }) }),
343
- /* @__PURE__ */ jsx5("tbody", { children: shownElements.map((value, rowIndex) => /* @__PURE__ */ jsxs3("tr", { children: [
344
- tableState.selection && /* @__PURE__ */ jsx5("td", { className: clsx3(cellPadding, { [headerPaddingBody]: rowIndex === 0 }), children: /* @__PURE__ */ jsx5(
345
- ControlledCheckbox,
346
- {
347
- checked: isDataObjectSelected(tableState, value, identifierMapping),
348
- onChange: () => {
349
- updateTableState(changeTableSelectionSingle(tableState, value, data.length, identifierMapping));
350
- }
351
- }
352
- ) }),
353
- rowMappingToCells(value).map((value1, index) => /* @__PURE__ */ jsx5("td", { className: clsx3(cellPadding, { [headerPaddingBody]: rowIndex === 0 }), children: value1 }, index))
354
- ] }, identifierMapping(value))) })
355
- ] }) }) }),
356
- /* @__PURE__ */ jsx5("div", { className: "row justify-center", children: tableState.pagination && /* @__PURE__ */ jsx5(Pagination, { page: currentPage, numberOfPages: pageCount, onPageChanged: (page) => updateTableState({
357
- ...tableState,
358
- pagination: { entriesPerPage, currentPage: page }
359
- }) }) })
360
- ] });
361
- };
362
-
363
- // src/components/user-input/Input.tsx
364
- import {
365
- useEffect as useEffect5,
366
- useRef as useRef2,
367
- useState as useState6,
368
- forwardRef
369
- } from "react";
370
- import clsx4 from "clsx";
371
-
372
- // src/hooks/useSaveDelay.ts
373
- import { useEffect as useEffect4, useState as useState5 } from "react";
374
- function useSaveDelay(setNotificationStatus, delay) {
375
- const [updateTimer, setUpdateTimer] = useState5(void 0);
376
- const [notificationTimer, setNotificationTimer] = useState5(void 0);
377
- const restartTimer = (onSave) => {
378
- clearTimeout(updateTimer);
379
- setUpdateTimer(setTimeout(() => {
380
- onSave();
381
- setNotificationStatus(true);
382
- clearTimeout(notificationTimer);
383
- setNotificationTimer(setTimeout(() => {
384
- setNotificationStatus(false);
385
- clearTimeout(notificationTimer);
386
- }, delay));
387
- clearTimeout(updateTimer);
388
- }, delay));
389
- };
390
- const clearUpdateTimer = (hasSaved = true) => {
391
- clearTimeout(updateTimer);
392
- if (hasSaved) {
393
- setNotificationStatus(true);
394
- clearTimeout(notificationTimer);
395
- setNotificationTimer(setTimeout(() => {
396
- setNotificationStatus(false);
397
- clearTimeout(notificationTimer);
398
- }, delay));
399
- } else {
400
- setNotificationStatus(false);
401
- }
402
- };
403
- useEffect4(() => {
404
- return () => {
405
- clearTimeout(updateTimer);
406
- clearTimeout(notificationTimer);
407
- };
408
- }, []);
409
- return { restartTimer, clearUpdateTimer };
410
- }
411
- var useSaveDelay_default = useSaveDelay;
412
-
413
- // src/components/user-input/Input.tsx
414
- import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
415
- var ControlledInput = ({
416
- id,
417
- type = "text",
418
- value,
419
- label,
420
- onChange = noop,
421
- onChangeEvent = noop,
422
- className = "",
423
- onEditCompleted,
424
- expanded = true,
425
- onBlur,
426
- containerClassName,
427
- ...restProps
428
- }) => {
429
- const {
430
- restartTimer,
431
- clearUpdateTimer
432
- } = useSaveDelay_default(() => void 0, 3e3);
433
- const ref = useRef2(null);
434
- useEffect5(() => {
435
- if (restProps.autoFocus) {
436
- ref.current?.focus();
437
- }
438
- }, [restProps.autoFocus]);
439
- return /* @__PURE__ */ jsxs4("div", { className: clsx4({ "w-full": expanded }, containerClassName), children: [
440
- label && /* @__PURE__ */ jsx6(Label, { ...label, htmlFor: id, className: clsx4("mb-1", label.className) }),
441
- /* @__PURE__ */ jsx6(
442
- "input",
443
- {
444
- ref,
445
- value,
446
- id,
447
- type,
448
- className: clsx4("block bg-surface text-on-surface px-3 py-2 rounded-md w-full border-2 border-gray-200 hover:border-primary focus:outline-none focus:border-primary focus:ring-primary", className),
449
- onBlur: (event) => {
450
- if (onBlur) {
451
- onBlur(event);
452
- }
453
- if (onEditCompleted) {
454
- onEditCompleted(event.target.value, event);
455
- clearUpdateTimer();
456
- }
457
- },
458
- onChange: (e) => {
459
- const value2 = e.target.value;
460
- if (onEditCompleted) {
461
- restartTimer(() => {
462
- onEditCompleted(value2, e);
463
- clearUpdateTimer();
464
- });
465
- }
466
- onChange(value2, e);
467
- onChangeEvent(e);
468
- },
469
- ...restProps
470
- }
471
- )
472
- ] });
473
- };
474
- var FormInput = forwardRef(function FormInput2({
475
- id,
476
- labelText,
477
- errorText,
478
- className,
479
- labelClassName,
480
- errorClassName,
481
- containerClassName,
482
- required,
483
- ...restProps
484
- }, ref) {
485
- const input = /* @__PURE__ */ jsx6(
486
- "input",
487
- {
488
- ref,
489
- id,
490
- ...restProps,
491
- className: clsx4(
492
- "block bg-surface text-on-surface px-3 py-2 rounded-md w-full border-2 border-gray-200 hover:border-primary focus:outline-none focus:border-primary focus:ring-primary",
493
- {
494
- "focus:border-primary focus:ring-primary": !errorText,
495
- "focus:border-negative focus:ring-negative text-negative": !!errorText
496
- },
497
- className
498
- )
499
- }
500
- );
501
- return /* @__PURE__ */ jsxs4("div", { className: clsx4("flex flex-col gap-y-1", containerClassName), children: [
502
- labelText && /* @__PURE__ */ jsxs4("label", { htmlFor: id, className: clsx4("textstyle-label-md", labelClassName), children: [
503
- labelText,
504
- required && /* @__PURE__ */ jsx6("span", { className: "text-primary font-bold", children: "*" })
505
- ] }),
506
- input,
507
- errorText && /* @__PURE__ */ jsx6("label", { htmlFor: id, className: clsx4("text-negative", errorClassName), children: errorText })
508
- ] });
509
- });
510
-
511
- // src/components/Button.tsx
512
- import clsx5 from "clsx";
513
- import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
514
- var ButtonSizePaddings = {
515
- small: "btn-sm",
516
- medium: "btn-md",
517
- large: "btn-lg"
518
- };
519
- var SolidButton = ({
520
- children,
521
- disabled = false,
522
- color = "primary",
523
- size = "medium",
524
- startIcon,
525
- endIcon,
526
- onClick,
527
- className,
528
- ...restProps
529
- }) => {
530
- const colorClasses = {
531
- primary: "bg-button-solid-primary-background text-button-solid-primary-text",
532
- secondary: "bg-button-solid-secondary-background text-button-solid-secondary-text",
533
- tertiary: "bg-button-solid-tertiary-background text-button-solid-tertiary-text",
534
- positive: "bg-button-solid-positive-background text-button-solid-positive-text",
535
- warning: "bg-button-solid-warning-background text-button-solid-warning-text",
536
- negative: "bg-button-solid-negative-background text-button-solid-negative-text"
537
- }[color];
538
- const iconColorClasses = {
539
- primary: "text-button-solid-primary-icon",
540
- secondary: "text-button-solid-secondary-icon",
541
- tertiary: "text-button-solid-tertiary-icon",
542
- positive: "text-button-solid-positive-icon",
543
- warning: "text-button-solid-warning-icon",
544
- negative: "text-button-solid-negative-icon"
545
- }[color];
546
- return /* @__PURE__ */ jsxs5(
547
- "button",
548
- {
549
- onClick: disabled ? void 0 : onClick,
550
- disabled: disabled || onClick === void 0,
551
- className: clsx5(
552
- className,
553
- {
554
- "text-disabled-text bg-disabled-background": disabled,
555
- [clsx5(colorClasses, "hover:brightness-90")]: !disabled
556
- },
557
- ButtonSizePaddings[size]
558
- ),
559
- ...restProps,
560
- children: [
561
- startIcon && /* @__PURE__ */ jsx7(
562
- "span",
563
- {
564
- className: clsx5({
565
- [iconColorClasses]: !disabled,
566
- [`text-disabled-icon`]: disabled
567
- }),
568
- children: startIcon
569
- }
570
- ),
571
- children,
572
- endIcon && /* @__PURE__ */ jsx7(
573
- "span",
574
- {
575
- className: clsx5({
576
- [iconColorClasses]: !disabled,
577
- [`text-disabled-icon`]: disabled
578
- }),
579
- children: endIcon
580
- }
581
- )
582
- ]
583
- }
584
- );
585
- };
586
- var TextButton = ({
587
- children,
588
- disabled = false,
589
- color = "neutral",
590
- size = "medium",
591
- startIcon,
592
- endIcon,
593
- onClick,
594
- className,
595
- ...restProps
596
- }) => {
597
- const colorClasses = {
598
- negative: "bg-transparent text-button-text-negative-text",
599
- neutral: "bg-transparent text-button-text-neutral-text"
600
- }[color];
601
- const iconColorClasses = {
602
- negative: "text-button-text-negative-icon",
603
- neutral: "text-button-text-neutral-icon"
604
- }[color];
605
- return /* @__PURE__ */ jsxs5(
606
- "button",
607
- {
608
- onClick: disabled ? void 0 : onClick,
609
- disabled: disabled || onClick === void 0,
610
- className: clsx5(
611
- className,
612
- {
613
- "text-disabled-text": disabled,
614
- [clsx5(colorClasses, "hover:bg-button-text-hover-background rounded-full")]: !disabled
615
- },
616
- ButtonSizePaddings[size]
617
- ),
618
- ...restProps,
619
- children: [
620
- startIcon && /* @__PURE__ */ jsx7(
621
- "span",
622
- {
623
- className: clsx5({
624
- [iconColorClasses]: !disabled,
625
- [`text-disabled-icon`]: disabled
626
- }),
627
- children: startIcon
628
- }
629
- ),
630
- children,
631
- endIcon && /* @__PURE__ */ jsx7(
632
- "span",
633
- {
634
- className: clsx5({
635
- [iconColorClasses]: !disabled,
636
- [`text-disabled-icon`]: disabled
637
- }),
638
- children: endIcon
639
- }
640
- )
641
- ]
642
- }
643
- );
644
- };
645
-
646
- // src/components/SortButton.tsx
647
- import { ChevronDown, ChevronsUpDown, ChevronUp } from "lucide-react";
648
- import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
649
- var SortButton = ({
650
- children,
651
- ascending,
652
- color,
653
- onClick,
654
- ...buttonProps
655
- }) => {
656
- return /* @__PURE__ */ jsx8(
657
- TextButton,
658
- {
659
- color,
660
- onClick: () => onClick(ascending === "descending" ? "ascending" : "descending"),
661
- ...buttonProps,
662
- children: /* @__PURE__ */ jsxs6("div", { className: "row gap-x-2", children: [
663
- children,
664
- ascending === "ascending" ? /* @__PURE__ */ jsx8(ChevronUp, {}) : !ascending ? /* @__PURE__ */ jsx8(ChevronsUpDown, {}) : /* @__PURE__ */ jsx8(ChevronDown, {})
665
- ] })
666
- }
667
- );
668
- };
669
-
670
- // src/components/examples/TableExample.tsx
671
- import { Fragment, jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
672
- var exampleData = [
673
- { id: "data1", name: "Name 1", age: 23 },
674
- { id: "data2", name: "Name 2", age: 21 },
675
- { id: "data3", name: "Name 3", age: 32 },
676
- { id: "data4", name: "Name 4", age: 42 },
677
- { id: "data5", name: "Name 5", age: 17 },
678
- { id: "data6", name: "Name 6", age: 26 },
679
- { id: "data7", name: "Name 7", age: 19 },
680
- { id: "data8", name: "Name 8", age: 31 }
681
- ];
682
- var TableExample = ({ data: initialData }) => {
683
- const [data, setData] = useState7(initialData);
684
- const [tableState, setTableState] = useState7({
685
- pagination: defaultTableStatePagination,
686
- selection: defaultTableStateSelection
687
- });
688
- useEffect6(() => {
689
- setData(initialData);
690
- }, [initialData]);
691
- const [sorting, setSorting] = useState7();
692
- const [sortingKey, ascending] = sorting ?? ["", "ascending"];
693
- const idMapping = (data2) => data2.id;
694
- const sortingFunctions = {
695
- id: {
696
- ascending: (t1, t2) => t1.id.localeCompare(t2.id),
697
- descending: (t1, t2) => t1.id.localeCompare(t2.id) * -1
698
- },
699
- name: {
700
- ascending: (t1, t2) => t1.name.localeCompare(t2.name),
701
- descending: (t1, t2) => t1.name.localeCompare(t2.name) * -1
702
- },
703
- age: {
704
- ascending: (t1, t2) => t1.age - t2.age,
705
- descending: (t1, t2) => (t1.age - t2.age) * -1
706
- }
707
- };
708
- return /* @__PURE__ */ jsxs7("div", { className: "col gap-y-12 items-center", children: [
709
- /* @__PURE__ */ jsx9(
710
- Table,
711
- {
712
- stateManagement: [tableState, (newTableState) => {
713
- setTableState(newTableState);
714
- setData(data);
715
- }],
716
- data,
717
- identifierMapping: idMapping,
718
- rowMappingToCells: (dataObject) => [
719
- /* @__PURE__ */ jsx9("span", { className: "textstyle-title-md w-[100px] text-ellipsis overflow-hidden block", children: dataObject.id }, "id"),
720
- /* @__PURE__ */ jsx9(ControlledInput, { value: dataObject.name, onChange: (text) => {
721
- setData(data.map((value) => value.id === dataObject.id ? { ...dataObject, name: text } : value));
722
- setSorting(void 0);
723
- } }, "name"),
724
- /* @__PURE__ */ jsx9(ControlledInput, { type: "number", value: dataObject.age.toString(), onChange: (text) => {
725
- setData(data.map((value) => value.id === dataObject.id ? { ...dataObject, age: parseInt(text) } : value));
726
- setSorting(void 0);
727
- } }, "age"),
728
- /* @__PURE__ */ jsx9(
729
- TextButton,
730
- {
731
- color: "negative",
732
- onClick: () => {
733
- const newData = data.filter((value) => value.id !== dataObject.id);
734
- setData(newData);
735
- setTableState(removeFromTableSelection(tableState, [dataObject], data.length, idMapping));
736
- },
737
- children: "Delete"
738
- },
739
- "delete"
740
- )
741
- ],
742
- header: [
743
- /* @__PURE__ */ jsx9(
744
- SortButton,
745
- {
746
- ascending: sortingKey === "id" ? ascending : void 0,
747
- onClick: (newTableSorting) => {
748
- setSorting(["id", newTableSorting]);
749
- setData(data.sort(sortingFunctions.id[newTableSorting]));
750
- },
751
- children: /* @__PURE__ */ jsx9("span", { className: "textstyle-table-header", children: "Id" })
752
- },
753
- "headerId"
754
- ),
755
- /* @__PURE__ */ jsx9(
756
- SortButton,
757
- {
758
- ascending: sortingKey === "name" ? ascending : void 0,
759
- onClick: (newTableSorting) => {
760
- setSorting(["name", newTableSorting]);
761
- setData(data.sort(sortingFunctions.name[newTableSorting]));
762
- },
763
- children: /* @__PURE__ */ jsx9("span", { className: "textstyle-table-header", children: "Name" })
764
- },
765
- "name"
766
- ),
767
- /* @__PURE__ */ jsx9(
768
- SortButton,
769
- {
770
- ascending: sortingKey === "age" ? ascending : void 0,
771
- onClick: (newTableSorting) => {
772
- setSorting(["age", newTableSorting]);
773
- setData(data.sort(sortingFunctions.age[newTableSorting]));
774
- },
775
- children: /* @__PURE__ */ jsx9("span", { className: "textstyle-table-header", children: "age" }, "age")
776
- },
777
- "name"
778
- ),
779
- /* @__PURE__ */ jsx9(Fragment, {})
780
- ]
781
- }
782
- ),
783
- /* @__PURE__ */ jsxs7("div", { className: "row gap-x-2", children: [
784
- /* @__PURE__ */ jsx9(
785
- SolidButton,
786
- {
787
- className: "w-auto",
788
- onClick: () => {
789
- const newData = {
790
- id: Math.random().toString(),
791
- name: "Name " + data.length,
792
- age: Math.ceil(Math.random() * 100)
793
- };
794
- const withNewData = [...data, newData];
795
- const sorted = sortingKey ? withNewData.sort(sortingFunctions[sortingKey][ascending]) : withNewData;
796
- setData(sorted);
797
- setTableState(addElementToTable(tableState, sorted, newData, idMapping));
798
- },
799
- children: "Add Data"
800
- }
801
- ),
802
- /* @__PURE__ */ jsx9(
803
- TextButton,
804
- {
805
- className: "w-auto",
806
- onClick: () => {
807
- const selectedData = data.filter((d) => tableState.selection?.currentSelection.includes(idMapping(d)));
808
- const unselectedData = data.filter((d) => !tableState.selection?.currentSelection.includes(idMapping(d)));
809
- setData(unselectedData);
810
- setTableState(removeFromTableSelection(tableState, selectedData, data.length, idMapping));
811
- },
812
- children: "Remove all selected"
813
- }
814
- )
815
- ] })
816
- ] });
817
- };
818
- var TableExample_default = TableExample;
819
- export {
820
- TableExample_default as default,
821
- exampleData
822
- };
823
- //# sourceMappingURL=TableExample.mjs.map