@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.
Files changed (301) hide show
  1. package/README.md +1 -1
  2. package/dist/coloring/shading.d.ts +2 -0
  3. package/dist/coloring/shading.js +40 -0
  4. package/dist/coloring/types.d.ts +11 -0
  5. package/dist/coloring/types.js +1 -0
  6. package/dist/components/Avatar.d.ts +14 -0
  7. package/dist/components/Avatar.js +35 -0
  8. package/dist/components/AvatarGroup.d.ts +10 -0
  9. package/dist/components/AvatarGroup.js +13 -0
  10. package/dist/components/BreadCrumb.d.ts +16 -0
  11. package/dist/components/BreadCrumb.js +12 -0
  12. package/dist/components/Button.d.ts +41 -0
  13. package/dist/components/Button.js +84 -0
  14. package/dist/components/ChipList.d.ts +21 -0
  15. package/dist/components/ChipList.js +38 -0
  16. package/dist/components/Circle.d.ts +6 -0
  17. package/dist/components/Circle.js +10 -0
  18. package/dist/components/ErrorComponent.d.ts +13 -0
  19. package/dist/components/ErrorComponent.js +19 -0
  20. package/dist/components/Expandable.d.ts +30 -0
  21. package/dist/components/Expandable.js +16 -0
  22. package/dist/components/HelpwaveBadge.d.ts +11 -0
  23. package/dist/components/HelpwaveBadge.js +14 -0
  24. package/dist/components/HideableContentSection.d.ts +10 -0
  25. package/dist/components/HideableContentSection.js +15 -0
  26. package/dist/components/InputGroup.d.ts +13 -0
  27. package/dist/components/InputGroup.js +33 -0
  28. package/dist/components/LoadingAndErrorComponent.d.ts +17 -0
  29. package/dist/components/LoadingAndErrorComponent.js +25 -0
  30. package/dist/components/LoadingAnimation.d.ts +13 -0
  31. package/dist/components/LoadingAnimation.js +19 -0
  32. package/dist/components/LoadingButton.d.ts +6 -0
  33. package/dist/components/LoadingButton.js +10 -0
  34. package/dist/components/MarkdownInterpreter.d.ts +25 -0
  35. package/dist/components/MarkdownInterpreter.js +190 -0
  36. package/dist/components/Pagination.d.ts +14 -0
  37. package/dist/components/Pagination.js +25 -0
  38. package/dist/components/Profile.d.ts +28 -0
  39. package/dist/components/Profile.js +45 -0
  40. package/dist/components/ProgressIndicator.d.ts +21 -0
  41. package/dist/components/ProgressIndicator.js +24 -0
  42. package/dist/components/Ring.d.ts +31 -0
  43. package/dist/components/Ring.js +113 -0
  44. package/dist/components/SearchableList.d.ts +18 -0
  45. package/dist/components/SearchableList.js +27 -0
  46. package/dist/components/SortButton.d.ts +10 -0
  47. package/dist/components/SortButton.js +9 -0
  48. package/dist/components/Span.js +1 -0
  49. package/dist/components/StepperBar.d.ts +23 -0
  50. package/dist/components/StepperBar.js +47 -0
  51. package/dist/components/Table.d.ts +87 -0
  52. package/dist/components/Table.js +187 -0
  53. package/dist/components/TechRadar.d.ts +36 -0
  54. package/dist/components/TechRadar.js +191 -0
  55. package/dist/components/TextImage.d.ts +20 -0
  56. package/dist/components/TextImage.js +31 -0
  57. package/dist/components/TimeDisplay.d.ts +30 -0
  58. package/dist/components/TimeDisplay.js +83 -0
  59. package/dist/components/Tooltip.d.ts +34 -0
  60. package/dist/components/Tooltip.js +38 -0
  61. package/dist/components/VerticalDivider.d.ts +11 -0
  62. package/dist/components/VerticalDivider.js +7 -0
  63. package/dist/components/date/DatePicker.d.ts +26 -0
  64. package/dist/components/date/DatePicker.js +58 -0
  65. package/dist/components/date/DayPicker.d.ts +16 -0
  66. package/dist/components/date/DayPicker.js +37 -0
  67. package/dist/components/date/TimePicker.d.ts +12 -0
  68. package/dist/components/date/TimePicker.js +79 -0
  69. package/dist/components/date/YearMonthPicker.d.ts +11 -0
  70. package/dist/components/date/YearMonthPicker.js +59 -0
  71. package/dist/components/examples/InputGroupExample.d.ts +6 -0
  72. package/dist/components/examples/InputGroupExample.js +21 -0
  73. package/dist/components/examples/MultiSelectExample.d.ts +7 -0
  74. package/dist/components/examples/MultiSelectExample.js +27 -0
  75. package/dist/components/examples/SearchableSelectExample.d.ts +6 -0
  76. package/dist/components/examples/SearchableSelectExample.js +17 -0
  77. package/dist/components/examples/SelectExample.d.ts +4 -0
  78. package/dist/components/examples/SelectExample.js +15 -0
  79. package/dist/components/examples/StackingModals.d.ts +4 -0
  80. package/dist/components/examples/StackingModals.js +15 -0
  81. package/dist/components/examples/TableExample.d.ts +9 -0
  82. package/dist/components/examples/TableExample.js +92 -0
  83. package/dist/components/examples/TextareaExample.d.ts +6 -0
  84. package/dist/components/examples/TextareaExample.js +10 -0
  85. package/dist/components/examples/TileExample.d.ts +9 -0
  86. package/dist/components/examples/TileExample.js +9 -0
  87. package/dist/components/examples/Title.js +1 -0
  88. package/dist/components/examples/date/DateTimePickerExample.d.ts +10 -0
  89. package/dist/components/examples/date/DateTimePickerExample.js +21 -0
  90. package/dist/components/examples/properties/CheckboxPropertyExample.d.ts +8 -0
  91. package/dist/components/examples/properties/CheckboxPropertyExample.js +13 -0
  92. package/dist/components/examples/properties/DatePropertyExample.d.ts +8 -0
  93. package/dist/components/examples/properties/DatePropertyExample.js +23 -0
  94. package/dist/components/examples/properties/MultiSelectPropertyExample.d.ts +8 -0
  95. package/dist/components/examples/properties/MultiSelectPropertyExample.js +16 -0
  96. package/dist/components/examples/properties/NumberPropertyExample.d.ts +6 -0
  97. package/dist/components/examples/properties/NumberPropertyExample.js +13 -0
  98. package/dist/components/examples/properties/SelectPropertyExample.d.ts +6 -0
  99. package/dist/components/examples/properties/SelectPropertyExample.js +18 -0
  100. package/dist/components/examples/properties/TextPropertyExample.d.ts +8 -0
  101. package/dist/components/examples/properties/TextPropertyExample.js +13 -0
  102. package/dist/components/icons/Helpwave.d.ts +10 -0
  103. package/dist/components/icons/Helpwave.js +20 -0
  104. package/dist/components/icons/Tag.d.ts +10 -0
  105. package/dist/components/icons/Tag.js +12 -0
  106. package/dist/components/layout/Carousel.d.ts +22 -0
  107. package/dist/components/layout/Carousel.js +233 -0
  108. package/dist/components/layout/DividerInserter.d.ts +11 -0
  109. package/dist/components/layout/DividerInserter.js +20 -0
  110. package/dist/components/layout/FAQSection.d.ts +23 -0
  111. package/dist/components/layout/FAQSection.js +14 -0
  112. package/dist/components/layout/Tile.d.ts +34 -0
  113. package/dist/components/layout/Tile.js +18 -0
  114. package/dist/components/modals/ConfirmDialog.d.ts +34 -0
  115. package/dist/components/modals/ConfirmDialog.js +31 -0
  116. package/dist/components/modals/DiscardChangesDialog.d.ts +19 -0
  117. package/dist/components/modals/DiscardChangesDialog.js +24 -0
  118. package/dist/components/modals/InputModal.d.ts +9 -0
  119. package/dist/components/modals/InputModal.js +9 -0
  120. package/dist/components/modals/LanguageModal.d.ts +17 -0
  121. package/dist/components/modals/LanguageModal.js +35 -0
  122. package/dist/components/modals/Modal.d.ts +38 -0
  123. package/dist/components/modals/Modal.js +57 -0
  124. package/dist/components/modals/ModalRegister.d.ts +11 -0
  125. package/dist/components/modals/ModalRegister.js +28 -0
  126. package/dist/components/properties/CheckboxProperty.d.ts +15 -0
  127. package/dist/components/properties/CheckboxProperty.js +27 -0
  128. package/dist/components/properties/DateProperty.d.ts +11 -0
  129. package/dist/components/properties/DateProperty.js +22 -0
  130. package/dist/components/properties/MultiSelectProperty.d.ts +12 -0
  131. package/dist/components/properties/MultiSelectProperty.js +33 -0
  132. package/dist/components/properties/NumberProperty.d.ts +16 -0
  133. package/dist/components/properties/NumberProperty.js +42 -0
  134. package/dist/components/properties/PropertyBase.d.ts +23 -0
  135. package/dist/components/properties/PropertyBase.js +27 -0
  136. package/dist/components/properties/SelectProperty.d.ts +12 -0
  137. package/dist/components/properties/SelectProperty.js +22 -0
  138. package/dist/components/properties/TextProperty.d.ts +15 -0
  139. package/dist/components/properties/TextProperty.js +37 -0
  140. package/dist/components/user-input/Checkbox.d.ts +37 -0
  141. package/dist/components/user-input/Checkbox.js +63 -0
  142. package/dist/components/user-input/DateAndTimePicker.d.ts +39 -0
  143. package/dist/components/user-input/DateAndTimePicker.js +65 -0
  144. package/dist/components/user-input/Input.d.ts +61 -0
  145. package/dist/components/user-input/Input.js +61 -0
  146. package/dist/components/user-input/Label.d.ts +12 -0
  147. package/dist/components/user-input/Label.js +12 -0
  148. package/dist/components/user-input/Menu.d.ts +21 -0
  149. package/dist/components/user-input/Menu.js +26 -0
  150. package/dist/components/user-input/MultiSelect.d.ts +39 -0
  151. package/dist/components/user-input/MultiSelect.js +57 -0
  152. package/dist/components/user-input/ScrollPicker.d.ts +11 -0
  153. package/dist/components/user-input/ScrollPicker.js +151 -0
  154. package/dist/components/user-input/SearchableSelect.d.ts +8 -0
  155. package/dist/components/user-input/SearchableSelect.js +14 -0
  156. package/dist/components/user-input/Select.d.ts +32 -0
  157. package/dist/components/user-input/Select.js +48 -0
  158. package/dist/components/user-input/Textarea.d.ts +20 -0
  159. package/dist/components/user-input/Textarea.js +33 -0
  160. package/dist/components/user-input/ToggleableInput.d.ts +32 -0
  161. package/dist/components/user-input/ToggleableInput.js +40 -0
  162. package/dist/css/globals.css +2450 -0
  163. package/dist/hooks/useHoverState.d.ts +40 -0
  164. package/dist/hooks/useHoverState.js +46 -0
  165. package/dist/hooks/useLanguage.d.ts +17 -0
  166. package/dist/hooks/useLanguage.js +51 -0
  167. package/dist/hooks/useLocalStorage.d.ts +4 -0
  168. package/dist/hooks/useLocalStorage.js +24 -0
  169. package/dist/hooks/useOutsideClick.d.ts +2 -0
  170. package/dist/hooks/useOutsideClick.js +22 -0
  171. package/dist/hooks/useSaveDelay.d.ts +5 -0
  172. package/dist/hooks/useSaveDelay.js +41 -0
  173. package/dist/hooks/useTheme.d.ts +16 -0
  174. package/dist/hooks/useTheme.js +32 -0
  175. package/dist/hooks/useTranslation.d.ts +24 -0
  176. package/dist/hooks/useTranslation.js +11 -0
  177. package/dist/util/array.d.ts +23 -0
  178. package/dist/util/array.js +103 -0
  179. package/{util/builder.ts → dist/util/builder.d.ts} +1 -4
  180. package/dist/util/builder.js +9 -0
  181. package/dist/util/date.d.ts +28 -0
  182. package/dist/util/date.js +133 -0
  183. package/dist/util/easeFunctions.d.ts +9 -0
  184. package/dist/util/easeFunctions.js +30 -0
  185. package/dist/util/emailValidation.d.ts +1 -0
  186. package/dist/util/emailValidation.js +3 -0
  187. package/dist/util/loopingArray.d.ts +23 -0
  188. package/dist/util/loopingArray.js +67 -0
  189. package/dist/util/math.d.ts +1 -0
  190. package/dist/util/math.js +3 -0
  191. package/dist/util/news.d.ts +98 -0
  192. package/dist/util/news.js +27 -0
  193. package/dist/util/noop.d.ts +1 -0
  194. package/dist/util/noop.js +1 -0
  195. package/{util/simpleSearch.ts → dist/util/simpleSearch.d.ts} +4 -21
  196. package/dist/util/simpleSearch.js +62 -0
  197. package/dist/util/storage.d.ts +15 -0
  198. package/dist/util/storage.js +32 -0
  199. package/dist/util/types.d.ts +1 -0
  200. package/dist/util/types.js +1 -0
  201. package/package.json +7 -8
  202. package/coloring/shading.ts +0 -46
  203. package/coloring/types.ts +0 -13
  204. package/components/Avatar.tsx +0 -58
  205. package/components/AvatarGroup.tsx +0 -48
  206. package/components/BreadCrumb.tsx +0 -35
  207. package/components/Button.tsx +0 -236
  208. package/components/ChipList.tsx +0 -89
  209. package/components/Circle.tsx +0 -27
  210. package/components/ErrorComponent.tsx +0 -40
  211. package/components/Expandable.tsx +0 -61
  212. package/components/HelpwaveBadge.tsx +0 -35
  213. package/components/HideableContentSection.tsx +0 -43
  214. package/components/InputGroup.tsx +0 -72
  215. package/components/LoadingAndErrorComponent.tsx +0 -47
  216. package/components/LoadingAnimation.tsx +0 -40
  217. package/components/LoadingButton.tsx +0 -27
  218. package/components/MarkdownInterpreter.tsx +0 -278
  219. package/components/Pagination.tsx +0 -65
  220. package/components/Profile.tsx +0 -124
  221. package/components/ProgressIndicator.tsx +0 -58
  222. package/components/Ring.tsx +0 -286
  223. package/components/SearchableList.tsx +0 -69
  224. package/components/SortButton.tsx +0 -33
  225. package/components/StepperBar.tsx +0 -124
  226. package/components/Table.tsx +0 -330
  227. package/components/TechRadar.tsx +0 -247
  228. package/components/TextImage.tsx +0 -86
  229. package/components/TimeDisplay.tsx +0 -121
  230. package/components/Tooltip.tsx +0 -92
  231. package/components/VerticalDivider.tsx +0 -51
  232. package/components/date/DatePicker.tsx +0 -164
  233. package/components/date/DayPicker.tsx +0 -95
  234. package/components/date/TimePicker.tsx +0 -167
  235. package/components/date/YearMonthPicker.tsx +0 -130
  236. package/components/examples/InputGroupExample.tsx +0 -58
  237. package/components/examples/MultiSelectExample.tsx +0 -57
  238. package/components/examples/SearchableSelectExample.tsx +0 -34
  239. package/components/examples/SelectExample.tsx +0 -28
  240. package/components/examples/StackingModals.tsx +0 -54
  241. package/components/examples/TableExample.tsx +0 -159
  242. package/components/examples/TextareaExample.tsx +0 -23
  243. package/components/examples/TileExample.tsx +0 -25
  244. package/components/examples/date/DateTimePickerExample.tsx +0 -53
  245. package/components/examples/properties/CheckboxPropertyExample.tsx +0 -29
  246. package/components/examples/properties/DatePropertyExample.tsx +0 -44
  247. package/components/examples/properties/MultiSelectPropertyExample.tsx +0 -39
  248. package/components/examples/properties/NumberPropertyExample.tsx +0 -28
  249. package/components/examples/properties/SelectPropertyExample.tsx +0 -39
  250. package/components/examples/properties/TextPropertyExample.tsx +0 -30
  251. package/components/icons/Helpwave.tsx +0 -51
  252. package/components/icons/Tag.tsx +0 -29
  253. package/components/layout/Carousel.tsx +0 -396
  254. package/components/layout/DividerInserter.tsx +0 -37
  255. package/components/layout/FAQSection.tsx +0 -57
  256. package/components/layout/Tile.tsx +0 -67
  257. package/components/modals/ConfirmDialog.tsx +0 -105
  258. package/components/modals/DiscardChangesDialog.tsx +0 -71
  259. package/components/modals/InputModal.tsx +0 -26
  260. package/components/modals/LanguageModal.tsx +0 -76
  261. package/components/modals/Modal.tsx +0 -149
  262. package/components/modals/ModalRegister.tsx +0 -45
  263. package/components/properties/CheckboxProperty.tsx +0 -62
  264. package/components/properties/DateProperty.tsx +0 -58
  265. package/components/properties/MultiSelectProperty.tsx +0 -82
  266. package/components/properties/NumberProperty.tsx +0 -86
  267. package/components/properties/PropertyBase.tsx +0 -84
  268. package/components/properties/SelectProperty.tsx +0 -67
  269. package/components/properties/TextProperty.tsx +0 -81
  270. package/components/user-input/Checkbox.tsx +0 -139
  271. package/components/user-input/DateAndTimePicker.tsx +0 -156
  272. package/components/user-input/Input.tsx +0 -192
  273. package/components/user-input/Label.tsx +0 -32
  274. package/components/user-input/Menu.tsx +0 -75
  275. package/components/user-input/MultiSelect.tsx +0 -158
  276. package/components/user-input/ScrollPicker.tsx +0 -240
  277. package/components/user-input/SearchableSelect.tsx +0 -36
  278. package/components/user-input/Select.tsx +0 -132
  279. package/components/user-input/Textarea.tsx +0 -86
  280. package/components/user-input/ToggleableInput.tsx +0 -115
  281. package/globals.css +0 -488
  282. package/hooks/useHoverState.ts +0 -88
  283. package/hooks/useLanguage.tsx +0 -78
  284. package/hooks/useLocalStorage.tsx +0 -33
  285. package/hooks/useOutsideClick.ts +0 -25
  286. package/hooks/useSaveDelay.ts +0 -46
  287. package/hooks/useTheme.tsx +0 -57
  288. package/hooks/useTranslation.ts +0 -43
  289. package/index.ts +0 -0
  290. package/util/array.ts +0 -115
  291. package/util/date.ts +0 -180
  292. package/util/easeFunctions.ts +0 -37
  293. package/util/emailValidation.ts +0 -3
  294. package/util/loopingArray.ts +0 -94
  295. package/util/math.ts +0 -3
  296. package/util/news.ts +0 -43
  297. package/util/noop.ts +0 -1
  298. package/util/storage.ts +0 -37
  299. package/util/types.ts +0 -4
  300. /package/{components/Span.tsx → dist/components/Span.d.ts} +0 -0
  301. /package/{components/examples/Title.tsx → dist/components/examples/Title.d.ts} +0 -0
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState, forwardRef } from 'react';
3
+ import clsx from 'clsx';
4
+ import useSaveDelay from '../../hooks/useSaveDelay';
5
+ import { noop } from '../../util/noop';
6
+ import { Label } from './Label';
7
+ /**
8
+ * A Component for inputting text or other information
9
+ *
10
+ * Its state is managed must be managed by the parent
11
+ */
12
+ const ControlledInput = ({ id, type = 'text', value, label, onChange = noop, onChangeEvent = noop, className = '', onEditCompleted, expanded = true, onBlur, containerClassName, ...restProps }) => {
13
+ const { restartTimer, clearUpdateTimer } = useSaveDelay(() => undefined, 3000);
14
+ const ref = useRef(null);
15
+ useEffect(() => {
16
+ var _a;
17
+ if (restProps.autoFocus) {
18
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.focus();
19
+ }
20
+ }, [restProps.autoFocus]);
21
+ return (_jsxs("div", { className: clsx({ 'w-full': expanded }, containerClassName), children: [label && _jsx(Label, { ...label, htmlFor: id, className: clsx('mb-1', label.className) }), _jsx("input", { ref: ref, value: value, id: id, type: type, className: clsx('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), onBlur: event => {
22
+ if (onBlur) {
23
+ onBlur(event);
24
+ }
25
+ if (onEditCompleted) {
26
+ onEditCompleted(event.target.value, event);
27
+ clearUpdateTimer();
28
+ }
29
+ }, onChange: e => {
30
+ const value = e.target.value;
31
+ if (onEditCompleted) {
32
+ restartTimer(() => {
33
+ onEditCompleted(value, e);
34
+ clearUpdateTimer();
35
+ });
36
+ }
37
+ onChange(value, e);
38
+ onChangeEvent(e);
39
+ }, ...restProps })] }));
40
+ };
41
+ /**
42
+ * A Component for inputting text or other information
43
+ *
44
+ * Its state is managed by the component itself
45
+ */
46
+ const UncontrolledInput = ({ defaultValue = '', onChange = noop, ...props }) => {
47
+ const [value, setValue] = useState(defaultValue);
48
+ const handleChange = (text, event) => {
49
+ setValue(text);
50
+ onChange(text, event);
51
+ };
52
+ return (_jsx(ControlledInput, { ...props, value: value, onChange: handleChange }));
53
+ };
54
+ const FormInput = forwardRef(function FormInput({ id, labelText, errorText, className, labelClassName, errorClassName, containerClassName, required, ...restProps }, ref) {
55
+ const input = (_jsx("input", { ref: ref, id: id, ...restProps, className: clsx('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', {
56
+ 'focus:border-primary focus:ring-primary': !errorText,
57
+ 'focus:border-negative focus:ring-negative text-negative': !!errorText,
58
+ }, className) }));
59
+ return (_jsxs("div", { className: clsx('flex flex-col gap-y-1', containerClassName), children: [labelText && (_jsxs("label", { htmlFor: id, className: clsx('textstyle-label-md', labelClassName), children: [labelText, required && _jsx("span", { className: "text-primary font-bold", children: "*" })] })), input, errorText && _jsx("label", { htmlFor: id, className: clsx('text-negative', errorClassName), children: errorText })] }));
60
+ });
61
+ export { UncontrolledInput, ControlledInput as Input, FormInput };
@@ -0,0 +1,12 @@
1
+ import type { LabelHTMLAttributes } from 'react';
2
+ export type LabelType = 'labelSmall' | 'labelMedium' | 'labelBig';
3
+ export type LabelProps = {
4
+ /** The text for the label */
5
+ name?: string;
6
+ /** The styling for the label */
7
+ labelType?: LabelType;
8
+ } & LabelHTMLAttributes<HTMLLabelElement>;
9
+ /**
10
+ * A Label component
11
+ */
12
+ export declare const Label: ({ children, name, labelType, ...props }: LabelProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const styleMapping = {
3
+ labelSmall: 'textstyle-label-sm',
4
+ labelMedium: 'textstyle-label-md',
5
+ labelBig: 'textstyle-label-lg',
6
+ };
7
+ /**
8
+ * A Label component
9
+ */
10
+ export const Label = ({ children, name, labelType = 'labelSmall', ...props }) => {
11
+ return (_jsx("label", { ...props, children: children ? children : (_jsx("span", { className: styleMapping[labelType], children: name })) }));
12
+ };
@@ -0,0 +1,21 @@
1
+ import { type PropsWithChildren, type ReactNode, type RefObject } from 'react';
2
+ type MenuProps<T> = PropsWithChildren<{
3
+ trigger: (onClick: () => void, ref: RefObject<T>) => ReactNode;
4
+ /**
5
+ * @default 'tl'
6
+ */
7
+ alignment?: 'tl' | 'tr' | 'bl' | 'br' | '_l' | '_r' | 't_' | 'b_';
8
+ showOnHover?: boolean;
9
+ menuClassName?: string;
10
+ }>;
11
+ export type MenuItemProps = {
12
+ onClick?: () => void;
13
+ alignment?: 'left' | 'right';
14
+ className?: string;
15
+ };
16
+ declare const MenuItem: ({ children, onClick, alignment, className }: PropsWithChildren<MenuItemProps>) => import("react/jsx-runtime").JSX.Element;
17
+ /**
18
+ * A Menu Component to allow the user to see different functions
19
+ */
20
+ declare const Menu: <T extends HTMLElement>({ trigger, children, alignment, showOnHover, menuClassName, }: MenuProps<T>) => import("react/jsx-runtime").JSX.Element;
21
+ export { Menu, MenuItem };
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from 'react';
3
+ import clsx from 'clsx';
4
+ import { useOutsideClick } from '../../hooks/useOutsideClick';
5
+ import { useHoverState } from '../../hooks/useHoverState';
6
+ const MenuItem = ({ children, onClick, alignment = 'left', className }) => (_jsx("div", { className: clsx('block px-3 py-1 bg-menu-background text-menu-text hover:brightness-90', {
7
+ 'text-right': alignment === 'right',
8
+ 'text-left': alignment === 'left',
9
+ }, className), onClick: onClick, children: children }));
10
+ // TODO: it is quite annoying that the type for the ref has to be specified manually, is there some solution around this?
11
+ /**
12
+ * A Menu Component to allow the user to see different functions
13
+ */
14
+ const Menu = ({ trigger, children, alignment = 'tl', showOnHover = false, menuClassName = '', }) => {
15
+ const { isHovered: isOpen, setIsHovered: setIsOpen, handlers } = useHoverState({ isDisabled: !showOnHover });
16
+ const triggerRef = useRef(null);
17
+ const menuRef = useRef(null);
18
+ useOutsideClick([triggerRef, menuRef], () => setIsOpen(false));
19
+ return (_jsxs("div", { className: "relative", ...handlers, children: [trigger(() => setIsOpen(!isOpen), triggerRef), isOpen ? (_jsx("div", { ref: menuRef, onClick: e => e.stopPropagation(), className: clsx('absolute top-full mt-1 py-2 w-60 rounded-lg bg-menu-background text-menu-text ring-1 ring-slate-900/5 text-sm leading-6 font-semibold shadow-md z-[1]', {
20
+ ' top-[8px]': alignment[0] === 't',
21
+ ' bottom-[8px]': alignment[0] === 'b',
22
+ ' left-[-8px]': alignment[1] === 'l',
23
+ ' right-[-8px]': alignment[1] === 'r',
24
+ }, menuClassName), children: children })) : null] }));
25
+ };
26
+ export { Menu, MenuItem };
@@ -0,0 +1,39 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { PropsForTranslation } from '../../hooks/useTranslation';
3
+ import type { LabelProps } from './Label';
4
+ type MultiSelectTranslation = {
5
+ select: string;
6
+ search: string;
7
+ selected: string;
8
+ };
9
+ export type MultiSelectOption<T> = {
10
+ label: string;
11
+ value: T;
12
+ selected: boolean;
13
+ disabled?: boolean;
14
+ className?: string;
15
+ };
16
+ export type SearchProps<T> = {
17
+ initialSearch?: string;
18
+ searchMapping: (value: MultiSelectOption<T>) => string[];
19
+ };
20
+ export type MultiSelectProps<T> = {
21
+ options: MultiSelectOption<T>[];
22
+ onChange: (options: MultiSelectOption<T>[]) => void;
23
+ search?: SearchProps<T>;
24
+ disabled?: boolean;
25
+ selectedDisplay?: (props: {
26
+ items: MultiSelectOption<T>[];
27
+ disabled: boolean;
28
+ }) => ReactNode;
29
+ label?: LabelProps;
30
+ hintText?: string;
31
+ showDisabledOptions?: boolean;
32
+ className?: string;
33
+ triggerClassName?: string;
34
+ };
35
+ /**
36
+ * A Component for multi selection
37
+ */
38
+ export declare const MultiSelect: <T>({ overwriteTranslation, options, onChange, search, disabled, selectedDisplay, label, hintText, showDisabledOptions, className, triggerClassName, }: PropsForTranslation<MultiSelectTranslation, MultiSelectProps<T>>) => import("react/jsx-runtime").JSX.Element;
39
+ export {};
@@ -0,0 +1,57 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Search } from 'lucide-react';
4
+ import { useTranslation } from '../../hooks/useTranslation';
5
+ import { MultiSearchWithMapping } from '../../util/simpleSearch';
6
+ import clsx from 'clsx';
7
+ import { Menu, MenuItem } from './Menu';
8
+ import { Input } from './Input';
9
+ import { Checkbox } from './Checkbox';
10
+ import { Label } from './Label';
11
+ const defaultMultiSelectTranslation = {
12
+ en: {
13
+ select: 'Select',
14
+ search: 'Search',
15
+ selected: 'selected'
16
+ },
17
+ de: {
18
+ select: 'Auswählen',
19
+ search: 'Suche',
20
+ selected: 'ausgewählt'
21
+ }
22
+ };
23
+ /**
24
+ * A Component for multi selection
25
+ */
26
+ export const MultiSelect = ({ overwriteTranslation, options, onChange, search, disabled = false, selectedDisplay, label, hintText, showDisabledOptions = true, className = '', triggerClassName = '', }) => {
27
+ var _a, _b;
28
+ const translation = useTranslation(defaultMultiSelectTranslation, overwriteTranslation);
29
+ const [searchText, setSearchText] = useState((_a = search === null || search === void 0 ? void 0 : search.initialSearch) !== null && _a !== void 0 ? _a : '');
30
+ let filteredOptions = options;
31
+ const enableSearch = !!search;
32
+ if (enableSearch && !!searchText) {
33
+ filteredOptions = MultiSearchWithMapping(searchText, filteredOptions, value => search.searchMapping(value));
34
+ }
35
+ if (!showDisabledOptions) {
36
+ filteredOptions = filteredOptions.filter(value => !value.disabled);
37
+ }
38
+ const selectedItems = options.filter(value => value.selected);
39
+ const menuButtonText = selectedItems.length === 0 ?
40
+ hintText !== null && hintText !== void 0 ? hintText : translation.select
41
+ : _jsx("span", { children: `${selectedItems.length} ${translation.selected}` });
42
+ const borderColor = 'border-menu-border';
43
+ return (_jsxs("div", { className: clsx(className), children: [label && (_jsx(Label, { ...label, htmlFor: label.name, className: clsx(' mb-1', label.className), labelType: (_b = label.labelType) !== null && _b !== void 0 ? _b : 'labelBig' })), _jsxs(Menu, { alignment: "t_", trigger: (onClick, ref) => (_jsx("div", { ref: ref, onClick: disabled ? undefined : onClick, className: clsx(borderColor, 'bg-menu-background text-menu-text inline-w-full justify-between items-center rounded-lg border-2 px-4 py-2 font-medium', {
44
+ 'hover:brightness-90 hover:border-primary cursor-pointer': !disabled,
45
+ 'bg-disabled-background text-disabled cursor-not-allowed': disabled
46
+ }, triggerClassName), children: selectedDisplay ? selectedDisplay({ items: options, disabled }) : menuButtonText })), menuClassName: clsx('!rounded-lg !shadow-lg !max-h-[500px] !min-w-[400px] !max-w-[70vh] !overflow-y-auto !border !border-2', borderColor, { '!py-0': !enableSearch, '!pb-0': enableSearch }), children: [enableSearch && (_jsxs("div", { className: "row gap-x-2 items-center px-2 py-2", children: [_jsx(Input, { autoFocus: true, value: searchText, onChange: setSearchText }), _jsx(Search, {})] }, "selectSearch")), filteredOptions.map((option, index) => (_jsx(MenuItem, { className: clsx({
47
+ 'cursor-not-allowed !bg-disabled-background !text-disabled-text hover:brightness-100': !!option.disabled,
48
+ 'cursor-pointer': !option.disabled,
49
+ }), children: _jsxs("div", { className: clsx('overflow-hidden whitespace-nowrap text-ellipsis row items-center gap-x-2', option.className), onClick: () => {
50
+ if (!option.disabled) {
51
+ onChange(options.map(value => value.value === option.value ? ({
52
+ ...option,
53
+ selected: !value.selected
54
+ }) : value));
55
+ }
56
+ }, children: [_jsx(Checkbox, { checked: option.selected, disabled: option.disabled, size: "small" }), option.label] }) }, `item${index}`)))] })] }));
57
+ };
@@ -0,0 +1,11 @@
1
+ export type ScrollPickerProps<T> = {
2
+ options: T[];
3
+ mapping: (value: T) => string;
4
+ selected?: T;
5
+ onChange?: (value: T) => void;
6
+ disabled?: boolean;
7
+ };
8
+ /**
9
+ * A component for picking an option by scrolling
10
+ */
11
+ export declare const ScrollPicker: <T>({ options, mapping, selected, onChange, disabled, }: ScrollPickerProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,151 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useState } from 'react';
3
+ import clsx from 'clsx';
4
+ import { noop } from '../../util/noop';
5
+ import { getNeighbours, range } from '../../util/array';
6
+ import { clamp } from '../../util/math';
7
+ const up = 1;
8
+ const down = -1;
9
+ /**
10
+ * A component for picking an option by scrolling
11
+ */
12
+ export const ScrollPicker = ({ options, mapping, selected, onChange = noop, disabled = false, }) => {
13
+ let selectedIndex = 0;
14
+ if (selected && options.indexOf(selected) !== -1) {
15
+ selectedIndex = options.indexOf(selected);
16
+ }
17
+ const [{ currentIndex, transition, items, lastTimeStamp }, setAnimation] = useState({
18
+ targetIndex: selectedIndex,
19
+ currentIndex: disabled ? selectedIndex : 0,
20
+ velocity: 0,
21
+ animationVelocity: Math.floor(options.length / 2),
22
+ transition: 0,
23
+ items: options,
24
+ });
25
+ const itemsShownCount = 5;
26
+ const shownItems = getNeighbours(range(0, items.length - 1), currentIndex).map(index => ({
27
+ name: mapping(items[index]), index
28
+ }));
29
+ const itemHeight = 40;
30
+ const distance = 8;
31
+ const containerHeight = itemHeight * (itemsShownCount - 2) + distance * (itemsShownCount - 2 + 1);
32
+ const getDirection = useCallback((targetIndex, currentIndex, transition, length) => {
33
+ if (targetIndex === currentIndex) {
34
+ return transition > 0 ? up : down;
35
+ }
36
+ let distanceForward = targetIndex - currentIndex;
37
+ if (distanceForward < 0) {
38
+ distanceForward += length;
39
+ }
40
+ return distanceForward >= length / 2 ? down : up;
41
+ }, []);
42
+ const animate = useCallback((timestamp, startTime) => {
43
+ setAnimation((prevState) => {
44
+ const { targetIndex, currentIndex, transition, animationVelocity, velocity, items, lastScrollTimeStamp } = prevState;
45
+ if (disabled) {
46
+ return { ...prevState, currentIndex: targetIndex, velocity: 0, lastTimeStamp: timestamp };
47
+ }
48
+ if ((targetIndex === currentIndex && velocity === 0 && transition === 0) || !startTime) {
49
+ return { ...prevState, lastTimeStamp: timestamp };
50
+ }
51
+ const progress = (timestamp - startTime) / 1000; // to seconds
52
+ const direction = getDirection(targetIndex, currentIndex, transition, items.length);
53
+ let newVelocity = velocity;
54
+ let usedVelocity;
55
+ let newCurrentIndex = currentIndex;
56
+ const isAutoScrolling = velocity === 0 && (!lastScrollTimeStamp || timestamp - lastScrollTimeStamp > 300);
57
+ const newLastScrollTimeStamp = velocity !== 0 ? timestamp : lastScrollTimeStamp;
58
+ // manual scrolling
59
+ if (isAutoScrolling) {
60
+ usedVelocity = direction * animationVelocity;
61
+ }
62
+ else {
63
+ usedVelocity = velocity;
64
+ newVelocity = velocity * 0.5; // drag loss
65
+ if (Math.abs(newVelocity) <= 0.05) {
66
+ newVelocity = 0;
67
+ }
68
+ }
69
+ let newTransition = transition + usedVelocity * progress;
70
+ const changeThreshold = 0.5;
71
+ while (newTransition >= changeThreshold) {
72
+ if (newCurrentIndex === targetIndex && newTransition >= changeThreshold && isAutoScrolling) {
73
+ newTransition = 0;
74
+ break;
75
+ }
76
+ newCurrentIndex = (currentIndex + 1) % items.length;
77
+ newTransition -= 1;
78
+ }
79
+ if (newTransition >= changeThreshold) {
80
+ newTransition = 0;
81
+ }
82
+ while (newTransition <= -changeThreshold) {
83
+ if (newCurrentIndex === targetIndex && newTransition <= -changeThreshold && isAutoScrolling) {
84
+ newTransition = 0;
85
+ break;
86
+ }
87
+ newCurrentIndex = currentIndex === 0 ? items.length - 1 : currentIndex - 1;
88
+ newTransition += 1;
89
+ }
90
+ let newTargetIndex = targetIndex;
91
+ if (!isAutoScrolling) {
92
+ newTargetIndex = newCurrentIndex;
93
+ }
94
+ if ((currentIndex !== newTargetIndex || newTargetIndex !== targetIndex) && newTargetIndex === newCurrentIndex) {
95
+ onChange(items[newCurrentIndex]);
96
+ }
97
+ return {
98
+ targetIndex: newTargetIndex,
99
+ currentIndex: newCurrentIndex,
100
+ animationVelocity,
101
+ transition: newTransition,
102
+ velocity: newVelocity,
103
+ items,
104
+ lastTimeStamp: timestamp,
105
+ lastScrollTimeStamp: newLastScrollTimeStamp
106
+ };
107
+ });
108
+ }, [disabled, getDirection, onChange]);
109
+ useEffect(() => {
110
+ // constant update
111
+ requestAnimationFrame((timestamp) => animate(timestamp, lastTimeStamp));
112
+ });
113
+ const opacity = (transition, index, itemsCount) => {
114
+ const max = 100;
115
+ const min = 0;
116
+ const distance = max - min;
117
+ let opacityValue = min;
118
+ const unitTransition = clamp((transition) / 0.5);
119
+ if (index === 1 || index === itemsCount - 2) {
120
+ if (index === 1 && transition > 0) {
121
+ opacityValue += Math.floor(unitTransition * distance);
122
+ }
123
+ if (index === itemsCount - 2 && transition < 0) {
124
+ opacityValue += Math.floor(unitTransition * distance);
125
+ }
126
+ }
127
+ else {
128
+ opacityValue = max;
129
+ }
130
+ // TODO this is not the right value for the bottom entry
131
+ return clamp(1 - (opacityValue / max));
132
+ };
133
+ return (_jsx("div", { className: "relative overflow-hidden", style: { height: containerHeight }, onWheel: event => {
134
+ if (event.deltaY !== 0) {
135
+ // TODO slower increase
136
+ setAnimation(({ velocity, ...animationData }) => ({ ...animationData, velocity: velocity + event.deltaY }));
137
+ }
138
+ }, children: _jsxs("div", { className: "absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2", children: [_jsx("div", { className: "absolute z-[1] top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-full min-w-[40px] border border-y-2 border-x-0 border-[#00000033]", style: { height: `${itemHeight}px` } }), _jsx("div", { className: "col select-none", style: {
139
+ transform: `translateY(${-transition * (distance + itemHeight)}px)`,
140
+ columnGap: `${distance}px`,
141
+ }, children: shownItems.map(({ name, index }, arrayIndex) => (_jsx("div", { className: clsx(`col items-center justify-center rounded-md`, {
142
+ 'text-primary font-bold': currentIndex === index,
143
+ 'text-on-background': currentIndex === index,
144
+ 'cursor-pointer': !disabled,
145
+ 'cursor-not-allowed': disabled,
146
+ }), style: {
147
+ opacity: currentIndex !== index ? opacity(transition, arrayIndex, shownItems.length) : undefined,
148
+ height: `${itemHeight}px`,
149
+ maxHeight: `${itemHeight}px`,
150
+ }, onClick: () => !disabled && setAnimation(prevState => ({ ...prevState, targetIndex: index })), children: name }, index))) })] }) }));
151
+ };
@@ -0,0 +1,8 @@
1
+ import type { SelectOption, SelectProps } from './Select';
2
+ export type SearchableSelectProps<T> = SelectProps<T> & {
3
+ searchMapping: (value: SelectOption<T>) => string[];
4
+ };
5
+ /**
6
+ * A Select where items can be searched
7
+ */
8
+ export declare const SearchableSelect: <T>({ value, options, searchMapping, ...selectProps }: SearchableSelectProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Search } from 'lucide-react';
4
+ import { MultiSearchWithMapping } from '../../util/simpleSearch';
5
+ import { Select } from './Select';
6
+ import { Input } from './Input';
7
+ /**
8
+ * A Select where items can be searched
9
+ */
10
+ export const SearchableSelect = ({ value, options, searchMapping, ...selectProps }) => {
11
+ const [search, setSearch] = useState('');
12
+ const filteredOptions = MultiSearchWithMapping(search, options, searchMapping);
13
+ return (_jsx(Select, { value: value, options: filteredOptions, additionalItems: [(_jsxs("div", { className: "row gap-x-2 items-center", children: [_jsx(Input, { autoFocus: true, value: search, onChange: setSearch }), _jsx(Search, {})] }, "selectSearch"))], ...selectProps }));
14
+ };
@@ -0,0 +1,32 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { LabelProps } from './Label';
3
+ export type SelectOption<T> = {
4
+ label: ReactNode;
5
+ value: T;
6
+ disabled?: boolean;
7
+ className?: string;
8
+ };
9
+ export type SelectProps<T> = {
10
+ value?: T;
11
+ label?: LabelProps;
12
+ options: SelectOption<T>[];
13
+ onChange: (value: T) => void;
14
+ isHidingCurrentValue?: boolean;
15
+ hintText?: string;
16
+ showDisabledOptions?: boolean;
17
+ className?: string;
18
+ isDisabled?: boolean;
19
+ textColor?: string;
20
+ hoverColor?: string;
21
+ /**
22
+ * The items will be at the start of the select and aren't selectable
23
+ */
24
+ additionalItems?: ReactNode[];
25
+ selectedDisplayOverwrite?: ReactNode;
26
+ };
27
+ /**
28
+ * A Select Component for selecting form a list of options
29
+ *
30
+ * The State is managed by the parent
31
+ */
32
+ export declare const Select: <T>({ value, label, options, onChange, isHidingCurrentValue, hintText, showDisabledOptions, isDisabled, className, textColor, hoverColor, additionalItems, selectedDisplayOverwrite, }: SelectProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Menu } from '@headlessui/react';
3
+ import { ChevronDown, ChevronUp } from 'lucide-react';
4
+ import clsx from 'clsx';
5
+ import { Label } from './Label';
6
+ /**
7
+ * A Select Component for selecting form a list of options
8
+ *
9
+ * The State is managed by the parent
10
+ */
11
+ export const Select = ({ value, label, options, onChange, isHidingCurrentValue = true, hintText = '', showDisabledOptions = true, isDisabled, className, textColor = 'text-menu-text', hoverColor = 'hover:brightness-90', additionalItems, selectedDisplayOverwrite, }) => {
12
+ var _a;
13
+ // Notice: for more complex types this check here might need an additional compare method
14
+ let filteredOptions = isHidingCurrentValue ? options.filter(option => option.value !== value) : options;
15
+ if (!showDisabledOptions) {
16
+ filteredOptions = filteredOptions.filter(value => !value.disabled);
17
+ }
18
+ const selectedOption = options.find(option => option.value === value);
19
+ if (value !== undefined && selectedOption === undefined && selectedDisplayOverwrite === undefined) {
20
+ console.warn('The selected value is not found in the options list. This might be an error on your part or' +
21
+ ' default behavior if it is complex data type on which === does not work. In case of the latter' +
22
+ ' use selectedDisplayOverwrite to set your selected text or component');
23
+ }
24
+ const borderColor = 'border-menu-border';
25
+ return (_jsxs("div", { className: clsx(className), children: [label && (_jsx(Label, { ...label, labelType: (_a = label.labelType) !== null && _a !== void 0 ? _a : 'labelBig', className: clsx('mb-1', label.className) })), _jsx(Menu, { as: "div", className: "relative text-menu-text", children: ({ open }) => {
26
+ var _a;
27
+ return (_jsxs(_Fragment, { children: [_jsxs(Menu.Button, { className: clsx('inline-flex w-full justify-between items-center rounded-t-lg border-2 px-4 py-2 font-medium bg-menu-background text-menu-text', textColor, borderColor, {
28
+ 'rounded-b-lg': !open,
29
+ [hoverColor]: !isDisabled,
30
+ 'bg-disabled-background cursor-not-allowed text-disabled': isDisabled
31
+ }), disabled: isDisabled, children: [_jsx("span", { children: (_a = selectedDisplayOverwrite !== null && selectedDisplayOverwrite !== void 0 ? selectedDisplayOverwrite : selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) !== null && _a !== void 0 ? _a : hintText }), open ? _jsx(ChevronUp, {}) : _jsx(ChevronDown, {})] }), _jsxs(Menu.Items, { className: "absolute w-full z-10 rounded-b-lg bg-menu-background text-menu-text shadow-lg max-h-[500px] overflow-y-auto", children: [(additionalItems !== null && additionalItems !== void 0 ? additionalItems : []).map((item, index) => {
32
+ var _a;
33
+ return (_jsx("div", { className: clsx(borderColor, 'px-4 py-2 overflow-hidden whitespace-nowrap text-ellipsis border-2 border-t-0', {
34
+ 'border-b-0 rounded-b-lg': filteredOptions.length === 0 && index === ((_a = additionalItems === null || additionalItems === void 0 ? void 0 : additionalItems.length) !== null && _a !== void 0 ? _a : 1) - 1,
35
+ }), children: item }, `additionalItems${index}`));
36
+ }), filteredOptions.map((option, index) => (_jsx(Menu.Item, { children: _jsx("div", { className: clsx('px-4 py-2 overflow-hidden whitespace-nowrap text-ellipsis border-2 border-t-0 cursor-pointer', option.className, borderColor, {
37
+ 'brightness-90': option.value === value,
38
+ 'brightness-95': index % 2 === 1,
39
+ 'text-disabled bg-disabled-background cursor-not-allowed': !!option.disabled,
40
+ 'bg-menu-background text-menu-text hover:brightness-90 cursor-pointer': !option.disabled,
41
+ 'rounded-b-lg': index === filteredOptions.length - 1,
42
+ }), onClick: () => {
43
+ if (!option.disabled) {
44
+ onChange(option.value);
45
+ }
46
+ }, children: option.label }) }, `item${index}`)))] })] }));
47
+ } })] }));
48
+ };
@@ -0,0 +1,20 @@
1
+ import type { TextareaHTMLAttributes } from 'react';
2
+ import type { LabelProps } from './Label';
3
+ export type TextareaProps = {
4
+ /** Outside the area */
5
+ label?: Omit<LabelProps, 'id'>;
6
+ /** Inside the area */
7
+ headline?: string;
8
+ id?: string;
9
+ resizable?: boolean;
10
+ onChange?: (text: string) => void;
11
+ disclaimer?: string;
12
+ onEditCompleted?: (text: string) => void;
13
+ defaultStyle?: boolean;
14
+ } & Omit<TextareaHTMLAttributes<Element>, 'id' | 'onChange'>;
15
+ /**
16
+ * A Textarea component for inputting longer texts
17
+ *
18
+ * The State is managed by the parent
19
+ */
20
+ export declare const Textarea: ({ label, headline, id, resizable, onChange, disclaimer, onBlur, onEditCompleted, defaultStyle, className, ...props }: TextareaProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import clsx from 'clsx';
4
+ import useSaveDelay from '../../hooks/useSaveDelay';
5
+ import { noop } from '../../util/noop';
6
+ import { Label } from './Label';
7
+ /**
8
+ * A Textarea component for inputting longer texts
9
+ *
10
+ * The State is managed by the parent
11
+ */
12
+ export const Textarea = ({ label, headline, id, resizable = false, onChange = noop, disclaimer, onBlur = noop, onEditCompleted = noop, defaultStyle = true, className, ...props }) => {
13
+ var _a;
14
+ const [hasFocus, setHasFocus] = useState(false);
15
+ const { restartTimer, clearUpdateTimer } = useSaveDelay(() => undefined, 3000);
16
+ const onEditCompletedWrapper = (text) => {
17
+ onEditCompleted(text);
18
+ clearUpdateTimer();
19
+ };
20
+ return (_jsxs("div", { className: "w-full", children: [label && (_jsx(Label, { ...label, htmlFor: id, className: clsx('mb-1', label.className), labelType: (_a = label.labelType) !== null && _a !== void 0 ? _a : 'labelSmall' })), _jsxs("div", { className: `${clsx(' bg-surface text-on-surface focus-within:border-primary relative', { 'shadow border-2 border-gray-300 hover:border-primary rounded-lg': defaultStyle })}`, children: [headline && (_jsx("span", { className: "mx-3 mt-3 block text-gray-700 font-bold", children: headline })), _jsx("textarea", { id: id, className: clsx('pt-0 px-3 border-transparent focus:border-transparent focus:ring-0 appearance-none border w-full leading-tight focus:outline-none', { 'resize-none': !resizable, 'h-32': defaultStyle, 'mt-3': !headline }, className), onChange: (event) => {
21
+ const value = event.target.value;
22
+ restartTimer(() => {
23
+ onEditCompletedWrapper(value);
24
+ });
25
+ onChange(value);
26
+ }, onFocus: () => {
27
+ setHasFocus(true);
28
+ }, onBlur: (event) => {
29
+ onBlur(event);
30
+ onEditCompletedWrapper(event.target.value);
31
+ setHasFocus(false);
32
+ }, ...props })] }), (hasFocus && disclaimer) && (_jsx("label", { className: "text-negative", children: disclaimer }))] }));
33
+ };
@@ -0,0 +1,32 @@
1
+ import type { HTMLInputTypeAttribute, InputHTMLAttributes } from 'react';
2
+ type InputProps = {
3
+ /**
4
+ * used for the label's `for` attribute
5
+ */
6
+ id: string;
7
+ value: string;
8
+ /**
9
+ * @default 'text'
10
+ */
11
+ type?: HTMLInputTypeAttribute;
12
+ /**
13
+ * Callback for when the input's value changes
14
+ * This is pretty much required but made optional for the rare cases where it actually isn't need such as when used with disabled
15
+ * That could be enforced through a union type but that seems a bit overkill
16
+ * @default noop
17
+ */
18
+ onChange?: (text: string) => void;
19
+ labelClassName?: string;
20
+ initialState?: 'editing' | 'display';
21
+ size?: number;
22
+ disclaimer?: string;
23
+ onEditCompleted?: (text: string) => void;
24
+ } & Omit<InputHTMLAttributes<HTMLInputElement>, 'id' | 'value' | 'label' | 'type' | 'onChange' | 'crossOrigin'>;
25
+ /**
26
+ * A Text input component for inputting text. It changes appearance upon entering the edit mode and switches
27
+ * back to display mode on loss of focus or on enter
28
+ *
29
+ * The State is managed by the parent
30
+ */
31
+ export declare const ToggleableInput: ({ id, type, value, onChange, labelClassName, initialState, size, disclaimer, onBlur, onEditCompleted, ...restProps }: InputProps) => import("react/jsx-runtime").JSX.Element;
32
+ export {};
@@ -0,0 +1,40 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Pencil } from 'lucide-react';
4
+ import clsx from 'clsx';
5
+ import useSaveDelay from '../../hooks/useSaveDelay';
6
+ import { noop } from '../../util/noop';
7
+ /**
8
+ * A Text input component for inputting text. It changes appearance upon entering the edit mode and switches
9
+ * back to display mode on loss of focus or on enter
10
+ *
11
+ * The State is managed by the parent
12
+ */
13
+ export const ToggleableInput = ({ id, type = 'text', value, onChange = noop, labelClassName = '', initialState = 'display', size = 20, disclaimer, onBlur, onEditCompleted = noop, ...restProps }) => {
14
+ const [isEditing, setIsEditing] = useState(initialState !== 'display');
15
+ const { restartTimer, clearUpdateTimer } = useSaveDelay(() => undefined, 3000);
16
+ const onEditCompletedWrapper = (text) => {
17
+ onEditCompleted(text);
18
+ clearUpdateTimer();
19
+ };
20
+ return (_jsxs("div", { children: [_jsxs("div", { className: "row items-center w-full gap-x-2 overflow-hidden", onClick: () => !isEditing ? setIsEditing(!isEditing) : undefined, children: [_jsx("div", { className: clsx('row overflow-hidden', { 'flex-1': isEditing }), children: isEditing ? (_jsx("input", { autoFocus: true, ...restProps, value: value, type: type, id: id, onChange: event => {
21
+ const value = event.target.value;
22
+ restartTimer(() => {
23
+ onEditCompletedWrapper(value);
24
+ });
25
+ onChange(value);
26
+ }, onBlur: (event) => {
27
+ if (onBlur) {
28
+ onBlur(event);
29
+ }
30
+ onEditCompletedWrapper(value);
31
+ setIsEditing(false);
32
+ }, onKeyDown: event => {
33
+ if (event.key === 'Enter') {
34
+ setIsEditing(false);
35
+ onEditCompletedWrapper(value);
36
+ }
37
+ }, className: clsx(labelClassName, `w-full border-none rounded-none focus:ring-0 shadow-transparent decoration-primary p-0 underline-offset-4`, {
38
+ underline: isEditing
39
+ }), onFocus: event => event.target.select() })) : (_jsx("span", { className: clsx(labelClassName, 'max-w-xs break-words overflow-hidden'), children: value })) }), _jsx(Pencil, { className: clsx(`min-w-[${size}px] cursor-pointer`, { 'text-transparent': isEditing }), size: size })] }), (isEditing && disclaimer) && (_jsx("label", { className: "text-negative", children: disclaimer }))] }));
40
+ };