aidos-ui 3.0.0

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 (339) hide show
  1. package/.prettierrc +4 -0
  2. package/LICENSE +21 -0
  3. package/README.md +55 -0
  4. package/dist/Badge.d.ts +7 -0
  5. package/dist/Badge.js +22 -0
  6. package/dist/Badge.js.map +1 -0
  7. package/dist/BaseButton.d.ts +13 -0
  8. package/dist/BaseButton.js +22 -0
  9. package/dist/BaseButton.js.map +1 -0
  10. package/dist/BaseInput.d.ts +15 -0
  11. package/dist/BaseInput.js +14 -0
  12. package/dist/BaseInput.js.map +1 -0
  13. package/dist/BaseLink.d.ts +17 -0
  14. package/dist/BaseLink.js +28 -0
  15. package/dist/BaseLink.js.map +1 -0
  16. package/dist/BaseList.d.ts +6 -0
  17. package/dist/BaseList.js +14 -0
  18. package/dist/BaseList.js.map +1 -0
  19. package/dist/BaseListAddOn.d.ts +5 -0
  20. package/dist/BaseListAddOn.js +7 -0
  21. package/dist/BaseListAddOn.js.map +1 -0
  22. package/dist/BaseListItem.d.ts +27 -0
  23. package/dist/BaseListItem.js +26 -0
  24. package/dist/BaseListItem.js.map +1 -0
  25. package/dist/BaseView.d.ts +12 -0
  26. package/dist/BaseView.js +26 -0
  27. package/dist/BaseView.js.map +1 -0
  28. package/dist/Box.d.ts +5 -0
  29. package/dist/Box.js +6 -0
  30. package/dist/Box.js.map +1 -0
  31. package/dist/Button.d.ts +20 -0
  32. package/dist/Button.js +20 -0
  33. package/dist/Button.js.map +1 -0
  34. package/dist/Calendar.d.ts +18 -0
  35. package/dist/Calendar.js +57 -0
  36. package/dist/Calendar.js.map +1 -0
  37. package/dist/Card.d.ts +4 -0
  38. package/dist/Card.js +12 -0
  39. package/dist/Card.js.map +1 -0
  40. package/dist/Checkbox.d.ts +12 -0
  41. package/dist/Checkbox.js +32 -0
  42. package/dist/Checkbox.js.map +1 -0
  43. package/dist/Circle.d.ts +6 -0
  44. package/dist/Circle.js +12 -0
  45. package/dist/Circle.js.map +1 -0
  46. package/dist/Column.d.ts +6 -0
  47. package/dist/Column.js +7 -0
  48. package/dist/Column.js.map +1 -0
  49. package/dist/DarkMode.d.ts +13 -0
  50. package/dist/DarkMode.js +61 -0
  51. package/dist/DarkMode.js.map +1 -0
  52. package/dist/DateInput.d.ts +13 -0
  53. package/dist/DateInput.js +29 -0
  54. package/dist/DateInput.js.map +1 -0
  55. package/dist/DatePicker.d.ts +12 -0
  56. package/dist/DatePicker.js +34 -0
  57. package/dist/DatePicker.js.map +1 -0
  58. package/dist/DatetimeInput.d.ts +13 -0
  59. package/dist/DatetimeInput.js +31 -0
  60. package/dist/DatetimeInput.js.map +1 -0
  61. package/dist/DesignBook.d.ts +2 -0
  62. package/dist/DesignBook.js +55 -0
  63. package/dist/DesignBook.js.map +1 -0
  64. package/dist/Dialog.d.ts +17 -0
  65. package/dist/Dialog.js +86 -0
  66. package/dist/Dialog.js.map +1 -0
  67. package/dist/Dropdown.d.ts +10 -0
  68. package/dist/Dropdown.js +64 -0
  69. package/dist/Dropdown.js.map +1 -0
  70. package/dist/Emitter.d.ts +6 -0
  71. package/dist/Emitter.js +19 -0
  72. package/dist/Emitter.js.map +1 -0
  73. package/dist/FlexLayout.d.ts +11 -0
  74. package/dist/FlexLayout.js +18 -0
  75. package/dist/FlexLayout.js.map +1 -0
  76. package/dist/Icon.d.ts +12 -0
  77. package/dist/Icon.js +69 -0
  78. package/dist/Icon.js.map +1 -0
  79. package/dist/IconButton.d.ts +9 -0
  80. package/dist/IconButton.js +31 -0
  81. package/dist/IconButton.js.map +1 -0
  82. package/dist/IconLink.d.ts +9 -0
  83. package/dist/IconLink.js +31 -0
  84. package/dist/IconLink.js.map +1 -0
  85. package/dist/IconType.d.ts +1 -0
  86. package/dist/IconType.js +2 -0
  87. package/dist/IconType.js.map +1 -0
  88. package/dist/Interactable.d.ts +48 -0
  89. package/dist/Interactable.js +131 -0
  90. package/dist/Interactable.js.map +1 -0
  91. package/dist/Link.d.ts +20 -0
  92. package/dist/Link.js +22 -0
  93. package/dist/Link.js.map +1 -0
  94. package/dist/List.d.ts +11 -0
  95. package/dist/List.js +17 -0
  96. package/dist/List.js.map +1 -0
  97. package/dist/ListButtonItem.d.ts +15 -0
  98. package/dist/ListButtonItem.js +9 -0
  99. package/dist/ListButtonItem.js.map +1 -0
  100. package/dist/ListDivider.d.ts +2 -0
  101. package/dist/ListDivider.js +12 -0
  102. package/dist/ListDivider.js.map +1 -0
  103. package/dist/ListHeaderItem.d.ts +11 -0
  104. package/dist/ListHeaderItem.js +13 -0
  105. package/dist/ListHeaderItem.js.map +1 -0
  106. package/dist/ListItem.d.ts +10 -0
  107. package/dist/ListItem.js +7 -0
  108. package/dist/ListItem.js.map +1 -0
  109. package/dist/ListLinkItem.d.ts +17 -0
  110. package/dist/ListLinkItem.js +9 -0
  111. package/dist/ListLinkItem.js.map +1 -0
  112. package/dist/ListSpacer.d.ts +2 -0
  113. package/dist/ListSpacer.js +13 -0
  114. package/dist/ListSpacer.js.map +1 -0
  115. package/dist/OnVisible.d.ts +5 -0
  116. package/dist/OnVisible.js +28 -0
  117. package/dist/OnVisible.js.map +1 -0
  118. package/dist/Popover.d.ts +21 -0
  119. package/dist/Popover.js +88 -0
  120. package/dist/Popover.js.map +1 -0
  121. package/dist/ProgressBar.d.ts +8 -0
  122. package/dist/ProgressBar.js +42 -0
  123. package/dist/ProgressBar.js.map +1 -0
  124. package/dist/ProgressCircle.d.ts +6 -0
  125. package/dist/ProgressCircle.js +12 -0
  126. package/dist/ProgressCircle.js.map +1 -0
  127. package/dist/Providers.d.ts +9 -0
  128. package/dist/Providers.js +16 -0
  129. package/dist/Providers.js.map +1 -0
  130. package/dist/RangeInput.d.ts +14 -0
  131. package/dist/RangeInput.js +32 -0
  132. package/dist/RangeInput.js.map +1 -0
  133. package/dist/ResultOrError.d.ts +13 -0
  134. package/dist/ResultOrError.js +7 -0
  135. package/dist/ResultOrError.js.map +1 -0
  136. package/dist/RootView.d.ts +5 -0
  137. package/dist/RootView.js +35 -0
  138. package/dist/RootView.js.map +1 -0
  139. package/dist/Router.d.ts +2 -0
  140. package/dist/Router.js +37 -0
  141. package/dist/Router.js.map +1 -0
  142. package/dist/RouterState.d.ts +38 -0
  143. package/dist/RouterState.js +111 -0
  144. package/dist/RouterState.js.map +1 -0
  145. package/dist/Row.d.ts +6 -0
  146. package/dist/Row.js +7 -0
  147. package/dist/Row.js.map +1 -0
  148. package/dist/StackContext.d.ts +8 -0
  149. package/dist/StackContext.js +25 -0
  150. package/dist/StackContext.js.map +1 -0
  151. package/dist/StaticCheckbox.d.ts +17 -0
  152. package/dist/StaticCheckbox.js +48 -0
  153. package/dist/StaticCheckbox.js.map +1 -0
  154. package/dist/Storage.d.ts +12 -0
  155. package/dist/Storage.js +148 -0
  156. package/dist/Storage.js.map +1 -0
  157. package/dist/Stream.d.ts +9 -0
  158. package/dist/Stream.js +36 -0
  159. package/dist/Stream.js.map +1 -0
  160. package/dist/Sublist.d.ts +12 -0
  161. package/dist/Sublist.js +18 -0
  162. package/dist/Sublist.js.map +1 -0
  163. package/dist/SubmitIconInput.d.ts +9 -0
  164. package/dist/SubmitIconInput.js +25 -0
  165. package/dist/SubmitIconInput.js.map +1 -0
  166. package/dist/Tabs.d.ts +20 -0
  167. package/dist/Tabs.js +35 -0
  168. package/dist/Tabs.js.map +1 -0
  169. package/dist/Text.d.ts +25 -0
  170. package/dist/Text.js +50 -0
  171. package/dist/Text.js.map +1 -0
  172. package/dist/TextArea.d.ts +10 -0
  173. package/dist/TextArea.js +22 -0
  174. package/dist/TextArea.js.map +1 -0
  175. package/dist/TextInput.d.ts +14 -0
  176. package/dist/TextInput.js +52 -0
  177. package/dist/TextInput.js.map +1 -0
  178. package/dist/TextInputWithState.d.ts +10 -0
  179. package/dist/TextInputWithState.js +14 -0
  180. package/dist/TextInputWithState.js.map +1 -0
  181. package/dist/TextPairing.d.ts +21 -0
  182. package/dist/TextPairing.js +26 -0
  183. package/dist/TextPairing.js.map +1 -0
  184. package/dist/TimeInput.d.ts +15 -0
  185. package/dist/TimeInput.js +58 -0
  186. package/dist/TimeInput.js.map +1 -0
  187. package/dist/Tooltip.d.ts +11 -0
  188. package/dist/Tooltip.js +72 -0
  189. package/dist/Tooltip.js.map +1 -0
  190. package/dist/aria.d.ts +8 -0
  191. package/dist/aria.js +42 -0
  192. package/dist/aria.js.map +1 -0
  193. package/dist/guid.d.ts +1 -0
  194. package/dist/guid.js +7 -0
  195. package/dist/guid.js.map +1 -0
  196. package/dist/hash.d.ts +1 -0
  197. package/dist/hash.js +20 -0
  198. package/dist/hash.js.map +1 -0
  199. package/dist/index.d.ts +65 -0
  200. package/dist/index.js +66 -0
  201. package/dist/index.js.map +1 -0
  202. package/dist/jss.d.ts +110 -0
  203. package/dist/jss.js +438 -0
  204. package/dist/jss.js.map +1 -0
  205. package/dist/numberToBase.d.ts +1 -0
  206. package/dist/numberToBase.js +44 -0
  207. package/dist/numberToBase.js.map +1 -0
  208. package/dist/stateMachineContextFactory.d.ts +36 -0
  209. package/dist/stateMachineContextFactory.js +48 -0
  210. package/dist/stateMachineContextFactory.js.map +1 -0
  211. package/dist/useCookie.d.ts +9 -0
  212. package/dist/useCookie.js +65 -0
  213. package/dist/useCookie.js.map +1 -0
  214. package/dist/useKeyboard.d.ts +8 -0
  215. package/dist/useKeyboard.js +26 -0
  216. package/dist/useKeyboard.js.map +1 -0
  217. package/dist/useNavigation.d.ts +5 -0
  218. package/dist/useNavigation.js +79 -0
  219. package/dist/useNavigation.js.map +1 -0
  220. package/dist/usePromise.d.ts +1 -0
  221. package/dist/usePromise.js +12 -0
  222. package/dist/usePromise.js.map +1 -0
  223. package/dist/useRefEffect.d.ts +1 -0
  224. package/dist/useRefEffect.js +15 -0
  225. package/dist/useRefEffect.js.map +1 -0
  226. package/next-env.d.ts +5 -0
  227. package/next.config.js +21 -0
  228. package/package.json +40 -0
  229. package/scripts/publish.js +27 -0
  230. package/src/Badge.tsx +36 -0
  231. package/src/BaseButton.tsx +58 -0
  232. package/src/BaseInput.tsx +57 -0
  233. package/src/BaseLink.tsx +77 -0
  234. package/src/BaseList.tsx +29 -0
  235. package/src/BaseListAddOn.tsx +10 -0
  236. package/src/BaseListItem.tsx +117 -0
  237. package/src/BaseView.tsx +57 -0
  238. package/src/Box.tsx +20 -0
  239. package/src/Button.tsx +84 -0
  240. package/src/Calendar.tsx +125 -0
  241. package/src/Card.tsx +17 -0
  242. package/src/Checkbox.tsx +63 -0
  243. package/src/Circle.tsx +24 -0
  244. package/src/Column.tsx +12 -0
  245. package/src/DarkMode.tsx +99 -0
  246. package/src/DateInput.tsx +63 -0
  247. package/src/DatePicker.tsx +67 -0
  248. package/src/DatetimeInput.tsx +71 -0
  249. package/src/DesignBook.tsx +697 -0
  250. package/src/Dialog.tsx +144 -0
  251. package/src/Dropdown.tsx +129 -0
  252. package/src/Emitter.ts +26 -0
  253. package/src/FlexLayout.tsx +53 -0
  254. package/src/Icon.tsx +96 -0
  255. package/src/IconButton.tsx +66 -0
  256. package/src/IconLink.tsx +58 -0
  257. package/src/IconType.ts +787 -0
  258. package/src/Interactable.tsx +159 -0
  259. package/src/Link.tsx +86 -0
  260. package/src/List.tsx +41 -0
  261. package/src/ListButtonItem.tsx +69 -0
  262. package/src/ListDivider.tsx +13 -0
  263. package/src/ListHeaderItem.tsx +45 -0
  264. package/src/ListItem.tsx +27 -0
  265. package/src/ListLinkItem.tsx +76 -0
  266. package/src/ListSpacer.tsx +14 -0
  267. package/src/OnVisible.tsx +42 -0
  268. package/src/Popover.tsx +141 -0
  269. package/src/ProgressBar.tsx +63 -0
  270. package/src/ProgressCircle.tsx +38 -0
  271. package/src/Providers.tsx +33 -0
  272. package/src/RangeInput.tsx +82 -0
  273. package/src/ResultOrError.ts +15 -0
  274. package/src/RootView.tsx +55 -0
  275. package/src/Router.tsx +62 -0
  276. package/src/RouterState.tsx +154 -0
  277. package/src/Row.tsx +12 -0
  278. package/src/StackContext.tsx +52 -0
  279. package/src/StaticCheckbox.tsx +74 -0
  280. package/src/Storage.tsx +200 -0
  281. package/src/Stream.tsx +50 -0
  282. package/src/Sublist.tsx +62 -0
  283. package/src/SubmitIconInput.tsx +45 -0
  284. package/src/Tabs.tsx +103 -0
  285. package/src/Text.tsx +102 -0
  286. package/src/TextArea.tsx +45 -0
  287. package/src/TextInput.tsx +111 -0
  288. package/src/TextInputWithState.tsx +35 -0
  289. package/src/TextPairing.tsx +115 -0
  290. package/src/TimeInput.tsx +109 -0
  291. package/src/Tooltip.tsx +108 -0
  292. package/src/aria.ts +72 -0
  293. package/src/examples/ExampleDialog.tsx +28 -0
  294. package/src/guid.ts +7 -0
  295. package/src/hash.ts +21 -0
  296. package/src/index.ts +65 -0
  297. package/src/jss.tsx +607 -0
  298. package/src/numberToBase.ts +52 -0
  299. package/src/pages/Badge.mdx +30 -0
  300. package/src/pages/Button.mdx +57 -0
  301. package/src/pages/Calendar.mdx +60 -0
  302. package/src/pages/Checkbox.mdx +56 -0
  303. package/src/pages/Dialog.mdx +32 -0
  304. package/src/pages/FlexLayout.mdx +77 -0
  305. package/src/pages/Hashing.mdx +20 -0
  306. package/src/pages/Icon.mdx +63 -0
  307. package/src/pages/IconButton.mdx +144 -0
  308. package/src/pages/Link.mdx +57 -0
  309. package/src/pages/List.mdx +292 -0
  310. package/src/pages/ListHeader.mdx +94 -0
  311. package/src/pages/Popover.mdx +101 -0
  312. package/src/pages/ProgressBar.mdx +20 -0
  313. package/src/pages/ProgressCircle.mdx +35 -0
  314. package/src/pages/RangeInput.mdx +109 -0
  315. package/src/pages/Tabs.mdx +168 -0
  316. package/src/pages/Text.mdx +133 -0
  317. package/src/pages/TextInput.mdx +110 -0
  318. package/src/pages/TextPairing.mdx +155 -0
  319. package/src/pages/TimeInput.mdx +73 -0
  320. package/src/pages/Tooltip.mdx +28 -0
  321. package/src/pages/_app.tsx +561 -0
  322. package/src/pages/_document.tsx +30 -0
  323. package/src/pages/css-in-js.mdx +127 -0
  324. package/src/pages/index.mdx +58 -0
  325. package/src/pages/navigation.mdx +56 -0
  326. package/src/pages/prism.css +3 -0
  327. package/src/pages/useCookie.mdx +15 -0
  328. package/src/pages/useKeyboard.mdx +20 -0
  329. package/src/pages/useNavigation.mdx +30 -0
  330. package/src/pages/usePromise.mdx +15 -0
  331. package/src/pages/useRefEffect.mdx +49 -0
  332. package/src/stateMachineContextFactory.tsx +111 -0
  333. package/src/useCookie.tsx +89 -0
  334. package/src/useKeyboard.tsx +43 -0
  335. package/src/useNavigation.tsx +89 -0
  336. package/src/usePromise.tsx +18 -0
  337. package/src/useRefEffect.tsx +18 -0
  338. package/tsconfig.build.json +23 -0
  339. package/tsconfig.json +23 -0
