@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,98 @@
1
+ // The previous and next pages at the foot of a page in a sequence (a guide,
2
+ // the docs): two bordered cards on the canvas. Hover darkens the hairline and
3
+ // lifts the fill by a shade, nothing more.
4
+
5
+ import { makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
6
+ import { ChevronLeft16Regular, ChevronRight16Regular } from "@fluentui/react-icons";
7
+ import type { ReactNode } from "react";
8
+ import { UiLink, useUiStrings } from "../provider/context.js";
9
+
10
+ const useStyles = makeStyles({
11
+ root: {
12
+ display: "grid",
13
+ gridTemplateColumns: "1fr 1fr",
14
+ gap: "16px",
15
+ "@media (max-width: 720px)": { gridTemplateColumns: "1fr" },
16
+ },
17
+ card: {
18
+ display: "block",
19
+ padding: "14px 16px",
20
+ borderRadius: tokens.borderRadiusLarge,
21
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
22
+ backgroundColor: tokens.colorNeutralBackground1,
23
+ color: tokens.colorNeutralForeground1,
24
+ textDecoration: "none",
25
+ transition: "border-color 80ms ease, background-color 80ms ease",
26
+ ":hover": {
27
+ borderTopColor: tokens.colorNeutralStroke1Hover,
28
+ borderRightColor: tokens.colorNeutralStroke1Hover,
29
+ borderBottomColor: tokens.colorNeutralStroke1Hover,
30
+ borderLeftColor: tokens.colorNeutralStroke1Hover,
31
+ backgroundColor: tokens.colorNeutralBackground1Hover,
32
+ color: tokens.colorNeutralForeground1,
33
+ textDecoration: "none",
34
+ },
35
+ ":focus-visible": {
36
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
37
+ outlineOffset: "1px",
38
+ },
39
+ },
40
+ next: { gridColumn: 2, textAlign: "right", "@media (max-width: 720px)": { gridColumn: 1 } },
41
+ label: {
42
+ display: "flex",
43
+ alignItems: "center",
44
+ gap: "4px",
45
+ fontSize: "12px",
46
+ color: tokens.colorNeutralForeground3,
47
+ },
48
+ labelNext: { justifyContent: "flex-end" },
49
+ title: {
50
+ display: "block",
51
+ marginTop: "4px",
52
+ fontSize: tokens.fontSizeBase300,
53
+ fontWeight: tokens.fontWeightSemibold,
54
+ },
55
+ });
56
+
57
+ export interface PrevNextLink {
58
+ /** The page's title. */
59
+ label: ReactNode;
60
+ /** Where it leads, through the app's router. */
61
+ to: string;
62
+ }
63
+
64
+ export interface PrevNextProps {
65
+ /** The page before: `{ label, to }`, on a card labelled with the library's "Previous". */
66
+ prev?: PrevNextLink;
67
+ /** The page after: `{ label, to }`, on a card labelled with the library's "Next". */
68
+ next?: PrevNextLink;
69
+ className?: string;
70
+ }
71
+
72
+ export function PrevNext({ prev, next, className }: PrevNextProps) {
73
+ const styles = useStyles();
74
+ const strings = useUiStrings();
75
+ if (!prev && !next) return null;
76
+ return (
77
+ <div className={mergeClasses(styles.root, className)}>
78
+ {prev && (
79
+ <UiLink to={prev.to} className={styles.card}>
80
+ <span className={styles.label}>
81
+ <ChevronLeft16Regular />
82
+ {strings.previous}
83
+ </span>
84
+ <span className={styles.title}>{prev.label}</span>
85
+ </UiLink>
86
+ )}
87
+ {next && (
88
+ <UiLink to={next.to} className={mergeClasses(styles.card, styles.next)}>
89
+ <span className={mergeClasses(styles.label, styles.labelNext)}>
90
+ {strings.next}
91
+ <ChevronRight16Regular />
92
+ </span>
93
+ <span className={styles.title}>{next.label}</span>
94
+ </UiLink>
95
+ )}
96
+ </div>
97
+ );
98
+ }
@@ -0,0 +1,90 @@
1
+ // Looks like a field, acts as a button: opens search, usually a
2
+ // CommandPalette. Prism has it at the top of its sidebar, Vellum in its top
3
+ // bar. It shows the shortcut that opens search too (useSearchShortcut).
4
+
5
+ import { makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
6
+ import { SearchRegular } from "@fluentui/react-icons";
7
+ import { useIsApple } from "../hooks/platform.js";
8
+ import { useUiStrings } from "../provider/context.js";
9
+
10
+ const useStyles = makeStyles({
11
+ button: {
12
+ display: "flex",
13
+ alignItems: "center",
14
+ gap: "8px",
15
+ width: "240px",
16
+ maxWidth: "100%",
17
+ height: "32px",
18
+ padding: "0 8px 0 10px",
19
+ boxSizing: "border-box",
20
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
21
+ borderRadius: tokens.borderRadiusMedium,
22
+ background: tokens.colorNeutralBackground1,
23
+ color: tokens.colorNeutralForeground3,
24
+ fontFamily: "inherit",
25
+ fontSize: "13px",
26
+ cursor: "pointer",
27
+ "& > svg": { fontSize: "16px", flexShrink: 0 },
28
+ ":hover": {
29
+ borderTopColor: tokens.colorNeutralStroke1,
30
+ borderRightColor: tokens.colorNeutralStroke1,
31
+ borderBottomColor: tokens.colorNeutralStroke1,
32
+ borderLeftColor: tokens.colorNeutralStroke1,
33
+ color: tokens.colorNeutralForeground2,
34
+ },
35
+ ":focus-visible": {
36
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
37
+ outlineOffset: "1px",
38
+ },
39
+ },
40
+ label: {
41
+ flex: 1,
42
+ minWidth: 0,
43
+ textAlign: "left",
44
+ overflow: "hidden",
45
+ textOverflow: "ellipsis",
46
+ whiteSpace: "nowrap",
47
+ },
48
+ kbd: {
49
+ padding: "0 5px",
50
+ borderRadius: tokens.borderRadiusSmall,
51
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
52
+ fontSize: "11px",
53
+ lineHeight: "18px",
54
+ fontFamily: "inherit",
55
+ whiteSpace: "nowrap",
56
+ },
57
+ });
58
+
59
+ export interface SearchButtonProps {
60
+ /** Called on a click: open your search here. */
61
+ onClick: () => void;
62
+ /** The text in the field. Defaults to the library's "Search". */
63
+ label?: string;
64
+ /**
65
+ * Show the Ctrl K / ⌘K hint. Defaults to true; turn it off where no shortcut
66
+ * opens search. The server renders Ctrl K and the browser corrects it,
67
+ * without a hydration mismatch.
68
+ */
69
+ shortcut?: boolean;
70
+ /** 240px wide by default: set the width here, e.g. `100%` in a sidebar. */
71
+ className?: string;
72
+ }
73
+
74
+ export function SearchButton({ onClick, label, shortcut = true, className }: SearchButtonProps) {
75
+ const styles = useStyles();
76
+ const strings = useUiStrings();
77
+ const apple = useIsApple();
78
+ return (
79
+ <button
80
+ type="button"
81
+ className={mergeClasses(styles.button, className)}
82
+ onClick={onClick}
83
+ aria-keyshortcuts={shortcut ? "Control+K Meta+K" : undefined}
84
+ >
85
+ <SearchRegular />
86
+ <span className={styles.label}>{label ?? strings.search}</span>
87
+ {shortcut && <kbd className={styles.kbd}>{apple ? "⌘K" : "Ctrl K"}</kbd>}
88
+ </button>
89
+ );
90
+ }
@@ -0,0 +1,97 @@
1
+ // A search input drawn as one field: the icon, a borderless Fluent Input and
2
+ // whatever follows it (a spinner, a clear or submit button) share one border
3
+ // and one focus ring. The Input's own border and focus underline are hidden,
4
+ // so focus shows once, on the field.
5
+
6
+ import {
7
+ Input,
8
+ makeStyles,
9
+ mergeClasses,
10
+ tokens,
11
+ type InputProps,
12
+ } from "@fluentui/react-components";
13
+ import { Search20Regular, Search24Regular } from "@fluentui/react-icons";
14
+ import { forwardRef, type ReactNode } from "react";
15
+
16
+ // Fluent sets the Input's border and background with its own atomic classes;
17
+ // these have to win over them.
18
+ const NONE = "0 !important" as "0";
19
+
20
+ const useStyles = makeStyles({
21
+ field: {
22
+ display: "flex",
23
+ alignItems: "center",
24
+ gap: "8px",
25
+ boxSizing: "border-box",
26
+ minHeight: "44px",
27
+ paddingLeft: "12px",
28
+ paddingRight: "12px",
29
+ backgroundColor: tokens.colorNeutralBackground1,
30
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
31
+ borderRadius: tokens.borderRadiusLarge,
32
+ transition: "border-color 120ms ease, box-shadow 120ms ease",
33
+ "&:hover": {
34
+ borderTopColor: tokens.colorNeutralStroke1Hover,
35
+ borderRightColor: tokens.colorNeutralStroke1Hover,
36
+ borderBottomColor: tokens.colorNeutralStroke1Hover,
37
+ borderLeftColor: tokens.colorNeutralStroke1Hover,
38
+ },
39
+ // The border turns brand and a 1px shadow thickens it to 2px, so the
40
+ // ring doesn't shift the layout.
41
+ "&:focus-within": {
42
+ borderTopColor: tokens.colorBrandStroke1,
43
+ borderRightColor: tokens.colorBrandStroke1,
44
+ borderBottomColor: tokens.colorBrandStroke1,
45
+ borderLeftColor: tokens.colorBrandStroke1,
46
+ boxShadow: `0 0 0 1px ${tokens.colorBrandStroke1}`,
47
+ },
48
+ },
49
+ large: {
50
+ minHeight: "52px",
51
+ paddingLeft: "16px",
52
+ paddingRight: "16px",
53
+ gap: "12px",
54
+ },
55
+ icon: { color: tokens.colorNeutralForeground3, flexShrink: 0 },
56
+ input: {
57
+ flex: 1,
58
+ minWidth: 0,
59
+ paddingLeft: 0,
60
+ paddingRight: 0,
61
+ borderTop: NONE,
62
+ borderLeft: NONE,
63
+ borderRight: NONE,
64
+ borderBottom: NONE,
65
+ backgroundColor: "transparent !important" as "transparent",
66
+ "&::after": { display: "none" },
67
+ "& input": { paddingLeft: 0, paddingRight: 0 },
68
+ },
69
+ });
70
+
71
+ export interface SearchFieldProps extends Omit<InputProps, "size" | "appearance" | "children"> {
72
+ /** `large` for a search page's main box. Defaults to `medium`. */
73
+ size?: "medium" | "large";
74
+ /** Shown inside the field, after the input: a spinner, a clear button. */
75
+ children?: ReactNode;
76
+ }
77
+
78
+ export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(function SearchField(
79
+ { size = "medium", className, children, ...input },
80
+ ref,
81
+ ) {
82
+ const styles = useStyles();
83
+ const Icon = size === "large" ? Search24Regular : Search20Regular;
84
+ return (
85
+ <div className={mergeClasses(styles.field, size === "large" && styles.large, className)}>
86
+ <Icon className={styles.icon} />
87
+ <Input
88
+ ref={ref}
89
+ {...input}
90
+ size={size}
91
+ appearance="filled-lighter"
92
+ className={styles.input}
93
+ />
94
+ {children}
95
+ </div>
96
+ );
97
+ });
@@ -0,0 +1,136 @@
1
+ // Compact segmented radio group: a hairline track with one highlighted
2
+ // segment. Used for the account menu's theme and language switches and the
3
+ // notification level pickers. A null value highlights nothing, which bulk
4
+ // controls use for "mixed". Values may be booleans for a two-way choice.
5
+
6
+ import { makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
7
+ import type { ReactNode } from "react";
8
+
9
+ const useStyles = makeStyles({
10
+ root: {
11
+ display: "inline-flex",
12
+ padding: "2px",
13
+ gap: "2px",
14
+ borderRadius: tokens.borderRadiusMedium,
15
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
16
+ boxSizing: "border-box",
17
+ },
18
+ fill: {
19
+ display: "flex",
20
+ width: "100%",
21
+ },
22
+ segment: {
23
+ display: "inline-flex",
24
+ alignItems: "center",
25
+ justifyContent: "center",
26
+ minWidth: "26px",
27
+ height: "24px",
28
+ padding: "0 6px",
29
+ border: "none",
30
+ borderRadius: tokens.borderRadiusSmall,
31
+ background: "transparent",
32
+ color: tokens.colorNeutralForeground3,
33
+ fontFamily: "inherit",
34
+ fontSize: "12px",
35
+ whiteSpace: "nowrap",
36
+ cursor: "pointer",
37
+ "& svg": { fontSize: "14px" },
38
+ ":hover": {
39
+ color: tokens.colorNeutralForeground1,
40
+ },
41
+ ":focus-visible": {
42
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
43
+ outlineOffset: "-2px",
44
+ },
45
+ ":disabled": { cursor: "default", opacity: 0.5 },
46
+ },
47
+ segmentFill: {
48
+ flex: 1,
49
+ },
50
+ active: {
51
+ background: tokens.colorNeutralBackground3,
52
+ color: tokens.colorNeutralForeground1,
53
+ fontWeight: tokens.fontWeightSemibold,
54
+ },
55
+ // For values that switch something on, so they stand out from "off" at a
56
+ // glance in a long list of pickers.
57
+ activeBrand: {
58
+ background: tokens.colorBrandBackground2,
59
+ color: tokens.colorBrandForeground2,
60
+ ":hover": { color: tokens.colorBrandForeground2 },
61
+ },
62
+ });
63
+
64
+ export interface SegmentedOption<T extends string | boolean> {
65
+ /** What `onChange` gets when this option is picked. */
66
+ value: T;
67
+ /** The option's text, or its accessible name when `content` is shown. */
68
+ label: string;
69
+ /** Rendered instead of the label, e.g. an icon; the label becomes its name. */
70
+ content?: ReactNode;
71
+ /** Highlight with the accent colour when selected. */
72
+ brand?: boolean;
73
+ }
74
+
75
+ export interface SegmentedProps<T extends string | boolean> {
76
+ /** Names the group for screen readers. */
77
+ label: string;
78
+ /** The selected option's value; `null` selects nothing. */
79
+ value: T | null;
80
+ /** The options, in order: `{ value, label, content?, brand? }`. Values are strings or booleans. */
81
+ options: SegmentedOption<T>[];
82
+ /** Called with the picked option's value. */
83
+ onChange: (value: T) => void;
84
+ /** Stretch to the container width with equal segments. */
85
+ fill?: boolean;
86
+ /** Disables every option. */
87
+ disabled?: boolean;
88
+ className?: string;
89
+ }
90
+
91
+ export function Segmented<T extends string | boolean>({
92
+ label,
93
+ value,
94
+ options,
95
+ onChange,
96
+ fill,
97
+ disabled,
98
+ className,
99
+ }: SegmentedProps<T>) {
100
+ const styles = useStyles();
101
+ return (
102
+ <div
103
+ role="radiogroup"
104
+ aria-label={label}
105
+ className={mergeClasses(styles.root, fill && styles.fill, className)}
106
+ >
107
+ {options.map((o) => {
108
+ const selected = o.value === value;
109
+ return (
110
+ <button
111
+ key={String(o.value)}
112
+ type="button"
113
+ role="radio"
114
+ aria-checked={selected}
115
+ aria-label={o.content ? o.label : undefined}
116
+ title={o.content ? o.label : undefined}
117
+ disabled={disabled}
118
+ className={mergeClasses(
119
+ styles.segment,
120
+ fill && styles.segmentFill,
121
+ selected && styles.active,
122
+ selected && o.brand && styles.activeBrand,
123
+ )}
124
+ // Re-picking the current value changes nothing, which matters
125
+ // where a pick saves at once.
126
+ onClick={() => {
127
+ if (!selected) onChange(o.value);
128
+ }}
129
+ >
130
+ {o.content ?? o.label}
131
+ </button>
132
+ );
133
+ })}
134
+ </div>
135
+ );
136
+ }
@@ -0,0 +1,110 @@
1
+ // Drop-in replacement for Fluent's <Select> that opens a Fluent listbox
2
+ // instead of the browser's native one, so the open list follows the theme.
3
+ //
4
+ // It keeps Select's markup and callback: plain <option value> children
5
+ // (optionally disabled) and onChange(event, { value }).
6
+ //
7
+ // <Select value={role} onChange={(_, d) => setRole(d.value)}>
8
+ // <option value="member">Member</option>
9
+ // <option value="admin">Admin</option>
10
+ // </Select>
11
+
12
+ import { Dropdown, Option, makeStyles, mergeClasses } from "@fluentui/react-components";
13
+ import {
14
+ Children,
15
+ isValidElement,
16
+ type CSSProperties,
17
+ type ReactNode,
18
+ type SyntheticEvent,
19
+ } from "react";
20
+
21
+ const useStyles = makeStyles({
22
+ // Fill the container like the native control did; Fluent's Dropdown
23
+ // otherwise insists on a 250px minimum.
24
+ root: { width: "100%", minWidth: 0, boxSizing: "border-box" },
25
+ });
26
+
27
+ interface SelectOption {
28
+ value: string;
29
+ text: string;
30
+ disabled: boolean;
31
+ }
32
+
33
+ /** Flatten <option> children (through arrays and fragments) to data. */
34
+ function readOptions(children: ReactNode): SelectOption[] {
35
+ const out: SelectOption[] = [];
36
+ Children.forEach(children, (child) => {
37
+ if (!isValidElement<{ children?: ReactNode }>(child)) return;
38
+ if (child.type !== "option") {
39
+ out.push(...readOptions(child.props.children));
40
+ return;
41
+ }
42
+ const props = child.props as {
43
+ value?: string | number;
44
+ disabled?: boolean;
45
+ children?: ReactNode;
46
+ };
47
+ const text = Children.toArray(props.children)
48
+ .filter((c) => typeof c === "string" || typeof c === "number")
49
+ .join("");
50
+ out.push({
51
+ value: String(props.value ?? text),
52
+ text,
53
+ disabled: !!props.disabled,
54
+ });
55
+ });
56
+ return out;
57
+ }
58
+
59
+ interface SelectProps {
60
+ /** The selected option's `value`. A value no option has selects nothing. */
61
+ value: string;
62
+ /** Called as `onChange(event, { value })` when a different option is picked. */
63
+ onChange: (event: SyntheticEvent, data: { value: string }) => void;
64
+ /** `<option>` elements, as in a native `<select>`, also inside arrays and fragments. An option without a `value` uses its text; a `disabled` one can't be picked. */
65
+ children: ReactNode;
66
+ /** Disables the select. */
67
+ disabled?: boolean;
68
+ /** The control's size, as Fluent's `Dropdown`. */
69
+ size?: "small" | "medium" | "large";
70
+ className?: string;
71
+ style?: CSSProperties;
72
+ /** Names the select for screen readers when no `Field` label does. */
73
+ "aria-label"?: string;
74
+ }
75
+
76
+ export function Select({
77
+ value,
78
+ onChange,
79
+ children,
80
+ disabled,
81
+ size,
82
+ className,
83
+ style,
84
+ "aria-label": ariaLabel,
85
+ }: SelectProps) {
86
+ const styles = useStyles();
87
+ const options = readOptions(children);
88
+ const selected = options.find((o) => o.value === value);
89
+ return (
90
+ <Dropdown
91
+ className={mergeClasses(styles.root, className)}
92
+ style={style}
93
+ size={size}
94
+ disabled={disabled}
95
+ aria-label={ariaLabel}
96
+ value={selected?.text ?? ""}
97
+ selectedOptions={selected ? [selected.value] : []}
98
+ onOptionSelect={(e, d) => {
99
+ if (d.optionValue !== undefined && d.optionValue !== value)
100
+ onChange(e, { value: d.optionValue });
101
+ }}
102
+ >
103
+ {options.map((o) => (
104
+ <Option key={o.value} value={o.value} text={o.text} disabled={o.disabled}>
105
+ {o.text}
106
+ </Option>
107
+ ))}
108
+ </Dropdown>
109
+ );
110
+ }