@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,844 +0,0 @@
1
- // src/components/examples/date/DateTimePickerExample.tsx
2
- import { useEffect as useEffect7, useState as useState8 } from "react";
3
-
4
- // src/components/user-input/DateAndTimePicker.tsx
5
- import clsx7 from "clsx";
6
-
7
- // src/hooks/useLanguage.tsx
8
- import { createContext, useContext, useEffect as useEffect2, useState as useState2 } from "react";
9
-
10
- // src/hooks/useLocalStorage.tsx
11
- import { useCallback, useEffect, useState } from "react";
12
-
13
- // src/hooks/useLanguage.tsx
14
- import { jsx } from "react/jsx-runtime";
15
- var DEFAULT_LANGUAGE = "en";
16
- var LanguageContext = createContext({ language: DEFAULT_LANGUAGE, setLanguage: (v) => v });
17
- var useLanguage = () => useContext(LanguageContext);
18
- var useLocale = (overWriteLanguage) => {
19
- const { language } = useLanguage();
20
- const mapping = {
21
- en: "en-US",
22
- de: "de-DE"
23
- };
24
- return mapping[overWriteLanguage ?? language];
25
- };
26
-
27
- // src/hooks/useTranslation.ts
28
- var useTranslation = (defaults, translationOverwrite = {}) => {
29
- const { language: languageProp, translation: overwrite } = translationOverwrite;
30
- const { language: inferredLanguage } = useLanguage();
31
- const usedLanguage = languageProp ?? inferredLanguage;
32
- let defaultValues = defaults[usedLanguage];
33
- if (overwrite && overwrite[usedLanguage]) {
34
- defaultValues = { ...defaultValues, ...overwrite[usedLanguage] };
35
- }
36
- return defaultValues;
37
- };
38
-
39
- // src/util/noop.ts
40
- var noop = () => void 0;
41
-
42
- // src/util/array.ts
43
- var equalSizeGroups = (array, groupSize) => {
44
- if (groupSize <= 0) {
45
- console.warn(`group size should be greater than 0: groupSize = ${groupSize}`);
46
- return [[...array]];
47
- }
48
- const groups = [];
49
- for (let i = 0; i < array.length; i += groupSize) {
50
- groups.push(array.slice(i, Math.min(i + groupSize, array.length)));
51
- }
52
- return groups;
53
- };
54
- var range = (start, end, allowEmptyRange = false) => {
55
- if (end < start) {
56
- if (!allowEmptyRange) {
57
- console.warn(`range: end (${end}) < start (${start}) should be allowed explicitly, set allowEmptyRange to true`);
58
- }
59
- return [];
60
- }
61
- return Array.from({ length: end - start + 1 }, (_, index) => index + start);
62
- };
63
- var closestMatch = (list, firstCloser) => {
64
- return list.reduce((item1, item2) => {
65
- return firstCloser(item1, item2) ? item1 : item2;
66
- });
67
- };
68
-
69
- // src/util/date.ts
70
- var monthsList = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
71
- var weekDayList = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
72
- var changeDuration = (date, duration, isAdding) => {
73
- const {
74
- years = 0,
75
- months = 0,
76
- days = 0,
77
- hours = 0,
78
- minutes = 0,
79
- seconds = 0,
80
- milliseconds = 0
81
- } = duration;
82
- if (years < 0) {
83
- console.error(`Range error years must be greater than 0: received ${years}`);
84
- return new Date(date);
85
- }
86
- if (months < 0 || months > 11) {
87
- console.error(`Range error month must be 0 <= month <= 11: received ${months}`);
88
- return new Date(date);
89
- }
90
- if (days < 0) {
91
- console.error(`Range error days must be greater than 0: received ${days}`);
92
- return new Date(date);
93
- }
94
- if (hours < 0 || hours > 23) {
95
- console.error(`Range error hours must be 0 <= hours <= 23: received ${hours}`);
96
- return new Date(date);
97
- }
98
- if (minutes < 0 || minutes > 59) {
99
- console.error(`Range error minutes must be 0 <= minutes <= 59: received ${minutes}`);
100
- return new Date(date);
101
- }
102
- if (seconds < 0 || seconds > 59) {
103
- console.error(`Range error seconds must be 0 <= seconds <= 59: received ${seconds}`);
104
- return new Date(date);
105
- }
106
- if (milliseconds < 0) {
107
- console.error(`Range error seconds must be greater than 0: received ${milliseconds}`);
108
- return new Date(date);
109
- }
110
- const multiplier = isAdding ? 1 : -1;
111
- const newDate = new Date(date);
112
- newDate.setFullYear(newDate.getFullYear() + multiplier * years);
113
- newDate.setMonth(newDate.getMonth() + multiplier * months);
114
- newDate.setDate(newDate.getDate() + multiplier * days);
115
- newDate.setHours(newDate.getHours() + multiplier * hours);
116
- newDate.setMinutes(newDate.getMinutes() + multiplier * minutes);
117
- newDate.setSeconds(newDate.getSeconds() + multiplier * seconds);
118
- newDate.setMilliseconds(newDate.getMilliseconds() + multiplier * milliseconds);
119
- return newDate;
120
- };
121
- var addDuration = (date, duration) => {
122
- return changeDuration(date, duration, true);
123
- };
124
- var subtractDuration = (date, duration) => {
125
- return changeDuration(date, duration, false);
126
- };
127
- var isInTimeSpan = (value, startDate, endDate) => {
128
- if (startDate && endDate) {
129
- console.assert(startDate <= endDate);
130
- return startDate <= value && value <= endDate;
131
- } else if (startDate) {
132
- return startDate <= value;
133
- } else if (endDate) {
134
- return endDate >= value;
135
- } else {
136
- return true;
137
- }
138
- };
139
- var equalDate = (date1, date2) => {
140
- return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate();
141
- };
142
- var getWeeksForCalenderMonth = (date, weekStart, weeks = 6) => {
143
- const month = date.getMonth();
144
- const year = date.getFullYear();
145
- const dayList = [];
146
- let currentDate = new Date(year, month, 1);
147
- const weekStartIndex = weekDayList.indexOf(weekStart);
148
- while (currentDate.getDay() !== weekStartIndex) {
149
- currentDate = subtractDuration(currentDate, { days: 1 });
150
- }
151
- while (dayList.length < 7 * weeks) {
152
- const date2 = new Date(currentDate);
153
- date2.setHours(date2.getHours(), date2.getMinutes());
154
- dayList.push(date2);
155
- currentDate = addDuration(currentDate, { days: 1 });
156
- }
157
- return equalSizeGroups(dayList, 7);
158
- };
159
-
160
- // src/components/Button.tsx
161
- import clsx from "clsx";
162
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
163
- var ButtonSizePaddings = {
164
- small: "btn-sm",
165
- medium: "btn-md",
166
- large: "btn-lg"
167
- };
168
- var SolidButton = ({
169
- children,
170
- disabled = false,
171
- color = "primary",
172
- size = "medium",
173
- startIcon,
174
- endIcon,
175
- onClick,
176
- className,
177
- ...restProps
178
- }) => {
179
- const colorClasses = {
180
- primary: "bg-button-solid-primary-background text-button-solid-primary-text",
181
- secondary: "bg-button-solid-secondary-background text-button-solid-secondary-text",
182
- tertiary: "bg-button-solid-tertiary-background text-button-solid-tertiary-text",
183
- positive: "bg-button-solid-positive-background text-button-solid-positive-text",
184
- warning: "bg-button-solid-warning-background text-button-solid-warning-text",
185
- negative: "bg-button-solid-negative-background text-button-solid-negative-text"
186
- }[color];
187
- const iconColorClasses = {
188
- primary: "text-button-solid-primary-icon",
189
- secondary: "text-button-solid-secondary-icon",
190
- tertiary: "text-button-solid-tertiary-icon",
191
- positive: "text-button-solid-positive-icon",
192
- warning: "text-button-solid-warning-icon",
193
- negative: "text-button-solid-negative-icon"
194
- }[color];
195
- return /* @__PURE__ */ jsxs(
196
- "button",
197
- {
198
- onClick: disabled ? void 0 : onClick,
199
- disabled: disabled || onClick === void 0,
200
- className: clsx(
201
- className,
202
- {
203
- "text-disabled-text bg-disabled-background": disabled,
204
- [clsx(colorClasses, "hover:brightness-90")]: !disabled
205
- },
206
- ButtonSizePaddings[size]
207
- ),
208
- ...restProps,
209
- children: [
210
- startIcon && /* @__PURE__ */ jsx2(
211
- "span",
212
- {
213
- className: clsx({
214
- [iconColorClasses]: !disabled,
215
- [`text-disabled-icon`]: disabled
216
- }),
217
- children: startIcon
218
- }
219
- ),
220
- children,
221
- endIcon && /* @__PURE__ */ jsx2(
222
- "span",
223
- {
224
- className: clsx({
225
- [iconColorClasses]: !disabled,
226
- [`text-disabled-icon`]: disabled
227
- }),
228
- children: endIcon
229
- }
230
- )
231
- ]
232
- }
233
- );
234
- };
235
- var TextButton = ({
236
- children,
237
- disabled = false,
238
- color = "neutral",
239
- size = "medium",
240
- startIcon,
241
- endIcon,
242
- onClick,
243
- className,
244
- ...restProps
245
- }) => {
246
- const colorClasses = {
247
- negative: "bg-transparent text-button-text-negative-text",
248
- neutral: "bg-transparent text-button-text-neutral-text"
249
- }[color];
250
- const iconColorClasses = {
251
- negative: "text-button-text-negative-icon",
252
- neutral: "text-button-text-neutral-icon"
253
- }[color];
254
- return /* @__PURE__ */ jsxs(
255
- "button",
256
- {
257
- onClick: disabled ? void 0 : onClick,
258
- disabled: disabled || onClick === void 0,
259
- className: clsx(
260
- className,
261
- {
262
- "text-disabled-text": disabled,
263
- [clsx(colorClasses, "hover:bg-button-text-hover-background rounded-full")]: !disabled
264
- },
265
- ButtonSizePaddings[size]
266
- ),
267
- ...restProps,
268
- children: [
269
- startIcon && /* @__PURE__ */ jsx2(
270
- "span",
271
- {
272
- className: clsx({
273
- [iconColorClasses]: !disabled,
274
- [`text-disabled-icon`]: disabled
275
- }),
276
- children: startIcon
277
- }
278
- ),
279
- children,
280
- endIcon && /* @__PURE__ */ jsx2(
281
- "span",
282
- {
283
- className: clsx({
284
- [iconColorClasses]: !disabled,
285
- [`text-disabled-icon`]: disabled
286
- }),
287
- children: endIcon
288
- }
289
- )
290
- ]
291
- }
292
- );
293
- };
294
-
295
- // src/components/date/TimePicker.tsx
296
- import { useEffect as useEffect3, useRef, useState as useState3 } from "react";
297
- import { Scrollbars } from "react-custom-scrollbars-2";
298
- import clsx2 from "clsx";
299
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
300
- var TimePicker = ({
301
- time = /* @__PURE__ */ new Date(),
302
- onChange = noop,
303
- is24HourFormat = true,
304
- minuteIncrement = "5min",
305
- maxHeight = 300,
306
- className = ""
307
- }) => {
308
- const minuteRef = useRef(null);
309
- const hourRef = useRef(null);
310
- const isPM = time.getHours() >= 11;
311
- const hours = is24HourFormat ? range(0, 23) : range(1, 12);
312
- let minutes = range(0, 59);
313
- useEffect3(() => {
314
- const scrollToItem = () => {
315
- if (minuteRef.current) {
316
- const container = minuteRef.current.parentElement;
317
- const hasOverflow = container.scrollHeight > maxHeight;
318
- if (hasOverflow) {
319
- minuteRef.current.scrollIntoView({
320
- behavior: "instant",
321
- block: "nearest"
322
- });
323
- }
324
- }
325
- };
326
- scrollToItem();
327
- }, [minuteRef, minuteRef.current]);
328
- useEffect3(() => {
329
- const scrollToItem = () => {
330
- if (hourRef.current) {
331
- const container = hourRef.current.parentElement;
332
- const hasOverflow = container.scrollHeight > maxHeight;
333
- if (hasOverflow) {
334
- hourRef.current.scrollIntoView({
335
- behavior: "instant",
336
- block: "nearest"
337
- });
338
- }
339
- }
340
- };
341
- scrollToItem();
342
- }, [hourRef, hourRef.current]);
343
- switch (minuteIncrement) {
344
- case "5min":
345
- minutes = minutes.filter((value) => value % 5 === 0);
346
- break;
347
- case "10min":
348
- minutes = minutes.filter((value) => value % 10 === 0);
349
- break;
350
- case "15min":
351
- minutes = minutes.filter((value) => value % 15 === 0);
352
- break;
353
- case "30min":
354
- minutes = minutes.filter((value) => value % 30 === 0);
355
- break;
356
- }
357
- const closestMinute = closestMatch(minutes, (item1, item2) => Math.abs(item1 - time.getMinutes()) < Math.abs(item2 - time.getMinutes()));
358
- const style = (selected) => clsx2(
359
- "chip-full hover:brightness-90 hover:bg-primary hover:text-on-primary rounded-md mr-3",
360
- { "bg-primary text-on-primary": selected, "bg-white text-black": !selected }
361
- );
362
- const onChangeWrapper = (transformer) => {
363
- const newDate = new Date(time);
364
- transformer(newDate);
365
- onChange(newDate);
366
- };
367
- return /* @__PURE__ */ jsxs2("div", { className: clsx2("row gap-x-2 w-fit min-w-[150px] select-none", className), children: [
368
- /* @__PURE__ */ jsx3(Scrollbars, { autoHeight: true, autoHeightMax: maxHeight, style: { height: "100%" }, children: /* @__PURE__ */ jsx3("div", { className: "col gap-y-1 h-full", children: hours.map((hour) => {
369
- const currentHour = hour === time.getHours() - (!is24HourFormat && isPM ? 12 : 0);
370
- return /* @__PURE__ */ jsx3(
371
- "button",
372
- {
373
- ref: currentHour ? hourRef : void 0,
374
- className: style(currentHour),
375
- onClick: () => onChangeWrapper((newDate) => newDate.setHours(hour + (!is24HourFormat && isPM ? 12 : 0))),
376
- children: hour.toString().padStart(2, "0")
377
- },
378
- hour
379
- );
380
- }) }) }),
381
- /* @__PURE__ */ jsx3(Scrollbars, { autoHeight: true, autoHeightMax: maxHeight, style: { height: "100%" }, children: /* @__PURE__ */ jsx3("div", { className: "col gap-y-1 h-full", children: minutes.map((minute) => {
382
- const currentMinute = minute === closestMinute;
383
- return /* @__PURE__ */ jsx3(
384
- "button",
385
- {
386
- ref: currentMinute ? minuteRef : void 0,
387
- className: style(currentMinute),
388
- onClick: () => onChangeWrapper((newDate) => newDate.setMinutes(minute)),
389
- children: minute.toString().padStart(2, "0")
390
- },
391
- minute + minuteIncrement
392
- );
393
- }) }) }),
394
- !is24HourFormat && /* @__PURE__ */ jsxs2("div", { className: "col gap-y-1", children: [
395
- /* @__PURE__ */ jsx3(
396
- "button",
397
- {
398
- className: style(!isPM),
399
- onClick: () => onChangeWrapper((newDate) => isPM && newDate.setHours(newDate.getHours() - 12)),
400
- children: "AM"
401
- }
402
- ),
403
- /* @__PURE__ */ jsx3(
404
- "button",
405
- {
406
- className: style(isPM),
407
- onClick: () => onChangeWrapper((newDate) => !isPM && newDate.setHours(newDate.getHours() + 12)),
408
- children: "PM"
409
- }
410
- )
411
- ] })
412
- ] });
413
- };
414
-
415
- // src/components/date/DatePicker.tsx
416
- import { useEffect as useEffect6, useState as useState7 } from "react";
417
- import { ArrowDown, ArrowUp, ChevronDown as ChevronDown2 } from "lucide-react";
418
- import clsx6 from "clsx";
419
-
420
- // src/components/date/YearMonthPicker.tsx
421
- import { useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
422
- import { Scrollbars as Scrollbars2 } from "react-custom-scrollbars-2";
423
- import clsx4 from "clsx";
424
-
425
- // src/components/Expandable.tsx
426
- import { forwardRef, useState as useState4 } from "react";
427
- import { ChevronDown, ChevronUp } from "lucide-react";
428
- import clsx3 from "clsx";
429
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
430
- var DefaultIcon = (expanded) => expanded ? /* @__PURE__ */ jsx4(ChevronUp, { size: 16, className: "min-w-[16px]" }) : /* @__PURE__ */ jsx4(ChevronDown, { size: 16, className: "min-w-[16px]" });
431
- var Expandable = forwardRef(({
432
- children,
433
- label,
434
- icon,
435
- initialExpansion = false,
436
- clickOnlyOnHeader = true,
437
- className = "",
438
- headerClassName = ""
439
- }, ref) => {
440
- const [isExpanded, setIsExpanded] = useState4(initialExpansion);
441
- icon ??= DefaultIcon;
442
- return /* @__PURE__ */ jsxs3(
443
- "div",
444
- {
445
- ref,
446
- className: clsx3("col bg-surface text-on-surface group rounded-lg shadow-sm", { "cursor-pointer": !clickOnlyOnHeader }, className),
447
- onClick: () => !clickOnlyOnHeader && setIsExpanded(!isExpanded),
448
- children: [
449
- /* @__PURE__ */ jsxs3(
450
- "button",
451
- {
452
- className: clsx3("btn-md rounded-lg justify-between items-center bg-surface text-on-surface", { "group-hover:brightness-95": !isExpanded }, headerClassName),
453
- onClick: () => clickOnlyOnHeader && setIsExpanded(!isExpanded),
454
- children: [
455
- label,
456
- icon(isExpanded)
457
- ]
458
- }
459
- ),
460
- isExpanded && /* @__PURE__ */ jsx4("div", { className: "col", children })
461
- ]
462
- }
463
- );
464
- });
465
- Expandable.displayName = "Expandable";
466
-
467
- // src/components/date/YearMonthPicker.tsx
468
- import { jsx as jsx5 } from "react/jsx-runtime";
469
- var YearMonthPicker = ({
470
- displayedYearMonth = /* @__PURE__ */ new Date(),
471
- start = subtractDuration(/* @__PURE__ */ new Date(), { years: 50 }),
472
- end = addDuration(/* @__PURE__ */ new Date(), { years: 50 }),
473
- onChange = noop,
474
- className = "",
475
- maxHeight = 300,
476
- showValueOpen = true
477
- }) => {
478
- const locale = useLocale();
479
- const ref = useRef2(null);
480
- useEffect4(() => {
481
- const scrollToItem = () => {
482
- if (ref.current) {
483
- ref.current.scrollIntoView({
484
- behavior: "instant",
485
- block: "center"
486
- });
487
- }
488
- };
489
- scrollToItem();
490
- }, [ref]);
491
- if (end < start) {
492
- console.error(`startYear: (${start}) less than endYear: (${end})`);
493
- return null;
494
- }
495
- const years = range(start.getFullYear(), end.getFullYear());
496
- return /* @__PURE__ */ jsx5("div", { className: clsx4("col select-none", className), children: /* @__PURE__ */ jsx5(Scrollbars2, { autoHeight: true, autoHeightMax: maxHeight, style: { height: "100%" }, children: /* @__PURE__ */ jsx5("div", { className: "col gap-y-1 mr-3", children: years.map((year) => {
497
- const selectedYear = displayedYearMonth.getFullYear() === year;
498
- return /* @__PURE__ */ jsx5(
499
- Expandable,
500
- {
501
- ref: (displayedYearMonth.getFullYear() ?? (/* @__PURE__ */ new Date()).getFullYear()) === year ? ref : void 0,
502
- label: /* @__PURE__ */ jsx5("span", { className: clsx4({ "text-primary font-bold": selectedYear }), children: year }),
503
- initialExpansion: showValueOpen && selectedYear,
504
- children: /* @__PURE__ */ jsx5("div", { className: "col gap-y-1 px-2 pb-2", children: equalSizeGroups([...monthsList], 3).map((monthList, index) => /* @__PURE__ */ jsx5("div", { className: "row", children: monthList.map((month) => {
505
- const monthIndex = monthsList.indexOf(month);
506
- const newDate = new Date(year, monthIndex);
507
- const selectedMonth = selectedYear && monthIndex === displayedYearMonth.getMonth();
508
- const firstOfMonth = new Date(year, monthIndex, 1);
509
- const lastOfMonth = new Date(year, monthIndex, 1);
510
- const isAfterStart = start === void 0 || start <= addDuration(subtractDuration(lastOfMonth, { days: 1 }), { months: 1 });
511
- const isBeforeEnd = end === void 0 || firstOfMonth <= end;
512
- const isValid = isAfterStart && isBeforeEnd;
513
- return /* @__PURE__ */ jsx5(
514
- "button",
515
- {
516
- disabled: !isValid,
517
- className: clsx4(
518
- "chip hover:brightness-95 flex-1",
519
- {
520
- "bg-gray-50 text-black": !selectedMonth && isValid,
521
- "bg-primary text-on-primary": selectedMonth && isValid,
522
- "bg-disabled-background text-disabled-text": !isValid
523
- }
524
- ),
525
- onClick: () => {
526
- onChange(newDate);
527
- },
528
- children: new Intl.DateTimeFormat(locale, { month: "short" }).format(newDate)
529
- },
530
- month
531
- );
532
- }) }, index)) })
533
- },
534
- year
535
- );
536
- }) }) }) });
537
- };
538
-
539
- // src/components/date/DayPicker.tsx
540
- import clsx5 from "clsx";
541
- import { useEffect as useEffect5, useState as useState6 } from "react";
542
- import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
543
- var DayPicker = ({
544
- displayedMonth,
545
- selected,
546
- start,
547
- end,
548
- onChange = noop,
549
- weekStart = "monday",
550
- markToday = true,
551
- className = ""
552
- }) => {
553
- const locale = useLocale();
554
- const month = displayedMonth.getMonth();
555
- const weeks = getWeeksForCalenderMonth(displayedMonth, weekStart);
556
- return /* @__PURE__ */ jsxs4("div", { className: clsx5("col gap-y-1 min-w-[220px] select-none", className), children: [
557
- /* @__PURE__ */ jsx6("div", { className: "row text-center", children: weeks[0].map((weekDay, index) => /* @__PURE__ */ jsx6("div", { className: "flex-1 font-semibold", children: new Intl.DateTimeFormat(locale, { weekday: "long" }).format(weekDay).substring(0, 2) }, index)) }),
558
- weeks.map((week, index) => /* @__PURE__ */ jsx6("div", { className: "row text-center", children: week.map((date) => {
559
- const isSelected = !!selected && equalDate(selected, date);
560
- const isToday = equalDate(/* @__PURE__ */ new Date(), date);
561
- const isSameMonth = date.getMonth() === month;
562
- const isDayValid = isInTimeSpan(date, start, end);
563
- return /* @__PURE__ */ jsx6(
564
- "button",
565
- {
566
- disabled: !isDayValid,
567
- className: clsx5(
568
- "flex-1 rounded-full border-2 border-transparent shadow-sm",
569
- {
570
- "text-gray-700 bg-gray-100": !isSameMonth && isDayValid,
571
- "text-black bg-white": !isSelected && isSameMonth && isDayValid,
572
- "text-on-primary bg-primary": isSelected,
573
- "border-black": isToday && markToday,
574
- "hover:brightness-90 hover:bg-primary hover:text-on-primary": isDayValid,
575
- "text-disabled-text bg-disabled-background": !isDayValid
576
- }
577
- ),
578
- onClick: () => onChange(date),
579
- children: date.getDate()
580
- },
581
- date.getDate()
582
- );
583
- }) }, index))
584
- ] });
585
- };
586
-
587
- // src/components/date/DatePicker.tsx
588
- import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
589
- var defaultDatePickerTranslation = {
590
- en: {
591
- today: "Today"
592
- },
593
- de: {
594
- today: "Heute"
595
- }
596
- };
597
- var DatePicker = ({
598
- overwriteTranslation,
599
- value = /* @__PURE__ */ new Date(),
600
- start = subtractDuration(/* @__PURE__ */ new Date(), { years: 50 }),
601
- end = addDuration(/* @__PURE__ */ new Date(), { years: 50 }),
602
- initialDisplay = "day",
603
- onChange = noop,
604
- yearMonthPickerProps,
605
- dayPickerProps,
606
- className = ""
607
- }) => {
608
- const locale = useLocale();
609
- const translation = useTranslation(defaultDatePickerTranslation, overwriteTranslation);
610
- const [displayedMonth, setDisplayedMonth] = useState7(value);
611
- const [displayMode, setDisplayMode] = useState7(initialDisplay);
612
- useEffect6(() => {
613
- setDisplayedMonth(value);
614
- }, [value]);
615
- return /* @__PURE__ */ jsxs5("div", { className: clsx6("col gap-y-4", className), children: [
616
- /* @__PURE__ */ jsxs5("div", { className: "row items-center justify-between h-7", children: [
617
- /* @__PURE__ */ jsxs5(
618
- TextButton,
619
- {
620
- className: clsx6("row gap-x-1 items-center cursor-pointer select-none", {
621
- "text-disabled-text": displayMode !== "day"
622
- }),
623
- onClick: () => setDisplayMode(displayMode === "day" ? "yearMonth" : "day"),
624
- children: [
625
- `${new Intl.DateTimeFormat(locale, { month: "long" }).format(displayedMonth)} ${displayedMonth.getFullYear()}`,
626
- /* @__PURE__ */ jsx7(ChevronDown2, { size: 16 })
627
- ]
628
- }
629
- ),
630
- displayMode === "day" && /* @__PURE__ */ jsxs5("div", { className: "row justify-end", children: [
631
- /* @__PURE__ */ jsx7(
632
- SolidButton,
633
- {
634
- size: "small",
635
- color: "primary",
636
- disabled: !isInTimeSpan(subtractDuration(displayedMonth, { months: 1 }), start, end),
637
- onClick: () => {
638
- setDisplayedMonth(subtractDuration(displayedMonth, { months: 1 }));
639
- },
640
- children: /* @__PURE__ */ jsx7(ArrowUp, { size: 20 })
641
- }
642
- ),
643
- /* @__PURE__ */ jsx7(
644
- SolidButton,
645
- {
646
- size: "small",
647
- color: "primary",
648
- disabled: !isInTimeSpan(addDuration(displayedMonth, { months: 1 }), start, end),
649
- onClick: () => {
650
- setDisplayedMonth(addDuration(displayedMonth, { months: 1 }));
651
- },
652
- children: /* @__PURE__ */ jsx7(ArrowDown, { size: 20 })
653
- }
654
- )
655
- ] })
656
- ] }),
657
- displayMode === "yearMonth" ? /* @__PURE__ */ jsx7(
658
- YearMonthPicker,
659
- {
660
- ...yearMonthPickerProps,
661
- displayedYearMonth: value,
662
- start,
663
- end,
664
- onChange: (newDate) => {
665
- setDisplayedMonth(newDate);
666
- setDisplayMode("day");
667
- }
668
- }
669
- ) : /* @__PURE__ */ jsxs5("div", { children: [
670
- /* @__PURE__ */ jsx7(
671
- DayPicker,
672
- {
673
- ...dayPickerProps,
674
- displayedMonth,
675
- start,
676
- end,
677
- selected: value,
678
- onChange: (date) => {
679
- onChange(date);
680
- }
681
- }
682
- ),
683
- /* @__PURE__ */ jsx7("div", { className: "mt-2", children: /* @__PURE__ */ jsx7(
684
- TextButton,
685
- {
686
- onClick: () => {
687
- const newDate = /* @__PURE__ */ new Date();
688
- newDate.setHours(value.getHours(), value.getMinutes());
689
- onChange(newDate);
690
- },
691
- children: translation.today
692
- }
693
- ) })
694
- ] })
695
- ] });
696
- };
697
-
698
- // src/components/user-input/DateAndTimePicker.tsx
699
- import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
700
- var defaultTimeTranslation = {
701
- en: {
702
- clear: "Clear",
703
- change: "Change",
704
- year: "Year",
705
- month: "Month",
706
- day: "Day",
707
- january: "January",
708
- february: "Febuary",
709
- march: "March",
710
- april: "April",
711
- may: "May",
712
- june: "June",
713
- july: "July",
714
- august: "August",
715
- september: "September",
716
- october: "October",
717
- november: "November",
718
- december: "December"
719
- },
720
- de: {
721
- clear: "Entfernen",
722
- change: "\xC4ndern",
723
- year: "Jahr",
724
- month: "Monat",
725
- day: "Tag",
726
- january: "Januar",
727
- february: "Febuar",
728
- march: "M\xE4rz",
729
- april: "April",
730
- may: "Mai",
731
- june: "Juni",
732
- july: "Juli",
733
- august: "August",
734
- september: "September",
735
- october: "October",
736
- november: "November",
737
- december: "December"
738
- }
739
- };
740
- var DateTimePicker = ({
741
- overwriteTranslation,
742
- value = /* @__PURE__ */ new Date(),
743
- start = subtractDuration(/* @__PURE__ */ new Date(), { years: 50 }),
744
- end = addDuration(/* @__PURE__ */ new Date(), { years: 50 }),
745
- mode = "dateTime",
746
- onFinish = noop,
747
- onChange = noop,
748
- onRemove = noop,
749
- timePickerProps,
750
- datePickerProps
751
- }) => {
752
- const translation = useTranslation(defaultTimeTranslation, overwriteTranslation);
753
- const useDate = mode === "dateTime" || mode === "date";
754
- const useTime = mode === "dateTime" || mode === "time";
755
- let dateDisplay;
756
- let timeDisplay;
757
- if (useDate) {
758
- dateDisplay = /* @__PURE__ */ jsx8(
759
- DatePicker,
760
- {
761
- ...datePickerProps,
762
- className: "min-w-[320px] min-h-[250px]",
763
- yearMonthPickerProps: { maxHeight: 218 },
764
- value,
765
- start,
766
- end,
767
- onChange
768
- }
769
- );
770
- }
771
- if (useTime) {
772
- timeDisplay = /* @__PURE__ */ jsx8(
773
- TimePicker,
774
- {
775
- ...timePickerProps,
776
- className: clsx7("h-full", { "justify-between w-full": mode === "time" }),
777
- maxHeight: 250,
778
- time: value,
779
- onChange
780
- }
781
- );
782
- }
783
- return /* @__PURE__ */ jsxs6("div", { className: "col w-fit", children: [
784
- /* @__PURE__ */ jsxs6("div", { className: "row gap-x-4", children: [
785
- dateDisplay,
786
- timeDisplay
787
- ] }),
788
- /* @__PURE__ */ jsx8("div", { className: "row justify-end", children: /* @__PURE__ */ jsxs6("div", { className: "row gap-x-2 mt-1", children: [
789
- /* @__PURE__ */ jsx8(SolidButton, { size: "medium", color: "negative", onClick: onRemove, children: translation.clear }),
790
- /* @__PURE__ */ jsx8(
791
- SolidButton,
792
- {
793
- size: "medium",
794
- onClick: () => onFinish(value),
795
- children: translation.change
796
- }
797
- )
798
- ] }) })
799
- ] });
800
- };
801
-
802
- // src/components/examples/date/DateTimePickerExample.tsx
803
- import { jsx as jsx9 } from "react/jsx-runtime";
804
- var DateTimePickerExample = ({
805
- value,
806
- onChange = noop,
807
- onRemove = noop,
808
- onFinish = noop,
809
- initialDisplay,
810
- is24HourFormat,
811
- minuteIncrement,
812
- showValueOpen,
813
- markToday,
814
- weekStart,
815
- ...props
816
- }) => {
817
- const [time, setTime] = useState8(value);
818
- useEffect7(() => setTime(value), [value]);
819
- return /* @__PURE__ */ jsx9(
820
- DateTimePicker,
821
- {
822
- ...props,
823
- value: time,
824
- onChange: (date) => {
825
- onChange(date);
826
- setTime(date);
827
- },
828
- onRemove: () => {
829
- onRemove();
830
- setTime(/* @__PURE__ */ new Date());
831
- },
832
- onFinish: (date) => {
833
- onFinish(date);
834
- setTime(date);
835
- },
836
- timePickerProps: { is24HourFormat, minuteIncrement },
837
- datePickerProps: { initialDisplay, dayPickerProps: { markToday, weekStart }, yearMonthPickerProps: { showValueOpen } }
838
- }
839
- );
840
- };
841
- export {
842
- DateTimePickerExample
843
- };
844
- //# sourceMappingURL=DateTimePickerExample.mjs.map