@@ -0,0 +1,111 @@
1
+ import React, { ReactNode } from "react";
2
+ import { BaseInput, BaseInputProps } from "./BaseInput";
3
+ import { Row } from "./Row";
4
+ import { Gap, JSStyle, Padding, cssVar, getPadding } from "./jss";
5
+ import { Column } from "./Column";
6
+
7
+ export interface TextInputProps extends BaseInputProps {
8
+ onValueChange?: (value: string) => void;
9
+ rootJSStyle?: JSStyle;
10
+ addOn?: ReactNode;
11
+ addOnPosition?: "start" | "end";
12
+ gap?: Gap;
13
+ onChange?: undefined;
14
+ padding?: Padding;
15
+ bare?: boolean;
16
+ }
17
+
18
+ export const TextInput = React.forwardRef(
19
+ (
20
+ {
21
+ value,
22
+ onValueChange,
23
+ rootJSStyle,
24
+ jsStyle,
25
+ addOn,
26
+ gap = "small",
27
+ addOnPosition = "start",
28
+ padding = "medium",
29
+ bare,
30
+ ...inputProps
31
+ }: TextInputProps,
32
+ ref?: React.Ref<HTMLInputElement>
33
+ ) => {
34
+ return (
35
+ <Row
36
+ gap={gap}
37
+ jsStyle={[
38
+ {
39
+ borderRadius: cssVar("--border-radius-m"),
40
+ overflow: "hidden",
41
+ },
42
+ bare
43
+ ? {
44
+ backgroundColor: "inherit",
45
+ ":has(:focus-visible)": {
46
+ backgroundColor: cssVar("--light-highlight"),
47
+ },
48
+ }
49
+ : {
50
+ border: `1px solid ${cssVar("--divider")}`,
51
+ backgroundColor: cssVar("--overlay-background"),
52
+ ":has(:focus-visible)": {
53
+ outline: `2px solid ${cssVar("--highlight")}`,
54
+ outlineOffset: -2,
55
+ },
56
+ },
57
+ rootJSStyle,
58
+ ]}
59
+ >
60
+ {addOnPosition === "start" && addOn && (
61
+ <Column
62
+ justify="center"
63
+ align="center"
64
+ jsStyle={[getPadding(padding), { paddingRight: 0 }]}
65
+ >
66
+ {addOn}
67
+ </Column>
68
+ )}
69
+ <BaseInput
70
+ {...inputProps}
71
+ ref={ref}
72
+ value={value}
73
+ onChange={
74
+ onValueChange ? (e) => onValueChange(e.target.value) : undefined
75
+ }
76
+ jsStyle={[
77
+ {
78
+ minWidth: 0,
79
+ flexGrow: 1,
80
+ backgroundColor: "inherit",
81
+ color: cssVar("--primary-text"),
82
+ outline: "none",
83
+ border: "none",
84
+ fontSize: 20,
85
+ lineHeight: 24 / 20,
86
+ "::placeholder": {
87
+ color: cssVar("--subtle-text"),
88
+ },
89
+ ":disabled": {
90
+ color: cssVar("--subtle-text"),
91
+ },
92
+ },
93
+ getPadding(padding),
94
+ addOn && addOnPosition === "start" ? { paddingLeft: 0 } : null,
95
+ addOn && addOnPosition === "end" ? { paddingRight: 0 } : null,
96
+ jsStyle,
97
+ ]}
98
+ />
99
+ {addOnPosition === "end" && addOn && (
100
+ <Column
101
+ justify="center"
102
+ align="center"
103
+ jsStyle={[getPadding(padding), { paddingLeft: 0 }]}
104
+ >
105
+ {addOn}
106
+ </Column>
107
+ )}
108
+ </Row>
109
+ );
110
+ }
111
+ );
@@ -0,0 +1,35 @@
1
+ import React, { useCallback } from "react";
2
+
3
+ import { TextInput } from "./TextInput";
4
+ import { BaseInputProps } from "./BaseInput";
5
+ import { IconType } from "./IconType";
6
+ import { ReactNode, useState } from "react";
7
+
8
+ export interface TextInputWithStateProps extends BaseInputProps {
9
+ onValueChange?: (value: string) => void;
10
+ valueRef: React.MutableRefObject<string>;
11
+ icon?: IconType;
12
+ onChange?: undefined;
13
+ }
14
+
15
+ export function TextInputWithState({
16
+ valueRef,
17
+ onValueChange: externalOnChange,
18
+ icon,
19
+ ...otherProps
20
+ }: TextInputWithStateProps) {
21
+ const [value, setValue] = useState(valueRef.current);
22
+
23
+ const onValueChange = useCallback(
24
+ (value) => {
25
+ valueRef.current = value;
26
+ setValue(value);
27
+ externalOnChange && externalOnChange(value);
28
+ },
29
+ [setValue, externalOnChange, valueRef]
30
+ );
31
+
32
+ return (
33
+ <TextInput {...otherProps} value={value} onValueChange={onValueChange} />
34
+ );
35
+ }
@@ -0,0 +1,115 @@
1
+ import React, { ReactNode } from "react";
2
+
3
+ import { Text, TextType } from "./Text";
4
+ import { Row } from "./Row";
5
+ import { BaseView } from "./BaseView";
6
+ import { Column } from "./Column";
7
+ import {
8
+ TextColor,
9
+ Size,
10
+ Position,
11
+ Gap,
12
+ Padding,
13
+ Align,
14
+ cssVar,
15
+ JSStyle,
16
+ } from "./jss";
17
+
18
+ export interface TextPairingProps {
19
+ headline: ReactNode;
20
+ body?: ReactNode;
21
+ headlineColor?: TextColor;
22
+ headlineSize?: Size;
23
+ headlineAddOn?: ReactNode;
24
+ bodyColor?: TextColor;
25
+ bodySize?: Size;
26
+ addOn?: ReactNode;
27
+ addOnPosition?: Position;
28
+ gap?: Gap;
29
+ padding?: Padding;
30
+ align?: Align;
31
+ grow?: boolean;
32
+ shrink?: boolean;
33
+ headlineBold?: boolean;
34
+ jsStyle?: JSStyle;
35
+ }
36
+
37
+ export function TextPairing({
38
+ headline,
39
+ body,
40
+ headlineColor = "primary",
41
+ headlineSize = "medium",
42
+ headlineAddOn,
43
+ bodyColor = "secondary",
44
+ bodySize = "medium",
45
+ addOn,
46
+ addOnPosition = "start",
47
+ gap = "small",
48
+ align = "stretch",
49
+ grow,
50
+ shrink,
51
+ headlineBold,
52
+ padding,
53
+ jsStyle,
54
+ }: TextPairingProps) {
55
+ const textElement = (
56
+ <Column
57
+ grow={grow}
58
+ shrink={shrink}
59
+ padding={addOn ? undefined : padding}
60
+ align={align}
61
+ jsStyle={[
62
+ {
63
+ overflow: "hidden",
64
+ },
65
+ jsStyle,
66
+ ]}
67
+ >
68
+ <Row
69
+ align="center"
70
+ jsStyle={{
71
+ textAlign: "start",
72
+ }}
73
+ >
74
+ <Text bold={headlineBold} color={headlineColor} size={headlineSize}>
75
+ {headline}
76
+ </Text>
77
+ {headlineAddOn && <BaseView>{headlineAddOn}</BaseView>}
78
+ </Row>
79
+ {body && (
80
+ <Row
81
+ align="center"
82
+ jsStyle={{
83
+ marginTop: cssVar("--spacing-xs"),
84
+ textAlign: "start",
85
+ }}
86
+ >
87
+ <Text ellipsis={true} color={bodyColor} size={bodySize}>
88
+ {body}
89
+ </Text>
90
+ </Row>
91
+ )}
92
+ </Column>
93
+ );
94
+
95
+ if (addOn) {
96
+ return (
97
+ <Row
98
+ grow={grow}
99
+ shrink={shrink}
100
+ gap={gap}
101
+ align="center"
102
+ padding={padding}
103
+ jsStyle={{
104
+ overflow: "hidden",
105
+ }}
106
+ >
107
+ {addOnPosition === "start" && addOn}
108
+ {textElement}
109
+ {addOnPosition === "end" && addOn}
110
+ </Row>
111
+ );
112
+ }
113
+
114
+ return textElement;
115
+ }
@@ -0,0 +1,109 @@
1
+ import React, { ReactNode } from "react";
2
+ import { BaseInput, BaseInputProps } from "./BaseInput";
3
+ import { Row } from "./Row";
4
+ import { Gap, Padding, cssVar } from "./jss";
5
+
6
+ export interface TimeInputProps extends BaseInputProps {
7
+ onTimeChange: (date: Date) => void;
8
+ time: Date;
9
+ gap?: Gap;
10
+ padding?: Padding;
11
+ addOn?: ReactNode;
12
+ addOnPosition?: "start" | "end";
13
+ onChange?: undefined;
14
+ bare?: boolean;
15
+ }
16
+
17
+ export const timeFormatter = Intl.DateTimeFormat("en-UK", {
18
+ hour: "2-digit",
19
+ minute: "2-digit",
20
+ });
21
+
22
+ function TimeInputInternal(
23
+ {
24
+ time: date,
25
+ onTimeChange: onDateChange,
26
+ jsStyle,
27
+ addOn,
28
+ padding = "small",
29
+ gap = "none",
30
+ addOnPosition = "start",
31
+ bare,
32
+ ...inputProps
33
+ }: TimeInputProps,
34
+ ref?: React.Ref<HTMLInputElement>
35
+ ) {
36
+ return (
37
+ <Row
38
+ padding={padding}
39
+ gap={gap}
40
+ align="center"
41
+ jsStyle={[
42
+ {
43
+ borderRadius: cssVar("--border-radius-m"),
44
+ overflow: "hidden",
45
+ },
46
+ bare
47
+ ? {
48
+ backgroundColor: "inherit",
49
+ ":has(:focus-visible)": {
50
+ backgroundColor: cssVar("--light-highlight"),
51
+ },
52
+ }
53
+ : {
54
+ border: `1px solid ${cssVar("--divider")}`,
55
+ backgroundColor: cssVar("--overlay-background"),
56
+ ":has(:focus-visible)": {
57
+ outline: `2px solid ${cssVar("--highlight")}`,
58
+ outlineOffset: -2,
59
+ },
60
+ },
61
+ ]}
62
+ >
63
+ {addOnPosition === "start" && addOn}
64
+ <BaseInput
65
+ {...inputProps}
66
+ type="time"
67
+ ref={ref}
68
+ value={timeFormatter.format(date)}
69
+ onChange={(e) => {
70
+ const value = e.target.value;
71
+ const [hour, minute] = value.split(":");
72
+ onDateChange(
73
+ new Date(
74
+ date.getFullYear(),
75
+ date.getMonth(),
76
+ date.getDate(),
77
+ parseInt(hour),
78
+ parseInt(minute)
79
+ )
80
+ );
81
+ }}
82
+ jsStyle={[
83
+ {
84
+ flexGrow: 1,
85
+ backgroundColor: "inherit",
86
+ color: "var(--primary-text)",
87
+ outline: "none",
88
+ border: "none",
89
+ fontSize: 20,
90
+ lineHeight: 24 / 20,
91
+ "::placeholder": {
92
+ color: "var(--subtle-text);",
93
+ },
94
+ ":disabled": {
95
+ color: "var(--subtle-text);",
96
+ },
97
+ "::-webkit-calendar-picker-indicator": {
98
+ backgroundColor: "none",
99
+ },
100
+ },
101
+ jsStyle,
102
+ ]}
103
+ />
104
+ {addOnPosition === "end" && addOn}
105
+ </Row>
106
+ );
107
+ }
108
+
109
+ export const TimeInput = React.forwardRef(TimeInputInternal);
@@ -0,0 +1,108 @@
1
+ import React, { useRef, useState } from "react";
2
+
3
+ import { BaseView } from "./BaseView";
4
+ import { useRefEffect } from "./useRefEffect";
5
+ import { Text } from "./Text";
6
+ import { JSStyle, cssVar, jss } from "./jss";
7
+
8
+ const jsStyles: { [key: string]: JSStyle } = {
9
+ tooltip: {
10
+ top: "-100%",
11
+ transform: "translateY(50%)",
12
+ backgroundColor: cssVar("--primary-background"),
13
+ padding: cssVar("--spacing-s"),
14
+ borderRadius: cssVar("--border-radius-m"),
15
+ border: `1px solid ${cssVar("--divider")}`,
16
+ boxShadow: `0px 1px 2px ${cssVar("--divider")}`,
17
+ overflow: "hidden",
18
+ },
19
+ };
20
+
21
+ interface TooltipProps {
22
+ content: string;
23
+ jsStyle?: JSStyle;
24
+ className?: undefined;
25
+ tag?: keyof HTMLElementTagNameMap;
26
+ children: JSX.Element;
27
+ }
28
+
29
+ export function Tooltip({ content, jsStyle, tag, children }: TooltipProps) {
30
+ const [tooltip, setTooltip] = useState<JSX.Element>(null);
31
+ const dialogRef = useRef(null);
32
+ const focusTrapRoot = useRefEffect((root: HTMLDialogElement) => {
33
+ dialogRef.current = root;
34
+
35
+ const keydown = (e) => {
36
+ if (e.key === "Escape") {
37
+ dialogRef.current?.close();
38
+ } else if (e.key === "Tab") {
39
+ dialogRef.current?.close();
40
+ }
41
+ };
42
+
43
+ const click = () => {
44
+ dialogRef.current?.close();
45
+ };
46
+
47
+ window.addEventListener("keydown", keydown);
48
+ window.addEventListener("click", click);
49
+
50
+ const activeElement = document.activeElement;
51
+ root.show();
52
+ // @ts-ignore
53
+ activeElement.focus();
54
+
55
+ return () => {
56
+ window.removeEventListener("keydown", keydown);
57
+ window.removeEventListener("click", click);
58
+ };
59
+ });
60
+
61
+ const toggle = () => {
62
+ if (tooltip == null) {
63
+ setTooltip(
64
+ <dialog
65
+ ref={(ref: null | HTMLDialogElement) => {
66
+ dialogRef.current = ref;
67
+ focusTrapRoot(ref);
68
+ }}
69
+ className={jss(jsStyles.tooltip)}
70
+ onClose={() => {
71
+ setTooltip(null);
72
+ }}
73
+ onClick={(e) => {
74
+ e.preventDefault();
75
+ e.stopPropagation();
76
+ }}
77
+ >
78
+ <Text size="medium" color="secondary">
79
+ {content}
80
+ </Text>
81
+ </dialog>
82
+ );
83
+ } else {
84
+ setTooltip(null);
85
+ }
86
+ };
87
+
88
+ return (
89
+ <BaseView
90
+ tag={tag}
91
+ relative={true}
92
+ jsStyle={[{ display: "inline-block" }, jsStyle]}
93
+ onMouseEnter={() => {
94
+ if (tooltip == null) {
95
+ toggle();
96
+ }
97
+ }}
98
+ onMouseLeave={() => {
99
+ if (tooltip != null) {
100
+ toggle();
101
+ }
102
+ }}
103
+ >
104
+ {children}
105
+ {tooltip}
106
+ </BaseView>
107
+ );
108
+ }
package/src/aria.ts ADDED
@@ -0,0 +1,72 @@
1
+ type Focusable = HTMLElement;
2
+
3
+ export function queryFocusables(root: HTMLElement): Focusable[] {
4
+ const focusables: Focusable[] = Array.from(
5
+ root.querySelectorAll(
6
+ "button,input,textarea,a,[tabindex='0'],[tabindex='-1']"
7
+ )
8
+ );
9
+
10
+ return focusables.filter((element: Focusable) => !element["disabled"]);
11
+ }
12
+
13
+ export function queryGrid(root: HTMLElement): HTMLElement[][] {
14
+ const rows: HTMLLIElement[] = Array.from(
15
+ root.querySelectorAll('li[role="row"]')
16
+ );
17
+
18
+ const rowsWithColumns = rows
19
+ .map((row) => Array.from(queryFocusables(row)))
20
+ .filter((row) => row.length > 0);
21
+
22
+ return rowsWithColumns;
23
+ }
24
+
25
+ export const normalizeGrid = (
26
+ rows: HTMLElement[][],
27
+ rowIndex: number,
28
+ columnIndex: number
29
+ ): void => {
30
+ for (const row of rows) {
31
+ for (const column of row) {
32
+ column.tabIndex = -1;
33
+ }
34
+ }
35
+
36
+ const row = rows[rowIndex];
37
+ const column = row[columnIndex] ?? row[row.length - 1];
38
+ column.tabIndex = 0;
39
+ };
40
+
41
+ export const focusGridElement = (
42
+ rows: HTMLElement[][],
43
+ rowIndex: number,
44
+ columnIndex: number
45
+ ): void => {
46
+ normalizeGrid(rows, rowIndex, columnIndex);
47
+ const row = rows[rowIndex];
48
+ const column = row[columnIndex] ?? row[row.length - 1];
49
+ column.focus();
50
+ column.scrollIntoView(false);
51
+ };
52
+
53
+ export const normalizeElements = (
54
+ focusables: HTMLElement[],
55
+ index: number
56
+ ): void => {
57
+ for (const element of focusables) {
58
+ element.tabIndex = -1;
59
+ }
60
+ const element = focusables[index] ?? focusables[focusables.length - 1];
61
+ element.tabIndex = 0;
62
+ };
63
+
64
+ export const focusElement = (
65
+ focusables: HTMLElement[],
66
+ index: number
67
+ ): void => {
68
+ normalizeElements(focusables, index);
69
+ const element = focusables[index] ?? focusables[focusables.length - 1];
70
+ element.focus();
71
+ // element.scrollIntoView(false);
72
+ };
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ import { DarkModeToggle } from "../DarkMode";
3
+ import { Row } from "../Row";
4
+ import { Dialog, useDialog } from "../Dialog";
5
+ import { Button } from "../Button";
6
+ import { Span } from "../Text";
7
+
8
+ function ExampleDialog({ close }) {
9
+ return (
10
+ <Dialog close={close} label="Example">
11
+ <Row padding="medium" align="center" justify="space-between">
12
+ <Span>Dark mode</Span>
13
+ <DarkModeToggle />
14
+ </Row>
15
+ </Dialog>
16
+ );
17
+ }
18
+
19
+ export function DialogTrigger() {
20
+ const { open } = useDialog<void>(
21
+ ({ close }) => <ExampleDialog close={close} />,
22
+ { closeOnOutsideClick: true }
23
+ );
24
+
25
+ return (
26
+ <Button label="Show dialog" color={"positive"} onClick={() => open()} />
27
+ );
28
+ }
package/src/guid.ts ADDED
@@ -0,0 +1,7 @@
1
+ export function guid(): string {
2
+ return "ID-xxxxxxxx".replace(/[xy]/g, function (c) {
3
+ const r = (Math.random() * 16) | 0,
4
+ v = c === "x" ? r : (r & 0x3) | 0x8;
5
+ return v.toString(16);
6
+ });
7
+ }
package/src/hash.ts ADDED
@@ -0,0 +1,21 @@
1
+ export function hash(source: string, modulus?: number): number {
2
+ let hash = 0;
3
+ let i: number;
4
+ let chr: number;
5
+
6
+ if (source.length === 0) {
7
+ return hash;
8
+ }
9
+
10
+ for (i = 0; i < source.length; i++) {
11
+ chr = source.charCodeAt(i);
12
+ hash = (hash << 5) - hash + chr;
13
+ hash |= 0; // Convert to 32bit integer
14
+ }
15
+
16
+ if (modulus) {
17
+ return Math.abs(hash) % modulus;
18
+ } else {
19
+ return Math.abs(hash);
20
+ }
21
+ }
package/src/index.ts ADDED
@@ -0,0 +1,65 @@
1
+ export * from "./aria";
2
+ export * from "./Badge";
3
+ export * from "./BaseButton";
4
+ export * from "./BaseInput";
5
+ export * from "./BaseLink";
6
+ export * from "./BaseList";
7
+ export * from "./BaseListAddOn";
8
+ export * from "./BaseListItem";
9
+ export * from "./BaseView";
10
+ export * from "./Box";
11
+ export * from "./Button";
12
+ export * from "./Calendar";
13
+ export * from "./Checkbox";
14
+ export * from "./Circle";
15
+ export * from "./Column";
16
+ export * from "./DarkMode";
17
+ export * from "./DateInput";
18
+ export * from "./DatePicker";
19
+ export * from "./DatetimeInput";
20
+ export * from "./Dialog";
21
+ export * from "./Dropdown";
22
+ export * from "./Emitter";
23
+ export * from "./FlexLayout";
24
+ export * from "./guid";
25
+ export * from "./Icon";
26
+ export * from "./IconButton";
27
+ export * from "./IconLink";
28
+ export * from "./IconType";
29
+ export * from "./jss";
30
+ export * from "./Link";
31
+ export * from "./List";
32
+ export * from "./ListButtonItem";
33
+ export * from "./ListDivider";
34
+ export * from "./ListHeaderItem";
35
+ export * from "./ListItem";
36
+ export * from "./ListLinkItem";
37
+ export * from "./ListSpacer";
38
+ export * from "./numberToBase";
39
+ export * from "./OnVisible";
40
+ export * from "./Popover";
41
+ export * from "./ProgressBar";
42
+ export * from "./ProgressCircle";
43
+ export * from "./Providers";
44
+ export * from "./RangeInput";
45
+ export * from "./RootView";
46
+ export * from "./Row";
47
+ export * from "./StackContext";
48
+ export * from "./stateMachineContextFactory";
49
+ export * from "./StaticCheckbox";
50
+ export * from "./Storage";
51
+ export * from "./Stream";
52
+ export * from "./Sublist";
53
+ export * from "./SubmitIconInput";
54
+ export * from "./Tabs";
55
+ export * from "./Text";
56
+ export * from "./TextArea";
57
+ export * from "./TextInput";
58
+ export * from "./TextInputWithState";
59
+ export * from "./TextPairing";
60
+ export * from "./TimeInput";
61
+ export * from "./TimeInput";
62
+ export * from "./useCookie";
63
+ export * from "./useNavigation";
64
+ export * from "./usePromise";
65
+ export * from "./useRefEffect";