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