@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.
Files changed (233) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/dist/components/BrandMark.d.ts +11 -0
  4. package/dist/components/BrandMark.d.ts.map +1 -0
  5. package/dist/components/BrandMark.js +11 -0
  6. package/dist/components/BrandMark.js.map +1 -0
  7. package/dist/components/CheckboxField.d.ts +15 -0
  8. package/dist/components/CheckboxField.d.ts.map +1 -0
  9. package/dist/components/CheckboxField.js +23 -0
  10. package/dist/components/CheckboxField.js.map +1 -0
  11. package/dist/components/ColorPickerInput.d.ts +17 -0
  12. package/dist/components/ColorPickerInput.d.ts.map +1 -0
  13. package/dist/components/ColorPickerInput.js +97 -0
  14. package/dist/components/ColorPickerInput.js.map +1 -0
  15. package/dist/components/CommandPalette.d.ts +53 -0
  16. package/dist/components/CommandPalette.d.ts.map +1 -0
  17. package/dist/components/CommandPalette.js +239 -0
  18. package/dist/components/CommandPalette.js.map +1 -0
  19. package/dist/components/CopyButton.d.ts +8 -0
  20. package/dist/components/CopyButton.d.ts.map +1 -0
  21. package/dist/components/CopyButton.js +17 -0
  22. package/dist/components/CopyButton.js.map +1 -0
  23. package/dist/components/CopyIdTrigger.d.ts +31 -0
  24. package/dist/components/CopyIdTrigger.d.ts.map +1 -0
  25. package/dist/components/CopyIdTrigger.js +72 -0
  26. package/dist/components/CopyIdTrigger.js.map +1 -0
  27. package/dist/components/DataList.d.ts +78 -0
  28. package/dist/components/DataList.d.ts.map +1 -0
  29. package/dist/components/DataList.js +150 -0
  30. package/dist/components/DataList.js.map +1 -0
  31. package/dist/components/DetailHeader.d.ts +22 -0
  32. package/dist/components/DetailHeader.d.ts.map +1 -0
  33. package/dist/components/DetailHeader.js +48 -0
  34. package/dist/components/DetailHeader.js.map +1 -0
  35. package/dist/components/DurationInput.d.ts +25 -0
  36. package/dist/components/DurationInput.d.ts.map +1 -0
  37. package/dist/components/DurationInput.js +83 -0
  38. package/dist/components/DurationInput.js.map +1 -0
  39. package/dist/components/EmptyState.d.ts +14 -0
  40. package/dist/components/EmptyState.d.ts.map +1 -0
  41. package/dist/components/EmptyState.js +41 -0
  42. package/dist/components/EmptyState.js.map +1 -0
  43. package/dist/components/FormPage.d.ts +22 -0
  44. package/dist/components/FormPage.d.ts.map +1 -0
  45. package/dist/components/FormPage.js +65 -0
  46. package/dist/components/FormPage.js.map +1 -0
  47. package/dist/components/GetStartedPanel.d.ts +16 -0
  48. package/dist/components/GetStartedPanel.d.ts.map +1 -0
  49. package/dist/components/GetStartedPanel.js +96 -0
  50. package/dist/components/GetStartedPanel.js.map +1 -0
  51. package/dist/components/LabeledLine.d.ts +12 -0
  52. package/dist/components/LabeledLine.d.ts.map +1 -0
  53. package/dist/components/LabeledLine.js +6 -0
  54. package/dist/components/LabeledLine.js.map +1 -0
  55. package/dist/components/ListSearch.d.ts +15 -0
  56. package/dist/components/ListSearch.d.ts.map +1 -0
  57. package/dist/components/ListSearch.js +23 -0
  58. package/dist/components/ListSearch.js.map +1 -0
  59. package/dist/components/LoadingBar.d.ts +8 -0
  60. package/dist/components/LoadingBar.d.ts.map +1 -0
  61. package/dist/components/LoadingBar.js +55 -0
  62. package/dist/components/LoadingBar.js.map +1 -0
  63. package/dist/components/Outline.d.ts +23 -0
  64. package/dist/components/Outline.d.ts.map +1 -0
  65. package/dist/components/Outline.js +150 -0
  66. package/dist/components/Outline.js.map +1 -0
  67. package/dist/components/Overview.d.ts +103 -0
  68. package/dist/components/Overview.d.ts.map +1 -0
  69. package/dist/components/Overview.js +286 -0
  70. package/dist/components/Overview.js.map +1 -0
  71. package/dist/components/PageHeader.d.ts +19 -0
  72. package/dist/components/PageHeader.d.ts.map +1 -0
  73. package/dist/components/PageHeader.js +50 -0
  74. package/dist/components/PageHeader.js.map +1 -0
  75. package/dist/components/Pagination.d.ts +19 -0
  76. package/dist/components/Pagination.d.ts.map +1 -0
  77. package/dist/components/Pagination.js +47 -0
  78. package/dist/components/Pagination.js.map +1 -0
  79. package/dist/components/PasswordInput.d.ts +3 -0
  80. package/dist/components/PasswordInput.d.ts.map +1 -0
  81. package/dist/components/PasswordInput.js +16 -0
  82. package/dist/components/PasswordInput.js.map +1 -0
  83. package/dist/components/PrevNext.d.ts +16 -0
  84. package/dist/components/PrevNext.d.ts.map +1 -0
  85. package/dist/components/PrevNext.js +61 -0
  86. package/dist/components/PrevNext.js.map +1 -0
  87. package/dist/components/SearchButton.d.ts +16 -0
  88. package/dist/components/SearchButton.d.ts.map +1 -0
  89. package/dist/components/SearchButton.js +63 -0
  90. package/dist/components/SearchButton.js.map +1 -0
  91. package/dist/components/SearchField.d.ts +10 -0
  92. package/dist/components/SearchField.d.ts.map +1 -0
  93. package/dist/components/SearchField.js +67 -0
  94. package/dist/components/SearchField.js.map +1 -0
  95. package/dist/components/Segmented.d.ts +28 -0
  96. package/dist/components/Segmented.d.ts.map +1 -0
  97. package/dist/components/Segmented.js +74 -0
  98. package/dist/components/Segmented.js.map +1 -0
  99. package/dist/components/Select.d.ts +22 -0
  100. package/dist/components/Select.d.ts.map +1 -0
  101. package/dist/components/Select.js +50 -0
  102. package/dist/components/Select.js.map +1 -0
  103. package/dist/components/Settings.d.ts +103 -0
  104. package/dist/components/Settings.d.ts.map +1 -0
  105. package/dist/components/Settings.js +246 -0
  106. package/dist/components/Settings.js.map +1 -0
  107. package/dist/components/SideNav.d.ts +34 -0
  108. package/dist/components/SideNav.d.ts.map +1 -0
  109. package/dist/components/SideNav.js +99 -0
  110. package/dist/components/SideNav.js.map +1 -0
  111. package/dist/components/Skeletons.d.ts +37 -0
  112. package/dist/components/Skeletons.d.ts.map +1 -0
  113. package/dist/components/Skeletons.js +109 -0
  114. package/dist/components/Skeletons.js.map +1 -0
  115. package/dist/components/StatusPage.d.ts +37 -0
  116. package/dist/components/StatusPage.d.ts.map +1 -0
  117. package/dist/components/StatusPage.js +106 -0
  118. package/dist/components/StatusPage.js.map +1 -0
  119. package/dist/components/ThemeMenu.d.ts +11 -0
  120. package/dist/components/ThemeMenu.d.ts.map +1 -0
  121. package/dist/components/ThemeMenu.js +42 -0
  122. package/dist/components/ThemeMenu.js.map +1 -0
  123. package/dist/components/ThemeSwitch.d.ts +14 -0
  124. package/dist/components/ThemeSwitch.d.ts.map +1 -0
  125. package/dist/components/ThemeSwitch.js +17 -0
  126. package/dist/components/ThemeSwitch.js.map +1 -0
  127. package/dist/components/TopBar.d.ts +45 -0
  128. package/dist/components/TopBar.d.ts.map +1 -0
  129. package/dist/components/TopBar.js +145 -0
  130. package/dist/components/TopBar.js.map +1 -0
  131. package/dist/components/ViewBanner.d.ts +17 -0
  132. package/dist/components/ViewBanner.d.ts.map +1 -0
  133. package/dist/components/ViewBanner.js +14 -0
  134. package/dist/components/ViewBanner.js.map +1 -0
  135. package/dist/hooks/platform.d.ts +7 -0
  136. package/dist/hooks/platform.d.ts.map +1 -0
  137. package/dist/hooks/platform.js +19 -0
  138. package/dist/hooks/platform.js.map +1 -0
  139. package/dist/hooks/useConfirm.d.ts +23 -0
  140. package/dist/hooks/useConfirm.d.ts.map +1 -0
  141. package/dist/hooks/useConfirm.js +55 -0
  142. package/dist/hooks/useConfirm.js.map +1 -0
  143. package/dist/hooks/useCopy.d.ts +9 -0
  144. package/dist/hooks/useCopy.d.ts.map +1 -0
  145. package/dist/hooks/useCopy.js +14 -0
  146. package/dist/hooks/useCopy.js.map +1 -0
  147. package/dist/hooks/useDebouncedSearch.d.ts +8 -0
  148. package/dist/hooks/useDebouncedSearch.d.ts.map +1 -0
  149. package/dist/hooks/useDebouncedSearch.js +19 -0
  150. package/dist/hooks/useDebouncedSearch.js.map +1 -0
  151. package/dist/hooks/usePageClamp.d.ts +4 -0
  152. package/dist/hooks/usePageClamp.d.ts.map +1 -0
  153. package/dist/hooks/usePageClamp.js +17 -0
  154. package/dist/hooks/usePageClamp.js.map +1 -0
  155. package/dist/hooks/useSearchShortcut.d.ts +8 -0
  156. package/dist/hooks/useSearchShortcut.d.ts.map +1 -0
  157. package/dist/hooks/useSearchShortcut.js +38 -0
  158. package/dist/hooks/useSearchShortcut.js.map +1 -0
  159. package/dist/hooks/useThemeMode.d.ts +17 -0
  160. package/dist/hooks/useThemeMode.d.ts.map +1 -0
  161. package/dist/hooks/useThemeMode.js +62 -0
  162. package/dist/hooks/useThemeMode.js.map +1 -0
  163. package/dist/hooks/useToastMessage.d.ts +22 -0
  164. package/dist/hooks/useToastMessage.d.ts.map +1 -0
  165. package/dist/hooks/useToastMessage.js +26 -0
  166. package/dist/hooks/useToastMessage.js.map +1 -0
  167. package/dist/index.d.ts +45 -0
  168. package/dist/index.d.ts.map +1 -0
  169. package/dist/index.js +55 -0
  170. package/dist/index.js.map +1 -0
  171. package/dist/provider/UiProvider.d.ts +37 -0
  172. package/dist/provider/UiProvider.d.ts.map +1 -0
  173. package/dist/provider/UiProvider.js +42 -0
  174. package/dist/provider/UiProvider.js.map +1 -0
  175. package/dist/provider/canvas.d.ts +2 -0
  176. package/dist/provider/canvas.d.ts.map +1 -0
  177. package/dist/provider/canvas.js +15 -0
  178. package/dist/provider/canvas.js.map +1 -0
  179. package/dist/provider/context.d.ts +45 -0
  180. package/dist/provider/context.d.ts.map +1 -0
  181. package/dist/provider/context.js +39 -0
  182. package/dist/provider/context.js.map +1 -0
  183. package/dist/theme/createTheme.d.ts +13 -0
  184. package/dist/theme/createTheme.d.ts.map +1 -0
  185. package/dist/theme/createTheme.js +18 -0
  186. package/dist/theme/createTheme.js.map +1 -0
  187. package/package.json +49 -4
  188. package/src/components/BrandMark.tsx +28 -0
  189. package/src/components/CheckboxField.tsx +50 -0
  190. package/src/components/ColorPickerInput.tsx +190 -0
  191. package/src/components/CommandPalette.tsx +437 -0
  192. package/src/components/CopyButton.tsx +48 -0
  193. package/src/components/CopyIdTrigger.tsx +127 -0
  194. package/src/components/DataList.tsx +332 -0
  195. package/src/components/DetailHeader.tsx +102 -0
  196. package/src/components/DurationInput.tsx +133 -0
  197. package/src/components/EmptyState.tsx +67 -0
  198. package/src/components/FormPage.tsx +109 -0
  199. package/src/components/GetStartedPanel.tsx +132 -0
  200. package/src/components/LabeledLine.tsx +28 -0
  201. package/src/components/ListSearch.tsx +64 -0
  202. package/src/components/LoadingBar.tsx +81 -0
  203. package/src/components/Outline.tsx +208 -0
  204. package/src/components/Overview.tsx +448 -0
  205. package/src/components/PageHeader.tsx +80 -0
  206. package/src/components/Pagination.tsx +105 -0
  207. package/src/components/PasswordInput.tsx +35 -0
  208. package/src/components/PrevNext.tsx +98 -0
  209. package/src/components/SearchButton.tsx +90 -0
  210. package/src/components/SearchField.tsx +97 -0
  211. package/src/components/Segmented.tsx +136 -0
  212. package/src/components/Select.tsx +110 -0
  213. package/src/components/Settings.tsx +432 -0
  214. package/src/components/SideNav.tsx +188 -0
  215. package/src/components/Skeletons.tsx +233 -0
  216. package/src/components/StatusPage.tsx +188 -0
  217. package/src/components/ThemeMenu.tsx +83 -0
  218. package/src/components/ThemeSwitch.tsx +39 -0
  219. package/src/components/TopBar.tsx +280 -0
  220. package/src/components/ViewBanner.tsx +51 -0
  221. package/src/hooks/platform.ts +22 -0
  222. package/src/hooks/useConfirm.tsx +97 -0
  223. package/src/hooks/useCopy.ts +20 -0
  224. package/src/hooks/useDebouncedSearch.ts +19 -0
  225. package/src/hooks/usePageClamp.ts +20 -0
  226. package/src/hooks/useSearchShortcut.ts +49 -0
  227. package/src/hooks/useThemeMode.ts +98 -0
  228. package/src/hooks/useToastMessage.ts +38 -0
  229. package/src/index.ts +140 -0
  230. package/src/provider/UiProvider.tsx +95 -0
  231. package/src/provider/canvas.ts +17 -0
  232. package/src/provider/context.tsx +85 -0
  233. package/src/theme/createTheme.ts +29 -0
