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.
- package/.prettierrc +4 -0
- package/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/Badge.d.ts +7 -0
- package/dist/Badge.js +22 -0
- package/dist/Badge.js.map +1 -0
- package/dist/BaseButton.d.ts +13 -0
- package/dist/BaseButton.js +22 -0
- package/dist/BaseButton.js.map +1 -0
- package/dist/BaseInput.d.ts +15 -0
- package/dist/BaseInput.js +14 -0
- package/dist/BaseInput.js.map +1 -0
- package/dist/BaseLink.d.ts +17 -0
- package/dist/BaseLink.js +28 -0
- package/dist/BaseLink.js.map +1 -0
- package/dist/BaseList.d.ts +6 -0
- package/dist/BaseList.js +14 -0
- package/dist/BaseList.js.map +1 -0
- package/dist/BaseListAddOn.d.ts +5 -0
- package/dist/BaseListAddOn.js +7 -0
- package/dist/BaseListAddOn.js.map +1 -0
- package/dist/BaseListItem.d.ts +27 -0
- package/dist/BaseListItem.js +26 -0
- package/dist/BaseListItem.js.map +1 -0
- package/dist/BaseView.d.ts +12 -0
- package/dist/BaseView.js +26 -0
- package/dist/BaseView.js.map +1 -0
- package/dist/Box.d.ts +5 -0
- package/dist/Box.js +6 -0
- package/dist/Box.js.map +1 -0
- package/dist/Button.d.ts +20 -0
- package/dist/Button.js +20 -0
- package/dist/Button.js.map +1 -0
- package/dist/Calendar.d.ts +18 -0
- package/dist/Calendar.js +57 -0
- package/dist/Calendar.js.map +1 -0
- package/dist/Card.d.ts +4 -0
- package/dist/Card.js +12 -0
- package/dist/Card.js.map +1 -0
- package/dist/Checkbox.d.ts +12 -0
- package/dist/Checkbox.js +32 -0
- package/dist/Checkbox.js.map +1 -0
- package/dist/Circle.d.ts +6 -0
- package/dist/Circle.js +12 -0
- package/dist/Circle.js.map +1 -0
- package/dist/Column.d.ts +6 -0
- package/dist/Column.js +7 -0
- package/dist/Column.js.map +1 -0
- package/dist/DarkMode.d.ts +13 -0
- package/dist/DarkMode.js +61 -0
- package/dist/DarkMode.js.map +1 -0
- package/dist/DateInput.d.ts +13 -0
- package/dist/DateInput.js +29 -0
- package/dist/DateInput.js.map +1 -0
- package/dist/DatePicker.d.ts +12 -0
- package/dist/DatePicker.js +34 -0
- package/dist/DatePicker.js.map +1 -0
- package/dist/DatetimeInput.d.ts +13 -0
- package/dist/DatetimeInput.js +31 -0
- package/dist/DatetimeInput.js.map +1 -0
- package/dist/DesignBook.d.ts +2 -0
- package/dist/DesignBook.js +55 -0
- package/dist/DesignBook.js.map +1 -0
- package/dist/Dialog.d.ts +17 -0
- package/dist/Dialog.js +86 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/Dropdown.d.ts +10 -0
- package/dist/Dropdown.js +64 -0
- package/dist/Dropdown.js.map +1 -0
- package/dist/Emitter.d.ts +6 -0
- package/dist/Emitter.js +19 -0
- package/dist/Emitter.js.map +1 -0
- package/dist/FlexLayout.d.ts +11 -0
- package/dist/FlexLayout.js +18 -0
- package/dist/FlexLayout.js.map +1 -0
- package/dist/Icon.d.ts +12 -0
- package/dist/Icon.js +69 -0
- package/dist/Icon.js.map +1 -0
- package/dist/IconButton.d.ts +9 -0
- package/dist/IconButton.js +31 -0
- package/dist/IconButton.js.map +1 -0
- package/dist/IconLink.d.ts +9 -0
- package/dist/IconLink.js +31 -0
- package/dist/IconLink.js.map +1 -0
- package/dist/IconType.d.ts +1 -0
- package/dist/IconType.js +2 -0
- package/dist/IconType.js.map +1 -0
- package/dist/Interactable.d.ts +48 -0
- package/dist/Interactable.js +131 -0
- package/dist/Interactable.js.map +1 -0
- package/dist/Link.d.ts +20 -0
- package/dist/Link.js +22 -0
- package/dist/Link.js.map +1 -0
- package/dist/List.d.ts +11 -0
- package/dist/List.js +17 -0
- package/dist/List.js.map +1 -0
- package/dist/ListButtonItem.d.ts +15 -0
- package/dist/ListButtonItem.js +9 -0
- package/dist/ListButtonItem.js.map +1 -0
- package/dist/ListDivider.d.ts +2 -0
- package/dist/ListDivider.js +12 -0
- package/dist/ListDivider.js.map +1 -0
- package/dist/ListHeaderItem.d.ts +11 -0
- package/dist/ListHeaderItem.js +13 -0
- package/dist/ListHeaderItem.js.map +1 -0
- package/dist/ListItem.d.ts +10 -0
- package/dist/ListItem.js +7 -0
- package/dist/ListItem.js.map +1 -0
- package/dist/ListLinkItem.d.ts +17 -0
- package/dist/ListLinkItem.js +9 -0
- package/dist/ListLinkItem.js.map +1 -0
- package/dist/ListSpacer.d.ts +2 -0
- package/dist/ListSpacer.js +13 -0
- package/dist/ListSpacer.js.map +1 -0
- package/dist/OnVisible.d.ts +5 -0
- package/dist/OnVisible.js +28 -0
- package/dist/OnVisible.js.map +1 -0
- package/dist/Popover.d.ts +21 -0
- package/dist/Popover.js +88 -0
- package/dist/Popover.js.map +1 -0
- package/dist/ProgressBar.d.ts +8 -0
- package/dist/ProgressBar.js +42 -0
- package/dist/ProgressBar.js.map +1 -0
- package/dist/ProgressCircle.d.ts +6 -0
- package/dist/ProgressCircle.js +12 -0
- package/dist/ProgressCircle.js.map +1 -0
- package/dist/Providers.d.ts +9 -0
- package/dist/Providers.js +16 -0
- package/dist/Providers.js.map +1 -0
- package/dist/RangeInput.d.ts +14 -0
- package/dist/RangeInput.js +32 -0
- package/dist/RangeInput.js.map +1 -0
- package/dist/ResultOrError.d.ts +13 -0
- package/dist/ResultOrError.js +7 -0
- package/dist/ResultOrError.js.map +1 -0
- package/dist/RootView.d.ts +5 -0
- package/dist/RootView.js +35 -0
- package/dist/RootView.js.map +1 -0
- package/dist/Router.d.ts +2 -0
- package/dist/Router.js +37 -0
- package/dist/Router.js.map +1 -0
- package/dist/RouterState.d.ts +38 -0
- package/dist/RouterState.js +111 -0
- package/dist/RouterState.js.map +1 -0
- package/dist/Row.d.ts +6 -0
- package/dist/Row.js +7 -0
- package/dist/Row.js.map +1 -0
- package/dist/StackContext.d.ts +8 -0
- package/dist/StackContext.js +25 -0
- package/dist/StackContext.js.map +1 -0
- package/dist/StaticCheckbox.d.ts +17 -0
- package/dist/StaticCheckbox.js +48 -0
- package/dist/StaticCheckbox.js.map +1 -0
- package/dist/Storage.d.ts +12 -0
- package/dist/Storage.js +148 -0
- package/dist/Storage.js.map +1 -0
- package/dist/Stream.d.ts +9 -0
- package/dist/Stream.js +36 -0
- package/dist/Stream.js.map +1 -0
- package/dist/Sublist.d.ts +12 -0
- package/dist/Sublist.js +18 -0
- package/dist/Sublist.js.map +1 -0
- package/dist/SubmitIconInput.d.ts +9 -0
- package/dist/SubmitIconInput.js +25 -0
- package/dist/SubmitIconInput.js.map +1 -0
- package/dist/Tabs.d.ts +20 -0
- package/dist/Tabs.js +35 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Text.d.ts +25 -0
- package/dist/Text.js +50 -0
- package/dist/Text.js.map +1 -0
- package/dist/TextArea.d.ts +10 -0
- package/dist/TextArea.js +22 -0
- package/dist/TextArea.js.map +1 -0
- package/dist/TextInput.d.ts +14 -0
- package/dist/TextInput.js +52 -0
- package/dist/TextInput.js.map +1 -0
- package/dist/TextInputWithState.d.ts +10 -0
- package/dist/TextInputWithState.js +14 -0
- package/dist/TextInputWithState.js.map +1 -0
- package/dist/TextPairing.d.ts +21 -0
- package/dist/TextPairing.js +26 -0
- package/dist/TextPairing.js.map +1 -0
- package/dist/TimeInput.d.ts +15 -0
- package/dist/TimeInput.js +58 -0
- package/dist/TimeInput.js.map +1 -0
- package/dist/Tooltip.d.ts +11 -0
- package/dist/Tooltip.js +72 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/aria.d.ts +8 -0
- package/dist/aria.js +42 -0
- package/dist/aria.js.map +1 -0
- package/dist/guid.d.ts +1 -0
- package/dist/guid.js +7 -0
- package/dist/guid.js.map +1 -0
- package/dist/hash.d.ts +1 -0
- package/dist/hash.js +20 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/jss.d.ts +110 -0
- package/dist/jss.js +438 -0
- package/dist/jss.js.map +1 -0
- package/dist/numberToBase.d.ts +1 -0
- package/dist/numberToBase.js +44 -0
- package/dist/numberToBase.js.map +1 -0
- package/dist/stateMachineContextFactory.d.ts +36 -0
- package/dist/stateMachineContextFactory.js +48 -0
- package/dist/stateMachineContextFactory.js.map +1 -0
- package/dist/useCookie.d.ts +9 -0
- package/dist/useCookie.js +65 -0
- package/dist/useCookie.js.map +1 -0
- package/dist/useKeyboard.d.ts +8 -0
- package/dist/useKeyboard.js +26 -0
- package/dist/useKeyboard.js.map +1 -0
- package/dist/useNavigation.d.ts +5 -0
- package/dist/useNavigation.js +79 -0
- package/dist/useNavigation.js.map +1 -0
- package/dist/usePromise.d.ts +1 -0
- package/dist/usePromise.js +12 -0
- package/dist/usePromise.js.map +1 -0
- package/dist/useRefEffect.d.ts +1 -0
- package/dist/useRefEffect.js +15 -0
- package/dist/useRefEffect.js.map +1 -0
- package/next-env.d.ts +5 -0
- package/next.config.js +21 -0
- package/package.json +40 -0
- package/scripts/publish.js +27 -0
- package/src/Badge.tsx +36 -0
- package/src/BaseButton.tsx +58 -0
- package/src/BaseInput.tsx +57 -0
- package/src/BaseLink.tsx +77 -0
- package/src/BaseList.tsx +29 -0
- package/src/BaseListAddOn.tsx +10 -0
- package/src/BaseListItem.tsx +117 -0
- package/src/BaseView.tsx +57 -0
- package/src/Box.tsx +20 -0
- package/src/Button.tsx +84 -0
- package/src/Calendar.tsx +125 -0
- package/src/Card.tsx +17 -0
- package/src/Checkbox.tsx +63 -0
- package/src/Circle.tsx +24 -0
- package/src/Column.tsx +12 -0
- package/src/DarkMode.tsx +99 -0
- package/src/DateInput.tsx +63 -0
- package/src/DatePicker.tsx +67 -0
- package/src/DatetimeInput.tsx +71 -0
- package/src/DesignBook.tsx +697 -0
- package/src/Dialog.tsx +144 -0
- package/src/Dropdown.tsx +129 -0
- package/src/Emitter.ts +26 -0
- package/src/FlexLayout.tsx +53 -0
- package/src/Icon.tsx +96 -0
- package/src/IconButton.tsx +66 -0
- package/src/IconLink.tsx +58 -0
- package/src/IconType.ts +787 -0
- package/src/Interactable.tsx +159 -0
- package/src/Link.tsx +86 -0
- package/src/List.tsx +41 -0
- package/src/ListButtonItem.tsx +69 -0
- package/src/ListDivider.tsx +13 -0
- package/src/ListHeaderItem.tsx +45 -0
- package/src/ListItem.tsx +27 -0
- package/src/ListLinkItem.tsx +76 -0
- package/src/ListSpacer.tsx +14 -0
- package/src/OnVisible.tsx +42 -0
- package/src/Popover.tsx +141 -0
- package/src/ProgressBar.tsx +63 -0
- package/src/ProgressCircle.tsx +38 -0
- package/src/Providers.tsx +33 -0
- package/src/RangeInput.tsx +82 -0
- package/src/ResultOrError.ts +15 -0
- package/src/RootView.tsx +55 -0
- package/src/Router.tsx +62 -0
- package/src/RouterState.tsx +154 -0
- package/src/Row.tsx +12 -0
- package/src/StackContext.tsx +52 -0
- package/src/StaticCheckbox.tsx +74 -0
- package/src/Storage.tsx +200 -0
- package/src/Stream.tsx +50 -0
- package/src/Sublist.tsx +62 -0
- package/src/SubmitIconInput.tsx +45 -0
- package/src/Tabs.tsx +103 -0
- package/src/Text.tsx +102 -0
- package/src/TextArea.tsx +45 -0
- package/src/TextInput.tsx +111 -0
- package/src/TextInputWithState.tsx +35 -0
- package/src/TextPairing.tsx +115 -0
- package/src/TimeInput.tsx +109 -0
- package/src/Tooltip.tsx +108 -0
- package/src/aria.ts +72 -0
- package/src/examples/ExampleDialog.tsx +28 -0
- package/src/guid.ts +7 -0
- package/src/hash.ts +21 -0
- package/src/index.ts +65 -0
- package/src/jss.tsx +607 -0
- package/src/numberToBase.ts +52 -0
- package/src/pages/Badge.mdx +30 -0
- package/src/pages/Button.mdx +57 -0
- package/src/pages/Calendar.mdx +60 -0
- package/src/pages/Checkbox.mdx +56 -0
- package/src/pages/Dialog.mdx +32 -0
- package/src/pages/FlexLayout.mdx +77 -0
- package/src/pages/Hashing.mdx +20 -0
- package/src/pages/Icon.mdx +63 -0
- package/src/pages/IconButton.mdx +144 -0
- package/src/pages/Link.mdx +57 -0
- package/src/pages/List.mdx +292 -0
- package/src/pages/ListHeader.mdx +94 -0
- package/src/pages/Popover.mdx +101 -0
- package/src/pages/ProgressBar.mdx +20 -0
- package/src/pages/ProgressCircle.mdx +35 -0
- package/src/pages/RangeInput.mdx +109 -0
- package/src/pages/Tabs.mdx +168 -0
- package/src/pages/Text.mdx +133 -0
- package/src/pages/TextInput.mdx +110 -0
- package/src/pages/TextPairing.mdx +155 -0
- package/src/pages/TimeInput.mdx +73 -0
- package/src/pages/Tooltip.mdx +28 -0
- package/src/pages/_app.tsx +561 -0
- package/src/pages/_document.tsx +30 -0
- package/src/pages/css-in-js.mdx +127 -0
- package/src/pages/index.mdx +58 -0
- package/src/pages/navigation.mdx +56 -0
- package/src/pages/prism.css +3 -0
- package/src/pages/useCookie.mdx +15 -0
- package/src/pages/useKeyboard.mdx +20 -0
- package/src/pages/useNavigation.mdx +30 -0
- package/src/pages/usePromise.mdx +15 -0
- package/src/pages/useRefEffect.mdx +49 -0
- package/src/stateMachineContextFactory.tsx +111 -0
- package/src/useCookie.tsx +89 -0
- package/src/useKeyboard.tsx +43 -0
- package/src/useNavigation.tsx +89 -0
- package/src/usePromise.tsx +18 -0
- package/src/useRefEffect.tsx +18 -0
- package/tsconfig.build.json +23 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BaseView } from "./BaseView";
|
|
3
|
+
import { Icon } from "./Icon";
|
|
4
|
+
import { JSStyle, Size, cssVar } from "./jss";
|
|
5
|
+
import { IconType } from "./IconType";
|
|
6
|
+
|
|
7
|
+
type StaticCheckboxProps = {
|
|
8
|
+
checked: boolean;
|
|
9
|
+
size: Size;
|
|
10
|
+
icon?: IconType;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const jsStyles: { [key: string]: JSStyle } = {
|
|
14
|
+
border: {
|
|
15
|
+
position: "absolute",
|
|
16
|
+
top: "var(--spacing-xs)",
|
|
17
|
+
bottom: "var(--spacing-xs)",
|
|
18
|
+
left: "var(--spacing-xs)",
|
|
19
|
+
right: "var(--spacing-xs)",
|
|
20
|
+
border: "1px solid var(--divider)",
|
|
21
|
+
borderRadius: "50%",
|
|
22
|
+
},
|
|
23
|
+
borderChecked: {
|
|
24
|
+
border: "none",
|
|
25
|
+
backgroundColor: "var(--highlight)",
|
|
26
|
+
},
|
|
27
|
+
icon: {
|
|
28
|
+
position: "absolute",
|
|
29
|
+
display: "flex",
|
|
30
|
+
justifyContent: "center",
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
top: "var(--spacing-xs)",
|
|
33
|
+
bottom: "var(--spacing-xs)",
|
|
34
|
+
left: "var(--spacing-xs)",
|
|
35
|
+
right: "var(--spacing-xs)",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const sizes = {
|
|
40
|
+
xsmall: 20,
|
|
41
|
+
small: 24,
|
|
42
|
+
medium: 32,
|
|
43
|
+
large: 40,
|
|
44
|
+
xlarge: 48,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function StaticCheckbox({
|
|
48
|
+
checked,
|
|
49
|
+
size,
|
|
50
|
+
icon = "fa-check",
|
|
51
|
+
}: StaticCheckboxProps) {
|
|
52
|
+
return (
|
|
53
|
+
<BaseView
|
|
54
|
+
jsStyle={{
|
|
55
|
+
position: "relative",
|
|
56
|
+
backgroundColor: cssVar("--primary-background"),
|
|
57
|
+
overflow: "hidden",
|
|
58
|
+
padding: cssVar("--spacing-xs"),
|
|
59
|
+
borderRadius: sizes[size] / 2,
|
|
60
|
+
height: sizes[size],
|
|
61
|
+
width: sizes[size],
|
|
62
|
+
}}
|
|
63
|
+
>
|
|
64
|
+
<BaseView
|
|
65
|
+
jsStyle={[jsStyles.border, checked && jsStyles.borderChecked]}
|
|
66
|
+
/>
|
|
67
|
+
{checked && (
|
|
68
|
+
<BaseView jsStyle={jsStyles.icon}>
|
|
69
|
+
<Icon size={size} color="light" icon={icon} />
|
|
70
|
+
</BaseView>
|
|
71
|
+
)}
|
|
72
|
+
</BaseView>
|
|
73
|
+
);
|
|
74
|
+
}
|
package/src/Storage.tsx
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
useState,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
createContext,
|
|
7
|
+
ReactNode,
|
|
8
|
+
useRef,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { Callback, createEmitter } from "./Emitter";
|
|
11
|
+
|
|
12
|
+
const VERSION = 1;
|
|
13
|
+
|
|
14
|
+
export function createStorage<State>({
|
|
15
|
+
initialState,
|
|
16
|
+
name = "aidos-storage",
|
|
17
|
+
}: {
|
|
18
|
+
initialState: State;
|
|
19
|
+
name?: string;
|
|
20
|
+
}) {
|
|
21
|
+
const StorageContext = createContext<{
|
|
22
|
+
subscribe: <T>(selector: (state: State) => T) => () => void;
|
|
23
|
+
mutate: (mutator: (state: State) => State) => void;
|
|
24
|
+
persist: () => Promise<void>;
|
|
25
|
+
}>({
|
|
26
|
+
subscribe: () => {
|
|
27
|
+
throw new Error("Not implemented");
|
|
28
|
+
},
|
|
29
|
+
mutate: () => {
|
|
30
|
+
throw new Error("Not implemented");
|
|
31
|
+
},
|
|
32
|
+
persist: () => {
|
|
33
|
+
throw new Error("Not implemented");
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const state = { current: initialState };
|
|
38
|
+
|
|
39
|
+
function Storage({ children }: { children: ReactNode }): JSX.Element {
|
|
40
|
+
const emitterRef = useRef(createEmitter<State>());
|
|
41
|
+
|
|
42
|
+
const subscribe = useCallback((callback: Callback<State>) => {
|
|
43
|
+
return emitterRef.current.subscribe(callback);
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
const mutate = useCallback((mutator: (state: State) => State) => {
|
|
47
|
+
state.current = mutator(state.current);
|
|
48
|
+
emitterRef.current.emit(state.current);
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
const persist = useCallback(async () => {
|
|
52
|
+
const s = JSON.stringify(state.current);
|
|
53
|
+
const bytes = new TextEncoder().encode(s);
|
|
54
|
+
const blob = new Blob([bytes], {
|
|
55
|
+
type: "application/json;charset=utf-8",
|
|
56
|
+
});
|
|
57
|
+
return saveBlob(blob);
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
getBlob().then((blob) => {
|
|
62
|
+
if (blob == null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const fr = new FileReader();
|
|
67
|
+
|
|
68
|
+
fr.onload = (event) => {
|
|
69
|
+
const text = event.target.result.toString();
|
|
70
|
+
state.current = JSON.parse(text);
|
|
71
|
+
emitterRef.current.emit(state.current);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
fr.onerror = (error) => {
|
|
75
|
+
// reject(error);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
fr.readAsText(blob);
|
|
79
|
+
});
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<StorageContext.Provider
|
|
84
|
+
value={{
|
|
85
|
+
subscribe,
|
|
86
|
+
mutate,
|
|
87
|
+
persist,
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
{children}
|
|
91
|
+
</StorageContext.Provider>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function useStorage<T>(selector: (state: State) => T): T {
|
|
96
|
+
const [localState, setLocalState] = useState(() => selector(state.current));
|
|
97
|
+
const { subscribe } = React.useContext(StorageContext);
|
|
98
|
+
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
return subscribe((newState) => {
|
|
101
|
+
const newLocalState = selector(newState);
|
|
102
|
+
if (newLocalState != localState) {
|
|
103
|
+
setLocalState(selector(newState));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
108
|
+
return localState;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function useMutation(): (mutator: (state: State) => State) => void {
|
|
112
|
+
const { mutate } = React.useContext(StorageContext);
|
|
113
|
+
return mutate;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function usePersist() {
|
|
117
|
+
const { persist } = React.useContext(StorageContext);
|
|
118
|
+
return persist;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const dbPromise: Promise<IDBDatabase> = new Promise((resolve, reject) => {
|
|
122
|
+
const request = window.indexedDB.open(name, VERSION);
|
|
123
|
+
|
|
124
|
+
request.onerror = (event) => {
|
|
125
|
+
reject(event);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
request.onupgradeneeded = (event) => {
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
const db: IDBDatabase = event.target.result;
|
|
131
|
+
const table = db.createObjectStore("blobs", {
|
|
132
|
+
keyPath: "key",
|
|
133
|
+
});
|
|
134
|
+
table.createIndex("key", "key", { unique: true });
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
request.onsuccess = (event) => {
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
const db: IDBDatabase = event.target.result;
|
|
140
|
+
resolve(db);
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const getBlob = async (): Promise<Blob | null> => {
|
|
145
|
+
const db = await dbPromise;
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
const transaction = db.transaction(["blobs"]);
|
|
148
|
+
const objectStore = transaction.objectStore("blobs");
|
|
149
|
+
const get: IDBRequest<Blob> = objectStore.get(1);
|
|
150
|
+
|
|
151
|
+
transaction.onerror = (event) => {
|
|
152
|
+
db.close();
|
|
153
|
+
reject(event);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
get.onsuccess = (event) => {
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
const result: DBStorage = event.target.result;
|
|
159
|
+
|
|
160
|
+
if (result && result.blob) {
|
|
161
|
+
resolve(result.blob);
|
|
162
|
+
} else {
|
|
163
|
+
resolve(null);
|
|
164
|
+
}
|
|
165
|
+
db.close();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
get.onerror = (event) => {
|
|
169
|
+
reject(event);
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const saveBlob = async (blob: Blob): Promise<void> => {
|
|
175
|
+
const db = await dbPromise;
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
const transaction = db.transaction(["blobs"], "readwrite");
|
|
178
|
+
|
|
179
|
+
transaction.oncomplete = () => {
|
|
180
|
+
db.close();
|
|
181
|
+
resolve();
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
transaction.onerror = (event) => {
|
|
185
|
+
db.close();
|
|
186
|
+
reject(event);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const objectStore = transaction.objectStore("blobs");
|
|
190
|
+
objectStore.put({ blob, key: 1 });
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
Storage,
|
|
196
|
+
useStorage,
|
|
197
|
+
useMutation,
|
|
198
|
+
usePersist,
|
|
199
|
+
};
|
|
200
|
+
}
|
package/src/Stream.tsx
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { startTransition, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
export const useStream = ({
|
|
4
|
+
render,
|
|
5
|
+
bufferStart,
|
|
6
|
+
bufferEnd,
|
|
7
|
+
index,
|
|
8
|
+
debounce = 100,
|
|
9
|
+
}) => {
|
|
10
|
+
const cache = useRef({
|
|
11
|
+
[index]: render(index),
|
|
12
|
+
});
|
|
13
|
+
const [frame, setFrame] = useState(cache.current[index]);
|
|
14
|
+
const timeout = useRef(null);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
clearTimeout(timeout.current);
|
|
18
|
+
const subscriptions = [];
|
|
19
|
+
|
|
20
|
+
timeout.current = setTimeout(() => {
|
|
21
|
+
for (let i = index - bufferStart; i < index + bufferEnd; i++) {
|
|
22
|
+
subscriptions.push(
|
|
23
|
+
requestIdleCallback(() => {
|
|
24
|
+
if (!(i in cache.current)) {
|
|
25
|
+
cache.current[i] = render(i);
|
|
26
|
+
|
|
27
|
+
if (i === index) {
|
|
28
|
+
setFrame(cache.current[index]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
startTransition(() => {
|
|
36
|
+
setFrame(cache.current[index]);
|
|
37
|
+
});
|
|
38
|
+
}, debounce);
|
|
39
|
+
|
|
40
|
+
return () => {
|
|
41
|
+
subscriptions.forEach((handle) => {
|
|
42
|
+
cancelIdleCallback(handle);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}, [index]);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
frame,
|
|
49
|
+
};
|
|
50
|
+
};
|
package/src/Sublist.tsx
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { ListButtonItem } from "./ListButtonItem";
|
|
3
|
+
import { Icon } from "./Icon";
|
|
4
|
+
import { Box } from "./Box";
|
|
5
|
+
import { Row } from "./Row";
|
|
6
|
+
import { JSStyle } from "./jss";
|
|
7
|
+
|
|
8
|
+
export function Sublist({
|
|
9
|
+
children,
|
|
10
|
+
label,
|
|
11
|
+
initialState = { collapsed: false },
|
|
12
|
+
jsStyle,
|
|
13
|
+
secondaryAddOn,
|
|
14
|
+
bare,
|
|
15
|
+
}: {
|
|
16
|
+
bare?: boolean;
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
label: string;
|
|
19
|
+
initialState?: {
|
|
20
|
+
collapsed: boolean;
|
|
21
|
+
};
|
|
22
|
+
jsStyle?: JSStyle;
|
|
23
|
+
secondaryAddOn?: ReactNode;
|
|
24
|
+
}) {
|
|
25
|
+
const [collapsed, setCollapsed] = React.useState(initialState.collapsed);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
<ListButtonItem
|
|
30
|
+
bare={bare}
|
|
31
|
+
headline={label}
|
|
32
|
+
onClick={() => setCollapsed((x) => !x)}
|
|
33
|
+
jsStyle={jsStyle}
|
|
34
|
+
addOn={
|
|
35
|
+
<Row gap="medium" align="center">
|
|
36
|
+
{secondaryAddOn}
|
|
37
|
+
<Box
|
|
38
|
+
padding="medium"
|
|
39
|
+
jsStyle={[
|
|
40
|
+
{
|
|
41
|
+
transition: "transform 0.15s ease-in",
|
|
42
|
+
},
|
|
43
|
+
!collapsed && {
|
|
44
|
+
transform: "rotateZ(90deg)",
|
|
45
|
+
},
|
|
46
|
+
]}
|
|
47
|
+
>
|
|
48
|
+
<Icon
|
|
49
|
+
color="primary"
|
|
50
|
+
size="medium"
|
|
51
|
+
icon="fa-solid:chevron-right"
|
|
52
|
+
/>
|
|
53
|
+
</Box>
|
|
54
|
+
</Row>
|
|
55
|
+
}
|
|
56
|
+
addOnPosition="end"
|
|
57
|
+
color="secondary"
|
|
58
|
+
/>
|
|
59
|
+
{collapsed ? null : children}
|
|
60
|
+
</>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BaseInput, BaseInputProps } from "./BaseInput";
|
|
3
|
+
import { Box } from "./Box";
|
|
4
|
+
import { Icon } from "./Icon";
|
|
5
|
+
import { IconType } from "./IconType";
|
|
6
|
+
|
|
7
|
+
interface SubmitIconInputProps extends BaseInputProps {
|
|
8
|
+
icon: IconType;
|
|
9
|
+
type?: "submit";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function SubmitIconInput({ icon, ...otherProps }: SubmitIconInputProps) {
|
|
13
|
+
return (
|
|
14
|
+
<BaseInput
|
|
15
|
+
label={
|
|
16
|
+
<Box
|
|
17
|
+
jsStyle={{
|
|
18
|
+
cursor: "pointer",
|
|
19
|
+
display: "flex",
|
|
20
|
+
justifyContent: "center",
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
":hover": {
|
|
23
|
+
backgroundColor: "var(--secondary-background)",
|
|
24
|
+
opacity: 0.8,
|
|
25
|
+
},
|
|
26
|
+
":active": {
|
|
27
|
+
transform: "scale(0.92)",
|
|
28
|
+
},
|
|
29
|
+
height: 32,
|
|
30
|
+
width: 32,
|
|
31
|
+
borderRadius: 16,
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
<Icon icon={icon} size="medium" color="primary" />
|
|
35
|
+
</Box>
|
|
36
|
+
}
|
|
37
|
+
{...otherProps}
|
|
38
|
+
type="submit"
|
|
39
|
+
jsStyle={{
|
|
40
|
+
visibility: "hidden",
|
|
41
|
+
}}
|
|
42
|
+
value=""
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
}
|
package/src/Tabs.tsx
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { BaseLink } from "./BaseLink";
|
|
2
|
+
import { Row, RowProps } from "./Row";
|
|
3
|
+
import { JSStyle, Padding, Size, cssVar, getPadding } from "./jss";
|
|
4
|
+
import { useNavigation } from "./useNavigation";
|
|
5
|
+
import { Text } from "./Text";
|
|
6
|
+
import { ReactNode } from "react";
|
|
7
|
+
|
|
8
|
+
export type Tab = {
|
|
9
|
+
label: string;
|
|
10
|
+
href?: string;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
addOn?: ReactNode;
|
|
14
|
+
addOnPosition?: "start" | "end";
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export interface TabsProps extends RowProps {
|
|
18
|
+
["aria-controls"]: string;
|
|
19
|
+
tabs: Array<Tab>;
|
|
20
|
+
labelSize?: Size;
|
|
21
|
+
bare?: boolean;
|
|
22
|
+
tabPadding?: Padding;
|
|
23
|
+
tabJSStyle?: JSStyle;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function Tabs({
|
|
27
|
+
tabs,
|
|
28
|
+
gap = "none",
|
|
29
|
+
padding = "none",
|
|
30
|
+
tabPadding = "medium",
|
|
31
|
+
labelSize = "large",
|
|
32
|
+
jsStyle,
|
|
33
|
+
tabJSStyle,
|
|
34
|
+
["aria-controls"]: ariaControls,
|
|
35
|
+
...otherProps
|
|
36
|
+
}: TabsProps) {
|
|
37
|
+
const root = useNavigation();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Row
|
|
41
|
+
role="tablist"
|
|
42
|
+
jsStyle={jsStyle}
|
|
43
|
+
gap={gap}
|
|
44
|
+
padding={padding}
|
|
45
|
+
ref={root}
|
|
46
|
+
{...otherProps}
|
|
47
|
+
>
|
|
48
|
+
{tabs.map(
|
|
49
|
+
({
|
|
50
|
+
label,
|
|
51
|
+
href,
|
|
52
|
+
onClick,
|
|
53
|
+
selected,
|
|
54
|
+
addOn,
|
|
55
|
+
addOnPosition = "start",
|
|
56
|
+
}) => (
|
|
57
|
+
<BaseLink
|
|
58
|
+
aria-controls={ariaControls}
|
|
59
|
+
role="tab"
|
|
60
|
+
aria-selected={selected ? "true" : undefined}
|
|
61
|
+
key={label}
|
|
62
|
+
bare
|
|
63
|
+
color={selected ? "positive" : "secondary"}
|
|
64
|
+
href={href}
|
|
65
|
+
onClick={onClick}
|
|
66
|
+
animateInteraction={false}
|
|
67
|
+
jsStyle={[
|
|
68
|
+
{
|
|
69
|
+
textDecoration: "none",
|
|
70
|
+
borderBottom: selected
|
|
71
|
+
? `3px solid ${cssVar("--highlight")}`
|
|
72
|
+
: `3px solid transparent`,
|
|
73
|
+
":active span": {
|
|
74
|
+
transform: "scale(0.97)",
|
|
75
|
+
},
|
|
76
|
+
":first-child": {
|
|
77
|
+
borderTopLeftRadius: cssVar("--border-radius-m"),
|
|
78
|
+
},
|
|
79
|
+
":last-child": {
|
|
80
|
+
borderTopRightRadius: cssVar("--border-radius-m"),
|
|
81
|
+
},
|
|
82
|
+
":hover": {
|
|
83
|
+
backgroundColor: cssVar("--hovered-background"),
|
|
84
|
+
},
|
|
85
|
+
":active:hover": {
|
|
86
|
+
backgroundColor: cssVar("--pressed-background"),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
getPadding(tabPadding),
|
|
90
|
+
tabJSStyle,
|
|
91
|
+
]}
|
|
92
|
+
>
|
|
93
|
+
{addOnPosition === "start" && addOn}
|
|
94
|
+
<Text size={labelSize} color={selected ? "primary" : "secondary"}>
|
|
95
|
+
{label}
|
|
96
|
+
</Text>
|
|
97
|
+
{addOnPosition === "end" && addOn}
|
|
98
|
+
</BaseLink>
|
|
99
|
+
)
|
|
100
|
+
)}
|
|
101
|
+
</Row>
|
|
102
|
+
);
|
|
103
|
+
}
|
package/src/Text.tsx
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { JSStyle, Size, TextColor, getTextColor, jss } from "./jss";
|
|
3
|
+
|
|
4
|
+
const fontSize = {
|
|
5
|
+
xsmall: "0.75rem",
|
|
6
|
+
small: "1rem",
|
|
7
|
+
medium: "1.25rem",
|
|
8
|
+
large: "1.5rem",
|
|
9
|
+
xlarge: "2rem",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type Display = "inline" | "block";
|
|
13
|
+
|
|
14
|
+
export interface TextProps {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
color?: TextColor;
|
|
17
|
+
size?: Size;
|
|
18
|
+
bold?: boolean;
|
|
19
|
+
ellipsis?: boolean | "default";
|
|
20
|
+
align?: "center" | "none";
|
|
21
|
+
type?: TextType;
|
|
22
|
+
grow?: boolean;
|
|
23
|
+
jsStyle?: JSStyle;
|
|
24
|
+
id?: string;
|
|
25
|
+
htmlFor?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type TextType =
|
|
29
|
+
| "label"
|
|
30
|
+
| "span"
|
|
31
|
+
| "p"
|
|
32
|
+
| "h1"
|
|
33
|
+
| "h2"
|
|
34
|
+
| "h3"
|
|
35
|
+
| "h4"
|
|
36
|
+
| "li";
|
|
37
|
+
|
|
38
|
+
export function Text({
|
|
39
|
+
children,
|
|
40
|
+
color = "primary",
|
|
41
|
+
size = "medium",
|
|
42
|
+
align = "none",
|
|
43
|
+
bold = false,
|
|
44
|
+
ellipsis = "default",
|
|
45
|
+
grow,
|
|
46
|
+
type: Type = "span",
|
|
47
|
+
jsStyle,
|
|
48
|
+
id,
|
|
49
|
+
htmlFor,
|
|
50
|
+
}: TextProps) {
|
|
51
|
+
if (ellipsis === "default") {
|
|
52
|
+
ellipsis = Type === "span" || Type === "label";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const className = jss([
|
|
56
|
+
getTextColor(color),
|
|
57
|
+
{ fontSize: fontSize[size], padding: 0, margin: 0 },
|
|
58
|
+
bold && { fontWeight: "bold" },
|
|
59
|
+
align === "center" && { textAlign: "center" },
|
|
60
|
+
ellipsis && {
|
|
61
|
+
overflow: "hidden",
|
|
62
|
+
textOverflow: "ellipsis",
|
|
63
|
+
whiteSpace: "nowrap",
|
|
64
|
+
},
|
|
65
|
+
grow && { flexGrow: 1 },
|
|
66
|
+
jsStyle,
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Type id={id} className={className} htmlFor={htmlFor}>
|
|
71
|
+
{children}
|
|
72
|
+
</Type>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function Label({ size = "small", type = "label", ...rest }: TextProps) {
|
|
77
|
+
return <Text size={size} type={type} {...rest} />;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function Span({ size = "small", type = "span", ...rest }: TextProps) {
|
|
81
|
+
return <Text size={size} type={type} {...rest} />;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function P({ size = "small", type = "p", ...rest }: TextProps) {
|
|
85
|
+
return <Text size={size} type={type} {...rest} />;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function H1({ size = "xlarge", type = "h1", ...rest }: TextProps) {
|
|
89
|
+
return <Text size={size} type={type} {...rest} />;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function H2({ size = "large", type = "h2", ...rest }: TextProps) {
|
|
93
|
+
return <Text size={size} type={type} {...rest} />;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function H3({ size = "medium", type = "h3", ...rest }: TextProps) {
|
|
97
|
+
return <Text size={size} type={type} {...rest} />;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function Li({ size = "small", type = "li", ...rest }: TextProps) {
|
|
101
|
+
return <Text size={size} type={type} {...rest} />;
|
|
102
|
+
}
|
package/src/TextArea.tsx
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { JSStyle, jss } from "./jss";
|
|
3
|
+
|
|
4
|
+
export interface TextAreaProps
|
|
5
|
+
extends React.InputHTMLAttributes<HTMLTextAreaElement> {
|
|
6
|
+
jsStyle?: JSStyle;
|
|
7
|
+
onValueChange?: (value: string) => void;
|
|
8
|
+
value?: string;
|
|
9
|
+
className?: undefined;
|
|
10
|
+
size?: undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const TextArea = React.forwardRef(
|
|
14
|
+
(
|
|
15
|
+
{ jsStyle, onValueChange, value, onChange, ...otherProps }: TextAreaProps,
|
|
16
|
+
ref?: React.Ref<HTMLTextAreaElement>
|
|
17
|
+
) => {
|
|
18
|
+
return (
|
|
19
|
+
<textarea
|
|
20
|
+
{...otherProps}
|
|
21
|
+
ref={ref}
|
|
22
|
+
className={jss([
|
|
23
|
+
{
|
|
24
|
+
padding: "var(--spacing-m)",
|
|
25
|
+
flexGrow: 1,
|
|
26
|
+
backgroundColor: "var(--primary-background)",
|
|
27
|
+
color: "var(--primary-text)",
|
|
28
|
+
outline: "none",
|
|
29
|
+
border: "none",
|
|
30
|
+
fontSize: 20,
|
|
31
|
+
lineHeight: 24 / 20,
|
|
32
|
+
"::placeholder": {
|
|
33
|
+
color: "var(--secondary-text);",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
jsStyle,
|
|
37
|
+
])}
|
|
38
|
+
value={value}
|
|
39
|
+
onChange={
|
|
40
|
+
onValueChange ? (e) => onValueChange(e.target.value) : undefined
|
|
41
|
+
}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
);
|