@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,233 @@
1
+ // Reusable skeleton components for loading states
2
+
3
+ import {
4
+ Skeleton,
5
+ SkeletonItem,
6
+ TableCell,
7
+ TableRow,
8
+ makeStyles,
9
+ tokens,
10
+ } from "@fluentui/react-components";
11
+
12
+ const useStyles = makeStyles({
13
+ card: {
14
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
15
+ borderRadius: "10px",
16
+ padding: "24px",
17
+ background: tokens.colorNeutralBackground1,
18
+ display: "flex",
19
+ flexDirection: "column",
20
+ gap: "16px",
21
+ },
22
+ row: {
23
+ display: "flex",
24
+ alignItems: "center",
25
+ gap: "12px",
26
+ },
27
+ tableRow: {
28
+ display: "flex",
29
+ alignItems: "center",
30
+ gap: "16px",
31
+ padding: "12px 0",
32
+ borderBottom: `1px solid ${tokens.colorNeutralStroke2}`,
33
+ },
34
+ grid: {
35
+ display: "grid",
36
+ gridTemplateColumns: "repeat(auto-fill, minmax(260px, 1fr))",
37
+ gap: "16px",
38
+ },
39
+ statCard: {
40
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
41
+ borderRadius: "10px",
42
+ padding: "16px",
43
+ background: tokens.colorNeutralBackground1,
44
+ display: "flex",
45
+ flexDirection: "column",
46
+ gap: "12px",
47
+ },
48
+ // Shaped like components/Settings' SettingsCard.
49
+ settingsCard: {
50
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
51
+ borderRadius: tokens.borderRadiusXLarge,
52
+ background: tokens.colorNeutralBackground1,
53
+ },
54
+ settingsHead: {
55
+ display: "flex",
56
+ flexDirection: "column",
57
+ gap: "8px",
58
+ padding: "20px 24px 18px",
59
+ },
60
+ settingsRow: {
61
+ display: "flex",
62
+ alignItems: "center",
63
+ justifyContent: "space-between",
64
+ gap: "16px",
65
+ minHeight: "60px",
66
+ padding: "0 24px",
67
+ boxSizing: "border-box",
68
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
69
+ },
70
+ settingsForm: {
71
+ display: "flex",
72
+ flexDirection: "column",
73
+ gap: "16px",
74
+ padding: "16px 24px 20px",
75
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
76
+ },
77
+ stack: {
78
+ display: "flex",
79
+ flexDirection: "column",
80
+ gap: "20px",
81
+ },
82
+ });
83
+
84
+ // --- building blocks ---
85
+
86
+ /** Placeholder rows in place of a whole table. */
87
+ export function SkeletonTableRows({
88
+ rows = 5,
89
+ cols = 4,
90
+ }: {
91
+ /** How many rows. */
92
+ rows?: number;
93
+ /** How many bars in each row. */
94
+ cols?: number;
95
+ }) {
96
+ const styles = useStyles();
97
+ const widths = ["30%", "40%", "20%", "25%", "35%", "15%", "45%"];
98
+ return (
99
+ <Skeleton>
100
+ {Array.from({ length: rows }).map((_, i) => (
101
+ <div key={i} className={styles.tableRow}>
102
+ {Array.from({ length: cols }).map((_, j) => (
103
+ <SkeletonItem
104
+ key={j}
105
+ style={{
106
+ width: widths[(i * cols + j) % widths.length],
107
+ height: 16,
108
+ }}
109
+ />
110
+ ))}
111
+ </div>
112
+ ))}
113
+ </Skeleton>
114
+ );
115
+ }
116
+
117
+ /** Placeholder rows for inside a <TableBody>: real rows and cells, so each
118
+ * bar sits under its column. (SkeletonTableRows draws divs, for use in
119
+ * place of a whole table.) */
120
+ export function SkeletonTableBodyRows({
121
+ rows = 5,
122
+ cols = 4,
123
+ }: {
124
+ /** How many rows. */
125
+ rows?: number;
126
+ /** Cells in each row: the table's column count. */
127
+ cols?: number;
128
+ }) {
129
+ const widths = ["60%", "80%", "45%", "70%", "55%", "35%", "75%"];
130
+ return (
131
+ <>
132
+ {Array.from({ length: rows }).map((_, i) => (
133
+ <TableRow key={i} aria-hidden>
134
+ {Array.from({ length: cols }).map((_, j) => (
135
+ <TableCell key={j}>
136
+ <Skeleton>
137
+ <SkeletonItem size={12} style={{ width: widths[(i + j * 3) % widths.length] }} />
138
+ </Skeleton>
139
+ </TableCell>
140
+ ))}
141
+ </TableRow>
142
+ ))}
143
+ </>
144
+ );
145
+ }
146
+
147
+ /** Placeholder metric tiles, in a grid. */
148
+ export function SkeletonStatCards({
149
+ count = 4,
150
+ }: {
151
+ /** How many tiles. */
152
+ count?: number;
153
+ }) {
154
+ const styles = useStyles();
155
+ return (
156
+ <div className={styles.grid}>
157
+ {Array.from({ length: count }).map((_, i) => (
158
+ <Skeleton key={i}>
159
+ <div className={styles.statCard}>
160
+ <div className={styles.row}>
161
+ <SkeletonItem shape="circle" size={24} />
162
+ <SkeletonItem style={{ width: "50%", height: 16 }} />
163
+ </div>
164
+ <SkeletonItem style={{ width: "30%", height: 28 }} />
165
+ <SkeletonItem style={{ width: "70%", height: 14 }} />
166
+ </div>
167
+ </Skeleton>
168
+ ))}
169
+ </div>
170
+ );
171
+ }
172
+
173
+ /** One SettingsCard: title and description, then `rows` label/control
174
+ * rows, or with `form`, `rows` stacked label-over-input fields. */
175
+ export function SkeletonSettingsCard({
176
+ rows = 3,
177
+ form = false,
178
+ }: {
179
+ /** How many rows, or fields with `form`. */
180
+ rows?: number;
181
+ /** Stacked label-over-input fields instead of rows. */
182
+ form?: boolean;
183
+ }) {
184
+ const styles = useStyles();
185
+ const widths = ["30%", "22%", "36%", "26%", "40%", "18%"];
186
+ return (
187
+ <Skeleton aria-busy>
188
+ <div className={styles.settingsCard}>
189
+ <div className={styles.settingsHead}>
190
+ <SkeletonItem size={16} style={{ width: 160 }} />
191
+ <SkeletonItem size={12} style={{ width: 320, maxWidth: "70%" }} />
192
+ </div>
193
+ {form ? (
194
+ <div className={styles.settingsForm}>
195
+ {Array.from({ length: rows }).map((_, i) => (
196
+ <div key={i} style={{ display: "flex", flexDirection: "column", gap: 6 }}>
197
+ <SkeletonItem size={12} style={{ width: widths[i % 6] }} />
198
+ <SkeletonItem size={32} style={{ width: "100%" }} />
199
+ </div>
200
+ ))}
201
+ </div>
202
+ ) : (
203
+ Array.from({ length: rows }).map((_, i) => (
204
+ <div key={i} className={styles.settingsRow}>
205
+ <SkeletonItem size={12} style={{ width: widths[i % 6] }} />
206
+ <SkeletonItem size={24} style={{ width: 120 }} />
207
+ </div>
208
+ ))
209
+ )}
210
+ </div>
211
+ </Skeleton>
212
+ );
213
+ }
214
+
215
+ /** Several SettingsCard skeletons stacked like a settings page. */
216
+ export function SkeletonSettingsPage({
217
+ cards,
218
+ form = false,
219
+ }: {
220
+ /** One number per card: its rows. */
221
+ cards: number[];
222
+ /** Every card shows fields instead of rows, as with `SkeletonSettingsCard`'s `form`. */
223
+ form?: boolean;
224
+ }) {
225
+ const styles = useStyles();
226
+ return (
227
+ <div className={styles.stack}>
228
+ {cards.map((rows, i) => (
229
+ <SkeletonSettingsCard key={i} rows={rows} form={form} />
230
+ ))}
231
+ </div>
232
+ );
233
+ }
@@ -0,0 +1,212 @@
1
+ // A full-page message: an icon or code, a title, a line of explanation and
2
+ // where to go next. Used for 404, error, access denied and signed-out pages:
3
+ // Prism's StatusPage, with what Vellum's 404 adds (the site above, the missing
4
+ // path, pages the reader may have meant).
5
+
6
+ import { Button, Text, Title2, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
7
+ import { ChevronRight16Regular } from "@fluentui/react-icons";
8
+ import type { ReactElement, ReactNode } from "react";
9
+ import { useCanvasClass } from "../provider/canvas.js";
10
+ import { UiLink } from "../provider/context.js";
11
+ import { BrandMark } from "./BrandMark.js";
12
+ import { ButtonLink } from "./ButtonLink.js";
13
+
14
+ const useStyles = makeStyles({
15
+ page: {
16
+ minHeight: "100vh",
17
+ display: "flex",
18
+ alignItems: "center",
19
+ justifyContent: "center",
20
+ padding: "16px",
21
+ boxSizing: "border-box",
22
+ },
23
+ card: {
24
+ width: "100%",
25
+ maxWidth: "480px",
26
+ padding: "48px 40px",
27
+ boxSizing: "border-box",
28
+ borderRadius: tokens.borderRadiusLarge,
29
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
30
+ background: tokens.colorNeutralBackground2,
31
+ display: "flex",
32
+ flexDirection: "column",
33
+ alignItems: "center",
34
+ gap: "16px",
35
+ textAlign: "center",
36
+ "@media (max-width: 540px)": { padding: "32px 20px" },
37
+ },
38
+ brand: {
39
+ display: "flex",
40
+ alignItems: "center",
41
+ gap: "8px",
42
+ color: tokens.colorNeutralForeground3,
43
+ fontSize: tokens.fontSizeBase200,
44
+ },
45
+ title: { margin: 0 },
46
+ description: { color: tokens.colorNeutralForeground3 },
47
+ hint: {
48
+ alignSelf: "stretch",
49
+ textAlign: "left",
50
+ padding: "10px 12px",
51
+ borderRadius: tokens.borderRadiusMedium,
52
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
53
+ backgroundColor: tokens.colorNeutralBackground1,
54
+ fontFamily: tokens.fontFamilyMonospace,
55
+ fontSize: tokens.fontSizeBase200,
56
+ color: tokens.colorNeutralForeground2,
57
+ overflowX: "auto",
58
+ },
59
+ actions: {
60
+ display: "flex",
61
+ flexWrap: "wrap",
62
+ justifyContent: "center",
63
+ gap: "8px",
64
+ marginTop: "8px",
65
+ },
66
+ links: {
67
+ alignSelf: "stretch",
68
+ display: "flex",
69
+ flexDirection: "column",
70
+ gap: "1px",
71
+ marginTop: "8px",
72
+ paddingTop: "16px",
73
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
74
+ textAlign: "left",
75
+ },
76
+ linksLabel: {
77
+ padding: "0 10px 6px",
78
+ fontSize: "12px",
79
+ color: tokens.colorNeutralForeground3,
80
+ },
81
+ link: {
82
+ display: "flex",
83
+ alignItems: "center",
84
+ gap: "8px",
85
+ minHeight: "32px",
86
+ padding: "0 10px",
87
+ borderRadius: tokens.borderRadiusMedium,
88
+ fontSize: "13px",
89
+ color: tokens.colorNeutralForeground2,
90
+ textDecoration: "none",
91
+ "& svg": { color: tokens.colorNeutralForeground3, flexShrink: 0 },
92
+ ":hover": {
93
+ backgroundColor: tokens.colorNeutralBackground3,
94
+ color: tokens.colorNeutralForeground1,
95
+ textDecoration: "none",
96
+ },
97
+ ":focus-visible": {
98
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
99
+ outlineOffset: "-2px",
100
+ },
101
+ },
102
+ });
103
+
104
+ /** A button on a status page: a link to a page in the app (`to`), or
105
+ * something to do there (`onClick`), such as reloading or signing in again. */
106
+ export type StatusPageAction = {
107
+ /** The button's text. */
108
+ label: string;
109
+ /** An icon before the label. */
110
+ icon?: ReactElement;
111
+ } & (
112
+ | {
113
+ /** An in-app path, opened through the app's router. */
114
+ to: string;
115
+ onClick?: never;
116
+ }
117
+ | {
118
+ /** What the button does, when it opens no page of its own. */
119
+ onClick: () => void;
120
+ to?: never;
121
+ }
122
+ );
123
+
124
+ function Action({ action, primary }: { action: StatusPageAction; primary?: boolean }) {
125
+ const appearance = primary ? "primary" : undefined;
126
+ return action.to !== undefined ? (
127
+ <ButtonLink appearance={appearance} icon={action.icon} to={action.to}>
128
+ {action.label}
129
+ </ButtonLink>
130
+ ) : (
131
+ <Button appearance={appearance} icon={action.icon} onClick={action.onClick}>
132
+ {action.label}
133
+ </Button>
134
+ );
135
+ }
136
+
137
+ export interface StatusPageProps {
138
+ /** The big figure above the title: a code, an icon or an illustration. */
139
+ mark: ReactNode;
140
+ /** The page's `h1`. */
141
+ title: ReactNode;
142
+ /** A line of explanation under the title. */
143
+ description: ReactNode;
144
+ /** The site, small above the mark, for a page outside the app's layout. */
145
+ brand?: { name: string; iconUrl?: string };
146
+ /** A detail in monospace under the description, such as the path that wasn't found. */
147
+ hint?: ReactNode;
148
+ /** Label for a button that goes back in the browser's history, when going back makes sense. */
149
+ back?: string;
150
+ /** More ways on, between "go back" and the main one, such as search: each
151
+ * `{ label, to }` or `{ label, onClick }`, with an optional `icon`. */
152
+ secondary?: StatusPageAction[];
153
+ /** The main way on, the primary button: `{ label, to }` to open a page, or
154
+ * `{ label, onClick }`, such as reloading after an error. */
155
+ primary: StatusPageAction;
156
+ /** Pages the reader may have meant, listed under the buttons. */
157
+ links?: { label: ReactNode; to: string }[];
158
+ /** The heading over `links`, such as "You might have been looking for". */
159
+ linksLabel?: ReactNode;
160
+ }
161
+
162
+ export function StatusPage({
163
+ mark,
164
+ title,
165
+ description,
166
+ brand,
167
+ hint,
168
+ back,
169
+ secondary,
170
+ primary,
171
+ links,
172
+ linksLabel,
173
+ }: StatusPageProps) {
174
+ const styles = useStyles();
175
+ const canvas = useCanvasClass();
176
+ return (
177
+ <div className={mergeClasses(styles.page, canvas)}>
178
+ <div className={styles.card}>
179
+ {brand && (
180
+ <div className={styles.brand}>
181
+ <BrandMark iconUrl={brand.iconUrl} size={20} />
182
+ <span>{brand.name}</span>
183
+ </div>
184
+ )}
185
+ {mark}
186
+ <Title2 as="h1" className={styles.title}>
187
+ {title}
188
+ </Title2>
189
+ <Text className={styles.description}>{description}</Text>
190
+ {hint != null && <div className={styles.hint}>{hint}</div>}
191
+ <div className={styles.actions}>
192
+ {back && <Button onClick={() => window.history.back()}>{back}</Button>}
193
+ {secondary?.map((action) => (
194
+ <Action key={action.to ?? action.label} action={action} />
195
+ ))}
196
+ <Action action={primary} primary />
197
+ </div>
198
+ {links && links.length > 0 && (
199
+ <div className={styles.links}>
200
+ {linksLabel != null && <div className={styles.linksLabel}>{linksLabel}</div>}
201
+ {links.map((link) => (
202
+ <UiLink key={link.to} to={link.to} className={styles.link}>
203
+ <ChevronRight16Regular />
204
+ <span>{link.label}</span>
205
+ </UiLink>
206
+ ))}
207
+ </div>
208
+ )}
209
+ </div>
210
+ </div>
211
+ );
212
+ }
@@ -0,0 +1,51 @@
1
+ // The theme switch for a top bar: an icon button (a sun or a moon, for the
2
+ // scheme drawn now) opening a small panel with the System / Light / Dark
3
+ // switch, as in Vellum's nav bar.
4
+
5
+ import { Button, Popover, PopoverTrigger, Tooltip } from "@fluentui/react-components";
6
+ import { WeatherMoon20Regular, WeatherSunny20Regular } from "@fluentui/react-icons";
7
+ import type { ThemeMode } from "@siiway/ui-core";
8
+ import { useState } from "react";
9
+ import { useUiScheme, useUiStrings } from "../provider/context.js";
10
+ import { MenuPanel, MenuPanelRow } from "./MenuPanel.js";
11
+ import { ThemeSwitch } from "./ThemeSwitch.js";
12
+
13
+ export interface ThemeMenuProps {
14
+ /** The selected mode: `system`, `light` or `dark`. Without `value` and
15
+ * `onChange`, the menu shows and changes the choice `<UiProvider>` keeps.
16
+ * The icon shows the provider's `scheme`, not this. */
17
+ value?: ThemeMode;
18
+ /** Called with the picked mode, as in `ThemeSwitch`. */
19
+ onChange?: (mode: ThemeMode) => void;
20
+ /** The button's name and the label in its panel. Defaults to the library's "Theme". */
21
+ label?: string;
22
+ }
23
+
24
+ export function ThemeMenu({ value, onChange, label }: ThemeMenuProps) {
25
+ const strings = useUiStrings();
26
+ const scheme = useUiScheme();
27
+ const [open, setOpen] = useState(false);
28
+ const name = label ?? strings.theme;
29
+ return (
30
+ <Popover
31
+ open={open}
32
+ onOpenChange={(_, data) => setOpen(data.open)}
33
+ positioning={{ position: "below", align: "end", offset: 6 }}
34
+ trapFocus
35
+ >
36
+ <PopoverTrigger disableButtonEnhancement>
37
+ <Tooltip content={name} relationship="label">
38
+ <Button
39
+ appearance="subtle"
40
+ icon={scheme === "dark" ? <WeatherMoon20Regular /> : <WeatherSunny20Regular />}
41
+ />
42
+ </Tooltip>
43
+ </PopoverTrigger>
44
+ <MenuPanel>
45
+ <MenuPanelRow label={name}>
46
+ <ThemeSwitch value={value} onChange={onChange} label={name} />
47
+ </MenuPanelRow>
48
+ </MenuPanel>
49
+ </Popover>
50
+ );
51
+ }
@@ -0,0 +1,49 @@
1
+ // System / Light / Dark switch: the segmented control in Prism's account menu
2
+ // and Vellum's theme popover. Icons only; each segment is named for screen
3
+ // readers and in its tooltip. It shows and changes the choice <UiProvider>
4
+ // keeps, or the app's own, given as value and onChange.
5
+
6
+ import { DesktopRegular, WeatherMoonRegular, WeatherSunnyRegular } from "@fluentui/react-icons";
7
+ import type { ThemeMode } from "@siiway/ui-core";
8
+ import { useUiStrings, useUiThemeMode } from "../provider/context.js";
9
+ import { Segmented } from "./Segmented.js";
10
+
11
+ export interface ThemeSwitchProps {
12
+ /** The selected mode: `system`, `light` or `dark`. Without `value` and
13
+ * `onChange`, the switch shows and changes the choice `<UiProvider>`
14
+ * keeps; given either, it's the app's, and the provider's is left alone. */
15
+ value?: ThemeMode;
16
+ /** Called with the picked mode. Without it, the switch is disabled, unless
17
+ * it uses the provider's choice. */
18
+ onChange?: (mode: ThemeMode) => void;
19
+ /** Names the group for screen readers; defaults to the library's "Theme". */
20
+ label?: string;
21
+ /** Disables all three segments. */
22
+ disabled?: boolean;
23
+ className?: string;
24
+ }
25
+
26
+ export function ThemeSwitch({ value, onChange, label, disabled, className }: ThemeSwitchProps) {
27
+ const strings = useUiStrings();
28
+ const kept = useUiThemeMode();
29
+ // The app's choice, given either prop, or else the provider's: never half
30
+ // of each, or picking would change one thing and show another.
31
+ const own = value !== undefined || onChange !== undefined;
32
+ const mode = own ? value : kept?.mode;
33
+ const change = own ? onChange : kept?.setMode;
34
+ return (
35
+ <Segmented<ThemeMode>
36
+ label={label ?? strings.theme}
37
+ // With no choice to show, none is selected.
38
+ value={mode ?? null}
39
+ onChange={change ?? (() => {})}
40
+ disabled={disabled || !change}
41
+ className={className}
42
+ options={[
43
+ { value: "system", label: strings.themeSystem, content: <DesktopRegular /> },
44
+ { value: "light", label: strings.themeLight, content: <WeatherSunnyRegular /> },
45
+ { value: "dark", label: strings.themeDark, content: <WeatherMoonRegular /> },
46
+ ]}
47
+ />
48
+ );
49
+ }