@@ -0,0 +1,432 @@
1
+ // Building blocks for account settings pages (Profile, Security), laid out
2
+ // like the Cloudflare dashboard's profile pages: a narrow column of cards,
3
+ // each with a title, a one-line description and an optional action on the
4
+ // right, holding either divided rows (label left, control right) or a padded
5
+ // form. Add flows open from the card's action instead of sitting open.
6
+
7
+ import {
8
+ Button,
9
+ MessageBar,
10
+ Spinner,
11
+ Subtitle2,
12
+ Text,
13
+ makeStyles,
14
+ mergeClasses,
15
+ tokens,
16
+ } from "@fluentui/react-components";
17
+ import { ChevronRightRegular } from "@fluentui/react-icons";
18
+ import type { ReactNode } from "react";
19
+ import { useUiStrings } from "../provider/context.js";
20
+ import { UiLink } from "../provider/context.js";
21
+
22
+ const NARROW = "@media (max-width: 640px)";
23
+
24
+ const useStyles = makeStyles({
25
+ page: {
26
+ maxWidth: "960px",
27
+ display: "flex",
28
+ flexDirection: "column",
29
+ gap: "20px",
30
+ },
31
+ // Keeps the latest result in view while scrolled down a long page.
32
+ toast: {
33
+ position: "sticky",
34
+ top: "8px",
35
+ zIndex: 2,
36
+ },
37
+ card: {
38
+ "--card-pad": "24px",
39
+ scrollMarginTop: "16px",
40
+ [NARROW]: { "--card-pad": "16px" },
41
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
42
+ borderRadius: tokens.borderRadiusXLarge,
43
+ background: tokens.colorNeutralBackground1,
44
+ },
45
+ head: {
46
+ display: "flex",
47
+ alignItems: "flex-start",
48
+ justifyContent: "space-between",
49
+ flexWrap: "wrap",
50
+ gap: "12px 16px",
51
+ padding: "20px var(--card-pad) 16px",
52
+ },
53
+ titles: {
54
+ display: "flex",
55
+ flexDirection: "column",
56
+ gap: "4px",
57
+ flex: "1 1 320px",
58
+ minWidth: 0,
59
+ },
60
+ titleLine: {
61
+ display: "flex",
62
+ alignItems: "center",
63
+ gap: "8px",
64
+ },
65
+ title: { margin: 0 },
66
+ muted: {
67
+ color: tokens.colorNeutralForeground3,
68
+ },
69
+ action: {
70
+ display: "flex",
71
+ alignItems: "center",
72
+ gap: "8px",
73
+ flexShrink: 0,
74
+ },
75
+ body: {
76
+ display: "flex",
77
+ flexDirection: "column",
78
+ gap: "16px",
79
+ padding: "16px var(--card-pad) 20px",
80
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
81
+ },
82
+ row: {
83
+ display: "flex",
84
+ alignItems: "center",
85
+ gap: "12px 16px",
86
+ minHeight: "60px",
87
+ padding: "12px var(--card-pad)",
88
+ boxSizing: "border-box",
89
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
90
+ [NARROW]: { flexWrap: "wrap" },
91
+ },
92
+ rowIcon: {
93
+ display: "inline-flex",
94
+ flexShrink: 0,
95
+ fontSize: "20px",
96
+ color: tokens.colorNeutralForeground3,
97
+ },
98
+ rowText: {
99
+ display: "flex",
100
+ flexDirection: "column",
101
+ gap: "2px",
102
+ flex: "1 1 240px",
103
+ minWidth: 0,
104
+ },
105
+ rowLabel: {
106
+ display: "flex",
107
+ alignItems: "center",
108
+ flexWrap: "wrap",
109
+ gap: "6px",
110
+ minWidth: 0,
111
+ overflowWrap: "anywhere",
112
+ },
113
+ // A div, not Text, so descriptions can hold block content.
114
+ rowDesc: {
115
+ fontSize: tokens.fontSizeBase200,
116
+ lineHeight: tokens.lineHeightBase200,
117
+ color: tokens.colorNeutralForeground3,
118
+ minWidth: 0,
119
+ },
120
+ rowControl: {
121
+ display: "flex",
122
+ alignItems: "center",
123
+ justifyContent: "flex-end",
124
+ flexWrap: "wrap",
125
+ gap: "8px",
126
+ flexShrink: 0,
127
+ maxWidth: "100%",
128
+ [NARROW]: { justifyContent: "flex-start" },
129
+ },
130
+ subhead: {
131
+ padding: "10px var(--card-pad)",
132
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
133
+ background: tokens.colorNeutralBackground2,
134
+ fontSize: tokens.fontSizeBase200,
135
+ color: tokens.colorNeutralForeground3,
136
+ },
137
+ empty: {
138
+ padding: "16px var(--card-pad)",
139
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
140
+ color: tokens.colorNeutralForeground3,
141
+ },
142
+ footer: {
143
+ display: "flex",
144
+ alignItems: "center",
145
+ justifyContent: "flex-end",
146
+ flexWrap: "wrap",
147
+ gap: "8px",
148
+ padding: "12px var(--card-pad)",
149
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
150
+ },
151
+ // A data table inside a card: edge cells line up with the card padding.
152
+ table: {
153
+ overflowX: "auto",
154
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
155
+ "& th:first-child, & td:first-child": {
156
+ paddingLeft: "var(--card-pad)",
157
+ },
158
+ "& th:last-child, & td:last-child": {
159
+ paddingRight: "var(--card-pad)",
160
+ },
161
+ "& tbody tr:last-child": { borderBottomStyle: "none" },
162
+ },
163
+ linkRow: {
164
+ display: "flex",
165
+ alignItems: "center",
166
+ gap: "12px",
167
+ minHeight: "60px",
168
+ padding: "10px var(--card-pad)",
169
+ boxSizing: "border-box",
170
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
171
+ color: "inherit",
172
+ textDecorationLine: "none",
173
+ ":hover": { background: tokens.colorNeutralBackground1Hover },
174
+ ":focus-visible": {
175
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
176
+ outlineOffset: "-2px",
177
+ },
178
+ },
179
+ linkMeta: {
180
+ flexShrink: 0,
181
+ display: "flex",
182
+ alignItems: "center",
183
+ gap: "8px",
184
+ fontSize: tokens.fontSizeBase200,
185
+ color: tokens.colorNeutralForeground3,
186
+ [NARROW]: { display: "none" },
187
+ },
188
+ chevron: {
189
+ flexShrink: 0,
190
+ fontSize: "16px",
191
+ color: tokens.colorNeutralForeground3,
192
+ },
193
+ footerStart: {
194
+ marginRight: "auto",
195
+ fontSize: tokens.fontSizeBase200,
196
+ color: tokens.colorNeutralForeground3,
197
+ },
198
+ });
199
+
200
+ /** The column a settings page's cards stack in. */
201
+ export function SettingsPage({
202
+ children,
203
+ }: {
204
+ /** The cards, one under another. */
205
+ children: ReactNode;
206
+ }) {
207
+ const styles = useStyles();
208
+ return <div className={styles.page}>{children}</div>;
209
+ }
210
+
211
+ /** A success or error message, such as a save's result, that stays in view
212
+ * while the page scrolls. */
213
+ export function SettingsToast({
214
+ message,
215
+ }: {
216
+ /** The message to show, or `null` for none. Pair it with `useToastMessage`. */
217
+ message: { type: "success" | "error"; text: string } | null;
218
+ }) {
219
+ const styles = useStyles();
220
+ if (!message) return null;
221
+ return (
222
+ <div className={styles.toast} role="status">
223
+ <MessageBar intent={message.type === "success" ? "success" : "error"}>
224
+ {message.text}
225
+ </MessageBar>
226
+ </div>
227
+ );
228
+ }
229
+
230
+ interface SettingsCardProps {
231
+ /** An anchor for links to the card (`/page#id`), e.g. from search. */
232
+ id?: string;
233
+ /** The card's heading. */
234
+ title: string;
235
+ /** Muted text under the title. */
236
+ description?: ReactNode;
237
+ /** Shown beside the title, e.g. an Enabled badge. */
238
+ badge?: ReactNode;
239
+ /** Shown at the top right of the card, e.g. an Add button. */
240
+ action?: ReactNode;
241
+ /** What goes under the header: rows, a `SettingsBody`, a `SettingsTable`, a footer. */
242
+ children?: ReactNode;
243
+ }
244
+
245
+ /** A card on a settings page: a header, then rows or a body. */
246
+ export function SettingsCard({
247
+ id,
248
+ title,
249
+ description,
250
+ badge,
251
+ action,
252
+ children,
253
+ }: SettingsCardProps) {
254
+ const styles = useStyles();
255
+ return (
256
+ <section id={id} className={styles.card}>
257
+ <div className={styles.head}>
258
+ <div className={styles.titles}>
259
+ <div className={styles.titleLine}>
260
+ <Subtitle2 as="h2" className={styles.title}>
261
+ {title}
262
+ </Subtitle2>
263
+ {badge}
264
+ </div>
265
+ {description && (
266
+ <Text size={200} className={styles.muted}>
267
+ {description}
268
+ </Text>
269
+ )}
270
+ </div>
271
+ {action && <div className={styles.action}>{action}</div>}
272
+ </div>
273
+ {children}
274
+ </section>
275
+ );
276
+ }
277
+
278
+ /** Padded content (a form, an editor) below the card header. */
279
+ export function SettingsBody({
280
+ children,
281
+ }: {
282
+ /** Content that isn't rows, such as a form or an editor. */
283
+ children: ReactNode;
284
+ }) {
285
+ const styles = useStyles();
286
+ return <div className={styles.body}>{children}</div>;
287
+ }
288
+
289
+ interface SettingsRowProps {
290
+ /** Shown before the label. */
291
+ icon?: ReactNode;
292
+ /** The setting's name. */
293
+ label: ReactNode;
294
+ /** Muted text under the label. It can hold block content. */
295
+ description?: ReactNode;
296
+ /** Controls on the right: a switch, a short input, row actions. On narrow
297
+ * screens they move under the label. */
298
+ children?: ReactNode;
299
+ /** Extra styles for the row. */
300
+ className?: string;
301
+ }
302
+
303
+ /** One setting: its label on the left, its control on the right. */
304
+ export function SettingsRow({ icon, label, description, children, className }: SettingsRowProps) {
305
+ const styles = useStyles();
306
+ return (
307
+ <div className={mergeClasses(styles.row, className)}>
308
+ {icon && <span className={styles.rowIcon}>{icon}</span>}
309
+ <div className={styles.rowText}>
310
+ <div className={styles.rowLabel}>{label}</div>
311
+ {description && <div className={styles.rowDesc}>{description}</div>}
312
+ </div>
313
+ {children && <div className={styles.rowControl}>{children}</div>}
314
+ </div>
315
+ );
316
+ }
317
+
318
+ /** A quiet heading between groups of rows. */
319
+ export function SettingsSubhead({
320
+ children,
321
+ }: {
322
+ /** The heading's text. */
323
+ children: ReactNode;
324
+ }) {
325
+ const styles = useStyles();
326
+ return <div className={styles.subhead}>{children}</div>;
327
+ }
328
+
329
+ /** "Nothing here" inside a card. */
330
+ export function SettingsEmpty({
331
+ children,
332
+ }: {
333
+ /** The message, e.g. "No webhooks." */
334
+ children: ReactNode;
335
+ }) {
336
+ const styles = useStyles();
337
+ return <div className={styles.empty}>{children}</div>;
338
+ }
339
+
340
+ /** The card's bottom bar. */
341
+ export function SettingsFooter({
342
+ start,
343
+ children,
344
+ }: {
345
+ /** A note on the left, e.g. a byte count. */
346
+ start?: ReactNode;
347
+ /** Buttons, on the right. */
348
+ children: ReactNode;
349
+ }) {
350
+ const styles = useStyles();
351
+ return (
352
+ <div className={styles.footer}>
353
+ {start && <span className={styles.footerStart}>{start}</span>}
354
+ {children}
355
+ </div>
356
+ );
357
+ }
358
+
359
+ /** Discard + Save for a card's edits. Discard shows while there are unsaved
360
+ * changes; Save needs changes and is held while saving. */
361
+ export function SaveFooter({
362
+ dirty,
363
+ saving,
364
+ disabled,
365
+ onDiscard,
366
+ onSave,
367
+ }: {
368
+ /** There are unsaved changes: shows Discard and enables Save. */
369
+ dirty: boolean;
370
+ /** A save is in flight: hides Discard and shows a spinner in Save. */
371
+ saving: boolean;
372
+ /** Also hold Save, e.g. for invalid input or another save in flight. */
373
+ disabled?: boolean;
374
+ /** Called by Discard, to undo the edits. */
375
+ onDiscard: () => void;
376
+ /** Called by Save. */
377
+ onSave: () => void;
378
+ }) {
379
+ const strings = useUiStrings();
380
+ return (
381
+ <SettingsFooter>
382
+ {dirty && !saving && (
383
+ <Button appearance="subtle" onClick={onDiscard}>
384
+ {strings.discardChanges}
385
+ </Button>
386
+ )}
387
+ <Button appearance="primary" disabled={!dirty || saving || disabled} onClick={onSave}>
388
+ {saving ? <Spinner size="tiny" /> : strings.saveChanges}
389
+ </Button>
390
+ </SettingsFooter>
391
+ );
392
+ }
393
+
394
+ /** A table in a card, edge-aligned with the card's padding. */
395
+ export function SettingsTable({
396
+ children,
397
+ }: {
398
+ /** A Fluent `Table`. */
399
+ children: ReactNode;
400
+ }) {
401
+ const styles = useStyles();
402
+ return <div className={styles.table}>{children}</div>;
403
+ }
404
+
405
+ interface SettingsLinkRowProps {
406
+ /** Where the row links, through the app's router. */
407
+ to: string;
408
+ /** Shown before the label, usually an `Avatar`. */
409
+ icon?: ReactNode;
410
+ /** The row's name. */
411
+ label: ReactNode;
412
+ /** Muted text under the label. */
413
+ description?: ReactNode;
414
+ /** Muted facts on the right, hidden on narrow screens. */
415
+ meta?: ReactNode;
416
+ }
417
+
418
+ /** A row that opens another page, e.g. one app in a team's app list. */
419
+ export function SettingsLinkRow({ to, icon, label, description, meta }: SettingsLinkRowProps) {
420
+ const styles = useStyles();
421
+ return (
422
+ <UiLink to={to} className={styles.linkRow}>
423
+ {icon}
424
+ <div className={styles.rowText}>
425
+ <div className={styles.rowLabel}>{label}</div>
426
+ {description && <div className={styles.rowDesc}>{description}</div>}
427
+ </div>
428
+ {meta && <div className={styles.linkMeta}>{meta}</div>}
429
+ <ChevronRightRegular className={styles.chevron} />
430
+ </UiLink>
431
+ );
432
+ }
@@ -0,0 +1,188 @@
1
+ // A navigation column, as Prism's sidebar and Vellum's docs sidebar draw it:
2
+ // flat on the canvas, 13px items with a grey (not brand) highlight on the
3
+ // current page, quiet 12px group labels, and nested items under a hairline.
4
+ // Where it sits (sticky, its width, a drawer on a phone) is the app's layout.
5
+
6
+ import { Text, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
7
+ import type { ReactNode } from "react";
8
+ import { UiLink } from "../provider/context.js";
9
+
10
+ const useStyles = makeStyles({
11
+ root: {
12
+ display: "flex",
13
+ flexDirection: "column",
14
+ padding: "10px",
15
+ boxSizing: "border-box",
16
+ },
17
+ group: { marginBottom: "6px" },
18
+ label: {
19
+ display: "block",
20
+ margin: 0,
21
+ padding: "16px 10px 6px",
22
+ fontSize: "12px",
23
+ fontWeight: tokens.fontWeightRegular,
24
+ lineHeight: "16px",
25
+ color: tokens.colorNeutralForeground3,
26
+ },
27
+ labelFirst: { paddingTop: "6px" },
28
+ list: { display: "flex", flexDirection: "column", gap: "1px" },
29
+ item: {
30
+ display: "flex",
31
+ alignItems: "center",
32
+ gap: "10px",
33
+ minHeight: "32px",
34
+ paddingInline: "10px",
35
+ paddingBlock: "6px",
36
+ boxSizing: "border-box",
37
+ borderRadius: tokens.borderRadiusMedium,
38
+ color: tokens.colorNeutralForeground2,
39
+ textDecoration: "none",
40
+ fontSize: "13px",
41
+ lineHeight: "18px",
42
+ ":hover": {
43
+ backgroundColor: tokens.colorNeutralBackground3,
44
+ color: tokens.colorNeutralForeground1,
45
+ textDecoration: "none",
46
+ },
47
+ ":focus-visible": {
48
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
49
+ outlineOffset: "-2px",
50
+ },
51
+ },
52
+ active: {
53
+ backgroundColor: tokens.colorNeutralBackground3,
54
+ color: tokens.colorNeutralForeground1,
55
+ fontWeight: tokens.fontWeightMedium,
56
+ },
57
+ // An item with items under it.
58
+ branch: {
59
+ fontWeight: tokens.fontWeightMedium,
60
+ color: tokens.colorNeutralForeground1,
61
+ },
62
+ // A branch without a link of its own.
63
+ heading: {
64
+ display: "flex",
65
+ alignItems: "center",
66
+ gap: "10px",
67
+ minHeight: "32px",
68
+ paddingInline: "10px",
69
+ paddingBlock: "6px",
70
+ boxSizing: "border-box",
71
+ fontSize: "13px",
72
+ lineHeight: "18px",
73
+ },
74
+ icon: {
75
+ display: "inline-flex",
76
+ flexShrink: 0,
77
+ fontSize: "16px",
78
+ color: tokens.colorNeutralForeground3,
79
+ },
80
+ nested: {
81
+ display: "flex",
82
+ flexDirection: "column",
83
+ gap: "1px",
84
+ marginLeft: "14px",
85
+ paddingLeft: "6px",
86
+ borderLeft: `1px solid ${tokens.colorNeutralStroke2}`,
87
+ },
88
+ });
89
+
90
+ export interface SideNavItem {
91
+ /** The item's text. */
92
+ label: ReactNode;
93
+ /** An in-app path. Without one, the item is a heading for its `items`. */
94
+ to?: string;
95
+ /** Shown before the label. */
96
+ icon?: ReactNode;
97
+ /**
98
+ * The page the reader is on. The app decides from its router, e.g.
99
+ * `!!useMatch(to)` in React Router. The item gets `aria-current="page"`.
100
+ */
101
+ active?: boolean;
102
+ /** Items under this one, indented. */
103
+ items?: SideNavItem[];
104
+ }
105
+
106
+ export interface SideNavGroup {
107
+ /** A quiet label above the group's items. */
108
+ label?: ReactNode;
109
+ /** The group's items: `{ label, to?, icon?, active?, items? }`. */
110
+ items: SideNavItem[];
111
+ }
112
+
113
+ export interface SideNavProps {
114
+ /** The groups, in order: `{ label?, items }`. */
115
+ groups: SideNavGroup[];
116
+ /** Names the navigation for screen readers, e.g. "Documentation". */
117
+ label: string;
118
+ /** Called on a click on any item, e.g. to close the drawer it's in. */
119
+ onNavigate?: () => void;
120
+ /** Where it sits is your layout: its width, `position: sticky`, its own scrolling. */
121
+ className?: string;
122
+ }
123
+
124
+ type Styles = ReturnType<typeof useStyles>;
125
+
126
+ export function SideNav({ groups, label, onNavigate, className }: SideNavProps) {
127
+ const styles = useStyles();
128
+ return (
129
+ <nav aria-label={label} className={mergeClasses(styles.root, className)}>
130
+ {groups.map((group, g) => (
131
+ <section key={g} className={styles.group}>
132
+ {group.label != null && (
133
+ <Text as="h2" className={mergeClasses(styles.label, g === 0 && styles.labelFirst)}>
134
+ {group.label}
135
+ </Text>
136
+ )}
137
+ <div className={styles.list}>
138
+ {group.items.map((item, i) => (
139
+ <Item key={item.to ?? i} item={item} onNavigate={onNavigate} styles={styles} />
140
+ ))}
141
+ </div>
142
+ </section>
143
+ ))}
144
+ </nav>
145
+ );
146
+ }
147
+
148
+ function Item({
149
+ item,
150
+ onNavigate,
151
+ styles,
152
+ }: {
153
+ item: SideNavItem;
154
+ onNavigate?: () => void;
155
+ styles: Styles;
156
+ }) {
157
+ const branch = !!item.items?.length;
158
+ const content = (
159
+ <>
160
+ {item.icon && <span className={styles.icon}>{item.icon}</span>}
161
+ {item.label}
162
+ </>
163
+ );
164
+ const head =
165
+ item.to != null ? (
166
+ <UiLink
167
+ to={item.to}
168
+ onClick={onNavigate}
169
+ aria-current={item.active ? "page" : undefined}
170
+ className={mergeClasses(styles.item, branch && styles.branch, item.active && styles.active)}
171
+ >
172
+ {content}
173
+ </UiLink>
174
+ ) : (
175
+ <div className={mergeClasses(styles.heading, styles.branch)}>{content}</div>
176
+ );
177
+ if (!branch) return head;
178
+ return (
179
+ <div>
180
+ {head}
181
+ <div className={styles.nested}>
182
+ {item.items!.map((sub, i) => (
183
+ <Item key={sub.to ?? i} item={sub} onNavigate={onNavigate} styles={styles} />
184
+ ))}
185
+ </div>
186
+ </div>
187
+ );
188
+ }