@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,109 @@
1
+ // Layout for full-page create flows (new app, new team, new token): a back
2
+ // link to the list, the page header, and the form in a single card whose
3
+ // footer holds the actions. Used instead of modal dialogs so a create flow
4
+ // has its own URL and room to explain each field.
5
+
6
+ import { makeStyles, tokens } from "@fluentui/react-components";
7
+ import { ArrowLeftRegular } from "@fluentui/react-icons";
8
+ import type { ReactNode } from "react";
9
+ import { UiLink } from "../provider/context.js";
10
+ import { PageHeader } from "./PageHeader.js";
11
+
12
+ const useStyles = makeStyles({
13
+ root: {
14
+ display: "flex",
15
+ flexDirection: "column",
16
+ width: "100%",
17
+ maxWidth: "720px",
18
+ },
19
+ back: {
20
+ display: "inline-flex",
21
+ alignItems: "center",
22
+ gap: "6px",
23
+ alignSelf: "flex-start",
24
+ marginBottom: "16px",
25
+ fontSize: "13px",
26
+ color: tokens.colorNeutralForeground3,
27
+ ":hover": { color: tokens.colorNeutralForeground1 },
28
+ ":focus-visible": {
29
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
30
+ outlineOffset: "2px",
31
+ borderRadius: "2px",
32
+ },
33
+ },
34
+ card: {
35
+ borderRadius: tokens.borderRadiusXLarge,
36
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
37
+ background: tokens.colorNeutralBackground1,
38
+ },
39
+ body: {
40
+ display: "flex",
41
+ flexDirection: "column",
42
+ gap: "18px",
43
+ padding: "24px",
44
+ "@media (max-width: 600px)": {
45
+ padding: "16px",
46
+ },
47
+ },
48
+ footer: {
49
+ display: "flex",
50
+ justifyContent: "flex-end",
51
+ flexWrap: "wrap",
52
+ gap: "8px",
53
+ padding: "14px 24px",
54
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
55
+ "@media (max-width: 600px)": {
56
+ padding: "12px 16px",
57
+ },
58
+ },
59
+ });
60
+
61
+ interface FormPageProps {
62
+ /** The path of the back link above the header, opened through the app's router. */
63
+ backTo: string;
64
+ /** The back link's text, such as the list's name. */
65
+ backLabel: string;
66
+ /** The page's heading. */
67
+ title: ReactNode;
68
+ /** A line under the title. */
69
+ subtitle?: ReactNode;
70
+ /** The buttons at the card's foot; give the main one `type="submit"`. Leave out when
71
+ * the card shows a final result instead. */
72
+ actions?: ReactNode;
73
+ /** Called on submit; the page doesn't reload. Enter in a text field submits like the
74
+ * main button. */
75
+ onSubmit?: () => void;
76
+ /** The fields. */
77
+ children: ReactNode;
78
+ }
79
+
80
+ export function FormPage({
81
+ backTo,
82
+ backLabel,
83
+ title,
84
+ subtitle,
85
+ actions,
86
+ onSubmit,
87
+ children,
88
+ }: FormPageProps) {
89
+ const styles = useStyles();
90
+ return (
91
+ <div className={styles.root}>
92
+ <UiLink to={backTo} className={styles.back}>
93
+ <ArrowLeftRegular />
94
+ {backLabel}
95
+ </UiLink>
96
+ <PageHeader title={title} subtitle={subtitle} />
97
+ <form
98
+ className={styles.card}
99
+ onSubmit={(e) => {
100
+ e.preventDefault();
101
+ onSubmit?.();
102
+ }}
103
+ >
104
+ <div className={styles.body}>{children}</div>
105
+ {actions && <div className={styles.footer}>{actions}</div>}
106
+ </form>
107
+ </div>
108
+ );
109
+ }
@@ -0,0 +1,132 @@
1
+ // Full empty state for a main list page that has nothing in it yet (no apps,
2
+ // no teams, no tokens…). Where EmptyState is a one-liner for empty tables and
3
+ // searches, this explains what the page is for and how to start: an
4
+ // illustration beside a heading, a short description, numbered steps and the
5
+ // page's primary action. Modelled on the Cloudflare dashboard's empty pages.
6
+
7
+ import { Text, makeStyles, tokens } from "@fluentui/react-components";
8
+ import type { ReactNode } from "react";
9
+
10
+ const useStyles = makeStyles({
11
+ root: {
12
+ display: "grid",
13
+ gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1.15fr)",
14
+ gap: "6px",
15
+ padding: "6px",
16
+ borderRadius: tokens.borderRadiusXLarge,
17
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
18
+ background: tokens.colorNeutralBackground1,
19
+ "@media (max-width: 720px)": {
20
+ gridTemplateColumns: "minmax(0, 1fr)",
21
+ },
22
+ },
23
+ art: {
24
+ minHeight: "220px",
25
+ display: "flex",
26
+ alignItems: "center",
27
+ justifyContent: "center",
28
+ borderRadius: tokens.borderRadiusLarge,
29
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
30
+ background: tokens.colorNeutralBackground2,
31
+ overflow: "hidden",
32
+ "& svg": {
33
+ display: "block",
34
+ width: "100%",
35
+ maxWidth: "360px",
36
+ height: "auto",
37
+ },
38
+ "@media (max-width: 720px)": {
39
+ minHeight: "170px",
40
+ },
41
+ },
42
+ body: {
43
+ display: "flex",
44
+ flexDirection: "column",
45
+ gap: "8px",
46
+ padding: "22px 22px 20px",
47
+ "@media (max-width: 720px)": {
48
+ padding: "14px 10px 10px",
49
+ },
50
+ },
51
+ title: { margin: 0 },
52
+ desc: {
53
+ color: tokens.colorNeutralForeground3,
54
+ fontSize: "13px",
55
+ lineHeight: "20px",
56
+ },
57
+ steps: {
58
+ listStyleType: "none",
59
+ display: "flex",
60
+ flexDirection: "column",
61
+ gap: "10px",
62
+ margin: "8px 0 4px",
63
+ padding: 0,
64
+ },
65
+ step: {
66
+ display: "flex",
67
+ alignItems: "flex-start",
68
+ gap: "10px",
69
+ fontSize: "13px",
70
+ lineHeight: "20px",
71
+ color: tokens.colorNeutralForeground2,
72
+ },
73
+ stepNum: {
74
+ flexShrink: 0,
75
+ width: "20px",
76
+ height: "20px",
77
+ borderRadius: "50%",
78
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
79
+ display: "flex",
80
+ alignItems: "center",
81
+ justifyContent: "center",
82
+ fontSize: "11px",
83
+ fontWeight: tokens.fontWeightSemibold,
84
+ color: tokens.colorNeutralForeground3,
85
+ },
86
+ action: {
87
+ display: "flex",
88
+ gap: "8px",
89
+ flexWrap: "wrap",
90
+ marginTop: "auto",
91
+ paddingTop: "12px",
92
+ },
93
+ });
94
+
95
+ interface GetStartedPanelProps {
96
+ /** An illustration beside the text, or above it on narrow screens. An SVG scales to fit. */
97
+ art: ReactNode;
98
+ /** The panel's heading, an `h2`. */
99
+ title: ReactNode;
100
+ /** What the page is for, under the title. */
101
+ description: ReactNode;
102
+ /** Numbered steps under the description. */
103
+ steps?: ReactNode[];
104
+ /** The first action, such as a "New app" button, at the foot. */
105
+ action?: ReactNode;
106
+ }
107
+
108
+ export function GetStartedPanel({ art, title, description, steps, action }: GetStartedPanelProps) {
109
+ const styles = useStyles();
110
+ return (
111
+ <section className={styles.root}>
112
+ <div className={styles.art}>{art}</div>
113
+ <div className={styles.body}>
114
+ <Text as="h2" size={500} weight="semibold" className={styles.title}>
115
+ {title}
116
+ </Text>
117
+ <span className={styles.desc}>{description}</span>
118
+ {steps && steps.length > 0 && (
119
+ <ol className={styles.steps}>
120
+ {steps.map((step, i) => (
121
+ <li key={i} className={styles.step}>
122
+ <span className={styles.stepNum}>{i + 1}</span>
123
+ <span>{step}</span>
124
+ </li>
125
+ ))}
126
+ </ol>
127
+ )}
128
+ {action && <div className={styles.action}>{action}</div>}
129
+ </div>
130
+ </section>
131
+ );
132
+ }
@@ -0,0 +1,28 @@
1
+ import { Text } from "@fluentui/react-components";
2
+ import type { ReactNode } from "react";
3
+
4
+ interface LabeledLineProps {
5
+ /** The label, before the colon. */
6
+ label: ReactNode;
7
+ /** The value. */
8
+ children: ReactNode;
9
+ /** Sets the value in monospace. */
10
+ mono?: boolean;
11
+ }
12
+
13
+ export function LabeledLine({ label, children, mono }: LabeledLineProps) {
14
+ return (
15
+ <Text size={200}>
16
+ <Text size={200} weight="semibold">
17
+ {label}:
18
+ </Text>{" "}
19
+ {mono ? (
20
+ <Text size={200} font="monospace">
21
+ {children}
22
+ </Text>
23
+ ) : (
24
+ children
25
+ )}
26
+ </Text>
27
+ );
28
+ }
@@ -0,0 +1,64 @@
1
+ // The search box above a list: a search icon, and a clear button once
2
+ // something is typed. Callers debounce the value themselves.
3
+
4
+ import { Button, Input, makeStyles, mergeClasses } from "@fluentui/react-components";
5
+ import { DismissRegular, SearchRegular } from "@fluentui/react-icons";
6
+ import type { ReactNode } from "react";
7
+ import { useUiStrings } from "../provider/context.js";
8
+
9
+ const useStyles = makeStyles({
10
+ bar: {
11
+ display: "flex",
12
+ gap: "8px",
13
+ marginBottom: "12px",
14
+ flexWrap: "wrap",
15
+ alignItems: "center",
16
+ },
17
+ input: { minWidth: "220px", flex: "1 1 220px" },
18
+ });
19
+
20
+ /** A search box above a list, with filters or buttons beside it. */
21
+ export function ListSearch({
22
+ value,
23
+ onChange,
24
+ placeholder,
25
+ children,
26
+ className,
27
+ }: {
28
+ /** The text in the box. */
29
+ value: string;
30
+ /** Called with the new text as it's typed, and with "" when it's cleared. */
31
+ onChange: (value: string) => void;
32
+ /** Shown while the box is empty, e.g. "Search teams". */
33
+ placeholder: string;
34
+ /** Filters or actions beside the box. */
35
+ children?: ReactNode;
36
+ /** Extra styles for the bar, e.g. padding inside a card. */
37
+ className?: string;
38
+ }) {
39
+ const styles = useStyles();
40
+ const strings = useUiStrings();
41
+ return (
42
+ <div className={mergeClasses(styles.bar, className)}>
43
+ <Input
44
+ className={styles.input}
45
+ value={value}
46
+ onChange={(_, d) => onChange(d.value)}
47
+ placeholder={placeholder}
48
+ contentBefore={<SearchRegular />}
49
+ contentAfter={
50
+ value ? (
51
+ <Button
52
+ appearance="transparent"
53
+ size="small"
54
+ icon={<DismissRegular />}
55
+ aria-label={strings.clear}
56
+ onClick={() => onChange("")}
57
+ />
58
+ ) : undefined
59
+ }
60
+ />
61
+ {children}
62
+ </div>
63
+ );
64
+ }
@@ -0,0 +1,81 @@
1
+ // A thin brand-coloured bar across the top of the window while the next page
2
+ // loads, like NProgress: it creeps towards the end while `active`, then runs
3
+ // to the end and fades. Tie `active` to the router's navigation state (React
4
+ // Router's `useNavigation().state !== "idle"`, Vellum's `isNavigating`).
5
+
6
+ import { makeStyles, tokens } from "@fluentui/react-components";
7
+ import { useEffect, useState } from "react";
8
+
9
+ const START = 0.08;
10
+ // It never gets past this while loading: the end is for when it's done.
11
+ const CAP = 0.9;
12
+
13
+ const useStyles = makeStyles({
14
+ bar: {
15
+ position: "fixed",
16
+ top: 0,
17
+ left: 0,
18
+ right: 0,
19
+ height: "2px",
20
+ zIndex: 1000,
21
+ pointerEvents: "none",
22
+ transformOrigin: "left center",
23
+ backgroundColor: tokens.colorBrandBackground,
24
+ // The fade waits for the bar to reach the end.
25
+ transition: "transform 200ms ease-out, opacity 250ms ease-out 250ms",
26
+ },
27
+ });
28
+
29
+ interface Bar {
30
+ progress: number;
31
+ visible: boolean;
32
+ }
33
+
34
+ export function LoadingBar({
35
+ active,
36
+ }: {
37
+ /**
38
+ * True while the next page loads, e.g. React Router's
39
+ * `useNavigation().state !== "idle"`.
40
+ */
41
+ active: boolean;
42
+ }) {
43
+ const styles = useStyles();
44
+ const [bar, setBar] = useState<Bar>(() =>
45
+ active ? { progress: START, visible: true } : { progress: 0, visible: false },
46
+ );
47
+ // Start and finish as `active` changes, in the render that sees it. A load
48
+ // that ends before the bar was drawn never shows it.
49
+ const [was, setWas] = useState(active);
50
+ if (active !== was) {
51
+ setWas(active);
52
+ if (active) setBar({ progress: START, visible: true });
53
+ else if (bar.visible) setBar({ progress: 1, visible: false });
54
+ }
55
+
56
+ useEffect(() => {
57
+ if (active) {
58
+ // Each step covers part of what's left, so it slows towards the cap.
59
+ let progress = START;
60
+ const tick = setInterval(() => {
61
+ progress = Math.min(CAP, progress + (CAP - progress) * 0.12);
62
+ setBar({ progress, visible: true });
63
+ }, 200);
64
+ return () => clearInterval(tick);
65
+ }
66
+ // Back to the start once it has faded out.
67
+ const reset = setTimeout(
68
+ () => setBar((now) => (now.progress === 0 ? now : { progress: 0, visible: false })),
69
+ 500,
70
+ );
71
+ return () => clearTimeout(reset);
72
+ }, [active]);
73
+
74
+ return (
75
+ <div
76
+ className={styles.bar}
77
+ style={{ transform: `scaleX(${bar.progress})`, opacity: bar.visible ? 1 : 0 }}
78
+ aria-hidden="true"
79
+ />
80
+ );
81
+ }
@@ -0,0 +1,208 @@
1
+ // "On this page": the page's headings beside it, with the one being read
2
+ // marked as the page scrolls. A click scrolls to the heading and puts it in
3
+ // the URL's hash, without going through the router (which would race the
4
+ // scroll). To keep it in view as the page scrolls, give it a className that
5
+ // makes it sticky and scroll on its own; it then keeps the marked heading in
6
+ // sight within itself.
7
+
8
+ import { Text, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
9
+ import {
10
+ useCallback,
11
+ useEffect,
12
+ useMemo,
13
+ useRef,
14
+ useState,
15
+ type MouseEvent,
16
+ type ReactNode,
17
+ } from "react";
18
+ import { useUiStrings } from "../provider/context.js";
19
+ import { TOP_BAR_HEIGHT } from "./TopBar.js";
20
+
21
+ const useStyles = makeStyles({
22
+ root: { fontSize: "13px", boxSizing: "border-box" },
23
+ heading: {
24
+ display: "block",
25
+ margin: 0,
26
+ padding: "0 0 8px 12px",
27
+ fontSize: "12px",
28
+ fontWeight: tokens.fontWeightRegular,
29
+ lineHeight: "16px",
30
+ color: tokens.colorNeutralForeground3,
31
+ },
32
+ list: {
33
+ margin: 0,
34
+ padding: 0,
35
+ listStyle: "none",
36
+ borderLeft: `1px solid ${tokens.colorNeutralStroke2}`,
37
+ },
38
+ link: {
39
+ display: "block",
40
+ marginLeft: "-1px",
41
+ padding: "4px 12px",
42
+ lineHeight: "18px",
43
+ borderLeft: "2px solid transparent",
44
+ color: tokens.colorNeutralForeground3,
45
+ textDecoration: "none",
46
+ cursor: "pointer",
47
+ ":hover": { color: tokens.colorNeutralForeground1 },
48
+ "& code": {
49
+ fontFamily: tokens.fontFamilyMonospace,
50
+ fontSize: "0.92em",
51
+ backgroundColor: tokens.colorNeutralBackground3,
52
+ padding: "1px 5px",
53
+ borderRadius: tokens.borderRadiusSmall,
54
+ },
55
+ },
56
+ active: {
57
+ borderLeftColor: tokens.colorNeutralForeground1,
58
+ color: tokens.colorNeutralForeground1,
59
+ fontWeight: tokens.fontWeightMedium,
60
+ },
61
+ });
62
+
63
+ export interface OutlineItem {
64
+ /** The heading's element id. */
65
+ id: string;
66
+ /** The heading's text. */
67
+ label: ReactNode;
68
+ /** The heading's level: 2 for an h2. Deeper levels are indented. */
69
+ depth: number;
70
+ /** The headings under this one, listed after it. */
71
+ children?: OutlineItem[];
72
+ }
73
+
74
+ export interface OutlineProps {
75
+ /** The page's headings, in order: `{ id, label, depth, children? }`. */
76
+ items: OutlineItem[];
77
+ /** The heading above the list. Defaults to the library's "On this page". */
78
+ label?: string;
79
+ /** The headings' language, when it isn't the page's. */
80
+ lang?: string;
81
+ /** To keep it in view, make it sticky and let it scroll on its own here. */
82
+ className?: string;
83
+ }
84
+
85
+ export function Outline({ items, label, lang, className }: OutlineProps) {
86
+ const styles = useStyles();
87
+ const strings = useUiStrings();
88
+ const rootRef = useRef<HTMLElement>(null);
89
+ const links = useRef(new Map<string, HTMLAnchorElement>());
90
+ const flat = useMemo(() => flatten(items), [items]);
91
+ const ids = useMemo(() => flat.map((item) => item.id), [flat]);
92
+ const top = Math.min(...flat.map((item) => item.depth));
93
+ const [active, snap] = useActiveHeading(ids);
94
+ const name = label ?? strings.onThisPage;
95
+
96
+ // Keep the marked heading in sight, when the outline scrolls on its own.
97
+ useEffect(() => {
98
+ const link = active ? links.current.get(active) : undefined;
99
+ const root = rootRef.current;
100
+ if (!link || !root) return;
101
+ const at = link.getBoundingClientRect();
102
+ const box = root.getBoundingClientRect();
103
+ if (at.top < box.top + 24 || at.bottom > box.bottom - 24) {
104
+ link.scrollIntoView({ block: "nearest", behavior: "smooth" });
105
+ }
106
+ }, [active]);
107
+
108
+ const go = useCallback(
109
+ (id: string) => (e: MouseEvent<HTMLAnchorElement>) => {
110
+ e.preventDefault();
111
+ snap(id);
112
+ document.getElementById(id)?.scrollIntoView({ behavior: "smooth", block: "start" });
113
+ const url = new URL(window.location.href);
114
+ url.hash = id;
115
+ window.history.replaceState(window.history.state, "", url);
116
+ },
117
+ [snap],
118
+ );
119
+
120
+ // A page without headings keeps the outline's place in the layout, empty.
121
+ if (!flat.length) return <div className={mergeClasses(styles.root, className)} />;
122
+
123
+ return (
124
+ <nav ref={rootRef} aria-label={name} className={mergeClasses(styles.root, className)}>
125
+ <Text as="h2" className={styles.heading}>
126
+ {name}
127
+ </Text>
128
+ <ul className={styles.list} lang={lang}>
129
+ {flat.map((item) => (
130
+ <li key={item.id} style={{ paddingLeft: `${(item.depth - top) * 12}px` }}>
131
+ <a
132
+ href={`#${item.id}`}
133
+ ref={(el) => {
134
+ if (el) links.current.set(item.id, el);
135
+ else links.current.delete(item.id);
136
+ }}
137
+ aria-current={active === item.id ? "location" : undefined}
138
+ className={mergeClasses(styles.link, active === item.id && styles.active)}
139
+ onClick={go(item.id)}
140
+ >
141
+ {item.label}
142
+ </a>
143
+ </li>
144
+ ))}
145
+ </ul>
146
+ </nav>
147
+ );
148
+ }
149
+
150
+ function flatten(items: OutlineItem[]): OutlineItem[] {
151
+ return items.flatMap((item) => [item, ...flatten(item.children ?? [])]);
152
+ }
153
+
154
+ // The heading being read: the topmost one in the upper part of the window,
155
+ // or, between headings, the last one above it. A click marks its heading at
156
+ // once and holds the mark while the smooth scroll runs, which would
157
+ // otherwise move it through the headings in between.
158
+ function useActiveHeading(ids: string[]): [string | null, (id: string) => void] {
159
+ const key = ids.join("\n");
160
+ // The mark belongs to one page's headings; on another page, it's their first.
161
+ const [mark, setMark] = useState<{ key: string; id: string | null }>({
162
+ key,
163
+ id: ids[0] ?? null,
164
+ });
165
+ const active = mark.key === key ? mark.id : (ids[0] ?? null);
166
+ const holdUntil = useRef(0);
167
+
168
+ useEffect(() => {
169
+ const headings = key
170
+ .split("\n")
171
+ .map((id) => document.getElementById(id))
172
+ .filter((el): el is HTMLElement => !!el);
173
+ if (!headings.length) return;
174
+ const visible = new Map<string, IntersectionObserverEntry>();
175
+ const observer = new IntersectionObserver(
176
+ (entries) => {
177
+ if (Date.now() < holdUntil.current) return;
178
+ for (const entry of entries) {
179
+ if (entry.isIntersecting) visible.set(entry.target.id, entry);
180
+ else visible.delete(entry.target.id);
181
+ }
182
+ let id: string | undefined;
183
+ if (visible.size) {
184
+ id = [...visible.values()].sort(
185
+ (a, b) => a.boundingClientRect.top - b.boundingClientRect.top,
186
+ )[0]!.target.id;
187
+ } else {
188
+ for (const h of headings) if (h.getBoundingClientRect().top < 100) id = h.id;
189
+ }
190
+ if (id) setMark({ key, id });
191
+ },
192
+ // Below the top bar, down to a little under half the window.
193
+ { rootMargin: `-${TOP_BAR_HEIGHT + 12}px 0px -55% 0px`, threshold: [0, 1] },
194
+ );
195
+ for (const h of headings) observer.observe(h);
196
+ return () => observer.disconnect();
197
+ }, [key]);
198
+
199
+ const snap = useCallback(
200
+ (id: string) => {
201
+ setMark({ key, id });
202
+ holdUntil.current = Date.now() + 700;
203
+ },
204
+ [key],
205
+ );
206
+
207
+ return [active, snap];
208
+ }