@siiway/ui-react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/components/BrandMark.d.ts +11 -0
- package/dist/components/BrandMark.d.ts.map +1 -0
- package/dist/components/BrandMark.js +11 -0
- package/dist/components/BrandMark.js.map +1 -0
- package/dist/components/CheckboxField.d.ts +15 -0
- package/dist/components/CheckboxField.d.ts.map +1 -0
- package/dist/components/CheckboxField.js +23 -0
- package/dist/components/CheckboxField.js.map +1 -0
- package/dist/components/ColorPickerInput.d.ts +17 -0
- package/dist/components/ColorPickerInput.d.ts.map +1 -0
- package/dist/components/ColorPickerInput.js +97 -0
- package/dist/components/ColorPickerInput.js.map +1 -0
- package/dist/components/CommandPalette.d.ts +53 -0
- package/dist/components/CommandPalette.d.ts.map +1 -0
- package/dist/components/CommandPalette.js +239 -0
- package/dist/components/CommandPalette.js.map +1 -0
- package/dist/components/CopyButton.d.ts +8 -0
- package/dist/components/CopyButton.d.ts.map +1 -0
- package/dist/components/CopyButton.js +17 -0
- package/dist/components/CopyButton.js.map +1 -0
- package/dist/components/CopyIdTrigger.d.ts +31 -0
- package/dist/components/CopyIdTrigger.d.ts.map +1 -0
- package/dist/components/CopyIdTrigger.js +72 -0
- package/dist/components/CopyIdTrigger.js.map +1 -0
- package/dist/components/DataList.d.ts +78 -0
- package/dist/components/DataList.d.ts.map +1 -0
- package/dist/components/DataList.js +150 -0
- package/dist/components/DataList.js.map +1 -0
- package/dist/components/DetailHeader.d.ts +22 -0
- package/dist/components/DetailHeader.d.ts.map +1 -0
- package/dist/components/DetailHeader.js +48 -0
- package/dist/components/DetailHeader.js.map +1 -0
- package/dist/components/DurationInput.d.ts +25 -0
- package/dist/components/DurationInput.d.ts.map +1 -0
- package/dist/components/DurationInput.js +83 -0
- package/dist/components/DurationInput.js.map +1 -0
- package/dist/components/EmptyState.d.ts +14 -0
- package/dist/components/EmptyState.d.ts.map +1 -0
- package/dist/components/EmptyState.js +41 -0
- package/dist/components/EmptyState.js.map +1 -0
- package/dist/components/FormPage.d.ts +22 -0
- package/dist/components/FormPage.d.ts.map +1 -0
- package/dist/components/FormPage.js +65 -0
- package/dist/components/FormPage.js.map +1 -0
- package/dist/components/GetStartedPanel.d.ts +16 -0
- package/dist/components/GetStartedPanel.d.ts.map +1 -0
- package/dist/components/GetStartedPanel.js +96 -0
- package/dist/components/GetStartedPanel.js.map +1 -0
- package/dist/components/LabeledLine.d.ts +12 -0
- package/dist/components/LabeledLine.d.ts.map +1 -0
- package/dist/components/LabeledLine.js +6 -0
- package/dist/components/LabeledLine.js.map +1 -0
- package/dist/components/ListSearch.d.ts +15 -0
- package/dist/components/ListSearch.d.ts.map +1 -0
- package/dist/components/ListSearch.js +23 -0
- package/dist/components/ListSearch.js.map +1 -0
- package/dist/components/LoadingBar.d.ts +8 -0
- package/dist/components/LoadingBar.d.ts.map +1 -0
- package/dist/components/LoadingBar.js +55 -0
- package/dist/components/LoadingBar.js.map +1 -0
- package/dist/components/Outline.d.ts +23 -0
- package/dist/components/Outline.d.ts.map +1 -0
- package/dist/components/Outline.js +150 -0
- package/dist/components/Outline.js.map +1 -0
- package/dist/components/Overview.d.ts +103 -0
- package/dist/components/Overview.d.ts.map +1 -0
- package/dist/components/Overview.js +286 -0
- package/dist/components/Overview.js.map +1 -0
- package/dist/components/PageHeader.d.ts +19 -0
- package/dist/components/PageHeader.d.ts.map +1 -0
- package/dist/components/PageHeader.js +50 -0
- package/dist/components/PageHeader.js.map +1 -0
- package/dist/components/Pagination.d.ts +19 -0
- package/dist/components/Pagination.d.ts.map +1 -0
- package/dist/components/Pagination.js +47 -0
- package/dist/components/Pagination.js.map +1 -0
- package/dist/components/PasswordInput.d.ts +3 -0
- package/dist/components/PasswordInput.d.ts.map +1 -0
- package/dist/components/PasswordInput.js +16 -0
- package/dist/components/PasswordInput.js.map +1 -0
- package/dist/components/PrevNext.d.ts +16 -0
- package/dist/components/PrevNext.d.ts.map +1 -0
- package/dist/components/PrevNext.js +61 -0
- package/dist/components/PrevNext.js.map +1 -0
- package/dist/components/SearchButton.d.ts +16 -0
- package/dist/components/SearchButton.d.ts.map +1 -0
- package/dist/components/SearchButton.js +63 -0
- package/dist/components/SearchButton.js.map +1 -0
- package/dist/components/SearchField.d.ts +10 -0
- package/dist/components/SearchField.d.ts.map +1 -0
- package/dist/components/SearchField.js +67 -0
- package/dist/components/SearchField.js.map +1 -0
- package/dist/components/Segmented.d.ts +28 -0
- package/dist/components/Segmented.d.ts.map +1 -0
- package/dist/components/Segmented.js +74 -0
- package/dist/components/Segmented.js.map +1 -0
- package/dist/components/Select.d.ts +22 -0
- package/dist/components/Select.d.ts.map +1 -0
- package/dist/components/Select.js +50 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Settings.d.ts +103 -0
- package/dist/components/Settings.d.ts.map +1 -0
- package/dist/components/Settings.js +246 -0
- package/dist/components/Settings.js.map +1 -0
- package/dist/components/SideNav.d.ts +34 -0
- package/dist/components/SideNav.d.ts.map +1 -0
- package/dist/components/SideNav.js +99 -0
- package/dist/components/SideNav.js.map +1 -0
- package/dist/components/Skeletons.d.ts +37 -0
- package/dist/components/Skeletons.d.ts.map +1 -0
- package/dist/components/Skeletons.js +109 -0
- package/dist/components/Skeletons.js.map +1 -0
- package/dist/components/StatusPage.d.ts +37 -0
- package/dist/components/StatusPage.d.ts.map +1 -0
- package/dist/components/StatusPage.js +106 -0
- package/dist/components/StatusPage.js.map +1 -0
- package/dist/components/ThemeMenu.d.ts +11 -0
- package/dist/components/ThemeMenu.d.ts.map +1 -0
- package/dist/components/ThemeMenu.js +42 -0
- package/dist/components/ThemeMenu.js.map +1 -0
- package/dist/components/ThemeSwitch.d.ts +14 -0
- package/dist/components/ThemeSwitch.d.ts.map +1 -0
- package/dist/components/ThemeSwitch.js +17 -0
- package/dist/components/ThemeSwitch.js.map +1 -0
- package/dist/components/TopBar.d.ts +45 -0
- package/dist/components/TopBar.d.ts.map +1 -0
- package/dist/components/TopBar.js +145 -0
- package/dist/components/TopBar.js.map +1 -0
- package/dist/components/ViewBanner.d.ts +17 -0
- package/dist/components/ViewBanner.d.ts.map +1 -0
- package/dist/components/ViewBanner.js +14 -0
- package/dist/components/ViewBanner.js.map +1 -0
- package/dist/hooks/platform.d.ts +7 -0
- package/dist/hooks/platform.d.ts.map +1 -0
- package/dist/hooks/platform.js +19 -0
- package/dist/hooks/platform.js.map +1 -0
- package/dist/hooks/useConfirm.d.ts +23 -0
- package/dist/hooks/useConfirm.d.ts.map +1 -0
- package/dist/hooks/useConfirm.js +55 -0
- package/dist/hooks/useConfirm.js.map +1 -0
- package/dist/hooks/useCopy.d.ts +9 -0
- package/dist/hooks/useCopy.d.ts.map +1 -0
- package/dist/hooks/useCopy.js +14 -0
- package/dist/hooks/useCopy.js.map +1 -0
- package/dist/hooks/useDebouncedSearch.d.ts +8 -0
- package/dist/hooks/useDebouncedSearch.d.ts.map +1 -0
- package/dist/hooks/useDebouncedSearch.js +19 -0
- package/dist/hooks/useDebouncedSearch.js.map +1 -0
- package/dist/hooks/usePageClamp.d.ts +4 -0
- package/dist/hooks/usePageClamp.d.ts.map +1 -0
- package/dist/hooks/usePageClamp.js +17 -0
- package/dist/hooks/usePageClamp.js.map +1 -0
- package/dist/hooks/useSearchShortcut.d.ts +8 -0
- package/dist/hooks/useSearchShortcut.d.ts.map +1 -0
- package/dist/hooks/useSearchShortcut.js +38 -0
- package/dist/hooks/useSearchShortcut.js.map +1 -0
- package/dist/hooks/useThemeMode.d.ts +17 -0
- package/dist/hooks/useThemeMode.d.ts.map +1 -0
- package/dist/hooks/useThemeMode.js +62 -0
- package/dist/hooks/useThemeMode.js.map +1 -0
- package/dist/hooks/useToastMessage.d.ts +22 -0
- package/dist/hooks/useToastMessage.d.ts.map +1 -0
- package/dist/hooks/useToastMessage.js +26 -0
- package/dist/hooks/useToastMessage.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/UiProvider.d.ts +37 -0
- package/dist/provider/UiProvider.d.ts.map +1 -0
- package/dist/provider/UiProvider.js +42 -0
- package/dist/provider/UiProvider.js.map +1 -0
- package/dist/provider/canvas.d.ts +2 -0
- package/dist/provider/canvas.d.ts.map +1 -0
- package/dist/provider/canvas.js +15 -0
- package/dist/provider/canvas.js.map +1 -0
- package/dist/provider/context.d.ts +45 -0
- package/dist/provider/context.d.ts.map +1 -0
- package/dist/provider/context.js +39 -0
- package/dist/provider/context.js.map +1 -0
- package/dist/theme/createTheme.d.ts +13 -0
- package/dist/theme/createTheme.d.ts.map +1 -0
- package/dist/theme/createTheme.js +18 -0
- package/dist/theme/createTheme.js.map +1 -0
- package/package.json +49 -4
- package/src/components/BrandMark.tsx +28 -0
- package/src/components/CheckboxField.tsx +50 -0
- package/src/components/ColorPickerInput.tsx +190 -0
- package/src/components/CommandPalette.tsx +437 -0
- package/src/components/CopyButton.tsx +48 -0
- package/src/components/CopyIdTrigger.tsx +127 -0
- package/src/components/DataList.tsx +332 -0
- package/src/components/DetailHeader.tsx +102 -0
- package/src/components/DurationInput.tsx +133 -0
- package/src/components/EmptyState.tsx +67 -0
- package/src/components/FormPage.tsx +109 -0
- package/src/components/GetStartedPanel.tsx +132 -0
- package/src/components/LabeledLine.tsx +28 -0
- package/src/components/ListSearch.tsx +64 -0
- package/src/components/LoadingBar.tsx +81 -0
- package/src/components/Outline.tsx +208 -0
- package/src/components/Overview.tsx +448 -0
- package/src/components/PageHeader.tsx +80 -0
- package/src/components/Pagination.tsx +105 -0
- package/src/components/PasswordInput.tsx +35 -0
- package/src/components/PrevNext.tsx +98 -0
- package/src/components/SearchButton.tsx +90 -0
- package/src/components/SearchField.tsx +97 -0
- package/src/components/Segmented.tsx +136 -0
- package/src/components/Select.tsx +110 -0
- package/src/components/Settings.tsx +432 -0
- package/src/components/SideNav.tsx +188 -0
- package/src/components/Skeletons.tsx +233 -0
- package/src/components/StatusPage.tsx +188 -0
- package/src/components/ThemeMenu.tsx +83 -0
- package/src/components/ThemeSwitch.tsx +39 -0
- package/src/components/TopBar.tsx +280 -0
- package/src/components/ViewBanner.tsx +51 -0
- package/src/hooks/platform.ts +22 -0
- package/src/hooks/useConfirm.tsx +97 -0
- package/src/hooks/useCopy.ts +20 -0
- package/src/hooks/useDebouncedSearch.ts +19 -0
- package/src/hooks/usePageClamp.ts +20 -0
- package/src/hooks/useSearchShortcut.ts +49 -0
- package/src/hooks/useThemeMode.ts +98 -0
- package/src/hooks/useToastMessage.ts +38 -0
- package/src/index.ts +140 -0
- package/src/provider/UiProvider.tsx +95 -0
- package/src/provider/canvas.ts +17 -0
- package/src/provider/context.tsx +85 -0
- package/src/theme/createTheme.ts +29 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/** A message for `SettingsToast`. */
|
|
4
|
+
export interface ToastMessage {
|
|
5
|
+
/** Shows it as a success or an error. */
|
|
6
|
+
type: "success" | "error";
|
|
7
|
+
/** The message, already translated. */
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A message that clears itself, for `SettingsToast`.
|
|
13
|
+
*
|
|
14
|
+
* @param timeoutMs How long a message shows, in milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
export function useToastMessage(timeoutMs = 5000) {
|
|
17
|
+
const [message, setMessage] = useState<ToastMessage | null>(null);
|
|
18
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
19
|
+
|
|
20
|
+
const showMsg = useCallback(
|
|
21
|
+
(type: ToastMessage["type"], text: string) => {
|
|
22
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
23
|
+
setMessage({ type, text });
|
|
24
|
+
timerRef.current = setTimeout(() => setMessage(null), timeoutMs);
|
|
25
|
+
},
|
|
26
|
+
[timeoutMs],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
/** The message to show, or `null`. Pass it to `SettingsToast`. */
|
|
31
|
+
message,
|
|
32
|
+
/** Shows a message, which clears after `timeoutMs`. A new one replaces
|
|
33
|
+
* the one showing and starts its own timeout. */
|
|
34
|
+
showMsg,
|
|
35
|
+
/** To clear or set the message yourself. */
|
|
36
|
+
setMessage,
|
|
37
|
+
};
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Theme and provider
|
|
2
|
+
export { createTheme, type CreateThemeOptions } from "./theme/createTheme.js";
|
|
3
|
+
export { UiProvider, type UiProviderProps } from "./provider/UiProvider.js";
|
|
4
|
+
export {
|
|
5
|
+
DEFAULT_ROUTER,
|
|
6
|
+
UiLink,
|
|
7
|
+
useUiNavigate,
|
|
8
|
+
useUiPageTitle,
|
|
9
|
+
useUiScheme,
|
|
10
|
+
useUiStrings,
|
|
11
|
+
type PageTitleHandler,
|
|
12
|
+
type UiLinkProps,
|
|
13
|
+
type UiRouter,
|
|
14
|
+
} from "./provider/context.js";
|
|
15
|
+
|
|
16
|
+
// Hooks
|
|
17
|
+
export { useConfirm, type ConfirmOptions } from "./hooks/useConfirm.js";
|
|
18
|
+
export { useCopy, type CopyState } from "./hooks/useCopy.js";
|
|
19
|
+
export { useDebouncedSearch } from "./hooks/useDebouncedSearch.js";
|
|
20
|
+
export { usePageClamp } from "./hooks/usePageClamp.js";
|
|
21
|
+
export { useSearchShortcut, type SearchShortcutOptions } from "./hooks/useSearchShortcut.js";
|
|
22
|
+
export { useThemeMode, type ThemeModeOptions, type ThemeModeState } from "./hooks/useThemeMode.js";
|
|
23
|
+
export { useToastMessage, type ToastMessage } from "./hooks/useToastMessage.js";
|
|
24
|
+
|
|
25
|
+
// Page structure
|
|
26
|
+
export { PageHeader } from "./components/PageHeader.js";
|
|
27
|
+
export { BackButton, DetailHeader } from "./components/DetailHeader.js";
|
|
28
|
+
export { FormPage } from "./components/FormPage.js";
|
|
29
|
+
export {
|
|
30
|
+
StatusPage,
|
|
31
|
+
type StatusPageAction,
|
|
32
|
+
type StatusPageProps,
|
|
33
|
+
} from "./components/StatusPage.js";
|
|
34
|
+
export { EmptyState } from "./components/EmptyState.js";
|
|
35
|
+
export { GetStartedPanel } from "./components/GetStartedPanel.js";
|
|
36
|
+
export { ViewBanner } from "./components/ViewBanner.js";
|
|
37
|
+
export { LabeledLine } from "./components/LabeledLine.js";
|
|
38
|
+
export { BrandMark } from "./components/BrandMark.js";
|
|
39
|
+
|
|
40
|
+
// Navigation
|
|
41
|
+
export {
|
|
42
|
+
TOP_BAR_HEIGHT,
|
|
43
|
+
TopBar,
|
|
44
|
+
type TopBarBrand,
|
|
45
|
+
type TopBarLink,
|
|
46
|
+
type TopBarProps,
|
|
47
|
+
} from "./components/TopBar.js";
|
|
48
|
+
export {
|
|
49
|
+
SideNav,
|
|
50
|
+
type SideNavGroup,
|
|
51
|
+
type SideNavItem,
|
|
52
|
+
type SideNavProps,
|
|
53
|
+
} from "./components/SideNav.js";
|
|
54
|
+
export { Outline, type OutlineItem, type OutlineProps } from "./components/Outline.js";
|
|
55
|
+
export { PrevNext, type PrevNextLink, type PrevNextProps } from "./components/PrevNext.js";
|
|
56
|
+
export { LoadingBar } from "./components/LoadingBar.js";
|
|
57
|
+
|
|
58
|
+
// Search
|
|
59
|
+
export { SearchField, type SearchFieldProps } from "./components/SearchField.js";
|
|
60
|
+
export { SearchButton, type SearchButtonProps } from "./components/SearchButton.js";
|
|
61
|
+
export {
|
|
62
|
+
CommandPalette,
|
|
63
|
+
type CommandGroup,
|
|
64
|
+
type CommandItem,
|
|
65
|
+
type CommandPaletteProps,
|
|
66
|
+
} from "./components/CommandPalette.js";
|
|
67
|
+
|
|
68
|
+
// Settings
|
|
69
|
+
export {
|
|
70
|
+
SaveFooter,
|
|
71
|
+
SettingsBody,
|
|
72
|
+
SettingsCard,
|
|
73
|
+
SettingsEmpty,
|
|
74
|
+
SettingsFooter,
|
|
75
|
+
SettingsLinkRow,
|
|
76
|
+
SettingsPage,
|
|
77
|
+
SettingsRow,
|
|
78
|
+
SettingsSubhead,
|
|
79
|
+
SettingsTable,
|
|
80
|
+
SettingsToast,
|
|
81
|
+
} from "./components/Settings.js";
|
|
82
|
+
|
|
83
|
+
// Lists and data
|
|
84
|
+
export {
|
|
85
|
+
DataList,
|
|
86
|
+
DataListLink,
|
|
87
|
+
DataListName,
|
|
88
|
+
DataListRow,
|
|
89
|
+
DataListSkeleton,
|
|
90
|
+
type DataListColumn,
|
|
91
|
+
} from "./components/DataList.js";
|
|
92
|
+
export { Pagination } from "./components/Pagination.js";
|
|
93
|
+
export { ListSearch } from "./components/ListSearch.js";
|
|
94
|
+
export {
|
|
95
|
+
Callout,
|
|
96
|
+
Callouts,
|
|
97
|
+
ListColumn,
|
|
98
|
+
ListGrid,
|
|
99
|
+
ListRow,
|
|
100
|
+
Metric,
|
|
101
|
+
MetricGrid,
|
|
102
|
+
MetricSuffix,
|
|
103
|
+
SectionTitle,
|
|
104
|
+
SummaryList,
|
|
105
|
+
SummaryRow,
|
|
106
|
+
} from "./components/Overview.js";
|
|
107
|
+
export {
|
|
108
|
+
SkeletonSettingsCard,
|
|
109
|
+
SkeletonSettingsPage,
|
|
110
|
+
SkeletonStatCards,
|
|
111
|
+
SkeletonTableBodyRows,
|
|
112
|
+
SkeletonTableRows,
|
|
113
|
+
} from "./components/Skeletons.js";
|
|
114
|
+
|
|
115
|
+
// Inputs
|
|
116
|
+
export { Segmented, type SegmentedOption } from "./components/Segmented.js";
|
|
117
|
+
export { ThemeSwitch, type ThemeSwitchProps } from "./components/ThemeSwitch.js";
|
|
118
|
+
export { ThemeMenu, type ThemeMenuProps } from "./components/ThemeMenu.js";
|
|
119
|
+
export { Select } from "./components/Select.js";
|
|
120
|
+
export { CheckboxField } from "./components/CheckboxField.js";
|
|
121
|
+
export { PasswordInput } from "./components/PasswordInput.js";
|
|
122
|
+
export { DurationInput } from "./components/DurationInput.js";
|
|
123
|
+
export { ColorPickerInput } from "./components/ColorPickerInput.js";
|
|
124
|
+
|
|
125
|
+
// Copy
|
|
126
|
+
export { CopyButton } from "./components/CopyButton.js";
|
|
127
|
+
export { CopyIdText, CopyIdTrigger } from "./components/CopyIdTrigger.js";
|
|
128
|
+
|
|
129
|
+
// Re-exported from @siiway/ui-core for convenience
|
|
130
|
+
export {
|
|
131
|
+
CANVAS,
|
|
132
|
+
DEFAULT_ACCENT,
|
|
133
|
+
THEME_STORAGE_KEY,
|
|
134
|
+
resolveScheme,
|
|
135
|
+
schemeBootScript,
|
|
136
|
+
type Scheme,
|
|
137
|
+
type ThemeMode,
|
|
138
|
+
type UiStrings,
|
|
139
|
+
type DurationUnit,
|
|
140
|
+
} from "@siiway/ui-core";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FluentProvider,
|
|
3
|
+
makeStaticStyles,
|
|
4
|
+
useIsomorphicLayoutEffect,
|
|
5
|
+
type FluentProviderProps,
|
|
6
|
+
} from "@fluentui/react-components";
|
|
7
|
+
import { CANVAS, pickStrings, type Scheme, type UiStrings } from "@siiway/ui-core";
|
|
8
|
+
import { useMemo } from "react";
|
|
9
|
+
import { createTheme } from "../theme/createTheme.js";
|
|
10
|
+
import { DEFAULT_ROUTER, UiContext, type PageTitleHandler, type UiRouter } from "./context.js";
|
|
11
|
+
|
|
12
|
+
export interface UiProviderProps extends Omit<FluentProviderProps, "theme"> {
|
|
13
|
+
/** The scheme to render in: `useThemeMode().scheme`, or the app's own. */
|
|
14
|
+
scheme: Scheme;
|
|
15
|
+
/**
|
|
16
|
+
* This provider is the page. It takes the canvas colour, removes the
|
|
17
|
+
* body's margin, and draws `<html>` in the scheme (`data-scheme`,
|
|
18
|
+
* `color-scheme`, the canvas background), as `schemeBootScript` does
|
|
19
|
+
* before the app loads. Set it on the app's outermost provider only.
|
|
20
|
+
*/
|
|
21
|
+
page?: boolean;
|
|
22
|
+
/** Brand colour; missing or invalid gives Fluent's blue. */
|
|
23
|
+
accent?: string | null;
|
|
24
|
+
/** BCP-47 tag for the library's own strings: `zh*` is Chinese, anything else English. */
|
|
25
|
+
locale?: string | null;
|
|
26
|
+
/** Replaces individual library strings. */
|
|
27
|
+
strings?: Partial<UiStrings>;
|
|
28
|
+
/**
|
|
29
|
+
* The app's router. Without one, links are `<a href>` and navigation
|
|
30
|
+
* reloads the page. Pass a stable object (define it at module level).
|
|
31
|
+
*/
|
|
32
|
+
router?: UiRouter;
|
|
33
|
+
/**
|
|
34
|
+
* Called with a page's title when a PageHeader mounts, and with null when
|
|
35
|
+
* it unmounts, so the app can set the browser tab's title. Pass a stable
|
|
36
|
+
* function.
|
|
37
|
+
*/
|
|
38
|
+
onPageTitle?: PageTitleHandler;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const usePageStyles = makeStaticStyles({ body: { margin: "0" } });
|
|
42
|
+
|
|
43
|
+
// <html> in the page's scheme, for what lies outside the provider: the
|
|
44
|
+
// overscroll area, the scrollbars, form controls' native parts.
|
|
45
|
+
function PageScheme({ scheme }: { scheme: Scheme }) {
|
|
46
|
+
usePageStyles();
|
|
47
|
+
useIsomorphicLayoutEffect(() => {
|
|
48
|
+
const root = document.documentElement;
|
|
49
|
+
root.setAttribute("data-scheme", scheme);
|
|
50
|
+
root.style.colorScheme = scheme;
|
|
51
|
+
root.style.backgroundColor = CANVAS[scheme];
|
|
52
|
+
return () => {
|
|
53
|
+
root.removeAttribute("data-scheme");
|
|
54
|
+
root.style.removeProperty("color-scheme");
|
|
55
|
+
root.style.removeProperty("background-color");
|
|
56
|
+
};
|
|
57
|
+
}, [scheme]);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Fluent's provider with the SiiWay theme, plus the library's strings and
|
|
63
|
+
* router. Wrap the app in it once, where FluentProvider used to be.
|
|
64
|
+
*/
|
|
65
|
+
export function UiProvider({
|
|
66
|
+
scheme,
|
|
67
|
+
page,
|
|
68
|
+
accent,
|
|
69
|
+
locale,
|
|
70
|
+
strings,
|
|
71
|
+
router,
|
|
72
|
+
onPageTitle,
|
|
73
|
+
children,
|
|
74
|
+
...rest
|
|
75
|
+
}: UiProviderProps) {
|
|
76
|
+
const theme = useMemo(() => createTheme({ scheme, accent }), [scheme, accent]);
|
|
77
|
+
const resolved = useMemo(() => pickStrings(locale, strings), [locale, strings]);
|
|
78
|
+
const value = useMemo(
|
|
79
|
+
() => ({
|
|
80
|
+
scheme,
|
|
81
|
+
strings: resolved,
|
|
82
|
+
router: router ?? DEFAULT_ROUTER,
|
|
83
|
+
onPageTitle: onPageTitle ?? null,
|
|
84
|
+
}),
|
|
85
|
+
[scheme, resolved, router, onPageTitle],
|
|
86
|
+
);
|
|
87
|
+
// Fluent paints its provider colorNeutralBackground1; the page is the canvas.
|
|
88
|
+
const style = page ? { backgroundColor: CANVAS[scheme], ...rest.style } : rest.style;
|
|
89
|
+
return (
|
|
90
|
+
<FluentProvider theme={theme} {...rest} style={style}>
|
|
91
|
+
{page && <PageScheme scheme={scheme} />}
|
|
92
|
+
<UiContext.Provider value={value}>{children}</UiContext.Provider>
|
|
93
|
+
</FluentProvider>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The page canvas as a class, for the parts of the page drawn on it that must
|
|
2
|
+
// be opaque: a sticky top bar, a full-page message. Tokens have no canvas
|
|
3
|
+
// (it's darker than colorNeutralBackground1 in dark), so this picks CANVAS by
|
|
4
|
+
// the provider's scheme.
|
|
5
|
+
|
|
6
|
+
import { makeStyles } from "@fluentui/react-components";
|
|
7
|
+
import { CANVAS } from "@siiway/ui-core";
|
|
8
|
+
import { useUiScheme } from "./context.js";
|
|
9
|
+
|
|
10
|
+
const useStyles = makeStyles({
|
|
11
|
+
light: { backgroundColor: CANVAS.light },
|
|
12
|
+
dark: { backgroundColor: CANVAS.dark },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export function useCanvasClass(): string {
|
|
16
|
+
return useStyles()[useUiScheme()];
|
|
17
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
type ComponentType,
|
|
5
|
+
type MouseEventHandler,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { UI_STRINGS, type Scheme, type UiStrings } from "@siiway/ui-core";
|
|
9
|
+
|
|
10
|
+
/** Props the library passes to the app's link component. */
|
|
11
|
+
export interface UiLinkProps {
|
|
12
|
+
/** An in-app path, e.g. `/apps/123`. */
|
|
13
|
+
to: string;
|
|
14
|
+
/** History state, for routers that keep it (React Router's `state`). */
|
|
15
|
+
state?: unknown;
|
|
16
|
+
className?: string;
|
|
17
|
+
onClick?: MouseEventHandler<HTMLAnchorElement>;
|
|
18
|
+
/** `"page"` on the link to the page the reader is on (SideNav, TopBar). */
|
|
19
|
+
"aria-current"?: "page";
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* How library components link and navigate. React Router fits as is:
|
|
25
|
+
* `router={{ Link, useNavigate }}`.
|
|
26
|
+
*/
|
|
27
|
+
export interface UiRouter {
|
|
28
|
+
Link: ComponentType<UiLinkProps>;
|
|
29
|
+
/** A hook returning a navigate function. Called during render, like any hook. */
|
|
30
|
+
useNavigate: () => (to: string) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function AnchorLink({ to, state: _state, ...rest }: UiLinkProps) {
|
|
34
|
+
return <a href={to} {...rest} />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function useLocationNavigate() {
|
|
38
|
+
return (to: string) => window.location.assign(to);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Plain `<a href>` links and full page loads: for apps without a client router. */
|
|
42
|
+
export const DEFAULT_ROUTER: UiRouter = { Link: AnchorLink, useNavigate: useLocationNavigate };
|
|
43
|
+
|
|
44
|
+
/** Receives the page's title from PageHeader, and null when the page goes. */
|
|
45
|
+
export type PageTitleHandler = (title: string | null) => void;
|
|
46
|
+
|
|
47
|
+
export interface UiContextValue {
|
|
48
|
+
scheme: Scheme;
|
|
49
|
+
strings: UiStrings;
|
|
50
|
+
router: UiRouter;
|
|
51
|
+
onPageTitle: PageTitleHandler | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const UiContext = createContext<UiContextValue>({
|
|
55
|
+
scheme: "light",
|
|
56
|
+
strings: UI_STRINGS.en,
|
|
57
|
+
router: DEFAULT_ROUTER,
|
|
58
|
+
onPageTitle: null,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/** The library's own strings, in the locale given to `<UiProvider>`. */
|
|
62
|
+
export function useUiStrings(): UiStrings {
|
|
63
|
+
return useContext(UiContext).strings;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The scheme `<UiProvider>` renders in. */
|
|
67
|
+
export function useUiScheme(): Scheme {
|
|
68
|
+
return useContext(UiContext).scheme;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A link through the app's router (React Router's `Link`, or `<a href>`). */
|
|
72
|
+
export function UiLink(props: UiLinkProps) {
|
|
73
|
+
const { Link } = useContext(UiContext).router;
|
|
74
|
+
return <Link {...props} />;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A function that navigates to an in-app path. */
|
|
78
|
+
export function useUiNavigate(): (to: string) => void {
|
|
79
|
+
return useContext(UiContext).router.useNavigate();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The app's page-title handler, if it gave `<UiProvider onPageTitle>`. */
|
|
83
|
+
export function useUiPageTitle(): PageTitleHandler | null {
|
|
84
|
+
return useContext(UiContext).onPageTitle;
|
|
85
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDarkTheme,
|
|
3
|
+
createLightTheme,
|
|
4
|
+
webDarkTheme,
|
|
5
|
+
webLightTheme,
|
|
6
|
+
type Theme,
|
|
7
|
+
} from "@fluentui/react-components";
|
|
8
|
+
import { brandRamp, themeOverrides, type Scheme } from "@siiway/ui-core";
|
|
9
|
+
|
|
10
|
+
export interface CreateThemeOptions {
|
|
11
|
+
scheme: Scheme;
|
|
12
|
+
/** Brand colour, `#rgb` to `#rrggbbaa`. Missing or invalid gives Fluent's blue. */
|
|
13
|
+
accent?: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The SiiWay Fluent theme: Fluent's own theme for the accent's brand ramp,
|
|
18
|
+
* with the neutral greys, radii and shadows replaced.
|
|
19
|
+
*/
|
|
20
|
+
export function createTheme({ scheme, accent }: CreateThemeOptions): Theme {
|
|
21
|
+
const brand = brandRamp(accent);
|
|
22
|
+
let base: Theme;
|
|
23
|
+
try {
|
|
24
|
+
base = scheme === "dark" ? createDarkTheme(brand) : createLightTheme(brand);
|
|
25
|
+
} catch {
|
|
26
|
+
base = scheme === "dark" ? webDarkTheme : webLightTheme;
|
|
27
|
+
}
|
|
28
|
+
return { ...base, ...themeOverrides(scheme) };
|
|
29
|
+
}
|