@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.
Files changed (258) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -1
  3. package/dist/components/AppShell.d.ts +29 -0
  4. package/dist/components/AppShell.d.ts.map +1 -0
  5. package/dist/components/AppShell.js +220 -0
  6. package/dist/components/AppShell.js.map +1 -0
  7. package/dist/components/AuthShell.d.ts +21 -0
  8. package/dist/components/AuthShell.d.ts.map +1 -0
  9. package/dist/components/AuthShell.js +53 -0
  10. package/dist/components/AuthShell.js.map +1 -0
  11. package/dist/components/BrandMark.d.ts +11 -0
  12. package/dist/components/BrandMark.d.ts.map +1 -0
  13. package/dist/components/BrandMark.js +11 -0
  14. package/dist/components/BrandMark.js.map +1 -0
  15. package/dist/components/ButtonLink.d.ts +11 -0
  16. package/dist/components/ButtonLink.d.ts.map +1 -0
  17. package/dist/components/ButtonLink.js +15 -0
  18. package/dist/components/ButtonLink.js.map +1 -0
  19. package/dist/components/CheckboxField.d.ts +15 -0
  20. package/dist/components/CheckboxField.d.ts.map +1 -0
  21. package/dist/components/CheckboxField.js +23 -0
  22. package/dist/components/CheckboxField.js.map +1 -0
  23. package/dist/components/ColorPickerInput.d.ts +17 -0
  24. package/dist/components/ColorPickerInput.d.ts.map +1 -0
  25. package/dist/components/ColorPickerInput.js +97 -0
  26. package/dist/components/ColorPickerInput.js.map +1 -0
  27. package/dist/components/CommandPalette.d.ts +65 -0
  28. package/dist/components/CommandPalette.d.ts.map +1 -0
  29. package/dist/components/CommandPalette.js +269 -0
  30. package/dist/components/CommandPalette.js.map +1 -0
  31. package/dist/components/CopyButton.d.ts +27 -0
  32. package/dist/components/CopyButton.d.ts.map +1 -0
  33. package/dist/components/CopyButton.js +20 -0
  34. package/dist/components/CopyButton.js.map +1 -0
  35. package/dist/components/CopyIdTrigger.d.ts +31 -0
  36. package/dist/components/CopyIdTrigger.d.ts.map +1 -0
  37. package/dist/components/CopyIdTrigger.js +72 -0
  38. package/dist/components/CopyIdTrigger.js.map +1 -0
  39. package/dist/components/DataList.d.ts +78 -0
  40. package/dist/components/DataList.d.ts.map +1 -0
  41. package/dist/components/DataList.js +150 -0
  42. package/dist/components/DataList.js.map +1 -0
  43. package/dist/components/DetailHeader.d.ts +26 -0
  44. package/dist/components/DetailHeader.d.ts.map +1 -0
  45. package/dist/components/DetailHeader.js +49 -0
  46. package/dist/components/DetailHeader.js.map +1 -0
  47. package/dist/components/DurationInput.d.ts +25 -0
  48. package/dist/components/DurationInput.d.ts.map +1 -0
  49. package/dist/components/DurationInput.js +83 -0
  50. package/dist/components/DurationInput.js.map +1 -0
  51. package/dist/components/EmptyState.d.ts +14 -0
  52. package/dist/components/EmptyState.d.ts.map +1 -0
  53. package/dist/components/EmptyState.js +41 -0
  54. package/dist/components/EmptyState.js.map +1 -0
  55. package/dist/components/FormPage.d.ts +22 -0
  56. package/dist/components/FormPage.d.ts.map +1 -0
  57. package/dist/components/FormPage.js +65 -0
  58. package/dist/components/FormPage.js.map +1 -0
  59. package/dist/components/GetStartedPanel.d.ts +16 -0
  60. package/dist/components/GetStartedPanel.d.ts.map +1 -0
  61. package/dist/components/GetStartedPanel.js +96 -0
  62. package/dist/components/GetStartedPanel.js.map +1 -0
  63. package/dist/components/LabeledLine.d.ts +12 -0
  64. package/dist/components/LabeledLine.d.ts.map +1 -0
  65. package/dist/components/LabeledLine.js +6 -0
  66. package/dist/components/LabeledLine.js.map +1 -0
  67. package/dist/components/ListSearch.d.ts +15 -0
  68. package/dist/components/ListSearch.d.ts.map +1 -0
  69. package/dist/components/ListSearch.js +23 -0
  70. package/dist/components/ListSearch.js.map +1 -0
  71. package/dist/components/LoadingBar.d.ts +8 -0
  72. package/dist/components/LoadingBar.d.ts.map +1 -0
  73. package/dist/components/LoadingBar.js +55 -0
  74. package/dist/components/LoadingBar.js.map +1 -0
  75. package/dist/components/LoadingPage.d.ts +6 -0
  76. package/dist/components/LoadingPage.d.ts.map +1 -0
  77. package/dist/components/LoadingPage.js +25 -0
  78. package/dist/components/LoadingPage.js.map +1 -0
  79. package/dist/components/MenuPanel.d.ts +34 -0
  80. package/dist/components/MenuPanel.d.ts.map +1 -0
  81. package/dist/components/MenuPanel.js +98 -0
  82. package/dist/components/MenuPanel.js.map +1 -0
  83. package/dist/components/Outline.d.ts +23 -0
  84. package/dist/components/Outline.d.ts.map +1 -0
  85. package/dist/components/Outline.js +150 -0
  86. package/dist/components/Outline.js.map +1 -0
  87. package/dist/components/Overview.d.ts +103 -0
  88. package/dist/components/Overview.d.ts.map +1 -0
  89. package/dist/components/Overview.js +286 -0
  90. package/dist/components/Overview.js.map +1 -0
  91. package/dist/components/PageHeader.d.ts +19 -0
  92. package/dist/components/PageHeader.d.ts.map +1 -0
  93. package/dist/components/PageHeader.js +41 -0
  94. package/dist/components/PageHeader.js.map +1 -0
  95. package/dist/components/Pagination.d.ts +19 -0
  96. package/dist/components/Pagination.d.ts.map +1 -0
  97. package/dist/components/Pagination.js +47 -0
  98. package/dist/components/Pagination.js.map +1 -0
  99. package/dist/components/PasswordInput.d.ts +3 -0
  100. package/dist/components/PasswordInput.d.ts.map +1 -0
  101. package/dist/components/PasswordInput.js +29 -0
  102. package/dist/components/PasswordInput.js.map +1 -0
  103. package/dist/components/PrevNext.d.ts +16 -0
  104. package/dist/components/PrevNext.d.ts.map +1 -0
  105. package/dist/components/PrevNext.js +61 -0
  106. package/dist/components/PrevNext.js.map +1 -0
  107. package/dist/components/SearchButton.d.ts +16 -0
  108. package/dist/components/SearchButton.d.ts.map +1 -0
  109. package/dist/components/SearchButton.js +63 -0
  110. package/dist/components/SearchButton.js.map +1 -0
  111. package/dist/components/SearchField.d.ts +10 -0
  112. package/dist/components/SearchField.d.ts.map +1 -0
  113. package/dist/components/SearchField.js +67 -0
  114. package/dist/components/SearchField.js.map +1 -0
  115. package/dist/components/Segmented.d.ts +28 -0
  116. package/dist/components/Segmented.d.ts.map +1 -0
  117. package/dist/components/Segmented.js +74 -0
  118. package/dist/components/Segmented.js.map +1 -0
  119. package/dist/components/Select.d.ts +22 -0
  120. package/dist/components/Select.d.ts.map +1 -0
  121. package/dist/components/Select.js +50 -0
  122. package/dist/components/Select.js.map +1 -0
  123. package/dist/components/Settings.d.ts +103 -0
  124. package/dist/components/Settings.d.ts.map +1 -0
  125. package/dist/components/Settings.js +246 -0
  126. package/dist/components/Settings.js.map +1 -0
  127. package/dist/components/SideNav.d.ts +47 -0
  128. package/dist/components/SideNav.d.ts.map +1 -0
  129. package/dist/components/SideNav.js +125 -0
  130. package/dist/components/SideNav.js.map +1 -0
  131. package/dist/components/Skeletons.d.ts +37 -0
  132. package/dist/components/Skeletons.d.ts.map +1 -0
  133. package/dist/components/Skeletons.js +109 -0
  134. package/dist/components/Skeletons.js.map +1 -0
  135. package/dist/components/StatusPage.d.ts +49 -0
  136. package/dist/components/StatusPage.d.ts.map +1 -0
  137. package/dist/components/StatusPage.js +110 -0
  138. package/dist/components/StatusPage.js.map +1 -0
  139. package/dist/components/ThemeMenu.d.ts +13 -0
  140. package/dist/components/ThemeMenu.d.ts.map +1 -0
  141. package/dist/components/ThemeMenu.js +18 -0
  142. package/dist/components/ThemeMenu.js.map +1 -0
  143. package/dist/components/ThemeSwitch.d.ts +17 -0
  144. package/dist/components/ThemeSwitch.d.ts.map +1 -0
  145. package/dist/components/ThemeSwitch.js +25 -0
  146. package/dist/components/ThemeSwitch.js.map +1 -0
  147. package/dist/components/TopBar.d.ts +49 -0
  148. package/dist/components/TopBar.d.ts.map +1 -0
  149. package/dist/components/TopBar.js +146 -0
  150. package/dist/components/TopBar.js.map +1 -0
  151. package/dist/components/ViewBanner.d.ts +17 -0
  152. package/dist/components/ViewBanner.d.ts.map +1 -0
  153. package/dist/components/ViewBanner.js +14 -0
  154. package/dist/components/ViewBanner.js.map +1 -0
  155. package/dist/hooks/platform.d.ts +7 -0
  156. package/dist/hooks/platform.d.ts.map +1 -0
  157. package/dist/hooks/platform.js +19 -0
  158. package/dist/hooks/platform.js.map +1 -0
  159. package/dist/hooks/useConfirm.d.ts +23 -0
  160. package/dist/hooks/useConfirm.d.ts.map +1 -0
  161. package/dist/hooks/useConfirm.js +55 -0
  162. package/dist/hooks/useConfirm.js.map +1 -0
  163. package/dist/hooks/useCopy.d.ts +12 -0
  164. package/dist/hooks/useCopy.d.ts.map +1 -0
  165. package/dist/hooks/useCopy.js +39 -0
  166. package/dist/hooks/useCopy.js.map +1 -0
  167. package/dist/hooks/useDebouncedSearch.d.ts +8 -0
  168. package/dist/hooks/useDebouncedSearch.d.ts.map +1 -0
  169. package/dist/hooks/useDebouncedSearch.js +19 -0
  170. package/dist/hooks/useDebouncedSearch.js.map +1 -0
  171. package/dist/hooks/usePageClamp.d.ts +4 -0
  172. package/dist/hooks/usePageClamp.d.ts.map +1 -0
  173. package/dist/hooks/usePageClamp.js +17 -0
  174. package/dist/hooks/usePageClamp.js.map +1 -0
  175. package/dist/hooks/useSearchShortcut.d.ts +8 -0
  176. package/dist/hooks/useSearchShortcut.d.ts.map +1 -0
  177. package/dist/hooks/useSearchShortcut.js +38 -0
  178. package/dist/hooks/useSearchShortcut.js.map +1 -0
  179. package/dist/hooks/useThemeMode.d.ts +29 -0
  180. package/dist/hooks/useThemeMode.d.ts.map +1 -0
  181. package/dist/hooks/useThemeMode.js +111 -0
  182. package/dist/hooks/useThemeMode.js.map +1 -0
  183. package/dist/hooks/useToastMessage.d.ts +22 -0
  184. package/dist/hooks/useToastMessage.d.ts.map +1 -0
  185. package/dist/hooks/useToastMessage.js +26 -0
  186. package/dist/hooks/useToastMessage.js.map +1 -0
  187. package/dist/index.d.ts +50 -0
  188. package/dist/index.d.ts.map +1 -0
  189. package/dist/index.js +60 -0
  190. package/dist/index.js.map +1 -0
  191. package/dist/provider/UiProvider.d.ts +60 -0
  192. package/dist/provider/UiProvider.d.ts.map +1 -0
  193. package/dist/provider/UiProvider.js +144 -0
  194. package/dist/provider/UiProvider.js.map +1 -0
  195. package/dist/provider/canvas.d.ts +7 -0
  196. package/dist/provider/canvas.d.ts.map +1 -0
  197. package/dist/provider/canvas.js +30 -0
  198. package/dist/provider/canvas.js.map +1 -0
  199. package/dist/provider/context.d.ts +69 -0
  200. package/dist/provider/context.d.ts.map +1 -0
  201. package/dist/provider/context.js +84 -0
  202. package/dist/provider/context.js.map +1 -0
  203. package/dist/theme/createTheme.d.ts +13 -0
  204. package/dist/theme/createTheme.d.ts.map +1 -0
  205. package/dist/theme/createTheme.js +18 -0
  206. package/dist/theme/createTheme.js.map +1 -0
  207. package/package.json +42 -2
  208. package/src/components/AppShell.tsx +337 -0
  209. package/src/components/AuthShell.tsx +104 -0
  210. package/src/components/BrandMark.tsx +28 -0
  211. package/src/components/ButtonLink.tsx +40 -0
  212. package/src/components/CheckboxField.tsx +50 -0
  213. package/src/components/ColorPickerInput.tsx +190 -0
  214. package/src/components/CommandPalette.tsx +479 -0
  215. package/src/components/CopyButton.tsx +76 -0
  216. package/src/components/CopyIdTrigger.tsx +127 -0
  217. package/src/components/DataList.tsx +332 -0
  218. package/src/components/DetailHeader.tsx +108 -0
  219. package/src/components/DurationInput.tsx +133 -0
  220. package/src/components/EmptyState.tsx +67 -0
  221. package/src/components/FormPage.tsx +109 -0
  222. package/src/components/GetStartedPanel.tsx +132 -0
  223. package/src/components/LabeledLine.tsx +28 -0
  224. package/src/components/ListSearch.tsx +64 -0
  225. package/src/components/LoadingBar.tsx +81 -0
  226. package/src/components/LoadingPage.tsx +41 -0
  227. package/src/components/MenuPanel.tsx +163 -0
  228. package/src/components/Outline.tsx +208 -0
  229. package/src/components/Overview.tsx +448 -0
  230. package/src/components/PageHeader.tsx +69 -0
  231. package/src/components/Pagination.tsx +105 -0
  232. package/src/components/PasswordInput.tsx +50 -0
  233. package/src/components/PrevNext.tsx +98 -0
  234. package/src/components/SearchButton.tsx +90 -0
  235. package/src/components/SearchField.tsx +97 -0
  236. package/src/components/Segmented.tsx +136 -0
  237. package/src/components/Select.tsx +110 -0
  238. package/src/components/Settings.tsx +432 -0
  239. package/src/components/SideNav.tsx +258 -0
  240. package/src/components/Skeletons.tsx +233 -0
  241. package/src/components/StatusPage.tsx +212 -0
  242. package/src/components/ThemeMenu.tsx +51 -0
  243. package/src/components/ThemeSwitch.tsx +49 -0
  244. package/src/components/TopBar.tsx +293 -0
  245. package/src/components/ViewBanner.tsx +51 -0
  246. package/src/hooks/platform.ts +22 -0
  247. package/src/hooks/useConfirm.tsx +97 -0
  248. package/src/hooks/useCopy.ts +39 -0
  249. package/src/hooks/useDebouncedSearch.ts +19 -0
  250. package/src/hooks/usePageClamp.ts +20 -0
  251. package/src/hooks/useSearchShortcut.ts +49 -0
  252. package/src/hooks/useThemeMode.ts +168 -0
  253. package/src/hooks/useToastMessage.ts +38 -0
  254. package/src/index.ts +156 -0
  255. package/src/provider/UiProvider.tsx +256 -0
  256. package/src/provider/canvas.ts +31 -0
  257. package/src/provider/context.tsx +145 -0
  258. package/src/theme/createTheme.ts +29 -0
