@helpwave/hightide 0.0.9 → 0.0.12
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.
- package/README.md +1 -1
- package/dist/coloring/shading.d.ts +2 -0
- package/dist/coloring/shading.js +40 -0
- package/dist/coloring/types.d.ts +11 -0
- package/dist/coloring/types.js +1 -0
- package/dist/components/Avatar.d.ts +14 -0
- package/dist/components/Avatar.js +35 -0
- package/dist/components/AvatarGroup.d.ts +10 -0
- package/dist/components/AvatarGroup.js +13 -0
- package/dist/components/BreadCrumb.d.ts +16 -0
- package/dist/components/BreadCrumb.js +12 -0
- package/dist/components/Button.d.ts +41 -0
- package/dist/components/Button.js +84 -0
- package/dist/components/ChipList.d.ts +21 -0
- package/dist/components/ChipList.js +38 -0
- package/dist/components/Circle.d.ts +6 -0
- package/dist/components/Circle.js +10 -0
- package/dist/components/ErrorComponent.d.ts +13 -0
- package/dist/components/ErrorComponent.js +19 -0
- package/dist/components/Expandable.d.ts +30 -0
- package/dist/components/Expandable.js +16 -0
- package/dist/components/HelpwaveBadge.d.ts +11 -0
- package/dist/components/HelpwaveBadge.js +14 -0
- package/dist/components/HideableContentSection.d.ts +10 -0
- package/dist/components/HideableContentSection.js +15 -0
- package/dist/components/InputGroup.d.ts +13 -0
- package/dist/components/InputGroup.js +33 -0
- package/dist/components/LoadingAndErrorComponent.d.ts +17 -0
- package/dist/components/LoadingAndErrorComponent.js +25 -0
- package/dist/components/LoadingAnimation.d.ts +13 -0
- package/dist/components/LoadingAnimation.js +19 -0
- package/dist/components/LoadingButton.d.ts +6 -0
- package/dist/components/LoadingButton.js +10 -0
- package/dist/components/MarkdownInterpreter.d.ts +25 -0
- package/dist/components/MarkdownInterpreter.js +190 -0
- package/dist/components/Pagination.d.ts +14 -0
- package/dist/components/Pagination.js +25 -0
- package/dist/components/Profile.d.ts +28 -0
- package/dist/components/Profile.js +45 -0
- package/dist/components/ProgressIndicator.d.ts +21 -0
- package/dist/components/ProgressIndicator.js +24 -0
- package/dist/components/Ring.d.ts +31 -0
- package/dist/components/Ring.js +113 -0
- package/dist/components/SearchableList.d.ts +18 -0
- package/dist/components/SearchableList.js +27 -0
- package/dist/components/SortButton.d.ts +10 -0
- package/dist/components/SortButton.js +9 -0
- package/dist/components/Span.js +1 -0
- package/dist/components/StepperBar.d.ts +23 -0
- package/dist/components/StepperBar.js +47 -0
- package/dist/components/Table.d.ts +87 -0
- package/dist/components/Table.js +187 -0
- package/dist/components/TechRadar.d.ts +36 -0
- package/dist/components/TechRadar.js +191 -0
- package/dist/components/TextImage.d.ts +20 -0
- package/dist/components/TextImage.js +31 -0
- package/dist/components/TimeDisplay.d.ts +30 -0
- package/dist/components/TimeDisplay.js +83 -0
- package/dist/components/Tooltip.d.ts +34 -0
- package/dist/components/Tooltip.js +38 -0
- package/dist/components/VerticalDivider.d.ts +11 -0
- package/dist/components/VerticalDivider.js +7 -0
- package/dist/components/date/DatePicker.d.ts +26 -0
- package/dist/components/date/DatePicker.js +58 -0
- package/dist/components/date/DayPicker.d.ts +16 -0
- package/dist/components/date/DayPicker.js +37 -0
- package/dist/components/date/TimePicker.d.ts +12 -0
- package/dist/components/date/TimePicker.js +79 -0
- package/dist/components/date/YearMonthPicker.d.ts +11 -0
- package/dist/components/date/YearMonthPicker.js +59 -0
- package/dist/components/examples/InputGroupExample.d.ts +6 -0
- package/dist/components/examples/InputGroupExample.js +21 -0
- package/dist/components/examples/MultiSelectExample.d.ts +7 -0
- package/dist/components/examples/MultiSelectExample.js +27 -0
- package/dist/components/examples/SearchableSelectExample.d.ts +6 -0
- package/dist/components/examples/SearchableSelectExample.js +17 -0
- package/dist/components/examples/SelectExample.d.ts +4 -0
- package/dist/components/examples/SelectExample.js +15 -0
- package/dist/components/examples/StackingModals.d.ts +4 -0
- package/dist/components/examples/StackingModals.js +15 -0
- package/dist/components/examples/TableExample.d.ts +9 -0
- package/dist/components/examples/TableExample.js +92 -0
- package/dist/components/examples/TextareaExample.d.ts +6 -0
- package/dist/components/examples/TextareaExample.js +10 -0
- package/dist/components/examples/TileExample.d.ts +9 -0
- package/dist/components/examples/TileExample.js +9 -0
- package/dist/components/examples/Title.js +1 -0
- package/dist/components/examples/date/DateTimePickerExample.d.ts +10 -0
- package/dist/components/examples/date/DateTimePickerExample.js +21 -0
- package/dist/components/examples/properties/CheckboxPropertyExample.d.ts +8 -0
- package/dist/components/examples/properties/CheckboxPropertyExample.js +13 -0
- package/dist/components/examples/properties/DatePropertyExample.d.ts +8 -0
- package/dist/components/examples/properties/DatePropertyExample.js +23 -0
- package/dist/components/examples/properties/MultiSelectPropertyExample.d.ts +8 -0
- package/dist/components/examples/properties/MultiSelectPropertyExample.js +16 -0
- package/dist/components/examples/properties/NumberPropertyExample.d.ts +6 -0
- package/dist/components/examples/properties/NumberPropertyExample.js +13 -0
- package/dist/components/examples/properties/SelectPropertyExample.d.ts +6 -0
- package/dist/components/examples/properties/SelectPropertyExample.js +18 -0
- package/dist/components/examples/properties/TextPropertyExample.d.ts +8 -0
- package/dist/components/examples/properties/TextPropertyExample.js +13 -0
- package/dist/components/icons/Helpwave.d.ts +10 -0
- package/dist/components/icons/Helpwave.js +20 -0
- package/dist/components/icons/Tag.d.ts +10 -0
- package/dist/components/icons/Tag.js +12 -0
- package/dist/components/layout/Carousel.d.ts +22 -0
- package/dist/components/layout/Carousel.js +233 -0
- package/dist/components/layout/DividerInserter.d.ts +11 -0
- package/dist/components/layout/DividerInserter.js +20 -0
- package/dist/components/layout/FAQSection.d.ts +23 -0
- package/dist/components/layout/FAQSection.js +14 -0
- package/dist/components/layout/Tile.d.ts +34 -0
- package/dist/components/layout/Tile.js +18 -0
- package/dist/components/modals/ConfirmDialog.d.ts +34 -0
- package/dist/components/modals/ConfirmDialog.js +31 -0
- package/dist/components/modals/DiscardChangesDialog.d.ts +19 -0
- package/dist/components/modals/DiscardChangesDialog.js +24 -0
- package/dist/components/modals/InputModal.d.ts +9 -0
- package/dist/components/modals/InputModal.js +9 -0
- package/dist/components/modals/LanguageModal.d.ts +17 -0
- package/dist/components/modals/LanguageModal.js +35 -0
- package/dist/components/modals/Modal.d.ts +38 -0
- package/dist/components/modals/Modal.js +57 -0
- package/dist/components/modals/ModalRegister.d.ts +11 -0
- package/dist/components/modals/ModalRegister.js +28 -0
- package/dist/components/properties/CheckboxProperty.d.ts +15 -0
- package/dist/components/properties/CheckboxProperty.js +27 -0
- package/dist/components/properties/DateProperty.d.ts +11 -0
- package/dist/components/properties/DateProperty.js +22 -0
- package/dist/components/properties/MultiSelectProperty.d.ts +12 -0
- package/dist/components/properties/MultiSelectProperty.js +33 -0
- package/dist/components/properties/NumberProperty.d.ts +16 -0
- package/dist/components/properties/NumberProperty.js +42 -0
- package/dist/components/properties/PropertyBase.d.ts +23 -0
- package/dist/components/properties/PropertyBase.js +27 -0
- package/dist/components/properties/SelectProperty.d.ts +12 -0
- package/dist/components/properties/SelectProperty.js +22 -0
- package/dist/components/properties/TextProperty.d.ts +15 -0
- package/dist/components/properties/TextProperty.js +37 -0
- package/dist/components/user-input/Checkbox.d.ts +37 -0
- package/dist/components/user-input/Checkbox.js +63 -0
- package/dist/components/user-input/DateAndTimePicker.d.ts +39 -0
- package/dist/components/user-input/DateAndTimePicker.js +65 -0
- package/dist/components/user-input/Input.d.ts +61 -0
- package/dist/components/user-input/Input.js +61 -0
- package/dist/components/user-input/Label.d.ts +12 -0
- package/dist/components/user-input/Label.js +12 -0
- package/dist/components/user-input/Menu.d.ts +21 -0
- package/dist/components/user-input/Menu.js +26 -0
- package/dist/components/user-input/MultiSelect.d.ts +39 -0
- package/dist/components/user-input/MultiSelect.js +57 -0
- package/dist/components/user-input/ScrollPicker.d.ts +11 -0
- package/dist/components/user-input/ScrollPicker.js +151 -0
- package/dist/components/user-input/SearchableSelect.d.ts +8 -0
- package/dist/components/user-input/SearchableSelect.js +14 -0
- package/dist/components/user-input/Select.d.ts +32 -0
- package/dist/components/user-input/Select.js +48 -0
- package/dist/components/user-input/Textarea.d.ts +20 -0
- package/dist/components/user-input/Textarea.js +33 -0
- package/dist/components/user-input/ToggleableInput.d.ts +32 -0
- package/dist/components/user-input/ToggleableInput.js +40 -0
- package/dist/css/globals.css +2450 -0
- package/dist/hooks/useHoverState.d.ts +40 -0
- package/dist/hooks/useHoverState.js +46 -0
- package/dist/hooks/useLanguage.d.ts +17 -0
- package/dist/hooks/useLanguage.js +51 -0
- package/dist/hooks/useLocalStorage.d.ts +4 -0
- package/dist/hooks/useLocalStorage.js +24 -0
- package/dist/hooks/useOutsideClick.d.ts +2 -0
- package/dist/hooks/useOutsideClick.js +22 -0
- package/dist/hooks/useSaveDelay.d.ts +5 -0
- package/dist/hooks/useSaveDelay.js +41 -0
- package/dist/hooks/useTheme.d.ts +16 -0
- package/dist/hooks/useTheme.js +32 -0
- package/dist/hooks/useTranslation.d.ts +24 -0
- package/dist/hooks/useTranslation.js +11 -0
- package/dist/util/array.d.ts +23 -0
- package/dist/util/array.js +103 -0
- package/{util/builder.ts → dist/util/builder.d.ts} +1 -4
- package/dist/util/builder.js +9 -0
- package/dist/util/date.d.ts +28 -0
- package/dist/util/date.js +133 -0
- package/dist/util/easeFunctions.d.ts +9 -0
- package/dist/util/easeFunctions.js +30 -0
- package/dist/util/emailValidation.d.ts +1 -0
- package/dist/util/emailValidation.js +3 -0
- package/dist/util/loopingArray.d.ts +23 -0
- package/dist/util/loopingArray.js +67 -0
- package/dist/util/math.d.ts +1 -0
- package/dist/util/math.js +3 -0
- package/dist/util/news.d.ts +98 -0
- package/dist/util/news.js +27 -0
- package/dist/util/noop.d.ts +1 -0
- package/dist/util/noop.js +1 -0
- package/{util/simpleSearch.ts → dist/util/simpleSearch.d.ts} +4 -21
- package/dist/util/simpleSearch.js +62 -0
- package/dist/util/storage.d.ts +15 -0
- package/dist/util/storage.js +32 -0
- package/dist/util/types.d.ts +1 -0
- package/dist/util/types.js +1 -0
- package/package.json +7 -8
- package/coloring/shading.ts +0 -46
- package/coloring/types.ts +0 -13
- package/components/Avatar.tsx +0 -58
- package/components/AvatarGroup.tsx +0 -48
- package/components/BreadCrumb.tsx +0 -35
- package/components/Button.tsx +0 -236
- package/components/ChipList.tsx +0 -89
- package/components/Circle.tsx +0 -27
- package/components/ErrorComponent.tsx +0 -40
- package/components/Expandable.tsx +0 -61
- package/components/HelpwaveBadge.tsx +0 -35
- package/components/HideableContentSection.tsx +0 -43
- package/components/InputGroup.tsx +0 -72
- package/components/LoadingAndErrorComponent.tsx +0 -47
- package/components/LoadingAnimation.tsx +0 -40
- package/components/LoadingButton.tsx +0 -27
- package/components/MarkdownInterpreter.tsx +0 -278
- package/components/Pagination.tsx +0 -65
- package/components/Profile.tsx +0 -124
- package/components/ProgressIndicator.tsx +0 -58
- package/components/Ring.tsx +0 -286
- package/components/SearchableList.tsx +0 -69
- package/components/SortButton.tsx +0 -33
- package/components/StepperBar.tsx +0 -124
- package/components/Table.tsx +0 -330
- package/components/TechRadar.tsx +0 -247
- package/components/TextImage.tsx +0 -86
- package/components/TimeDisplay.tsx +0 -121
- package/components/Tooltip.tsx +0 -92
- package/components/VerticalDivider.tsx +0 -51
- package/components/date/DatePicker.tsx +0 -164
- package/components/date/DayPicker.tsx +0 -95
- package/components/date/TimePicker.tsx +0 -167
- package/components/date/YearMonthPicker.tsx +0 -130
- package/components/examples/InputGroupExample.tsx +0 -58
- package/components/examples/MultiSelectExample.tsx +0 -57
- package/components/examples/SearchableSelectExample.tsx +0 -34
- package/components/examples/SelectExample.tsx +0 -28
- package/components/examples/StackingModals.tsx +0 -54
- package/components/examples/TableExample.tsx +0 -159
- package/components/examples/TextareaExample.tsx +0 -23
- package/components/examples/TileExample.tsx +0 -25
- package/components/examples/date/DateTimePickerExample.tsx +0 -53
- package/components/examples/properties/CheckboxPropertyExample.tsx +0 -29
- package/components/examples/properties/DatePropertyExample.tsx +0 -44
- package/components/examples/properties/MultiSelectPropertyExample.tsx +0 -39
- package/components/examples/properties/NumberPropertyExample.tsx +0 -28
- package/components/examples/properties/SelectPropertyExample.tsx +0 -39
- package/components/examples/properties/TextPropertyExample.tsx +0 -30
- package/components/icons/Helpwave.tsx +0 -51
- package/components/icons/Tag.tsx +0 -29
- package/components/layout/Carousel.tsx +0 -396
- package/components/layout/DividerInserter.tsx +0 -37
- package/components/layout/FAQSection.tsx +0 -57
- package/components/layout/Tile.tsx +0 -67
- package/components/modals/ConfirmDialog.tsx +0 -105
- package/components/modals/DiscardChangesDialog.tsx +0 -71
- package/components/modals/InputModal.tsx +0 -26
- package/components/modals/LanguageModal.tsx +0 -76
- package/components/modals/Modal.tsx +0 -149
- package/components/modals/ModalRegister.tsx +0 -45
- package/components/properties/CheckboxProperty.tsx +0 -62
- package/components/properties/DateProperty.tsx +0 -58
- package/components/properties/MultiSelectProperty.tsx +0 -82
- package/components/properties/NumberProperty.tsx +0 -86
- package/components/properties/PropertyBase.tsx +0 -84
- package/components/properties/SelectProperty.tsx +0 -67
- package/components/properties/TextProperty.tsx +0 -81
- package/components/user-input/Checkbox.tsx +0 -139
- package/components/user-input/DateAndTimePicker.tsx +0 -156
- package/components/user-input/Input.tsx +0 -192
- package/components/user-input/Label.tsx +0 -32
- package/components/user-input/Menu.tsx +0 -75
- package/components/user-input/MultiSelect.tsx +0 -158
- package/components/user-input/ScrollPicker.tsx +0 -240
- package/components/user-input/SearchableSelect.tsx +0 -36
- package/components/user-input/Select.tsx +0 -132
- package/components/user-input/Textarea.tsx +0 -86
- package/components/user-input/ToggleableInput.tsx +0 -115
- package/globals.css +0 -488
- package/hooks/useHoverState.ts +0 -88
- package/hooks/useLanguage.tsx +0 -78
- package/hooks/useLocalStorage.tsx +0 -33
- package/hooks/useOutsideClick.ts +0 -25
- package/hooks/useSaveDelay.ts +0 -46
- package/hooks/useTheme.tsx +0 -57
- package/hooks/useTranslation.ts +0 -43
- package/index.ts +0 -0
- package/util/array.ts +0 -115
- package/util/date.ts +0 -180
- package/util/easeFunctions.ts +0 -37
- package/util/emailValidation.ts +0 -3
- package/util/loopingArray.ts +0 -94
- package/util/math.ts +0 -3
- package/util/news.ts +0 -43
- package/util/noop.ts +0 -1
- package/util/storage.ts +0 -37
- package/util/types.ts +0 -4
- /package/{components/Span.tsx → dist/components/Span.d.ts} +0 -0
- /package/{components/examples/Title.tsx → dist/components/examples/Title.d.ts} +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { Languages } from '../hooks/useLanguage'
|
|
2
|
-
import type { PropsForTranslation } from '../hooks/useTranslation'
|
|
3
|
-
import { useTranslation } from '../hooks/useTranslation'
|
|
4
|
-
|
|
5
|
-
type TimeDisplayTranslation = {
|
|
6
|
-
today: string,
|
|
7
|
-
yesterday: string,
|
|
8
|
-
tomorrow: string,
|
|
9
|
-
inDays: (days: number) => string,
|
|
10
|
-
agoDays: (days: number) => string,
|
|
11
|
-
january: string,
|
|
12
|
-
february: string,
|
|
13
|
-
march: string,
|
|
14
|
-
april: string,
|
|
15
|
-
may: string,
|
|
16
|
-
june: string,
|
|
17
|
-
july: string,
|
|
18
|
-
august: string,
|
|
19
|
-
september: string,
|
|
20
|
-
october: string,
|
|
21
|
-
november: string,
|
|
22
|
-
december: string,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const defaultTimeDisplayTranslations: Record<Languages, TimeDisplayTranslation> = {
|
|
26
|
-
en: {
|
|
27
|
-
today: 'today',
|
|
28
|
-
yesterday: 'yesterday',
|
|
29
|
-
tomorrow: 'tomorrow',
|
|
30
|
-
inDays: (days: number) => `in ${days} days`,
|
|
31
|
-
agoDays: (days: number) => `${days} days ago`,
|
|
32
|
-
january: 'January',
|
|
33
|
-
february: 'February',
|
|
34
|
-
march: 'March',
|
|
35
|
-
april: 'April',
|
|
36
|
-
may: 'May',
|
|
37
|
-
june: 'June',
|
|
38
|
-
july: 'July',
|
|
39
|
-
august: 'August',
|
|
40
|
-
september: 'September',
|
|
41
|
-
october: 'October',
|
|
42
|
-
november: 'November',
|
|
43
|
-
december: 'December'
|
|
44
|
-
},
|
|
45
|
-
de: {
|
|
46
|
-
today: 'heute',
|
|
47
|
-
yesterday: 'gestern',
|
|
48
|
-
tomorrow: 'morgen',
|
|
49
|
-
inDays: (days: number) => `in ${days} Tagen`,
|
|
50
|
-
agoDays: (days: number) => `vor ${days} Tagen`,
|
|
51
|
-
january: 'Januar',
|
|
52
|
-
february: 'Februar',
|
|
53
|
-
march: 'März',
|
|
54
|
-
april: 'April',
|
|
55
|
-
may: 'Mai',
|
|
56
|
-
june: 'Juni',
|
|
57
|
-
july: 'Juli',
|
|
58
|
-
august: 'August',
|
|
59
|
-
september: 'September',
|
|
60
|
-
october: 'October',
|
|
61
|
-
november: 'November',
|
|
62
|
-
december: 'December'
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type TimeDisplayMode = 'daysFromToday' | 'date'
|
|
67
|
-
|
|
68
|
-
type TimeDisplayProps = {
|
|
69
|
-
date: Date,
|
|
70
|
-
mode?: TimeDisplayMode,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A Component for displaying time and dates in a unified fashion
|
|
75
|
-
*/
|
|
76
|
-
export const TimeDisplay = ({
|
|
77
|
-
overwriteTranslation,
|
|
78
|
-
date,
|
|
79
|
-
mode = 'daysFromToday'
|
|
80
|
-
}: PropsForTranslation<TimeDisplayTranslation, TimeDisplayProps>) => {
|
|
81
|
-
const translation = useTranslation(defaultTimeDisplayTranslations, overwriteTranslation)
|
|
82
|
-
const difference = new Date().setHours(0, 0, 0, 0).valueOf() - new Date(date).setHours(0, 0, 0, 0).valueOf()
|
|
83
|
-
const isBefore = difference > 0
|
|
84
|
-
const differenceInDays = Math.floor(Math.abs(difference) / (1000 * 3600 * 24))
|
|
85
|
-
|
|
86
|
-
let displayString
|
|
87
|
-
if (differenceInDays === 0) {
|
|
88
|
-
displayString = translation.today
|
|
89
|
-
} else if (differenceInDays === 1) {
|
|
90
|
-
displayString = isBefore ? translation.yesterday : translation.tomorrow
|
|
91
|
-
} else {
|
|
92
|
-
displayString = isBefore ? translation.agoDays(differenceInDays) : translation.inDays(differenceInDays)
|
|
93
|
-
}
|
|
94
|
-
const monthToTranslation: { [key: number]: string } = {
|
|
95
|
-
0: translation.january,
|
|
96
|
-
1: translation.february,
|
|
97
|
-
2: translation.march,
|
|
98
|
-
3: translation.april,
|
|
99
|
-
4: translation.may,
|
|
100
|
-
5: translation.june,
|
|
101
|
-
6: translation.july,
|
|
102
|
-
7: translation.august,
|
|
103
|
-
8: translation.september,
|
|
104
|
-
9: translation.october,
|
|
105
|
-
10: translation.november,
|
|
106
|
-
11: translation.december
|
|
107
|
-
} as const
|
|
108
|
-
|
|
109
|
-
let fullString
|
|
110
|
-
if (mode === 'daysFromToday') {
|
|
111
|
-
fullString = `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')} - ${displayString}`
|
|
112
|
-
} else {
|
|
113
|
-
fullString = `${date.getDate()}. ${monthToTranslation[date.getMonth()]} ${date.getFullYear()}`
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return (
|
|
117
|
-
<span>
|
|
118
|
-
{fullString}
|
|
119
|
-
</span>
|
|
120
|
-
)
|
|
121
|
-
}
|
package/components/Tooltip.tsx
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { CSSProperties, PropsWithChildren, ReactNode } from 'react'
|
|
2
|
-
import { useHoverState } from '../hooks/useHoverState'
|
|
3
|
-
import { clsx } from 'clsx'
|
|
4
|
-
|
|
5
|
-
type Position = 'top' | 'bottom' | 'left' | 'right'
|
|
6
|
-
|
|
7
|
-
export type TooltipProps = PropsWithChildren<{
|
|
8
|
-
tooltip: string | ReactNode,
|
|
9
|
-
/**
|
|
10
|
-
* Number of milliseconds until the tooltip appears
|
|
11
|
-
*
|
|
12
|
-
* defaults to 1000ms
|
|
13
|
-
*/
|
|
14
|
-
animationDelay?: number,
|
|
15
|
-
/**
|
|
16
|
-
* Class names of additional styling properties for the tooltip
|
|
17
|
-
*/
|
|
18
|
-
tooltipClassName?: string,
|
|
19
|
-
/**
|
|
20
|
-
* Class names of additional styling properties for the container from which the tooltip will be created
|
|
21
|
-
*/
|
|
22
|
-
containerClassName?: string,
|
|
23
|
-
position?: Position,
|
|
24
|
-
zIndex?: number,
|
|
25
|
-
}>
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A Component for showing a tooltip when hovering over Content
|
|
29
|
-
* @param tooltip The tooltip to show can be a text or any ReactNode
|
|
30
|
-
* @param children The Content for which the tooltip should be created
|
|
31
|
-
* @param animationDelay The delay before the tooltip appears
|
|
32
|
-
* @param tooltipClassName Additional ClassNames for the Container of the tooltip
|
|
33
|
-
* @param containerClassName Additional ClassNames for the Container holding the content
|
|
34
|
-
* @param position The direction of the tooltip relative to the Container
|
|
35
|
-
* @param zIndex The z Index of the tooltip (you may require this when stacking modals)
|
|
36
|
-
* @constructor
|
|
37
|
-
*/
|
|
38
|
-
export const Tooltip = ({
|
|
39
|
-
tooltip,
|
|
40
|
-
children,
|
|
41
|
-
animationDelay = 650,
|
|
42
|
-
tooltipClassName = '',
|
|
43
|
-
containerClassName = '',
|
|
44
|
-
position = 'bottom',
|
|
45
|
-
zIndex = 10,
|
|
46
|
-
}: TooltipProps) => {
|
|
47
|
-
const { isHovered, handlers } = useHoverState()
|
|
48
|
-
|
|
49
|
-
const positionClasses = {
|
|
50
|
-
top: `bottom-full left-1/2 -translate-x-1/2 mb-[6px]`,
|
|
51
|
-
bottom: `top-full left-1/2 -translate-x-1/2 mt-[6px]`,
|
|
52
|
-
left: `right-full top-1/2 -translate-y-1/2 mr-[6px]`,
|
|
53
|
-
right: `left-full top-1/2 -translate-y-1/2 ml-[6px]`
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const triangleSize = 6
|
|
57
|
-
const triangleClasses = {
|
|
58
|
-
top: `top-full left-1/2 -translate-x-1/2 border-t-gray-600 border-l-transparent border-r-transparent`,
|
|
59
|
-
bottom: `bottom-full left-1/2 -translate-x-1/2 border-b-gray-600 border-l-transparent border-r-transparent`,
|
|
60
|
-
left: `left-full top-1/2 -translate-y-1/2 border-l-gray-600 border-t-transparent border-b-transparent`,
|
|
61
|
-
right: `right-full top-1/2 -translate-y-1/2 border-r-gray-600 border-t-transparent border-b-transparent`
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const triangleStyle: Record<Position, CSSProperties> = {
|
|
65
|
-
top: { borderWidth: `${triangleSize}px ${triangleSize}px 0 ${triangleSize}px` },
|
|
66
|
-
bottom: { borderWidth: `0 ${triangleSize}px ${triangleSize}px ${triangleSize}px` },
|
|
67
|
-
left: { borderWidth: `${triangleSize}px 0 ${triangleSize}px ${triangleSize}px` },
|
|
68
|
-
right: { borderWidth: `${triangleSize}px ${triangleSize}px ${triangleSize}px 0` }
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<div
|
|
73
|
-
className={clsx('relative inline-block', containerClassName)}
|
|
74
|
-
{...handlers}
|
|
75
|
-
>
|
|
76
|
-
{children}
|
|
77
|
-
{isHovered && (
|
|
78
|
-
<div
|
|
79
|
-
className={clsx(`opacity-0 absolute text-black text-xs font-semibold text-gray-600 px-2 py-1 rounded whitespace-nowrap border-2 border-gray-600
|
|
80
|
-
animate-tooltip-fade-in shadow-lg bg-gray-100`, positionClasses[position], tooltipClassName)}
|
|
81
|
-
style={{ zIndex, animationDelay: animationDelay + 'ms' }}
|
|
82
|
-
>
|
|
83
|
-
{tooltip}
|
|
84
|
-
<div
|
|
85
|
-
className={clsx(`absolute w-0 h-0`, triangleClasses[position])}
|
|
86
|
-
style={{ ...triangleStyle[position], zIndex }}
|
|
87
|
-
/>
|
|
88
|
-
</div>
|
|
89
|
-
)}
|
|
90
|
-
</div>
|
|
91
|
-
)
|
|
92
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export type VerticalDividerProps = {
|
|
2
|
-
width?: number,
|
|
3
|
-
height?: number,
|
|
4
|
-
strokeWidth?: number,
|
|
5
|
-
dashGap?: number,
|
|
6
|
-
dashLength?: number,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A Component for creating a vertical Divider
|
|
11
|
-
*/
|
|
12
|
-
export const VerticalDivider = ({
|
|
13
|
-
width = 1,
|
|
14
|
-
height = 100,
|
|
15
|
-
strokeWidth = 4,
|
|
16
|
-
dashGap = 4,
|
|
17
|
-
dashLength = 4,
|
|
18
|
-
}: VerticalDividerProps) => {
|
|
19
|
-
return (
|
|
20
|
-
<div style={{ width: width + 'px', height: height + 'px' }}>
|
|
21
|
-
<svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} fill="none"
|
|
22
|
-
xmlns="http://www.w3.org/2000/svg">
|
|
23
|
-
<line
|
|
24
|
-
opacity="0.5"
|
|
25
|
-
x1={width / 2}
|
|
26
|
-
y1={height}
|
|
27
|
-
x2={width / 2}
|
|
28
|
-
y2="0"
|
|
29
|
-
stroke="url(#paint_linear)"
|
|
30
|
-
strokeWidth={strokeWidth}
|
|
31
|
-
strokeDasharray={`${dashLength} ${dashLength + dashGap}`}
|
|
32
|
-
strokeLinecap="round"
|
|
33
|
-
/>
|
|
34
|
-
<defs>
|
|
35
|
-
<linearGradient
|
|
36
|
-
id="paint_linear"
|
|
37
|
-
x1={width / 2}
|
|
38
|
-
y1="0"
|
|
39
|
-
x2={width / 2}
|
|
40
|
-
y2={height}
|
|
41
|
-
gradientUnits="userSpaceOnUse"
|
|
42
|
-
>
|
|
43
|
-
<stop stopOpacity="0" stopColor="currentColor"/>
|
|
44
|
-
<stop offset="0.5" stopColor="currentColor"/>
|
|
45
|
-
<stop offset="1" stopColor="currentColor" stopOpacity="0"/>
|
|
46
|
-
</linearGradient>
|
|
47
|
-
</defs>
|
|
48
|
-
</svg>
|
|
49
|
-
</div>
|
|
50
|
-
)
|
|
51
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
import { ArrowDown, ArrowUp, ChevronDown } from 'lucide-react'
|
|
3
|
-
import type { Languages } from '../../hooks/useLanguage'
|
|
4
|
-
import type { PropsForTranslation } from '../../hooks/useTranslation'
|
|
5
|
-
import { useTranslation } from '../../hooks/useTranslation'
|
|
6
|
-
import { noop } from '../../util/noop'
|
|
7
|
-
import { addDuration, isInTimeSpan, subtractDuration } from '../../util/date'
|
|
8
|
-
import clsx from 'clsx'
|
|
9
|
-
import { SolidButton, TextButton } from '../Button'
|
|
10
|
-
import { useLocale } from '../../hooks/useLanguage'
|
|
11
|
-
import type { YearMonthPickerProps } from './YearMonthPicker'
|
|
12
|
-
import { YearMonthPicker } from './YearMonthPicker'
|
|
13
|
-
import type { DayPickerProps } from './DayPicker'
|
|
14
|
-
import { DayPicker } from './DayPicker'
|
|
15
|
-
|
|
16
|
-
type DatePickerTranslation = {
|
|
17
|
-
today: string,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const defaultDatePickerTranslation: Record<Languages, DatePickerTranslation> = {
|
|
21
|
-
en: {
|
|
22
|
-
today: 'Today',
|
|
23
|
-
},
|
|
24
|
-
de: {
|
|
25
|
-
today: 'Heute',
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type DisplayMode = 'yearMonth' | 'day'
|
|
30
|
-
|
|
31
|
-
export type DatePickerProps = {
|
|
32
|
-
value?: Date,
|
|
33
|
-
start?: Date,
|
|
34
|
-
end?: Date,
|
|
35
|
-
initialDisplay?: DisplayMode,
|
|
36
|
-
onChange?: (date: Date) => void,
|
|
37
|
-
dayPickerProps?: Omit<DayPickerProps, 'displayedMonth' | 'onChange' | 'selected'>,
|
|
38
|
-
yearMonthPickerProps?: Omit<YearMonthPickerProps, 'displayedYearMonth' | 'onChange' | 'start' | 'end'>,
|
|
39
|
-
className?: string,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A Component for picking a date
|
|
44
|
-
*/
|
|
45
|
-
export const DatePicker = ({
|
|
46
|
-
overwriteTranslation,
|
|
47
|
-
value = new Date(),
|
|
48
|
-
start = subtractDuration(new Date(), { years: 50 }),
|
|
49
|
-
end = addDuration(new Date(), { years: 50 }),
|
|
50
|
-
initialDisplay = 'day',
|
|
51
|
-
onChange = noop,
|
|
52
|
-
yearMonthPickerProps,
|
|
53
|
-
dayPickerProps,
|
|
54
|
-
className = ''
|
|
55
|
-
}: PropsForTranslation<DatePickerTranslation, DatePickerProps>) => {
|
|
56
|
-
const locale = useLocale()
|
|
57
|
-
const translation = useTranslation(defaultDatePickerTranslation, overwriteTranslation)
|
|
58
|
-
const [displayedMonth, setDisplayedMonth] = useState<Date>(value)
|
|
59
|
-
const [displayMode, setDisplayMode] = useState<DisplayMode>(initialDisplay)
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
setDisplayedMonth(value)
|
|
63
|
-
}, [value])
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<div className={clsx('col gap-y-4', className)}>
|
|
67
|
-
<div className="row items-center justify-between h-7">
|
|
68
|
-
<TextButton
|
|
69
|
-
className={clsx('row gap-x-1 items-center cursor-pointer select-none', {
|
|
70
|
-
'text-disabled-text': displayMode !== 'day',
|
|
71
|
-
})}
|
|
72
|
-
onClick={() => setDisplayMode(displayMode === 'day' ? 'yearMonth' : 'day')}
|
|
73
|
-
>
|
|
74
|
-
{`${new Intl.DateTimeFormat(locale, { month: 'long' }).format(displayedMonth)} ${displayedMonth.getFullYear()}`}
|
|
75
|
-
<ChevronDown size={16}/>
|
|
76
|
-
</TextButton>
|
|
77
|
-
{displayMode === 'day' && (
|
|
78
|
-
<div className="row justify-end">
|
|
79
|
-
<SolidButton
|
|
80
|
-
size="small"
|
|
81
|
-
color="primary"
|
|
82
|
-
disabled={!isInTimeSpan(subtractDuration(displayedMonth, { months: 1 }), start, end)}
|
|
83
|
-
onClick={() => {
|
|
84
|
-
setDisplayedMonth(subtractDuration(displayedMonth, { months: 1 }))
|
|
85
|
-
}}
|
|
86
|
-
>
|
|
87
|
-
<ArrowUp size={20}/>
|
|
88
|
-
</SolidButton>
|
|
89
|
-
<SolidButton
|
|
90
|
-
size="small"
|
|
91
|
-
color="primary"
|
|
92
|
-
disabled={!isInTimeSpan(addDuration(displayedMonth, { months: 1 }), start, end)}
|
|
93
|
-
onClick={() => {
|
|
94
|
-
setDisplayedMonth(addDuration(displayedMonth, { months: 1 }))
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
<ArrowDown size={20}/>
|
|
98
|
-
</SolidButton>
|
|
99
|
-
</div>
|
|
100
|
-
)}
|
|
101
|
-
</div>
|
|
102
|
-
{displayMode === 'yearMonth' ? (
|
|
103
|
-
<YearMonthPicker
|
|
104
|
-
{...yearMonthPickerProps}
|
|
105
|
-
displayedYearMonth={value}
|
|
106
|
-
start={start}
|
|
107
|
-
end={end}
|
|
108
|
-
onChange={newDate => {
|
|
109
|
-
setDisplayedMonth(newDate)
|
|
110
|
-
setDisplayMode('day')
|
|
111
|
-
}}
|
|
112
|
-
/>
|
|
113
|
-
) : (
|
|
114
|
-
<div>
|
|
115
|
-
<DayPicker
|
|
116
|
-
{...dayPickerProps}
|
|
117
|
-
displayedMonth={displayedMonth}
|
|
118
|
-
start={start}
|
|
119
|
-
end={end}
|
|
120
|
-
selected={value}
|
|
121
|
-
onChange={date => {
|
|
122
|
-
onChange(date)
|
|
123
|
-
}}
|
|
124
|
-
/>
|
|
125
|
-
<div className="mt-2">
|
|
126
|
-
<TextButton
|
|
127
|
-
onClick={() => {
|
|
128
|
-
const newDate = new Date()
|
|
129
|
-
newDate.setHours(value.getHours(), value.getMinutes())
|
|
130
|
-
onChange(newDate)
|
|
131
|
-
}}
|
|
132
|
-
>
|
|
133
|
-
{translation.today}
|
|
134
|
-
</TextButton>
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
137
|
-
)}
|
|
138
|
-
</div>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Example for the Date Picker
|
|
144
|
-
*/
|
|
145
|
-
export const ControlledDatePicker = ({
|
|
146
|
-
value = new Date(),
|
|
147
|
-
onChange = noop,
|
|
148
|
-
...props
|
|
149
|
-
}: DatePickerProps) => {
|
|
150
|
-
const [date, setDate] = useState<Date>(value)
|
|
151
|
-
|
|
152
|
-
useEffect(() => setDate(value), [value])
|
|
153
|
-
|
|
154
|
-
return (
|
|
155
|
-
<DatePicker
|
|
156
|
-
{...props}
|
|
157
|
-
value={date}
|
|
158
|
-
onChange={date1 => {
|
|
159
|
-
setDate(date1)
|
|
160
|
-
onChange(date1)
|
|
161
|
-
}}
|
|
162
|
-
/>
|
|
163
|
-
)
|
|
164
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import type { WeekDay } from '../../util/date'
|
|
2
|
-
import { isInTimeSpan } from '../../util/date'
|
|
3
|
-
import { equalDate, getWeeksForCalenderMonth } from '../../util/date'
|
|
4
|
-
import { noop } from '../../util/noop'
|
|
5
|
-
import clsx from 'clsx'
|
|
6
|
-
import { useLocale } from '../../hooks/useLanguage'
|
|
7
|
-
import { useEffect, useState } from 'react'
|
|
8
|
-
|
|
9
|
-
export type DayPickerProps = {
|
|
10
|
-
displayedMonth: Date,
|
|
11
|
-
selected?: Date,
|
|
12
|
-
start?: Date,
|
|
13
|
-
end?: Date,
|
|
14
|
-
onChange?: (date: Date) => void,
|
|
15
|
-
weekStart?: WeekDay,
|
|
16
|
-
markToday?: boolean,
|
|
17
|
-
className?: string,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A component for selecting a day of a month
|
|
22
|
-
*/
|
|
23
|
-
export const DayPicker = ({
|
|
24
|
-
displayedMonth,
|
|
25
|
-
selected,
|
|
26
|
-
start,
|
|
27
|
-
end,
|
|
28
|
-
onChange = noop,
|
|
29
|
-
weekStart = 'monday',
|
|
30
|
-
markToday = true,
|
|
31
|
-
className = ''
|
|
32
|
-
}: DayPickerProps) => {
|
|
33
|
-
const locale = useLocale()
|
|
34
|
-
const month = displayedMonth.getMonth()
|
|
35
|
-
const weeks = getWeeksForCalenderMonth(displayedMonth, weekStart)
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className={clsx('col gap-y-1 min-w-[220px] select-none', className)}>
|
|
39
|
-
<div className="row text-center">
|
|
40
|
-
{weeks[0]!.map((weekDay, index) => (
|
|
41
|
-
<div key={index} className="flex-1 font-semibold">
|
|
42
|
-
{new Intl.DateTimeFormat(locale, { weekday: 'long' }).format(weekDay).substring(0, 2)}
|
|
43
|
-
</div>
|
|
44
|
-
))}
|
|
45
|
-
</div>
|
|
46
|
-
{weeks.map((week, index) => (
|
|
47
|
-
<div key={index} className="row text-center">
|
|
48
|
-
{week.map((date) => {
|
|
49
|
-
const isSelected = !!selected && equalDate(selected, date)
|
|
50
|
-
const isToday = equalDate(new Date(), date)
|
|
51
|
-
const isSameMonth = date.getMonth() === month
|
|
52
|
-
const isDayValid = isInTimeSpan(date, start, end)
|
|
53
|
-
return (
|
|
54
|
-
<button
|
|
55
|
-
disabled={!isDayValid}
|
|
56
|
-
key={date.getDate()}
|
|
57
|
-
className={clsx(
|
|
58
|
-
'flex-1 rounded-full border-2 border-transparent shadow-sm',
|
|
59
|
-
{
|
|
60
|
-
'text-gray-700 bg-gray-100': !isSameMonth && isDayValid,
|
|
61
|
-
'text-black bg-white': !isSelected && isSameMonth && isDayValid,
|
|
62
|
-
'text-on-primary bg-primary': isSelected,
|
|
63
|
-
'border-black': isToday && markToday,
|
|
64
|
-
'hover:brightness-90 hover:bg-primary hover:text-on-primary': isDayValid,
|
|
65
|
-
'text-disabled-text bg-disabled-background': !isDayValid
|
|
66
|
-
}
|
|
67
|
-
)}
|
|
68
|
-
onClick={() => onChange(date)}
|
|
69
|
-
>
|
|
70
|
-
{date.getDate()}
|
|
71
|
-
</button>
|
|
72
|
-
)
|
|
73
|
-
})}
|
|
74
|
-
</div>
|
|
75
|
-
))}
|
|
76
|
-
</div>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const DayPickerControlled = ({ displayedMonth, onChange = noop, ...restProps }: DayPickerProps) => {
|
|
81
|
-
const [date, setDate] = useState(displayedMonth)
|
|
82
|
-
|
|
83
|
-
useEffect(() => setDate(displayedMonth), [displayedMonth])
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<DayPicker
|
|
87
|
-
displayedMonth={date}
|
|
88
|
-
onChange={newDate => {
|
|
89
|
-
setDate(newDate)
|
|
90
|
-
onChange(newDate)
|
|
91
|
-
}}
|
|
92
|
-
{...restProps}
|
|
93
|
-
/>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react'
|
|
2
|
-
import { Scrollbars } from 'react-custom-scrollbars-2'
|
|
3
|
-
import { noop } from '../../util/noop'
|
|
4
|
-
import { closestMatch, range } from '../../util/array'
|
|
5
|
-
import clsx from 'clsx'
|
|
6
|
-
|
|
7
|
-
type MinuteIncrement = '1min' | '5min' | '10min' | '15min' | '30min'
|
|
8
|
-
|
|
9
|
-
export type TimePickerProps = {
|
|
10
|
-
time?: Date,
|
|
11
|
-
onChange?: (time: Date) => void,
|
|
12
|
-
is24HourFormat?: boolean,
|
|
13
|
-
minuteIncrement?: MinuteIncrement,
|
|
14
|
-
maxHeight?: number,
|
|
15
|
-
className?: string,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const TimePicker = ({
|
|
19
|
-
time = new Date(),
|
|
20
|
-
onChange = noop,
|
|
21
|
-
is24HourFormat = true,
|
|
22
|
-
minuteIncrement = '5min',
|
|
23
|
-
maxHeight = 300,
|
|
24
|
-
className = ''
|
|
25
|
-
}: TimePickerProps) => {
|
|
26
|
-
const minuteRef = useRef<HTMLButtonElement>(null)
|
|
27
|
-
const hourRef = useRef<HTMLButtonElement>(null)
|
|
28
|
-
|
|
29
|
-
const isPM = time.getHours() >= 11
|
|
30
|
-
const hours = is24HourFormat ? range(0, 23) : range(1, 12)
|
|
31
|
-
let minutes = range(0, 59)
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
const scrollToItem = () => {
|
|
35
|
-
if (minuteRef.current) {
|
|
36
|
-
const container = minuteRef.current.parentElement!
|
|
37
|
-
|
|
38
|
-
const hasOverflow = container.scrollHeight > maxHeight
|
|
39
|
-
if (hasOverflow) {
|
|
40
|
-
minuteRef.current.scrollIntoView({
|
|
41
|
-
behavior: 'instant',
|
|
42
|
-
block: 'nearest',
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
scrollToItem()
|
|
48
|
-
}, [minuteRef, minuteRef.current]) // eslint-disable-line
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
const scrollToItem = () => {
|
|
52
|
-
if (hourRef.current) {
|
|
53
|
-
const container = hourRef.current.parentElement!
|
|
54
|
-
|
|
55
|
-
const hasOverflow = container.scrollHeight > maxHeight
|
|
56
|
-
if (hasOverflow) {
|
|
57
|
-
hourRef.current.scrollIntoView({
|
|
58
|
-
behavior: 'instant',
|
|
59
|
-
block: 'nearest',
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
scrollToItem()
|
|
65
|
-
}, [hourRef, hourRef.current]) // eslint-disable-line
|
|
66
|
-
|
|
67
|
-
switch (minuteIncrement) {
|
|
68
|
-
case '5min':
|
|
69
|
-
minutes = minutes.filter(value => value % 5 === 0)
|
|
70
|
-
break
|
|
71
|
-
case '10min':
|
|
72
|
-
minutes = minutes.filter(value => value % 10 === 0)
|
|
73
|
-
break
|
|
74
|
-
case '15min':
|
|
75
|
-
minutes = minutes.filter(value => value % 15 === 0)
|
|
76
|
-
break
|
|
77
|
-
case '30min':
|
|
78
|
-
minutes = minutes.filter(value => value % 30 === 0)
|
|
79
|
-
break
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const closestMinute = closestMatch(minutes, (item1, item2) => Math.abs(item1 - time.getMinutes()) < Math.abs(item2 - time.getMinutes()))
|
|
83
|
-
|
|
84
|
-
const style = (selected: boolean) => clsx('chip-full hover:brightness-90 hover:bg-primary hover:text-on-primary rounded-md mr-3',
|
|
85
|
-
{ 'bg-primary text-on-primary': selected, 'bg-white text-black': !selected })
|
|
86
|
-
|
|
87
|
-
const onChangeWrapper = (transformer: (newDate: Date) => void) => {
|
|
88
|
-
const newDate = new Date(time)
|
|
89
|
-
transformer(newDate)
|
|
90
|
-
onChange(newDate)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return (
|
|
94
|
-
<div className={clsx('row gap-x-2 w-fit min-w-[150px] select-none', className)}>
|
|
95
|
-
<Scrollbars autoHeight autoHeightMax={maxHeight} style={{ height: '100%' }}>
|
|
96
|
-
<div className="col gap-y-1 h-full">
|
|
97
|
-
{hours.map(hour => {
|
|
98
|
-
const currentHour = hour === time.getHours() - (!is24HourFormat && isPM ? 12 : 0)
|
|
99
|
-
return (
|
|
100
|
-
<button
|
|
101
|
-
key={hour}
|
|
102
|
-
ref={currentHour ? hourRef : undefined}
|
|
103
|
-
className={style(currentHour)}
|
|
104
|
-
onClick={() => onChangeWrapper(newDate => newDate.setHours(hour + (!is24HourFormat && isPM ? 12 : 0)))}
|
|
105
|
-
>
|
|
106
|
-
{hour.toString().padStart(2, '0')}
|
|
107
|
-
</button>
|
|
108
|
-
)
|
|
109
|
-
})}
|
|
110
|
-
</div>
|
|
111
|
-
</Scrollbars>
|
|
112
|
-
<Scrollbars autoHeight autoHeightMax={maxHeight} style={{ height: '100%' }}>
|
|
113
|
-
<div className="col gap-y-1 h-full">
|
|
114
|
-
{minutes.map(minute => {
|
|
115
|
-
const currentMinute = minute === closestMinute
|
|
116
|
-
return (
|
|
117
|
-
<button
|
|
118
|
-
key={minute + minuteIncrement} // minute increment so that scroll works
|
|
119
|
-
ref={currentMinute ? minuteRef : undefined}
|
|
120
|
-
className={style(currentMinute)}
|
|
121
|
-
onClick={() => onChangeWrapper(newDate => newDate.setMinutes(minute))}
|
|
122
|
-
>
|
|
123
|
-
{minute.toString().padStart(2, '0')}
|
|
124
|
-
</button>
|
|
125
|
-
)
|
|
126
|
-
})}
|
|
127
|
-
</div>
|
|
128
|
-
</Scrollbars>
|
|
129
|
-
{!is24HourFormat && (
|
|
130
|
-
<div className="col gap-y-1">
|
|
131
|
-
<button
|
|
132
|
-
className={style(!isPM)}
|
|
133
|
-
onClick={() => onChangeWrapper(newDate => isPM && newDate.setHours(newDate.getHours() - 12))}
|
|
134
|
-
>
|
|
135
|
-
AM
|
|
136
|
-
</button>
|
|
137
|
-
<button
|
|
138
|
-
className={style(isPM)}
|
|
139
|
-
onClick={() => onChangeWrapper(newDate => !isPM && newDate.setHours(newDate.getHours() + 12))}
|
|
140
|
-
>
|
|
141
|
-
PM
|
|
142
|
-
</button>
|
|
143
|
-
</div>
|
|
144
|
-
)}
|
|
145
|
-
</div>
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export const ControlledTimePicker = ({
|
|
150
|
-
time,
|
|
151
|
-
onChange = noop,
|
|
152
|
-
...props
|
|
153
|
-
}: TimePickerProps) => {
|
|
154
|
-
const [value, setValue] = useState(time)
|
|
155
|
-
useEffect(() => setValue(time), [time])
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<TimePicker
|
|
159
|
-
{...props}
|
|
160
|
-
time={value}
|
|
161
|
-
onChange={time1 => {
|
|
162
|
-
setValue(time1)
|
|
163
|
-
onChange(time1)
|
|
164
|
-
}}
|
|
165
|
-
/>
|
|
166
|
-
)
|
|
167
|
-
}
|