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,141 @@
1
+ import React, { useRef, useState } from "react";
2
+ import { queryFocusables } from "./aria";
3
+
4
+ import { BaseView } from "./BaseView";
5
+ import { useRefEffect } from "./useRefEffect";
6
+ import { JSStyle, jss } from "./jss";
7
+
8
+ const jsStyles: { [key: string]: JSStyle } = {
9
+ popover: {
10
+ padding: 0,
11
+ zIndex: 1,
12
+ backgroundColor: "var(--primary-background)",
13
+ borderRadius: "var(--border-radius-m)",
14
+ border: "1px solid var(--divider)",
15
+ overflow: "hidden",
16
+ },
17
+ };
18
+
19
+ export function Popover({ children, close }) {
20
+ const activeElementRef = useRef(null);
21
+
22
+ const focusTrapRoot = useRefEffect((root: HTMLElement) => {
23
+ activeElementRef.current = document.activeElement;
24
+ const [element] = queryFocusables(root);
25
+ element ? element.focus() : root.focus();
26
+
27
+ const keydown = (e) => {
28
+ if (e.key === "Escape") {
29
+ close();
30
+ } else if (e.key === "Tab") {
31
+ const focusables = queryFocusables(root).filter(
32
+ (element) => element.tabIndex !== -1
33
+ );
34
+
35
+ if (focusables.length === 0) {
36
+ e.stopPropagation();
37
+ e.preventDefault();
38
+ }
39
+
40
+ const focusedIndex = focusables.findIndex(
41
+ (x) => x === document.activeElement
42
+ );
43
+
44
+ if (focusables.length === 0) {
45
+ e.stopPropagation();
46
+ e.preventDefault();
47
+ } else if (focusedIndex === focusables.length - 1) {
48
+ // Cycle back to the first element
49
+ focusables[0].focus();
50
+ e.stopPropagation();
51
+ e.preventDefault();
52
+ } else {
53
+ // Just do the usual thing
54
+ }
55
+ }
56
+ };
57
+
58
+ const click = () => {
59
+ close();
60
+ };
61
+
62
+ // This is needed so that the trigger click is not captured immediatly, which would close the popover as it opens
63
+ setTimeout(() => {
64
+ window.addEventListener("keydown", keydown);
65
+ window.addEventListener("click", click);
66
+ }, 0);
67
+
68
+ return () => {
69
+ activeElementRef.current && activeElementRef.current.focus();
70
+ window.removeEventListener("keydown", keydown);
71
+ window.removeEventListener("click", click);
72
+ };
73
+ });
74
+
75
+ return <BaseView ref={focusTrapRoot}>{children}</BaseView>;
76
+ }
77
+
78
+ interface PopoverTriggerProps<Input> {
79
+ PopoverComponent: (props: { close: () => void } & Input) => JSX.Element;
80
+ jsStyle?: JSStyle;
81
+ className?: undefined;
82
+ grow?: boolean;
83
+ shrink?: boolean;
84
+ tag?: keyof HTMLElementTagNameMap;
85
+ children: (props: { toggle: (input: Input) => void }) => JSX.Element;
86
+ }
87
+
88
+ export function PopoverTrigger<Input>({
89
+ PopoverComponent,
90
+ jsStyle,
91
+ grow,
92
+ shrink,
93
+ tag,
94
+ children,
95
+ }: PopoverTriggerProps<Input>) {
96
+ const [popover, setPopover] = useState<JSX.Element>(null);
97
+ const dialogRef = useRef<null | HTMLDialogElement>(null);
98
+
99
+ const toggle = (input: Input) => {
100
+ if (popover == null) {
101
+ dialogRef && dialogRef.current.show();
102
+ setPopover(
103
+ <PopoverComponent
104
+ {...input}
105
+ close={() => {
106
+ dialogRef && dialogRef.current.close();
107
+ }}
108
+ />
109
+ );
110
+ } else {
111
+ dialogRef && dialogRef.current.close();
112
+ }
113
+ };
114
+
115
+ return (
116
+ <BaseView
117
+ grow={grow}
118
+ shrink={shrink}
119
+ tag={tag}
120
+ relative={true}
121
+ jsStyle={[jsStyle, { position: "relative", display: "inline-block" }]}
122
+ >
123
+ {children({ toggle })}
124
+ <dialog
125
+ ref={(ref: null | HTMLDialogElement) => {
126
+ dialogRef.current = ref;
127
+ }}
128
+ className={jss(jsStyles.popover)}
129
+ onClose={() => {
130
+ setPopover(null);
131
+ }}
132
+ onClick={(e) => {
133
+ e.preventDefault();
134
+ e.stopPropagation();
135
+ }}
136
+ >
137
+ {popover}
138
+ </dialog>
139
+ </BaseView>
140
+ );
141
+ }
@@ -0,0 +1,63 @@
1
+ import React from "react";
2
+ import { BaseView } from "./BaseView";
3
+ import { Color, Size, JSStyle, getBackground } from "./jss";
4
+
5
+ const jsStyles: { [key: string]: JSStyle } = {
6
+ root: {
7
+ width: "100%",
8
+ display: "flex",
9
+ position: "relative",
10
+ backgroundColor: "var(--primary-background)",
11
+ borderRadius: "var(--border-radius-s)",
12
+ border: "1px solid var(--divider)",
13
+ overflow: "hidden",
14
+ },
15
+ fill: {
16
+ borderRadius: "var(--border-radius-s)",
17
+ position: "absolute",
18
+ transformOrigin: "center left",
19
+ top: 0,
20
+ bottom: 0,
21
+ left: 0,
22
+ right: 0,
23
+ },
24
+ };
25
+
26
+ const sizes = {
27
+ xsmall: 4,
28
+ small: 8,
29
+ medium: 12,
30
+ large: 16,
31
+ xlarge: 20,
32
+ };
33
+
34
+ export function ProgressBar({
35
+ color,
36
+ progress,
37
+ size,
38
+ jsStyle,
39
+ }: {
40
+ progress: number;
41
+ color: Color;
42
+ size: Size;
43
+ jsStyle?: JSStyle;
44
+ }) {
45
+ return (
46
+ <BaseView
47
+ jsStyle={[
48
+ jsStyles.root,
49
+ {
50
+ height: sizes[size],
51
+ },
52
+ jsStyle,
53
+ ]}
54
+ >
55
+ <BaseView
56
+ jsStyle={[jsStyles.fill, getBackground(color)]}
57
+ style={{
58
+ transform: `scaleX(${progress > 1 ? 1 : progress})`,
59
+ }}
60
+ />
61
+ </BaseView>
62
+ );
63
+ }
@@ -0,0 +1,38 @@
1
+ import React from "react";
2
+ import { cssVar, jss } from "./jss";
3
+
4
+ export function ProgressCircle({
5
+ progress,
6
+ stroke = 4,
7
+ outerRadius,
8
+ }: {
9
+ progress: number;
10
+ stroke?: number;
11
+ outerRadius: number;
12
+ }) {
13
+ const circumference = outerRadius * 2 * Math.PI;
14
+ const strokeDashoffset = circumference - progress * circumference;
15
+
16
+ return (
17
+ <svg
18
+ className={jss({
19
+ backgroundColor: cssVar("--secondary-background"),
20
+ transform: "rotate(-90deg)",
21
+ borderRadius: "50%",
22
+ })}
23
+ width={(outerRadius + stroke) * 2}
24
+ height={(outerRadius + stroke) * 2}
25
+ >
26
+ <circle
27
+ stroke="var(--highlight)"
28
+ fill="transparent"
29
+ strokeWidth={stroke}
30
+ strokeDasharray={`${circumference} ${circumference}`}
31
+ style={{ strokeDashoffset }}
32
+ r={outerRadius}
33
+ cx={outerRadius + stroke}
34
+ cy={outerRadius + stroke}
35
+ />
36
+ </svg>
37
+ );
38
+ }
@@ -0,0 +1,33 @@
1
+ import React, { ReactElement, useEffect } from "react";
2
+ import { DarkModeProvider } from "./DarkMode";
3
+ import { DialogProvider } from "./Dialog";
4
+ import { IconProvider } from "./Icon";
5
+ import { useCookie } from "./useCookie";
6
+ import { JSStylesProvider, Theme } from "./jss";
7
+
8
+ export function Providers({
9
+ children,
10
+ themes,
11
+ }: {
12
+ children: JSX.Element;
13
+ themes: { light: Theme; dark: Theme };
14
+ }) {
15
+ const [darkModeEnabled, setDarkModeEnabled] = useCookie("dark-mode", {
16
+ initialValue: false,
17
+ loadingValue: false,
18
+ });
19
+ const toggleDarkMode = React.useCallback(
20
+ () => setDarkModeEnabled((x) => !x),
21
+ []
22
+ );
23
+
24
+ return (
25
+ <JSStylesProvider themes={themes}>
26
+ <IconProvider>
27
+ <DarkModeProvider enabled={darkModeEnabled} toggle={toggleDarkMode}>
28
+ <DialogProvider>{children}</DialogProvider>
29
+ </DarkModeProvider>
30
+ </IconProvider>
31
+ </JSStylesProvider>
32
+ );
33
+ }
@@ -0,0 +1,82 @@
1
+ import React from "react";
2
+ import { BaseInput, BaseInputProps } from "./BaseInput";
3
+ import { Row } from "./Row";
4
+ import { Gap, JSStyle, Padding, cssVar } from "./jss";
5
+
6
+ export interface RangeInputProps extends BaseInputProps {
7
+ onValueChange: (value: number) => void;
8
+ value: number;
9
+ rootJSStyle?: JSStyle;
10
+ onChange?: undefined;
11
+ padding?: Padding;
12
+ gap?: Gap;
13
+ addOn?: JSX.Element;
14
+ addOnPosition?: "start" | "end";
15
+ }
16
+
17
+ export const RangeInput = React.forwardRef(
18
+ (
19
+ {
20
+ value,
21
+ onValueChange,
22
+ rootJSStyle,
23
+ jsStyle,
24
+ gap = "medium",
25
+ padding = "none",
26
+ min = 0,
27
+ max = 100,
28
+ step = 1,
29
+ label,
30
+ addOn,
31
+ addOnPosition = "start",
32
+ ...inputProps
33
+ }: RangeInputProps,
34
+ ref?: React.Ref<HTMLInputElement>
35
+ ) => {
36
+ return (
37
+ <Row
38
+ gap={gap}
39
+ padding={padding}
40
+ align="center"
41
+ jsStyle={[
42
+ {
43
+ ":has(:focus-visible)": {
44
+ borderRadius: cssVar("--border-radius-m"),
45
+ backgroundColor: cssVar("--light-highlight"),
46
+ },
47
+ },
48
+ rootJSStyle,
49
+ ]}
50
+ >
51
+ {addOnPosition === "start" && addOn}
52
+ <BaseInput
53
+ {...inputProps}
54
+ label={label}
55
+ min={min}
56
+ max={max}
57
+ type="range"
58
+ ref={ref}
59
+ value={value}
60
+ onChange={(e) => {
61
+ onValueChange(parseFloat(e.target.value));
62
+ }}
63
+ jsStyle={[
64
+ {
65
+ backgroundColor: cssVar("--primary-background"),
66
+ flexGrow: 1,
67
+ color: cssVar("--primary-text"),
68
+ margin: 0,
69
+ paddingTop: cssVar("--spacing-m"),
70
+ paddingBottom: cssVar("--spacing-m"),
71
+ ":disabled": {
72
+ color: cssVar("--subtle-text"),
73
+ },
74
+ },
75
+ jsStyle,
76
+ ]}
77
+ />
78
+ {addOnPosition === "end" && addOn}
79
+ </Row>
80
+ );
81
+ }
82
+ );
@@ -0,0 +1,15 @@
1
+ export type Result<T> = { success: true; value: T };
2
+ export type Error<T> = { success: false; error: T };
3
+ export type ResultOrError<R, E> = Result<R> | Error<E>;
4
+
5
+ export function makeResult<T>(t: void): Result<void>;
6
+ export function makeResult<T>(t: T): Result<T>;
7
+ export function makeResult<T>(t: T): Result<T> {
8
+ return { success: true, value: t };
9
+ }
10
+
11
+ export function makeError<T>(t: void): Error<void>;
12
+ export function makeError<T>(t: T): Error<T>;
13
+ export function makeError<T>(t: T): Error<T> {
14
+ return { success: false, error: t };
15
+ }
@@ -0,0 +1,55 @@
1
+ import React, { ReactNode, useRef, useCallback } from "react";
2
+
3
+ import { Column } from "./Column";
4
+ import { useIsTopOfStack } from "./StackContext";
5
+ import { queryFocusables } from "./aria";
6
+ import { cssVar } from "./jss";
7
+
8
+ export function RootView({
9
+ children,
10
+ focusOnlyOnFirstMount = true,
11
+ }: {
12
+ children: ReactNode;
13
+ focusOnlyOnFirstMount?: boolean;
14
+ }) {
15
+ const isTopOfStack = useIsTopOfStack();
16
+ const firstMountRef = useRef(true);
17
+ const refCallback = useCallback(
18
+ (element) => {
19
+ if (!element) {
20
+ return;
21
+ }
22
+
23
+ if (!isTopOfStack) {
24
+ return;
25
+ }
26
+
27
+ if (focusOnlyOnFirstMount && !firstMountRef.current) {
28
+ return;
29
+ }
30
+
31
+ const focusables = queryFocusables(element);
32
+ const firstFocusable = focusables[0];
33
+ firstMountRef.current = false;
34
+ firstFocusable && firstFocusable.focus();
35
+ },
36
+ [isTopOfStack, focusOnlyOnFirstMount]
37
+ );
38
+
39
+ return (
40
+ <Column
41
+ ref={refCallback}
42
+ jsStyle={{
43
+ marginBottom: 0,
44
+ flexGrow: 1,
45
+ flexShrink: 1,
46
+ flexBasis: "0%",
47
+ overflow: "auto",
48
+ backgroundColor: cssVar("--secondary-background"),
49
+ minHeight: "600px",
50
+ }}
51
+ >
52
+ {children}
53
+ </Column>
54
+ );
55
+ }
package/src/Router.tsx ADDED
@@ -0,0 +1,62 @@
1
+ import React, { Suspense } from "react";
2
+
3
+ import { StackContextProvider } from "./StackContext";
4
+ import { Column } from "./Column";
5
+ import { ListDivider } from "./ListDivider";
6
+ import { BaseView } from "./BaseView";
7
+ import { useRouterState } from "./RouterState";
8
+ import { JSStyle } from "./jss";
9
+
10
+ const jsStyles: { [key: string]: JSStyle } = {
11
+ root: {
12
+ display: "flex",
13
+ flexDirection: "column",
14
+ flexGrow: 1,
15
+ minHeight: 0,
16
+ flexShrink: 1,
17
+ flexBasis: "0%",
18
+ position: "relative",
19
+ },
20
+ route: {
21
+ display: "flex",
22
+ flexDirection: "column",
23
+ flexGrow: 1,
24
+ minHeight: 0,
25
+ flexShrink: 1,
26
+ flexBasis: "0%",
27
+ },
28
+ hidden: {
29
+ display: "none",
30
+ },
31
+ };
32
+
33
+ export function Router() {
34
+ const {
35
+ context: { navigationStack },
36
+ } = useRouterState();
37
+
38
+ return (
39
+ <BaseView jsStyle={jsStyles.root}>
40
+ {navigationStack.map(({ route, routeProps }, index, list) => {
41
+ const isTopOfStack = index === list.length - 1;
42
+
43
+ return (
44
+ <StackContextProvider
45
+ key={route.title(routeProps)}
46
+ isTopOfStack={isTopOfStack}
47
+ >
48
+ <Column
49
+ jsStyle={[jsStyles.route, !isTopOfStack && jsStyles.hidden]}
50
+ aria-hidden={!isTopOfStack}
51
+ >
52
+ <ListDivider />
53
+ <Suspense fallback={null}>
54
+ <route.root {...routeProps} />
55
+ </Suspense>
56
+ </Column>
57
+ </StackContextProvider>
58
+ );
59
+ })}
60
+ </BaseView>
61
+ );
62
+ }
@@ -0,0 +1,154 @@
1
+ import { useEffect, useState, ComponentType } from "react";
2
+
3
+ import {
4
+ stateMachineContextFactory,
5
+ Reducer,
6
+ } from "./stateMachineContextFactory";
7
+
8
+ import { DesignBook } from "./DesignBook";
9
+
10
+ export enum RouteState {
11
+ Menu = "Menu",
12
+ DesignBook = "DesignBook",
13
+ Encounter = "Encounter",
14
+ }
15
+
16
+ export enum RouteTransition {
17
+ Pop = "Pop",
18
+ ToDesignBook = "ToDesignBook",
19
+ ToEncounter = "ToEncounter",
20
+ }
21
+
22
+ type Context = {
23
+ navigationStack: Array<StackNode<any>>;
24
+ };
25
+
26
+ type StackNode<Props> = {
27
+ route: Route<Props, any>;
28
+ routeProps: Props;
29
+ };
30
+
31
+ type Route<Props, State extends RouteState> = {
32
+ state: State;
33
+ title: (props: Props) => string;
34
+ root: ComponentType<Props>;
35
+ };
36
+
37
+ // const MenuRoute: Route<{}, RouteState.Menu> = {
38
+ // state: RouteState.Menu,
39
+ // title: () => "Menu",
40
+ // root: Menu,
41
+ // };
42
+
43
+ const DesignBookRoute: Route<{}, RouteState.DesignBook> = {
44
+ state: RouteState.DesignBook,
45
+ title: () => "DesignBook",
46
+ root: DesignBook,
47
+ };
48
+
49
+ const INITIAL_CONTEXT: Context = {
50
+ navigationStack: [{ route: DesignBookRoute, routeProps: {} }],
51
+ };
52
+
53
+ const pop: Reducer<RouteState, Context> = ({ state, context }) => {
54
+ if (context.navigationStack.length > 1) {
55
+ const navigationStack = [...context.navigationStack];
56
+ navigationStack.pop();
57
+ const finalState = navigationStack[navigationStack.length - 1].route.state;
58
+
59
+ return {
60
+ state: finalState,
61
+ context: {
62
+ ...context,
63
+ navigationStack,
64
+ },
65
+ };
66
+ }
67
+
68
+ return { state, context };
69
+ };
70
+
71
+ const pushFactory =
72
+ <Props, State extends RouteState>(
73
+ route: Route<Props, State>
74
+ ): Reducer<RouteState, Context> =>
75
+ ({ context, data }) => {
76
+ return {
77
+ state: route.state,
78
+ context: {
79
+ ...context,
80
+ navigationStack: [
81
+ ...context.navigationStack,
82
+ {
83
+ route,
84
+ routeProps: data,
85
+ },
86
+ ],
87
+ },
88
+ };
89
+ };
90
+
91
+ const replaceFactory =
92
+ <Props, State extends RouteState>(
93
+ route: Route<Props, State>
94
+ ): Reducer<RouteState, Context> =>
95
+ ({ context, data }) => {
96
+ return {
97
+ state: route.state,
98
+ context: {
99
+ ...context,
100
+ navigationStack: [
101
+ ...context.navigationStack.slice(0, -1),
102
+ {
103
+ route,
104
+ routeProps: data,
105
+ },
106
+ ],
107
+ },
108
+ };
109
+ };
110
+
111
+ const stateMachine = {
112
+ states: {
113
+ [RouteState.Menu]: {
114
+ on: {
115
+ ToDesignBook: pushFactory(DesignBookRoute),
116
+ },
117
+ },
118
+ [RouteState.Encounter]: {
119
+ on: {
120
+ Pop: pop,
121
+ },
122
+ },
123
+ [RouteState.DesignBook]: {
124
+ on: {
125
+ Pop: pop,
126
+ },
127
+ },
128
+ },
129
+ state: RouteState.Menu,
130
+ context: INITIAL_CONTEXT,
131
+ };
132
+
133
+ export const { Provider, useStateMachine } =
134
+ stateMachineContextFactory(stateMachine);
135
+
136
+ export const useRouterState = () => {
137
+ const [state, setState] = useState<{ state: RouteState; context: Context }>({
138
+ state: RouteState.Menu,
139
+ context: INITIAL_CONTEXT,
140
+ });
141
+ const { subscribe } = useStateMachine();
142
+
143
+ useEffect(() => {
144
+ return subscribe(setState);
145
+ }, [subscribe]);
146
+
147
+ return state;
148
+ };
149
+
150
+ export const useRouterSend = () => {
151
+ const { send } = useStateMachine();
152
+
153
+ return send;
154
+ };
package/src/Row.tsx ADDED
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { FlexLayout, FlexLayoutProps } from "./FlexLayout";
3
+
4
+ export interface RowProps extends FlexLayoutProps {
5
+ direction?: "row";
6
+ }
7
+
8
+ export const Row = React.forwardRef(
9
+ (props: RowProps, ref?: React.Ref<HTMLElement>) => {
10
+ return <FlexLayout ref={ref} direction="row" {...props} />;
11
+ }
12
+ );
@@ -0,0 +1,52 @@
1
+ import React, {
2
+ useContext,
3
+ useState,
4
+ ReactNode,
5
+ useMemo,
6
+ useRef,
7
+ useEffect,
8
+ } from "react";
9
+ import { createEmitter, Subscribe } from "./Emitter";
10
+
11
+ type State = {
12
+ subscribe: Subscribe<boolean>;
13
+ };
14
+
15
+ const StackContext = React.createContext<State>({
16
+ subscribe: () => {
17
+ return () => {};
18
+ },
19
+ });
20
+
21
+ type Props = {
22
+ children: ReactNode;
23
+ isTopOfStack: boolean;
24
+ };
25
+
26
+ export function StackContextProvider({ children, isTopOfStack }: Props) {
27
+ const emitterRef = useRef(createEmitter<boolean>());
28
+
29
+ useEffect(() => {
30
+ emitterRef.current.emit(isTopOfStack);
31
+ }, [isTopOfStack]);
32
+
33
+ const value = useMemo(
34
+ () => ({ subscribe: emitterRef.current.subscribe }),
35
+ []
36
+ );
37
+
38
+ return (
39
+ <StackContext.Provider value={value}>{children}</StackContext.Provider>
40
+ );
41
+ }
42
+
43
+ export function useIsTopOfStack() {
44
+ const [isTopOfStack, setIsTopOfStack] = useState<boolean>(true);
45
+ const { subscribe } = useContext(StackContext);
46
+
47
+ useEffect(() => {
48
+ return subscribe(setIsTopOfStack);
49
+ }, [subscribe]);
50
+
51
+ return isTopOfStack;
52
+ }