@siiway/ui-react 0.0.0 → 0.2.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 +19 -1
- package/dist/components/AppShell.d.ts +29 -0
- package/dist/components/AppShell.d.ts.map +1 -0
- package/dist/components/AppShell.js +220 -0
- package/dist/components/AppShell.js.map +1 -0
- package/dist/components/AuthShell.d.ts +21 -0
- package/dist/components/AuthShell.d.ts.map +1 -0
- package/dist/components/AuthShell.js +53 -0
- package/dist/components/AuthShell.js.map +1 -0
- 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/ButtonLink.d.ts +11 -0
- package/dist/components/ButtonLink.d.ts.map +1 -0
- package/dist/components/ButtonLink.js +15 -0
- package/dist/components/ButtonLink.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 +65 -0
- package/dist/components/CommandPalette.d.ts.map +1 -0
- package/dist/components/CommandPalette.js +269 -0
- package/dist/components/CommandPalette.js.map +1 -0
- package/dist/components/CopyButton.d.ts +27 -0
- package/dist/components/CopyButton.d.ts.map +1 -0
- package/dist/components/CopyButton.js +20 -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 +26 -0
- package/dist/components/DetailHeader.d.ts.map +1 -0
- package/dist/components/DetailHeader.js +49 -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/LoadingPage.d.ts +6 -0
- package/dist/components/LoadingPage.d.ts.map +1 -0
- package/dist/components/LoadingPage.js +25 -0
- package/dist/components/LoadingPage.js.map +1 -0
- package/dist/components/MenuPanel.d.ts +34 -0
- package/dist/components/MenuPanel.d.ts.map +1 -0
- package/dist/components/MenuPanel.js +98 -0
- package/dist/components/MenuPanel.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 +41 -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 +29 -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 +47 -0
- package/dist/components/SideNav.d.ts.map +1 -0
- package/dist/components/SideNav.js +125 -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 +49 -0
- package/dist/components/StatusPage.d.ts.map +1 -0
- package/dist/components/StatusPage.js +110 -0
- package/dist/components/StatusPage.js.map +1 -0
- package/dist/components/ThemeMenu.d.ts +13 -0
- package/dist/components/ThemeMenu.d.ts.map +1 -0
- package/dist/components/ThemeMenu.js +18 -0
- package/dist/components/ThemeMenu.js.map +1 -0
- package/dist/components/ThemeSwitch.d.ts +17 -0
- package/dist/components/ThemeSwitch.d.ts.map +1 -0
- package/dist/components/ThemeSwitch.js +25 -0
- package/dist/components/ThemeSwitch.js.map +1 -0
- package/dist/components/TopBar.d.ts +49 -0
- package/dist/components/TopBar.d.ts.map +1 -0
- package/dist/components/TopBar.js +146 -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 +12 -0
- package/dist/hooks/useCopy.d.ts.map +1 -0
- package/dist/hooks/useCopy.js +39 -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 +29 -0
- package/dist/hooks/useThemeMode.d.ts.map +1 -0
- package/dist/hooks/useThemeMode.js +111 -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 +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/UiProvider.d.ts +60 -0
- package/dist/provider/UiProvider.d.ts.map +1 -0
- package/dist/provider/UiProvider.js +144 -0
- package/dist/provider/UiProvider.js.map +1 -0
- package/dist/provider/canvas.d.ts +7 -0
- package/dist/provider/canvas.d.ts.map +1 -0
- package/dist/provider/canvas.js +30 -0
- package/dist/provider/canvas.js.map +1 -0
- package/dist/provider/context.d.ts +69 -0
- package/dist/provider/context.d.ts.map +1 -0
- package/dist/provider/context.js +84 -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 +42 -2
- package/src/components/AppShell.tsx +337 -0
- package/src/components/AuthShell.tsx +104 -0
- package/src/components/BrandMark.tsx +28 -0
- package/src/components/ButtonLink.tsx +40 -0
- package/src/components/CheckboxField.tsx +50 -0
- package/src/components/ColorPickerInput.tsx +190 -0
- package/src/components/CommandPalette.tsx +479 -0
- package/src/components/CopyButton.tsx +76 -0
- package/src/components/CopyIdTrigger.tsx +127 -0
- package/src/components/DataList.tsx +332 -0
- package/src/components/DetailHeader.tsx +108 -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/LoadingPage.tsx +41 -0
- package/src/components/MenuPanel.tsx +163 -0
- package/src/components/Outline.tsx +208 -0
- package/src/components/Overview.tsx +448 -0
- package/src/components/PageHeader.tsx +69 -0
- package/src/components/Pagination.tsx +105 -0
- package/src/components/PasswordInput.tsx +50 -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 +258 -0
- package/src/components/Skeletons.tsx +233 -0
- package/src/components/StatusPage.tsx +212 -0
- package/src/components/ThemeMenu.tsx +51 -0
- package/src/components/ThemeSwitch.tsx +49 -0
- package/src/components/TopBar.tsx +293 -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 +39 -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 +168 -0
- package/src/hooks/useToastMessage.ts +38 -0
- package/src/index.ts +156 -0
- package/src/provider/UiProvider.tsx +256 -0
- package/src/provider/canvas.ts +31 -0
- package/src/provider/context.tsx +145 -0
- package/src/theme/createTheme.ts +29 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// An app's frame: a sidebar beside the page, which below a width becomes a
|
|
2
|
+
// drawer that slides in over it. Prism's layout, which Vellum and Glint built
|
|
3
|
+
// with Fluent's OverlayDrawer and a width check in JavaScript. This one is CSS,
|
|
4
|
+
// so it renders on the server; only focus and closing need the browser.
|
|
5
|
+
//
|
|
6
|
+
// While a drawer, the sidebar is inert until opened, and again as soon as it
|
|
7
|
+
// starts to close. Open, it is a modal dialog: focus moves into it and Tab
|
|
8
|
+
// wraps around in it, the page behind is
|
|
9
|
+
// inert, and Escape, the backdrop, a link in it, AppShellClose or the window
|
|
10
|
+
// growing past the width close it, with focus back where it was, or on the
|
|
11
|
+
// page when that has gone from view.
|
|
12
|
+
|
|
13
|
+
import { Button, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
|
|
14
|
+
import { DismissRegular } from "@fluentui/react-icons";
|
|
15
|
+
import {
|
|
16
|
+
createContext,
|
|
17
|
+
useCallback,
|
|
18
|
+
useContext,
|
|
19
|
+
useEffect,
|
|
20
|
+
useRef,
|
|
21
|
+
useSyncExternalStore,
|
|
22
|
+
type KeyboardEvent,
|
|
23
|
+
type MouseEvent,
|
|
24
|
+
type ReactNode,
|
|
25
|
+
} from "react";
|
|
26
|
+
import { useCanvasClass } from "../provider/canvas.js";
|
|
27
|
+
import { useUiStrings } from "../provider/context.js";
|
|
28
|
+
|
|
29
|
+
const SLIDE = "transform 0.2s ease-out";
|
|
30
|
+
|
|
31
|
+
// Below each width the sidebar is a drawer. Griffel needs its media queries
|
|
32
|
+
// written out, so each width has its classes.
|
|
33
|
+
const useStyles = makeStyles({
|
|
34
|
+
shell: {
|
|
35
|
+
display: "flex",
|
|
36
|
+
height: "100vh",
|
|
37
|
+
overflow: "hidden",
|
|
38
|
+
// A phone's collapsing address bar: the visible height, where supported.
|
|
39
|
+
"@supports (height: 100dvh)": { height: "100dvh" },
|
|
40
|
+
},
|
|
41
|
+
sidebar: {
|
|
42
|
+
display: "flex",
|
|
43
|
+
flexDirection: "column",
|
|
44
|
+
flexShrink: 0,
|
|
45
|
+
boxSizing: "border-box",
|
|
46
|
+
borderRight: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
47
|
+
":focus-visible": { outline: "none" },
|
|
48
|
+
},
|
|
49
|
+
drawer768: {
|
|
50
|
+
"@media (max-width: 768px)": {
|
|
51
|
+
position: "fixed",
|
|
52
|
+
top: 0,
|
|
53
|
+
bottom: 0,
|
|
54
|
+
left: 0,
|
|
55
|
+
zIndex: 200,
|
|
56
|
+
transform: "translateX(-100%)",
|
|
57
|
+
visibility: "hidden",
|
|
58
|
+
// Hidden once it has slid out, not before.
|
|
59
|
+
transition: `${SLIDE}, visibility 0s linear 0.2s`,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
drawer960: {
|
|
63
|
+
"@media (max-width: 960px)": {
|
|
64
|
+
position: "fixed",
|
|
65
|
+
top: 0,
|
|
66
|
+
bottom: 0,
|
|
67
|
+
left: 0,
|
|
68
|
+
zIndex: 200,
|
|
69
|
+
transform: "translateX(-100%)",
|
|
70
|
+
visibility: "hidden",
|
|
71
|
+
transition: `${SLIDE}, visibility 0s linear 0.2s`,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
open768: {
|
|
75
|
+
"@media (max-width: 768px)": { transform: "none", visibility: "visible", transition: SLIDE },
|
|
76
|
+
},
|
|
77
|
+
open960: {
|
|
78
|
+
"@media (max-width: 960px)": { transform: "none", visibility: "visible", transition: SLIDE },
|
|
79
|
+
},
|
|
80
|
+
still: {
|
|
81
|
+
"@media (prefers-reduced-motion: reduce)": { transition: "none" },
|
|
82
|
+
},
|
|
83
|
+
backdrop: {
|
|
84
|
+
position: "fixed",
|
|
85
|
+
inset: 0,
|
|
86
|
+
zIndex: 199,
|
|
87
|
+
background: "rgba(0, 0, 0, 0.5)",
|
|
88
|
+
},
|
|
89
|
+
above768: { "@media (min-width: 769px)": { display: "none" } },
|
|
90
|
+
above960: { "@media (min-width: 961px)": { display: "none" } },
|
|
91
|
+
column: {
|
|
92
|
+
flex: 1,
|
|
93
|
+
display: "flex",
|
|
94
|
+
flexDirection: "column",
|
|
95
|
+
minWidth: 0,
|
|
96
|
+
},
|
|
97
|
+
header: { flexShrink: 0 },
|
|
98
|
+
main: {
|
|
99
|
+
flex: 1,
|
|
100
|
+
overflowY: "auto",
|
|
101
|
+
display: "flex",
|
|
102
|
+
flexDirection: "column",
|
|
103
|
+
// Focused only when the drawer closes and its opener has gone.
|
|
104
|
+
":focus-visible": { outline: "none" },
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Whether the window is below the width, kept up to date; on the server, and
|
|
109
|
+
// while hydrating, it isn't (the CSS draws the drawer either way).
|
|
110
|
+
function useBelow(query: string): boolean {
|
|
111
|
+
const subscribe = useCallback(
|
|
112
|
+
(onChange: () => void) => {
|
|
113
|
+
const media = window.matchMedia(query);
|
|
114
|
+
media.addEventListener("change", onChange);
|
|
115
|
+
return () => media.removeEventListener("change", onChange);
|
|
116
|
+
},
|
|
117
|
+
[query],
|
|
118
|
+
);
|
|
119
|
+
return useSyncExternalStore(
|
|
120
|
+
subscribe,
|
|
121
|
+
() => window.matchMedia(query).matches,
|
|
122
|
+
() => false,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Something focus can go back to: still in the page and drawn.
|
|
127
|
+
function canFocus(element: HTMLElement | null): element is HTMLElement {
|
|
128
|
+
return !!element && element.isConnected && element.getClientRects().length > 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const TABBABLE =
|
|
132
|
+
'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
133
|
+
|
|
134
|
+
// What Tab reaches in the drawer, in order.
|
|
135
|
+
function tabbables(root: HTMLElement): HTMLElement[] {
|
|
136
|
+
return Array.from(root.querySelectorAll<HTMLElement>(TABBABLE)).filter(
|
|
137
|
+
(element) => element.tabIndex >= 0 && canFocus(element),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface ShellState {
|
|
142
|
+
drawerBelow: 768 | 960;
|
|
143
|
+
close: () => void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const ShellContext = createContext<ShellState | null>(null);
|
|
147
|
+
|
|
148
|
+
export interface AppShellProps {
|
|
149
|
+
/** The sidebar, top to bottom: the brand, search, the navigation, an account menu. */
|
|
150
|
+
sidebar: ReactNode;
|
|
151
|
+
/** The page, in the scrolling area beside the sidebar: the `main` landmark. */
|
|
152
|
+
children: ReactNode;
|
|
153
|
+
/** Above the page, such as a `TopBar` whose menu button opens the drawer. */
|
|
154
|
+
header?: ReactNode;
|
|
155
|
+
/** Show `header` only where the sidebar is a drawer, as the bar that opens it. */
|
|
156
|
+
headerOnlyWithDrawer?: boolean;
|
|
157
|
+
/** Whether the drawer is open. */
|
|
158
|
+
open: boolean;
|
|
159
|
+
/** Called to open or close the drawer: with false on Escape, the backdrop,
|
|
160
|
+
* a link in the drawer, `AppShellClose`, or the window growing past
|
|
161
|
+
* `drawerBelow`. */
|
|
162
|
+
onOpenChange: (open: boolean) => void;
|
|
163
|
+
/** The width from which down the sidebar is a drawer: 960 (the default) or
|
|
164
|
+
* 768. `TopBar`'s `menuBelow` has the same default; change both together. */
|
|
165
|
+
drawerBelow?: 768 | 960;
|
|
166
|
+
/** The sidebar's width in px. Defaults to 240. */
|
|
167
|
+
sidebarWidth?: number;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function AppShell({
|
|
171
|
+
sidebar,
|
|
172
|
+
children,
|
|
173
|
+
header,
|
|
174
|
+
headerOnlyWithDrawer,
|
|
175
|
+
open,
|
|
176
|
+
onOpenChange,
|
|
177
|
+
drawerBelow = 960,
|
|
178
|
+
sidebarWidth = 240,
|
|
179
|
+
}: AppShellProps) {
|
|
180
|
+
const styles = useStyles();
|
|
181
|
+
const strings = useUiStrings();
|
|
182
|
+
const canvas = useCanvasClass();
|
|
183
|
+
const aside = useRef<HTMLElement>(null);
|
|
184
|
+
const column = useRef<HTMLDivElement>(null);
|
|
185
|
+
const main = useRef<HTMLElement>(null);
|
|
186
|
+
const query = `(max-width: ${drawerBelow}px)`;
|
|
187
|
+
const narrow = drawerBelow === 768;
|
|
188
|
+
const isDrawer = useBelow(query);
|
|
189
|
+
const modal = open && isDrawer;
|
|
190
|
+
|
|
191
|
+
// A closed drawer is inert at once, though it takes a moment to slide out.
|
|
192
|
+
// Set here, not as a prop: React 18 and 19 read `inert` differently.
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
const drawer = aside.current;
|
|
195
|
+
if (isDrawer && !open) drawer?.setAttribute("inert", "");
|
|
196
|
+
else drawer?.removeAttribute("inert");
|
|
197
|
+
}, [isDrawer, open]);
|
|
198
|
+
|
|
199
|
+
// Open as a drawer, including an open sidebar the window narrows under:
|
|
200
|
+
// focus in, the page inert, and back out on close.
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
if (!modal) return;
|
|
203
|
+
const before = document.activeElement as HTMLElement | null;
|
|
204
|
+
const drawer = aside.current;
|
|
205
|
+
const page = column.current;
|
|
206
|
+
const fallback = main.current;
|
|
207
|
+
drawer?.focus();
|
|
208
|
+
page?.setAttribute("inert", "");
|
|
209
|
+
return () => {
|
|
210
|
+
page?.removeAttribute("inert");
|
|
211
|
+
const active = document.activeElement;
|
|
212
|
+
if (!drawer?.contains(active) && active !== document.body) return;
|
|
213
|
+
// The opener may have gone from view, such as a header shown only
|
|
214
|
+
// with the drawer, after the window grew.
|
|
215
|
+
if (canFocus(before)) before.focus();
|
|
216
|
+
else fallback?.focus();
|
|
217
|
+
};
|
|
218
|
+
}, [modal]);
|
|
219
|
+
|
|
220
|
+
// A window that grows past the width has no drawer to keep open.
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
if (!open) return;
|
|
223
|
+
const media = window.matchMedia(query);
|
|
224
|
+
const onChange = () => {
|
|
225
|
+
if (!media.matches) onOpenChange(false);
|
|
226
|
+
};
|
|
227
|
+
media.addEventListener("change", onChange);
|
|
228
|
+
return () => media.removeEventListener("change", onChange);
|
|
229
|
+
}, [open, query, onOpenChange]);
|
|
230
|
+
|
|
231
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
232
|
+
if (!modal) return;
|
|
233
|
+
if (event.key === "Escape") {
|
|
234
|
+
event.stopPropagation();
|
|
235
|
+
onOpenChange(false);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// Tab wraps around in the drawer, so it never reaches the browser's bar.
|
|
239
|
+
if (event.key !== "Tab" || !aside.current) return;
|
|
240
|
+
const stops = tabbables(aside.current);
|
|
241
|
+
const first = stops[0];
|
|
242
|
+
const last = stops[stops.length - 1];
|
|
243
|
+
const active = document.activeElement;
|
|
244
|
+
if (!first || !last) {
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
} else if (event.shiftKey && (active === first || active === aside.current)) {
|
|
247
|
+
event.preventDefault();
|
|
248
|
+
last.focus();
|
|
249
|
+
} else if (!event.shiftKey && active === last) {
|
|
250
|
+
event.preventDefault();
|
|
251
|
+
first.focus();
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
// A link followed from the drawer leaves it behind.
|
|
255
|
+
const onClick = (event: MouseEvent) => {
|
|
256
|
+
if (open && (event.target as Element).closest("a[href]")) onOpenChange(false);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<ShellContext.Provider value={{ drawerBelow, close: () => onOpenChange(false) }}>
|
|
261
|
+
<div className={mergeClasses(styles.shell, canvas)}>
|
|
262
|
+
{open && (
|
|
263
|
+
<div
|
|
264
|
+
className={mergeClasses(styles.backdrop, narrow ? styles.above768 : styles.above960)}
|
|
265
|
+
onClick={() => onOpenChange(false)}
|
|
266
|
+
/>
|
|
267
|
+
)}
|
|
268
|
+
<aside
|
|
269
|
+
ref={aside}
|
|
270
|
+
tabIndex={-1}
|
|
271
|
+
role={modal ? "dialog" : undefined}
|
|
272
|
+
aria-modal={modal ? true : undefined}
|
|
273
|
+
aria-label={modal ? strings.navigation : undefined}
|
|
274
|
+
className={mergeClasses(
|
|
275
|
+
styles.sidebar,
|
|
276
|
+
canvas,
|
|
277
|
+
narrow ? styles.drawer768 : styles.drawer960,
|
|
278
|
+
open && (narrow ? styles.open768 : styles.open960),
|
|
279
|
+
styles.still,
|
|
280
|
+
)}
|
|
281
|
+
style={{ width: sidebarWidth }}
|
|
282
|
+
onKeyDown={onKeyDown}
|
|
283
|
+
onClick={onClick}
|
|
284
|
+
>
|
|
285
|
+
{sidebar}
|
|
286
|
+
</aside>
|
|
287
|
+
<div ref={column} className={styles.column}>
|
|
288
|
+
{header != null && (
|
|
289
|
+
<div
|
|
290
|
+
className={mergeClasses(
|
|
291
|
+
styles.header,
|
|
292
|
+
headerOnlyWithDrawer && (narrow ? styles.above768 : styles.above960),
|
|
293
|
+
)}
|
|
294
|
+
>
|
|
295
|
+
{header}
|
|
296
|
+
</div>
|
|
297
|
+
)}
|
|
298
|
+
<main ref={main} tabIndex={-1} className={styles.main}>
|
|
299
|
+
{children}
|
|
300
|
+
</main>
|
|
301
|
+
</div>
|
|
302
|
+
</div>
|
|
303
|
+
</ShellContext.Provider>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const useCloseStyles = makeStyles({
|
|
308
|
+
close: { flexShrink: 0 },
|
|
309
|
+
above768: { "@media (min-width: 769px)": { display: "none" } },
|
|
310
|
+
above960: { "@media (min-width: 961px)": { display: "none" } },
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
/** A button that closes the drawer, shown only while the sidebar is one. Put
|
|
314
|
+
* it at the end of the sidebar's first row, by the brand. */
|
|
315
|
+
export function AppShellClose({
|
|
316
|
+
label,
|
|
317
|
+
}: {
|
|
318
|
+
/** Defaults to the library's "Close navigation". */ label?: string;
|
|
319
|
+
}) {
|
|
320
|
+
const styles = useCloseStyles();
|
|
321
|
+
const strings = useUiStrings();
|
|
322
|
+
const shell = useContext(ShellContext);
|
|
323
|
+
if (!shell) return null;
|
|
324
|
+
return (
|
|
325
|
+
<Button
|
|
326
|
+
appearance="subtle"
|
|
327
|
+
size="small"
|
|
328
|
+
icon={<DismissRegular />}
|
|
329
|
+
aria-label={label ?? strings.closeNavigation}
|
|
330
|
+
className={mergeClasses(
|
|
331
|
+
styles.close,
|
|
332
|
+
shell.drawerBelow === 768 ? styles.above768 : styles.above960,
|
|
333
|
+
)}
|
|
334
|
+
onClick={shell.close}
|
|
335
|
+
/>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// A sign-in page's frame: the site at the top left and a narrow column on the
|
|
2
|
+
// canvas for the form, with room for notices above it and legal links at the
|
|
3
|
+
// foot. No card: Prism's sign-in, register, consent and two-factor pages, and
|
|
4
|
+
// Glint's sign-in, laid out alike.
|
|
5
|
+
|
|
6
|
+
import { Text, makeStyles, mergeClasses } from "@fluentui/react-components";
|
|
7
|
+
import type { ReactNode } from "react";
|
|
8
|
+
import { useCanvasClass } from "../provider/canvas.js";
|
|
9
|
+
import { BrandMark } from "./BrandMark.js";
|
|
10
|
+
|
|
11
|
+
const useStyles = makeStyles({
|
|
12
|
+
page: {
|
|
13
|
+
minHeight: "100vh",
|
|
14
|
+
display: "flex",
|
|
15
|
+
flexDirection: "column",
|
|
16
|
+
boxSizing: "border-box",
|
|
17
|
+
},
|
|
18
|
+
header: {
|
|
19
|
+
display: "flex",
|
|
20
|
+
alignItems: "center",
|
|
21
|
+
gap: "10px",
|
|
22
|
+
minHeight: "64px",
|
|
23
|
+
padding: "0 32px",
|
|
24
|
+
"@media (max-width: 480px)": { padding: "0 20px" },
|
|
25
|
+
},
|
|
26
|
+
main: {
|
|
27
|
+
flex: 1,
|
|
28
|
+
display: "flex",
|
|
29
|
+
flexDirection: "column",
|
|
30
|
+
alignItems: "center",
|
|
31
|
+
gap: "20px",
|
|
32
|
+
padding: "8vh 20px 48px",
|
|
33
|
+
"@media (max-width: 480px)": { paddingTop: "24px" },
|
|
34
|
+
},
|
|
35
|
+
// Gone when what's above renders nothing, so it leaves no gap.
|
|
36
|
+
above: {
|
|
37
|
+
width: "100%",
|
|
38
|
+
":empty": { display: "none" },
|
|
39
|
+
},
|
|
40
|
+
column: {
|
|
41
|
+
width: "100%",
|
|
42
|
+
display: "flex",
|
|
43
|
+
flexDirection: "column",
|
|
44
|
+
boxSizing: "border-box",
|
|
45
|
+
},
|
|
46
|
+
footer: {
|
|
47
|
+
padding: "0 20px 16px",
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export interface AuthShellProps {
|
|
52
|
+
/** The form and what goes with it, stacked in the column. */
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
/** The site at the top left. Leave it out while it isn't known yet. */
|
|
55
|
+
brand?: { name: string; iconUrl?: string };
|
|
56
|
+
/** Above the column, as wide as it: notices, such as planned maintenance,
|
|
57
|
+
* which matter most to someone who can't sign in. */
|
|
58
|
+
above?: ReactNode;
|
|
59
|
+
/** At the foot of the page, such as legal links. */
|
|
60
|
+
footer?: ReactNode;
|
|
61
|
+
/** The column's width in px. Defaults to 400; a consent screen may want 440. */
|
|
62
|
+
maxWidth?: number;
|
|
63
|
+
/** The space between the column's children in px. Defaults to 20. */
|
|
64
|
+
gap?: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function AuthShell({
|
|
68
|
+
children,
|
|
69
|
+
brand,
|
|
70
|
+
above,
|
|
71
|
+
footer,
|
|
72
|
+
maxWidth = 400,
|
|
73
|
+
gap = 20,
|
|
74
|
+
}: AuthShellProps) {
|
|
75
|
+
const styles = useStyles();
|
|
76
|
+
const canvas = useCanvasClass();
|
|
77
|
+
return (
|
|
78
|
+
<div className={mergeClasses(styles.page, canvas)}>
|
|
79
|
+
{brand ? (
|
|
80
|
+
<header className={styles.header}>
|
|
81
|
+
{/* No alt text: the name is written beside it. */}
|
|
82
|
+
<BrandMark iconUrl={brand.iconUrl} />
|
|
83
|
+
<Text weight="semibold" size={400}>
|
|
84
|
+
{brand.name}
|
|
85
|
+
</Text>
|
|
86
|
+
</header>
|
|
87
|
+
) : (
|
|
88
|
+
// The same space, with no empty banner landmark.
|
|
89
|
+
<div className={styles.header} />
|
|
90
|
+
)}
|
|
91
|
+
<main className={styles.main}>
|
|
92
|
+
{above != null && (
|
|
93
|
+
<div className={styles.above} style={{ maxWidth }}>
|
|
94
|
+
{above}
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
<div className={styles.column} style={{ maxWidth, gap }}>
|
|
98
|
+
{children}
|
|
99
|
+
</div>
|
|
100
|
+
</main>
|
|
101
|
+
{footer != null && <footer className={styles.footer}>{footer}</footer>}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Site logo: the configured site icon, or nothing. With no icon set, the
|
|
2
|
+
// site name beside it carries the brand on its own — a placeholder mark
|
|
3
|
+
// would only invent a logo the operator never chose.
|
|
4
|
+
|
|
5
|
+
import { Image } from "@fluentui/react-components";
|
|
6
|
+
|
|
7
|
+
interface BrandMarkProps {
|
|
8
|
+
/** The image's alt text. Leave it out when the name is written beside the mark. */
|
|
9
|
+
name?: string | null;
|
|
10
|
+
/** The icon's URL. Without one, the mark renders nothing. */
|
|
11
|
+
iconUrl?: string | null;
|
|
12
|
+
/** Width and height, in pixels. */
|
|
13
|
+
size?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function BrandMark({ name, iconUrl, size = 28 }: BrandMarkProps) {
|
|
17
|
+
if (!iconUrl) return null;
|
|
18
|
+
return (
|
|
19
|
+
<Image
|
|
20
|
+
src={iconUrl}
|
|
21
|
+
alt={name ?? ""}
|
|
22
|
+
fit="cover"
|
|
23
|
+
width={size}
|
|
24
|
+
height={size}
|
|
25
|
+
style={{ borderRadius: Math.round(size * 0.28), flexShrink: 0 }}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// A link drawn as a Fluent button, for a button whose only job is to open a
|
|
2
|
+
// page: as a link, it opens in a new tab on a middle-click, shows its address
|
|
3
|
+
// on hover, and reads as a link to screen readers. It goes through the app's
|
|
4
|
+
// router like any library link.
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
mergeClasses,
|
|
8
|
+
useButtonStyles_unstable,
|
|
9
|
+
useButton_unstable,
|
|
10
|
+
type ButtonProps,
|
|
11
|
+
} from "@fluentui/react-components";
|
|
12
|
+
import type { ReactElement, ReactNode } from "react";
|
|
13
|
+
import { UiLink } from "../provider/context.js";
|
|
14
|
+
|
|
15
|
+
export function ButtonLink({
|
|
16
|
+
to,
|
|
17
|
+
appearance,
|
|
18
|
+
size,
|
|
19
|
+
icon,
|
|
20
|
+
className,
|
|
21
|
+
children,
|
|
22
|
+
}: {
|
|
23
|
+
to: string;
|
|
24
|
+
appearance?: ButtonProps["appearance"];
|
|
25
|
+
size?: ButtonProps["size"];
|
|
26
|
+
icon?: ReactElement;
|
|
27
|
+
className?: string;
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
}) {
|
|
30
|
+
// Fluent's own state and classes for a button drawn as an anchor. Only the
|
|
31
|
+
// classes are used: the anchor is the router's.
|
|
32
|
+
const state = useButton_unstable({ as: "a", appearance, size, icon, children }, null);
|
|
33
|
+
useButtonStyles_unstable(state);
|
|
34
|
+
return (
|
|
35
|
+
<UiLink to={to} className={mergeClasses(state.root.className, className)}>
|
|
36
|
+
{state.icon && <span className={state.icon.className}>{icon}</span>}
|
|
37
|
+
{children}
|
|
38
|
+
</UiLink>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// A checkbox for a form that applies on submit, with an optional line of
|
|
2
|
+
// explanation under its label. Switches are for things that take effect
|
|
3
|
+
// the moment they flip; inside a form that waits for Save, this is the
|
|
4
|
+
// control to use.
|
|
5
|
+
|
|
6
|
+
import { Checkbox, makeStyles, tokens } from "@fluentui/react-components";
|
|
7
|
+
|
|
8
|
+
const useStyles = makeStyles({
|
|
9
|
+
// Fluent pads the box; pull it back to the form's text edge.
|
|
10
|
+
root: { marginLeft: "-8px", alignSelf: "flex-start", maxWidth: "100%" },
|
|
11
|
+
label: { display: "flex", flexDirection: "column", gap: "2px" },
|
|
12
|
+
hint: {
|
|
13
|
+
fontSize: tokens.fontSizeBase200,
|
|
14
|
+
lineHeight: tokens.lineHeightBase200,
|
|
15
|
+
color: tokens.colorNeutralForeground3,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
interface CheckboxFieldProps {
|
|
20
|
+
/** The checkbox's label. */
|
|
21
|
+
label: string;
|
|
22
|
+
/** A line of explanation under the label, in smaller, dimmer text. */
|
|
23
|
+
hint?: string;
|
|
24
|
+
/** Whether the box is checked. */
|
|
25
|
+
checked: boolean;
|
|
26
|
+
/** Disables the checkbox. */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/** Called with the new checked state. */
|
|
29
|
+
onChange: (checked: boolean) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function CheckboxField({ label, hint, checked, disabled, onChange }: CheckboxFieldProps) {
|
|
33
|
+
const styles = useStyles();
|
|
34
|
+
return (
|
|
35
|
+
<Checkbox
|
|
36
|
+
className={styles.root}
|
|
37
|
+
checked={checked}
|
|
38
|
+
disabled={disabled}
|
|
39
|
+
onChange={(_, d) => onChange(!!d.checked)}
|
|
40
|
+
label={{
|
|
41
|
+
children: (
|
|
42
|
+
<span className={styles.label}>
|
|
43
|
+
<span>{label}</span>
|
|
44
|
+
{hint && <span className={styles.hint}>{hint}</span>}
|
|
45
|
+
</span>
|
|
46
|
+
),
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|