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,57 @@
1
+ import React from "react";
2
+ import { JSStyle, jss } from "./jss";
3
+
4
+ const jsStyles: { [key: string]: JSStyle } = {
5
+ relative: {
6
+ position: "relative",
7
+ },
8
+ grow: {
9
+ flexGrow: 1,
10
+ },
11
+ shrink: {
12
+ flexShrink: 1,
13
+ },
14
+ };
15
+
16
+ export interface BaseViewProps extends React.HTMLAttributes<HTMLElement> {
17
+ jsStyle?: JSStyle;
18
+ ref?: React.Ref<HTMLDivElement>;
19
+ className?: undefined;
20
+ grow?: boolean;
21
+ shrink?: boolean;
22
+ relative?: boolean;
23
+ tag?: keyof HTMLElementTagNameMap;
24
+ }
25
+
26
+ export const BaseView = React.forwardRef(
27
+ (
28
+ {
29
+ jsStyle,
30
+ children,
31
+ tag,
32
+ grow,
33
+ shrink,
34
+ relative,
35
+ ...otherProps
36
+ }: BaseViewProps,
37
+ ref?: React.Ref<HTMLElement>
38
+ ) => {
39
+ const Tag: string = tag ?? "div";
40
+
41
+ return (
42
+ // @ts-ignore
43
+ <Tag
44
+ ref={ref}
45
+ className={jss([
46
+ jsStyle,
47
+ grow && jsStyles.grow,
48
+ shrink && jsStyles.shrink,
49
+ relative && jsStyles.relative,
50
+ ])}
51
+ {...otherProps}
52
+ >
53
+ {children}
54
+ </Tag>
55
+ );
56
+ }
57
+ );
package/src/Box.tsx ADDED
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import { FlexLayout, FlexLayoutProps } from "./FlexLayout";
3
+
4
+ export interface BoxProps extends FlexLayoutProps {}
5
+
6
+ export function Box({
7
+ padding = "medium",
8
+ align = "center",
9
+ justify = "center",
10
+ ...otherProps
11
+ }: BoxProps) {
12
+ return (
13
+ <FlexLayout
14
+ padding={padding}
15
+ align={align}
16
+ justify={justify}
17
+ {...otherProps}
18
+ />
19
+ );
20
+ }
package/src/Button.tsx ADDED
@@ -0,0 +1,84 @@
1
+ import React from "react";
2
+
3
+ import { BaseButton, BaseButtonProps } from "./BaseButton";
4
+ import { Text } from "./Text";
5
+ import { IconType } from "./IconType";
6
+ import { Row } from "./Row";
7
+ import { Icon } from "./Icon";
8
+ import { FlexLayoutProps } from "./FlexLayout";
9
+ import { InteractableColor, getGlyphColor } from "./Interactable";
10
+ import { Align, Gap, Justify, Size, cssVar, getPadding } from "./jss";
11
+
12
+ export interface ButtonProps extends BaseButtonProps {
13
+ label: string;
14
+ color: InteractableColor;
15
+ size?: Size;
16
+ icon?: IconType;
17
+ iconSize?: Size;
18
+ children?: undefined;
19
+ iconPosition?: "left" | "right";
20
+ rowProps?: FlexLayoutProps;
21
+ align?: Align;
22
+ gap?: Gap;
23
+ justify?: Justify;
24
+ }
25
+
26
+ export const Button = React.forwardRef(
27
+ (
28
+ {
29
+ label,
30
+ color,
31
+ bare,
32
+ disabled,
33
+ icon,
34
+ iconSize = "medium",
35
+ iconPosition = "left",
36
+ align = "center",
37
+ gap = "small",
38
+ justify = "center",
39
+ jsStyle,
40
+ size = "medium",
41
+ ...otherProps
42
+ }: ButtonProps,
43
+ ref?: React.Ref<HTMLButtonElement>
44
+ ) => {
45
+ return (
46
+ <BaseButton
47
+ {...otherProps}
48
+ bare={bare}
49
+ ref={ref}
50
+ color={color}
51
+ disabled={disabled}
52
+ jsStyle={[
53
+ {
54
+ borderRadius: cssVar("--border-radius-m"),
55
+ justifyContent: "center",
56
+ userSelect: "none",
57
+ },
58
+ getPadding("medium"),
59
+ jsStyle,
60
+ ]}
61
+ >
62
+ <Row grow={true} align={align} gap={gap} justify={justify}>
63
+ {icon && iconPosition === "left" && (
64
+ <Icon
65
+ icon={icon}
66
+ size={iconSize}
67
+ color={getGlyphColor(color, disabled, bare)}
68
+ />
69
+ )}
70
+ <Text size={size} color={getGlyphColor(color, disabled, bare)}>
71
+ {label}
72
+ </Text>
73
+ {icon && iconPosition === "right" && (
74
+ <Icon
75
+ icon={icon}
76
+ size={iconSize}
77
+ color={getGlyphColor(color, disabled, bare)}
78
+ />
79
+ )}
80
+ </Row>
81
+ </BaseButton>
82
+ );
83
+ }
84
+ );
@@ -0,0 +1,125 @@
1
+ import React, { useMemo } from "react";
2
+ import { BaseView } from "./BaseView";
3
+ import { JSStyle } from "./jss";
4
+
5
+ const dateFormatter = Intl.DateTimeFormat("en-UK", {
6
+ weekday: "short",
7
+ });
8
+
9
+ const MON = dateFormatter.format(new Date(2000, 1, 7));
10
+ const TUE = dateFormatter.format(new Date(2000, 1, 8));
11
+ const WED = dateFormatter.format(new Date(2000, 1, 9));
12
+ const THU = dateFormatter.format(new Date(2000, 1, 10));
13
+ const FRI = dateFormatter.format(new Date(2000, 1, 11));
14
+ const SAT = dateFormatter.format(new Date(2000, 1, 12));
15
+ const SUN = dateFormatter.format(new Date(2000, 1, 13));
16
+
17
+ export const Calendar = React.forwardRef(
18
+ (
19
+ {
20
+ date,
21
+ cell,
22
+ header,
23
+ jsStyle,
24
+ }: {
25
+ date: Date;
26
+ header: (props: { weekday: string }) => JSX.Element;
27
+ jsStyle?: JSStyle;
28
+ cell: (props: {
29
+ today?: boolean;
30
+ date: Date;
31
+ outOfMonth: boolean;
32
+ top: boolean;
33
+ left: boolean;
34
+ right: boolean;
35
+ bottom: boolean;
36
+ }) => JSX.Element;
37
+ },
38
+ ref?: React.Ref<HTMLElement>
39
+ ) => {
40
+ const year = date.getFullYear();
41
+ const month = date.getMonth();
42
+
43
+ const daysInMonth = new Date(year, month + 1, 0).getDate();
44
+
45
+ const firstDayOfTheMonth = new Date(year, month, 1).getDay();
46
+ const offset = firstDayOfTheMonth === 0 ? 6 : firstDayOfTheMonth - 1;
47
+ const headers = useMemo(() => {
48
+ return (
49
+ <>
50
+ {header({ weekday: MON })}
51
+ {header({ weekday: TUE })}
52
+ {header({ weekday: WED })}
53
+ {header({ weekday: THU })}
54
+ {header({ weekday: FRI })}
55
+ {header({ weekday: SAT })}
56
+ {header({ weekday: SUN })}
57
+ </>
58
+ );
59
+ }, []);
60
+
61
+ return (
62
+ <BaseView
63
+ ref={ref}
64
+ jsStyle={[
65
+ {
66
+ display: "grid",
67
+ gridTemplateColumns: "1fr 1fr 1fr 1fr 1fr 1fr 1fr",
68
+ gridTemplateRows: "1fr",
69
+ },
70
+ jsStyle,
71
+ ]}
72
+ >
73
+ {headers}
74
+ {Array.from(Array(offset).keys()).map((index) => {
75
+ const dayDate = new Date(
76
+ date.getFullYear(),
77
+ date.getMonth(),
78
+ index + 1 - offset
79
+ );
80
+
81
+ return (
82
+ <React.Fragment key={dayDate.toISOString()}>
83
+ {cell({
84
+ date: dayDate,
85
+ today: false,
86
+ top: true,
87
+ left: index % 7 === 0,
88
+ outOfMonth: true,
89
+ right: false,
90
+ bottom: false,
91
+ })}
92
+ </React.Fragment>
93
+ );
94
+ })}
95
+
96
+ {Array.from(Array(daysInMonth).keys()).map((index) => {
97
+ const dayDate = new Date(
98
+ date.getFullYear(),
99
+ date.getMonth(),
100
+ index + 1,
101
+ 12 // If we do not add this the ISO string would be from the day before at midnight
102
+ );
103
+
104
+ return (
105
+ <React.Fragment key={dayDate.toISOString()}>
106
+ {cell({
107
+ date: dayDate,
108
+ top: index + offset < 7,
109
+ left: (index + offset) % 7 === 0,
110
+ right:
111
+ (index + offset) % 7 === 7 - 1 || index === daysInMonth - 1,
112
+ bottom: index > daysInMonth - 7 - 1,
113
+ outOfMonth: false,
114
+ today:
115
+ dayDate.getDate() == new Date().getDate() &&
116
+ dayDate.getMonth() == new Date().getMonth() &&
117
+ dayDate.getFullYear() == new Date().getFullYear(),
118
+ })}
119
+ </React.Fragment>
120
+ );
121
+ })}
122
+ </BaseView>
123
+ );
124
+ }
125
+ );
package/src/Card.tsx ADDED
@@ -0,0 +1,17 @@
1
+ import { BaseView } from "./BaseView";
2
+ import { cssVar } from "./jss";
3
+
4
+ export function Card({ children }: { children: JSX.Element }) {
5
+ return (
6
+ <BaseView
7
+ jsStyle={{
8
+ backgroundColor: cssVar("--primary-background"),
9
+ borderRadius: cssVar("--border-radius-l"),
10
+ padding: cssVar("--spacing-l"),
11
+ border: `1px solid ${cssVar("--divider")}`,
12
+ }}
13
+ >
14
+ {children}
15
+ </BaseView>
16
+ );
17
+ }
@@ -0,0 +1,63 @@
1
+ import React from "react";
2
+ import { BaseInput, BaseInputProps } from "./BaseInput";
3
+ import {} from "./BaseView";
4
+ import { Size, jss } from "./jss";
5
+ import { StaticCheckbox, sizes } from "./StaticCheckbox";
6
+
7
+ // @ts-ignore
8
+ interface CheckboxProps extends BaseInputProps {
9
+ checked: boolean;
10
+ onClick: () => void;
11
+ size: Size;
12
+ value?: undefined;
13
+ onChange?: undefined;
14
+ }
15
+
16
+ export function Checkbox({
17
+ checked,
18
+ onClick,
19
+ size,
20
+ ...inputProps
21
+ }: CheckboxProps) {
22
+ return (
23
+ <label
24
+ className={jss({
25
+ position: "relative",
26
+ display: "flex",
27
+ justifyContent: "center",
28
+ alignItems: "center",
29
+ height: sizes[size],
30
+ width: sizes[size],
31
+ ":has(:focus-visible)": {
32
+ outline: "2px solid var(--outline)",
33
+ borderRadius: "50%",
34
+ },
35
+ ":has(:active)": {
36
+ transform: "scale(0.92)",
37
+ },
38
+ })}
39
+ >
40
+ <StaticCheckbox checked={checked} size={size} />
41
+ <BaseInput
42
+ {...inputProps}
43
+ type="checkbox"
44
+ role="checkbox"
45
+ aria-checked={`${checked}`}
46
+ tabIndex={0}
47
+ checked={checked}
48
+ onChange={onClick}
49
+ jsStyle={{
50
+ position: "absolute",
51
+ opacity: 0,
52
+ cursor: "pointer",
53
+ top: 0,
54
+ bottom: 0,
55
+ left: 0,
56
+ right: 0,
57
+ width: "100%",
58
+ height: "100%",
59
+ }}
60
+ />
61
+ </label>
62
+ );
63
+ }
package/src/Circle.tsx ADDED
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { Box, BoxProps } from "./Box";
3
+
4
+ interface CircleProps extends BoxProps {}
5
+
6
+ export function Circle({
7
+ jsStyle,
8
+ padding = "medium",
9
+ ...otherProps
10
+ }: CircleProps) {
11
+ return (
12
+ <Box
13
+ padding={padding}
14
+ jsStyle={[
15
+ {
16
+ borderRadius: "50%",
17
+ overflow: "hidden",
18
+ },
19
+ jsStyle,
20
+ ]}
21
+ {...otherProps}
22
+ />
23
+ );
24
+ }
package/src/Column.tsx ADDED
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import { FlexLayout, FlexLayoutProps } from "./FlexLayout";
3
+
4
+ export interface ColumnProps extends FlexLayoutProps {
5
+ direction?: "column";
6
+ }
7
+
8
+ export const Column = React.forwardRef(
9
+ (props: ColumnProps, ref?: React.Ref<HTMLDivElement>) => {
10
+ return <FlexLayout ref={ref} direction="column" {...props} />;
11
+ }
12
+ );
@@ -0,0 +1,99 @@
1
+ import React, { ReactNode, useContext, useEffect, useState } from "react";
2
+ import { IconButton } from "./IconButton";
3
+ import { BaseView } from "./BaseView";
4
+
5
+ type State = {
6
+ enabled: boolean;
7
+ toggle: () => void;
8
+ };
9
+
10
+ export const DarkModeContext = React.createContext<State>({
11
+ enabled: false,
12
+ toggle: () => {},
13
+ });
14
+
15
+ if (typeof window !== "undefined") {
16
+ const darkMode = document.cookie
17
+ .split(";")
18
+ .map((c) => c.trim())
19
+ .filter((c) => c.startsWith("dark-mode="))
20
+ .map((s) => s.split("=")[1])
21
+ .map((s) => s)
22
+ .pop();
23
+
24
+ if (darkMode === "true") {
25
+ document.body.classList.add("dark-mode");
26
+ }
27
+ }
28
+
29
+ export function DarkModeProvider({
30
+ children,
31
+ enabled,
32
+ toggle,
33
+ }: {
34
+ children: ReactNode;
35
+ enabled: boolean;
36
+ toggle: () => void;
37
+ }) {
38
+ useEffect(() => {
39
+ const statusBarMeta = document.head.querySelector(
40
+ 'meta[name="apple-mobile-web-app-status-bar-style"]'
41
+ );
42
+ const themeColorMeta = document.head.querySelector(
43
+ 'meta[name="theme-color"]'
44
+ );
45
+
46
+ if (enabled) {
47
+ document.body.classList.add("dark-mode");
48
+ if (statusBarMeta != null) {
49
+ // @ts-ignore
50
+ statusBarMeta.content = "black-translucent";
51
+ }
52
+ if (themeColorMeta != null) {
53
+ // @ts-ignore
54
+ themeColorMeta.content = "rgb(42, 43, 46)";
55
+ }
56
+ } else {
57
+ document.body.classList.remove("dark-mode");
58
+ if (statusBarMeta != null) {
59
+ // @ts-ignore
60
+ statusBarMeta.content = "default";
61
+ }
62
+ if (themeColorMeta != null) {
63
+ // @ts-ignore
64
+ themeColorMeta.content = "rgb(239, 239, 244)";
65
+ }
66
+ }
67
+ }, [enabled]);
68
+
69
+ return (
70
+ <DarkModeContext.Provider value={{ enabled, toggle }}>
71
+ {children}
72
+ </DarkModeContext.Provider>
73
+ );
74
+ }
75
+
76
+ export function DarkModeToggle() {
77
+ const darkMode = useContext(DarkModeContext);
78
+
79
+ const [show, setShow] = useState(false);
80
+
81
+ useEffect(() => {
82
+ setShow(true);
83
+ }, []);
84
+
85
+ if (!show) {
86
+ return <BaseView jsStyle={{ width: 32, height: 32 }} />;
87
+ }
88
+
89
+ return (
90
+ <IconButton
91
+ aria-label="Toggle dark mode"
92
+ icon={darkMode.enabled ? "fa-sun-o" : "fa-moon-o"}
93
+ size="medium"
94
+ onClick={darkMode.toggle}
95
+ color="secondary"
96
+ bare
97
+ />
98
+ );
99
+ }
@@ -0,0 +1,63 @@
1
+ import React, { ReactNode } from "react";
2
+ import { BaseInput, BaseInputProps } from "./BaseInput";
3
+ import { Box } from "./Box";
4
+ import { Icon } from "./Icon";
5
+ import { IconType } from "./IconType";
6
+ import { Row } from "./Row";
7
+ import { JSStyle } from "./jss";
8
+
9
+ export interface DateInputProps extends BaseInputProps {
10
+ onDateChange: (date: Date) => void;
11
+ date: Date;
12
+ icon?: IconType;
13
+ addOn?: ReactNode;
14
+ onChange?: undefined;
15
+ jsStyles?: JSStyle;
16
+ }
17
+
18
+ export const DateInput = React.forwardRef(
19
+ (
20
+ { date, onDateChange, jsStyle, icon, addOn, ...inputProps }: DateInputProps,
21
+ ref?: React.Ref<HTMLInputElement>
22
+ ) => {
23
+ return (
24
+ <Row
25
+ jsStyle={{
26
+ backgroundColor: "inherit",
27
+ }}
28
+ >
29
+ {icon && (
30
+ <Box padding="medium">
31
+ <Icon size="medium" color="secondary" icon={icon} />
32
+ </Box>
33
+ )}
34
+ <BaseInput
35
+ {...inputProps}
36
+ type="date"
37
+ ref={ref}
38
+ value={date.toISOString().substring(0, 10)}
39
+ onChange={(e) => onDateChange(new Date(e.target.value))}
40
+ jsStyle={[
41
+ {
42
+ flexGrow: 1,
43
+ backgroundColor: "inherit",
44
+ color: "var(--primary-text)",
45
+ outline: "none",
46
+ border: "none",
47
+ fontSize: 20,
48
+ lineHeight: 24 / 20,
49
+ "::placeholder": {
50
+ color: "var(--subtle-text);",
51
+ },
52
+ ":disabled": {
53
+ color: "var(--subtle-text);",
54
+ },
55
+ },
56
+ jsStyle,
57
+ ]}
58
+ />
59
+ {addOn}
60
+ </Row>
61
+ );
62
+ }
63
+ );
@@ -0,0 +1,67 @@
1
+ import React, { useRef } from "react";
2
+ import { Text } from "./Text";
3
+ import { TextColor, jss } from "./jss";
4
+
5
+ const jsStyles = {
6
+ dateInput: {
7
+ border: "1px solid var(--divider)",
8
+ backgroundColor: "var(--primary-background)",
9
+ padding: "var(--spacing-m)",
10
+ color: "var(--primary-text)",
11
+ fontSize: 20,
12
+ lineHeight: 24 / 20,
13
+ },
14
+ };
15
+
16
+ export interface DatePickerProps {
17
+ id: string;
18
+ label: string;
19
+ date: Date;
20
+ color?: TextColor;
21
+ min?: string;
22
+ max?: string;
23
+ onDateChange: (date: Date) => void;
24
+ }
25
+
26
+ export function DatePicker({
27
+ id,
28
+ label,
29
+ color = "primary",
30
+ date,
31
+ onDateChange,
32
+ }: DatePickerProps) {
33
+ const initialDate = useRef(date);
34
+ const year = initialDate.current.getFullYear();
35
+ const month = initialDate.current.getMonth();
36
+ const day = initialDate.current.getDate();
37
+ const min = new Date(year - 1, month, day).toISOString().substring(0, 10);
38
+ const max = new Date(year + 1, month, day).toISOString().substring(0, 10);
39
+
40
+ return (
41
+ <>
42
+ <label htmlFor={id}>
43
+ <Text size="small" color={color}>
44
+ {label}
45
+ </Text>
46
+ </label>
47
+ <input
48
+ min={min}
49
+ max={max}
50
+ className={jss(jsStyles.dateInput)}
51
+ type="date"
52
+ id={id}
53
+ value={date.toISOString().substring(0, 10)}
54
+ onChange={(event) => {
55
+ let parsedDate;
56
+ try {
57
+ parsedDate = new Date(event.target.value);
58
+ } finally {
59
+ if (parsedDate != null) {
60
+ onDateChange(parsedDate);
61
+ }
62
+ }
63
+ }}
64
+ ></input>
65
+ </>
66
+ );
67
+ }
@@ -0,0 +1,71 @@
1
+ import React, { ReactNode } from "react";
2
+ import { BaseInput, BaseInputProps } from "./BaseInput";
3
+ import { Box } from "./Box";
4
+ import { Icon } from "./Icon";
5
+ import { IconType } from "./IconType";
6
+ import { Row } from "./Row";
7
+ import { JSStyle } from "./jss";
8
+
9
+ export interface DatetimeInputProps extends BaseInputProps {
10
+ onDateChange: (date: Date) => void;
11
+ date: Date;
12
+ icon?: IconType;
13
+ addOn?: ReactNode;
14
+ onChange?: undefined;
15
+ jsStyle?: JSStyle;
16
+ }
17
+
18
+ const jsStyles = {
19
+ root: {
20
+ backgroundColor: "var(--primary-background)",
21
+ },
22
+ input: {
23
+ padding: "var(--spacing-m)",
24
+ flexGrow: 1,
25
+ backgroundColor: "var(--primary-background)",
26
+ color: "var(--primary-text)",
27
+ outline: "none",
28
+ border: "none",
29
+ fontSize: 20,
30
+ lineHeight: 24 / 20,
31
+ "::placeholder": {
32
+ color: "var(--subtle-text);",
33
+ },
34
+ ":disabled": {
35
+ color: "var(--subtle-text);",
36
+ },
37
+ },
38
+ };
39
+
40
+ export const DatetimeInput = React.forwardRef(
41
+ (
42
+ {
43
+ date,
44
+ onDateChange,
45
+ jsStyle,
46
+ icon,
47
+ addOn,
48
+ ...inputProps
49
+ }: DatetimeInputProps,
50
+ ref?: React.Ref<HTMLInputElement>
51
+ ) => {
52
+ return (
53
+ <Row jsStyle={jsStyles.root}>
54
+ {icon && (
55
+ <Box padding="medium">
56
+ <Icon size="medium" color="secondary" icon={icon} />
57
+ </Box>
58
+ )}
59
+ <BaseInput
60
+ {...inputProps}
61
+ type="datetime-local"
62
+ ref={ref}
63
+ value={date.toISOString().substring(0, 16)}
64
+ onChange={(e) => onDateChange(new Date(e.target.value))}
65
+ jsStyle={[jsStyles.input, jsStyle]}
66
+ />
67
+ {addOn}
68
+ </Row>
69
+ );
70
+ }
71
+ );