@@ -0,0 +1,293 @@
1
+ // The strip across the top of a page, as in Vellum: the canvas with a
2
+ // hairline under it, the brand (and a crumb after it), links, then the app's
3
+ // actions (search, a ThemeMenu) at the end, all as compact 32px controls with
4
+ // a grey (not brand) selection.
5
+ //
6
+ // On a narrow screen it gives way in steps: the menu button that opens the
7
+ // app's navigation shows from 960px (or 768px) down, at the end or the start,
8
+ // the links go at 720px, the crumb at 540px.
9
+
10
+ import {
11
+ Button,
12
+ Menu,
13
+ MenuItem,
14
+ MenuList,
15
+ MenuPopover,
16
+ MenuTrigger,
17
+ makeStyles,
18
+ mergeClasses,
19
+ tokens,
20
+ } from "@fluentui/react-components";
21
+ import { ChevronDown12Regular, Navigation20Regular } from "@fluentui/react-icons";
22
+ import type { ReactNode } from "react";
23
+ import { useCanvasClass } from "../provider/canvas.js";
24
+ import { UiLink, useUiNavigate, useUiStrings } from "../provider/context.js";
25
+ import { BrandMark } from "./BrandMark.js";
26
+
27
+ /** The top bar's height in pixels, for what sticks below it. */
28
+ export const TOP_BAR_HEIGHT = 52;
29
+
30
+ const useStyles = makeStyles({
31
+ root: {
32
+ display: "flex",
33
+ alignItems: "center",
34
+ gap: "8px",
35
+ height: `${TOP_BAR_HEIGHT}px`,
36
+ paddingInline: "16px 12px",
37
+ boxSizing: "border-box",
38
+ borderBottom: `1px solid ${tokens.colorNeutralStroke2}`,
39
+ "@media (max-width: 720px)": { gap: "4px", paddingInline: "8px" },
40
+ },
41
+ sticky: { position: "sticky", top: 0, zIndex: 100 },
42
+ brandGroup: {
43
+ display: "flex",
44
+ alignItems: "center",
45
+ gap: "8px",
46
+ minWidth: 0,
47
+ flexShrink: 1,
48
+ },
49
+ brand: {
50
+ display: "flex",
51
+ alignItems: "center",
52
+ gap: "10px",
53
+ minWidth: 0,
54
+ color: tokens.colorNeutralForeground1,
55
+ textDecoration: "none",
56
+ ":hover": { color: tokens.colorNeutralForeground1, textDecoration: "none" },
57
+ },
58
+ brandText: {
59
+ fontSize: tokens.fontSizeBase300,
60
+ fontWeight: tokens.fontWeightSemibold,
61
+ whiteSpace: "nowrap",
62
+ overflow: "hidden",
63
+ textOverflow: "ellipsis",
64
+ },
65
+ // Muted, like a path segment after the site's name.
66
+ crumb: {
67
+ gap: "8px",
68
+ color: tokens.colorNeutralForeground3,
69
+ ":hover": { color: tokens.colorNeutralForeground1 },
70
+ "@media (max-width: 540px)": { display: "none" },
71
+ },
72
+ crumbText: {
73
+ fontSize: tokens.fontSizeBase300,
74
+ whiteSpace: "nowrap",
75
+ overflow: "hidden",
76
+ textOverflow: "ellipsis",
77
+ },
78
+ separator: {
79
+ color: tokens.colorNeutralStroke1,
80
+ fontSize: tokens.fontSizeBase400,
81
+ userSelect: "none",
82
+ "@media (max-width: 540px)": { display: "none" },
83
+ },
84
+ // A wrapper, because Fluent's Button sets its own display at the same
85
+ // specificity as a class on it. Griffel's media queries are static, so the
86
+ // widths it shows from are presets.
87
+ menuButton: { display: "none" },
88
+ menuBelow960: { "@media (max-width: 960px)": { display: "inline-flex" } },
89
+ menuBelow768: { "@media (max-width: 768px)": { display: "inline-flex" } },
90
+ links: {
91
+ display: "flex",
92
+ alignItems: "center",
93
+ gap: "1px",
94
+ marginLeft: "12px",
95
+ "@media (max-width: 720px)": { display: "none" },
96
+ },
97
+ link: {
98
+ display: "inline-flex",
99
+ alignItems: "center",
100
+ gap: "4px",
101
+ minHeight: "32px",
102
+ paddingInline: "10px",
103
+ boxSizing: "border-box",
104
+ border: "none",
105
+ borderRadius: tokens.borderRadiusMedium,
106
+ background: "transparent",
107
+ color: tokens.colorNeutralForeground2,
108
+ textDecoration: "none",
109
+ fontFamily: "inherit",
110
+ fontSize: "13px",
111
+ fontWeight: tokens.fontWeightMedium,
112
+ whiteSpace: "nowrap",
113
+ cursor: "pointer",
114
+ ":hover": {
115
+ backgroundColor: tokens.colorNeutralBackground3,
116
+ color: tokens.colorNeutralForeground1,
117
+ textDecoration: "none",
118
+ },
119
+ ":focus-visible": {
120
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
121
+ outlineOffset: "-2px",
122
+ },
123
+ },
124
+ linkActive: {
125
+ backgroundColor: tokens.colorNeutralBackground3,
126
+ color: tokens.colorNeutralForeground1,
127
+ },
128
+ chevron: { color: tokens.colorNeutralForeground3 },
129
+ spacer: { flex: 1 },
130
+ actions: { display: "flex", alignItems: "center", gap: "2px" },
131
+ });
132
+
133
+ export interface TopBarBrand {
134
+ /** The site's (or, for a crumb, the section's) name. */
135
+ label: string;
136
+ /** Where it leads: the home page, the section's first page. */
137
+ to: string;
138
+ /** An icon URL, drawn as a BrandMark before the name. */
139
+ logo?: string;
140
+ }
141
+
142
+ export interface TopBarLink {
143
+ /** The link's text. */
144
+ label: ReactNode;
145
+ /** An in-app path, or a full URL, which opens in a new tab. */
146
+ to?: string;
147
+ /** The reader is in this part of the site. A menu is active when one of its items is. */
148
+ active?: boolean;
149
+ /** Makes the link a menu of these. */
150
+ items?: TopBarLink[];
151
+ }
152
+
153
+ export interface TopBarProps {
154
+ /** `{ label, to, logo? }`: the site's name, where it leads, an icon URL. */
155
+ brand: TopBarBrand;
156
+ /** A second step after the brand, such as the section or project. Hidden from 540px down. */
157
+ crumb?: TopBarBrand;
158
+ /**
159
+ * `{ label, to?, active?, items? }`. A full URL opens in a new tab; `items`
160
+ * makes a menu, active when one of its items is. Hidden from 720px down.
161
+ */
162
+ links?: TopBarLink[];
163
+ /** Shows a menu button from `menuBelow` down that calls this, to open the app's navigation. */
164
+ onMenu?: () => void;
165
+ /** Where the menu button sits: `"end"`, before the actions (the default), or `"start"`, before the brand. */
166
+ menuPosition?: "start" | "end";
167
+ /** The width the menu button shows from, and down: `960` (the default) or `768`, to match where the app's navigation becomes a drawer. */
168
+ menuBelow?: 768 | 960;
169
+ /** The menu button's name. Defaults to the library's "Open navigation". */
170
+ menuLabel?: string;
171
+ /** Names the links for screen readers. Defaults to the library's "Primary". */
172
+ linksLabel?: string;
173
+ /** Keeps it at the top of the window as the page scrolls. */
174
+ sticky?: boolean;
175
+ /** The actions at the end: a SearchButton, a ThemeMenu, icon buttons. */
176
+ children?: ReactNode;
177
+ className?: string;
178
+ }
179
+
180
+ const EXTERNAL = /^[a-z]+:\/\//i;
181
+
182
+ export function TopBar({
183
+ brand,
184
+ crumb,
185
+ links,
186
+ onMenu,
187
+ menuPosition = "end",
188
+ menuBelow = 960,
189
+ menuLabel,
190
+ linksLabel,
191
+ sticky,
192
+ children,
193
+ className,
194
+ }: TopBarProps) {
195
+ const styles = useStyles();
196
+ const canvas = useCanvasClass();
197
+ const strings = useUiStrings();
198
+ const menu = onMenu && (
199
+ <span
200
+ className={mergeClasses(
201
+ styles.menuButton,
202
+ menuBelow === 768 ? styles.menuBelow768 : styles.menuBelow960,
203
+ )}
204
+ >
205
+ <Button
206
+ appearance="subtle"
207
+ icon={<Navigation20Regular />}
208
+ aria-label={menuLabel ?? strings.openNavigation}
209
+ onClick={onMenu}
210
+ />
211
+ </span>
212
+ );
213
+ return (
214
+ <header className={mergeClasses(styles.root, canvas, sticky && styles.sticky, className)}>
215
+ {menuPosition === "start" && menu}
216
+ <div className={styles.brandGroup}>
217
+ <UiLink to={brand.to} className={styles.brand}>
218
+ <BrandMark iconUrl={brand.logo} size={24} />
219
+ <span className={styles.brandText}>{brand.label}</span>
220
+ </UiLink>
221
+ {crumb && (
222
+ <>
223
+ <span className={styles.separator} aria-hidden="true">
224
+ /
225
+ </span>
226
+ <UiLink to={crumb.to} className={mergeClasses(styles.brand, styles.crumb)}>
227
+ <BrandMark iconUrl={crumb.logo} size={20} />
228
+ <span className={styles.crumbText}>{crumb.label}</span>
229
+ </UiLink>
230
+ </>
231
+ )}
232
+ </div>
233
+ {links && links.length > 0 && (
234
+ <nav className={styles.links} aria-label={linksLabel ?? strings.primaryNavigation}>
235
+ {links.map((link, i) => (
236
+ <BarLink key={i} link={link} styles={styles} />
237
+ ))}
238
+ </nav>
239
+ )}
240
+ <div className={styles.spacer} />
241
+ <div className={styles.actions}>
242
+ {menuPosition !== "start" && menu}
243
+ {children}
244
+ </div>
245
+ </header>
246
+ );
247
+ }
248
+
249
+ function BarLink({ link, styles }: { link: TopBarLink; styles: ReturnType<typeof useStyles> }) {
250
+ const navigate = useUiNavigate();
251
+ if (link.items) {
252
+ const active = link.active ?? link.items.some((item) => item.active);
253
+ return (
254
+ <Menu>
255
+ <MenuTrigger disableButtonEnhancement>
256
+ <button type="button" className={mergeClasses(styles.link, active && styles.linkActive)}>
257
+ {link.label}
258
+ <ChevronDown12Regular className={styles.chevron} />
259
+ </button>
260
+ </MenuTrigger>
261
+ <MenuPopover>
262
+ <MenuList>
263
+ {link.items.map((item, i) => (
264
+ <MenuItem
265
+ key={i}
266
+ onClick={() => {
267
+ if (!item.to) return;
268
+ if (EXTERNAL.test(item.to)) window.open(item.to, "_blank", "noopener,noreferrer");
269
+ else navigate(item.to);
270
+ }}
271
+ >
272
+ {item.label}
273
+ </MenuItem>
274
+ ))}
275
+ </MenuList>
276
+ </MenuPopover>
277
+ </Menu>
278
+ );
279
+ }
280
+ const className = mergeClasses(styles.link, link.active && styles.linkActive);
281
+ if (link.to && EXTERNAL.test(link.to)) {
282
+ return (
283
+ <a href={link.to} target="_blank" rel="noopener noreferrer" className={className}>
284
+ {link.label}
285
+ </a>
286
+ );
287
+ }
288
+ return (
289
+ <UiLink to={link.to ?? "#"} className={className}>
290
+ {link.label}
291
+ </UiLink>
292
+ );
293
+ }
@@ -0,0 +1,51 @@
1
+ // The banner on app and team pages that says which authority a site admin is
2
+ // acting with (the site override or their own membership), with the button
3
+ // that switches. Built on MessageBar's own layout, so a long message moves
4
+ // the action under the text and the dismiss stays in the corner rather than
5
+ // wrapping onto a line of its own.
6
+
7
+ import { Button, MessageBar, MessageBarActions, MessageBarBody } from "@fluentui/react-components";
8
+ import { DismissRegular } from "@fluentui/react-icons";
9
+ import type { ReactNode } from "react";
10
+ import { useUiStrings } from "../provider/context.js";
11
+
12
+ interface Props {
13
+ /** The banner's colour and icon. */
14
+ intent: "info" | "warning";
15
+ /** The message. */
16
+ children: ReactNode;
17
+ /** A button at the end: the switch, e.g. "Switch to normal view". */
18
+ action?: { label: string; onClick: () => void };
19
+ /** Called by a close button, which shows only when this is set. */
20
+ onDismiss?: () => void;
21
+ }
22
+
23
+ export function ViewBanner({ intent, children, action, onDismiss }: Props) {
24
+ const strings = useUiStrings();
25
+ return (
26
+ <MessageBar intent={intent}>
27
+ <MessageBarBody>{children}</MessageBarBody>
28
+ {(action || onDismiss) && (
29
+ <MessageBarActions
30
+ containerAction={
31
+ onDismiss && (
32
+ <Button
33
+ appearance="transparent"
34
+ size="small"
35
+ icon={<DismissRegular />}
36
+ aria-label={strings.close}
37
+ onClick={onDismiss}
38
+ />
39
+ )
40
+ }
41
+ >
42
+ {action && (
43
+ <Button size="small" onClick={action.onClick}>
44
+ {action.label}
45
+ </Button>
46
+ )}
47
+ </MessageBarActions>
48
+ )}
49
+ </MessageBar>
50
+ );
51
+ }
@@ -0,0 +1,22 @@
1
+ import { useSyncExternalStore } from "react";
2
+
3
+ function subscribe() {
4
+ return () => {};
5
+ }
6
+
7
+ function isApple() {
8
+ return /Mac|iPhone|iPad/.test(navigator.platform);
9
+ }
10
+
11
+ function serverIsApple() {
12
+ return false;
13
+ }
14
+
15
+ /**
16
+ * Whether the reader is on an Apple device, where shortcuts use ⌘ rather than
17
+ * Ctrl. The server can't tell, so it renders Ctrl, and the browser corrects
18
+ * it without a hydration mismatch.
19
+ */
20
+ export function useIsApple(): boolean {
21
+ return useSyncExternalStore(subscribe, isApple, serverIsApple);
22
+ }
@@ -0,0 +1,97 @@
1
+ // Promise-based confirmation dialog for one-click destructive actions:
2
+ //
3
+ // const { confirm, confirmDialog } = useConfirm();
4
+ // if (!(await confirm({ title, body, confirmLabel }))) return;
5
+ // ...
6
+ // return <>{...}{confirmDialog}</>;
7
+ //
8
+ // One dialog per page, reused for every action on it.
9
+
10
+ import {
11
+ Button,
12
+ Dialog,
13
+ DialogActions,
14
+ DialogBody,
15
+ DialogContent,
16
+ DialogSurface,
17
+ DialogTitle,
18
+ makeStyles,
19
+ tokens,
20
+ } from "@fluentui/react-components";
21
+ import { useCallback, useRef, useState, type ReactNode } from "react";
22
+ import { useUiStrings } from "../provider/context.js";
23
+
24
+ const useStyles = makeStyles({
25
+ danger: {
26
+ background: tokens.colorPaletteRedBackground3,
27
+ ":hover": { background: tokens.colorPaletteRedForeground1 },
28
+ ":hover:active": { background: tokens.colorPaletteRedForeground1 },
29
+ },
30
+ });
31
+
32
+ /** What `confirm` asks. */
33
+ export interface ConfirmOptions {
34
+ /** The question, as the dialog's title. */
35
+ title: string;
36
+ /** More detail under the title. */
37
+ body?: ReactNode;
38
+ /** Label of the confirming button, e.g. "Remove". */
39
+ confirmLabel: string;
40
+ }
41
+
42
+ /**
43
+ * Asks a yes-or-no question in a dialog and waits for the answer. Render
44
+ * `confirmDialog` once, anywhere in the component.
45
+ */
46
+ export function useConfirm() {
47
+ const styles = useStyles();
48
+ const strings = useUiStrings();
49
+ const [options, setOptions] = useState<ConfirmOptions | null>(null);
50
+ const resolver = useRef<((ok: boolean) => void) | null>(null);
51
+
52
+ const confirm = useCallback((next: ConfirmOptions) => {
53
+ // A second request while one is open answers the first with "no".
54
+ resolver.current?.(false);
55
+ setOptions(next);
56
+ return new Promise<boolean>((resolve) => {
57
+ resolver.current = resolve;
58
+ });
59
+ }, []);
60
+
61
+ const close = (ok: boolean) => {
62
+ resolver.current?.(ok);
63
+ resolver.current = null;
64
+ setOptions(null);
65
+ };
66
+
67
+ const confirmDialog = (
68
+ <Dialog
69
+ open={options !== null}
70
+ onOpenChange={(_, d) => {
71
+ if (!d.open) close(false);
72
+ }}
73
+ >
74
+ <DialogSurface>
75
+ <DialogBody>
76
+ <DialogTitle>{options?.title}</DialogTitle>
77
+ {options?.body && <DialogContent>{options.body}</DialogContent>}
78
+ <DialogActions>
79
+ <Button onClick={() => close(false)}>{strings.cancel}</Button>
80
+ <Button appearance="primary" className={styles.danger} onClick={() => close(true)}>
81
+ {options?.confirmLabel}
82
+ </Button>
83
+ </DialogActions>
84
+ </DialogBody>
85
+ </DialogSurface>
86
+ </Dialog>
87
+ );
88
+
89
+ return {
90
+ /** Opens the dialog. Resolves to `true` when confirmed and `false` when
91
+ * cancelled or closed. A second call while it's open answers the first
92
+ * with `false`. */
93
+ confirm,
94
+ /** The dialog. Render it once. */
95
+ confirmDialog,
96
+ };
97
+ }
@@ -0,0 +1,39 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+
3
+ export type CopyState = "idle" | "copied" | "failed";
4
+
5
+ /** Copy text to the clipboard and report how it went for a moment, so the
6
+ * control can say "Copied" — or "Copy failed" when clipboard access is
7
+ * denied (permission, insecure context), rather than claiming success.
8
+ * `copy` takes the text, or a function that returns it, called as it copies:
9
+ * for a value only known then, such as what a code block shows. It resolves
10
+ * to how that copy went. */
11
+ export function useCopy(resetMs = 1500) {
12
+ const [state, setState] = useState<CopyState>("idle");
13
+ const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
14
+ // The latest copy: only it reports, so an earlier one that settles later
15
+ // can't replace its outcome.
16
+ const latest = useRef(0);
17
+ useEffect(() => () => clearTimeout(timer.current), []);
18
+ function flash(next: CopyState) {
19
+ // A second copy starts its own moment, not the rest of the first.
20
+ clearTimeout(timer.current);
21
+ setState(next);
22
+ timer.current = setTimeout(() => setState("idle"), resetMs);
23
+ }
24
+ // Up to the first await, this runs in the click that called it, as Safari
25
+ // needs. No clipboard (a plain-http page) or a throwing `text` is a failure.
26
+ async function copy(text: string | (() => string)): Promise<"copied" | "failed"> {
27
+ const id = ++latest.current;
28
+ let outcome: "copied" | "failed";
29
+ try {
30
+ await navigator.clipboard.writeText(typeof text === "function" ? text() : text);
31
+ outcome = "copied";
32
+ } catch {
33
+ outcome = "failed";
34
+ }
35
+ if (id === latest.current) flash(outcome);
36
+ return outcome;
37
+ }
38
+ return { state, copy };
39
+ }
@@ -0,0 +1,19 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ /** A search box value plus its debounced, trimmed copy; resets the page when
4
+ * the search settles. */
5
+ export function useDebouncedSearch(onSettle?: () => void, delay = 250) {
6
+ const [query, setQuery] = useState("");
7
+ const [search, setSearch] = useState("");
8
+ useEffect(() => {
9
+ const id = setTimeout(() => {
10
+ setSearch(query.trim());
11
+ onSettle?.();
12
+ }, delay);
13
+ return () => clearTimeout(id);
14
+ // onSettle is a setter-style callback; re-running on its identity would
15
+ // restart the timer every render.
16
+ // eslint-disable-next-line react-hooks/exhaustive-deps
17
+ }, [query, delay]);
18
+ return { query, setQuery, search };
19
+ }
@@ -0,0 +1,20 @@
1
+ // Keep a paged list on a page that exists. Removing the last row on the last
2
+ // page (or filtering elsewhere) can leave `page` past the end, where the
3
+ // list would show as empty with no pager to get back; this steps back to
4
+ // the last page that still has rows.
5
+
6
+ import { useEffect } from "react";
7
+
8
+ export function usePageClamp(
9
+ page: number,
10
+ /** Total rows from the latest response; undefined while loading. */
11
+ total: number | undefined,
12
+ pageSize: number,
13
+ setPage: (page: number) => void,
14
+ ) {
15
+ useEffect(() => {
16
+ if (total === undefined) return;
17
+ const last = Math.max(1, Math.ceil(total / pageSize));
18
+ if (page > last) setPage(last);
19
+ }, [page, total, pageSize, setPage]);
20
+ }
@@ -0,0 +1,49 @@
1
+ // The keys that open search, as Prism and Vellum both have them: Ctrl K (⌘K
2
+ // on Apple devices) toggles it from anywhere, and with `slash`, "/" opens it
3
+ // when the reader isn't typing.
4
+
5
+ import { useEffect, type Dispatch, type SetStateAction } from "react";
6
+
7
+ export interface SearchShortcutOptions {
8
+ /** Also open on "/", as docs sites do. Defaults to false. */
9
+ slash?: boolean;
10
+ }
11
+
12
+ function typing(target: EventTarget | null): boolean {
13
+ if (!(target instanceof HTMLElement)) return false;
14
+ return (
15
+ target.isContentEditable ||
16
+ target.tagName === "INPUT" ||
17
+ target.tagName === "TEXTAREA" ||
18
+ target.tagName === "SELECT"
19
+ );
20
+ }
21
+
22
+ /** Pass the state setter of the search's `open`, e.g. from `useState(false)`. */
23
+ export function useSearchShortcut(
24
+ setOpen: Dispatch<SetStateAction<boolean>>,
25
+ { slash = false }: SearchShortcutOptions = {},
26
+ ): void {
27
+ useEffect(() => {
28
+ function onKey(e: KeyboardEvent) {
29
+ // An input method's keys belong to the text it's composing.
30
+ if (e.isComposing) return;
31
+ if ((e.ctrlKey || e.metaKey) && !e.altKey && e.key.toLowerCase() === "k") {
32
+ e.preventDefault();
33
+ setOpen((open) => !open);
34
+ } else if (
35
+ slash &&
36
+ e.key === "/" &&
37
+ !e.ctrlKey &&
38
+ !e.metaKey &&
39
+ !e.altKey &&
40
+ !typing(e.target)
41
+ ) {
42
+ e.preventDefault();
43
+ setOpen(true);
44
+ }
45
+ }
46
+ window.addEventListener("keydown", onKey);
47
+ return () => window.removeEventListener("keydown", onKey);
48
+ }, [setOpen, slash]);
49
+ }