@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,76 @@
1
+ // A button that copies a value and briefly shows how it went: an icon with a
2
+ // tooltip, or, given children, a button whose text says it.
3
+
4
+ import { Button, Tooltip, type ButtonProps } from "@fluentui/react-components";
5
+ import { CheckmarkRegular, CopyRegular, DismissRegular } from "@fluentui/react-icons";
6
+ import type { ReactElement, ReactNode } from "react";
7
+ import { useUiStrings } from "../provider/context.js";
8
+ import { useCopy } from "../hooks/useCopy.js";
9
+
10
+ export interface CopyButtonProps {
11
+ /** The value to copy, or a function that returns it, called on click: for a
12
+ * value only known then, such as the code a block shows. */
13
+ text: string | (() => string);
14
+ /** The icon button's tooltip and accessible name. Defaults to the library's
15
+ * "Copy". Not used with `children`. */
16
+ label?: string;
17
+ /** Text on the button, such as "Copy": it says "Copied" for a moment after,
18
+ * and the button has no tooltip. Without it, the button is an icon. */
19
+ children?: ReactNode;
20
+ /** The icon before a copy, such as a code icon for copying a command.
21
+ * Defaults to a copy icon. */
22
+ icon?: ReactElement;
23
+ /** Defaults to `subtle`. */
24
+ appearance?: ButtonProps["appearance"];
25
+ /** Defaults to `small`. */
26
+ size?: ButtonProps["size"];
27
+ /** Can't be clicked, though it stays focusable so its tooltip still says why. */
28
+ disabled?: boolean;
29
+ /** On the button, to place it, e.g. over the corner of a code block. */
30
+ className?: string;
31
+ }
32
+
33
+ /** A button that copies `text`. */
34
+ export function CopyButton({
35
+ text,
36
+ label,
37
+ children,
38
+ icon,
39
+ appearance = "subtle",
40
+ size = "small",
41
+ disabled,
42
+ className,
43
+ }: CopyButtonProps) {
44
+ const strings = useUiStrings();
45
+ const { state, copy } = useCopy();
46
+ const outcome =
47
+ state === "copied" ? strings.copied : state === "failed" ? strings.copyFailed : null;
48
+ // Text that renders something; `true`, `false` and "" leave the icon alone.
49
+ const withText = children != null && typeof children !== "boolean" && children !== "";
50
+ const button = (
51
+ <Button
52
+ appearance={appearance}
53
+ size={size}
54
+ className={className}
55
+ disabledFocusable={disabled}
56
+ icon={
57
+ state === "copied" ? (
58
+ <CheckmarkRegular />
59
+ ) : state === "failed" ? (
60
+ <DismissRegular />
61
+ ) : (
62
+ (icon ?? <CopyRegular />)
63
+ )
64
+ }
65
+ onClick={() => void copy(text)}
66
+ >
67
+ {withText ? (outcome ?? children) : undefined}
68
+ </Button>
69
+ );
70
+ if (withText) return button;
71
+ return (
72
+ <Tooltip content={outcome ?? label ?? strings.copy} relationship="label" withArrow>
73
+ {button}
74
+ </Tooltip>
75
+ );
76
+ }
@@ -0,0 +1,127 @@
1
+ // Click-to-copy wrapper for list avatars/icons.
2
+ //
3
+ // The My Apps / Teams / Team members / Authorized apps lists show an avatar
4
+ // per row; wrapping it in this trigger lets a click copy the row's id
5
+ // (client id for apps, user id for users, team id for teams) without
6
+ // navigating. The click is stopped so a surrounding card's navigate handler
7
+ // doesn't fire too.
8
+
9
+ import { Tooltip, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
10
+ import { type ReactNode, type KeyboardEvent, type MouseEvent } from "react";
11
+ import { useUiStrings } from "../provider/context.js";
12
+ import { CopyRegular } from "@fluentui/react-icons";
13
+ import { useCopy } from "../hooks/useCopy.js";
14
+
15
+ const useStyles = makeStyles({
16
+ text: {
17
+ justifyContent: "flex-start",
18
+ gap: "6px",
19
+ maxWidth: "100%",
20
+ fontFamily: tokens.fontFamilyMonospace,
21
+ fontSize: tokens.fontSizeBase200,
22
+ color: tokens.colorNeutralForeground2,
23
+ },
24
+ ellipsis: {
25
+ overflow: "hidden",
26
+ textOverflow: "ellipsis",
27
+ whiteSpace: "nowrap",
28
+ },
29
+ trigger: {
30
+ display: "flex",
31
+ alignItems: "center",
32
+ justifyContent: "center",
33
+ cursor: "pointer",
34
+ borderRadius: tokens.borderRadiusMedium,
35
+ transitionProperty: "opacity",
36
+ transitionDuration: "0.1s",
37
+ ":hover": { opacity: 0.75 },
38
+ ":focus-visible": {
39
+ outline: `2px solid ${tokens.colorCompoundBrandForeground1}`,
40
+ },
41
+ },
42
+ });
43
+
44
+ interface CopyIdTriggerProps {
45
+ /** The ID to copy. */
46
+ id: string;
47
+ /** The tooltip and accessible name: what a click copies, e.g. "Copy team ID". */
48
+ label: string;
49
+ /** Tooltip label to flash on success. Defaults to the library's "Copied!".
50
+ * Callers should pass a specific label (e.g. "Copied team ID") so the
51
+ * confirmation says *what* landed on the clipboard. */
52
+ copiedLabel?: string;
53
+ /** Extra styles for the trigger, e.g. left-aligned text in a table cell. */
54
+ className?: string;
55
+ /** What to click: a name in a header, a cell, an avatar. */
56
+ children: ReactNode;
57
+ }
58
+
59
+ /** Makes its children copy an ID on click, or on Enter or Space. The click
60
+ * doesn't reach a clickable row or card around it. */
61
+ export function CopyIdTrigger({ id, label, copiedLabel, className, children }: CopyIdTriggerProps) {
62
+ const styles = useStyles();
63
+ const strings = useUiStrings();
64
+ const { state, copy: copyText } = useCopy();
65
+ const copy = () => void copyText(id);
66
+
67
+ const onClick = (e: MouseEvent) => {
68
+ e.stopPropagation();
69
+ copy();
70
+ };
71
+
72
+ const onKeyDown = (e: KeyboardEvent) => {
73
+ if (e.key === "Enter" || e.key === " ") {
74
+ e.preventDefault();
75
+ e.stopPropagation();
76
+ copy();
77
+ }
78
+ };
79
+
80
+ return (
81
+ <Tooltip
82
+ content={
83
+ state === "copied"
84
+ ? (copiedLabel ?? strings.copied)
85
+ : state === "failed"
86
+ ? strings.copyFailed
87
+ : label
88
+ }
89
+ relationship="label"
90
+ >
91
+ <div
92
+ className={mergeClasses(styles.trigger, className)}
93
+ role="button"
94
+ tabIndex={0}
95
+ aria-label={label}
96
+ onClick={onClick}
97
+ onKeyDown={onKeyDown}
98
+ >
99
+ {children}
100
+ </div>
101
+ </Tooltip>
102
+ );
103
+ }
104
+
105
+ /** An id in monospace with a copy icon, copied on click — a list cell or a
106
+ * page footer. */
107
+ export function CopyIdText({
108
+ id,
109
+ label,
110
+ copiedLabel,
111
+ }: {
112
+ /** The ID to show and copy. */
113
+ id: string;
114
+ /** The tooltip and accessible name, e.g. "Copy user ID". */
115
+ label: string;
116
+ /** Tooltip label to flash on success, e.g. "Copied user ID". Defaults to
117
+ * the library's "Copied!". */
118
+ copiedLabel?: string;
119
+ }) {
120
+ const styles = useStyles();
121
+ return (
122
+ <CopyIdTrigger id={id} label={label} copiedLabel={copiedLabel} className={styles.text}>
123
+ <span className={styles.ellipsis}>{id}</span>
124
+ <CopyRegular />
125
+ </CopyIdTrigger>
126
+ );
127
+ }
@@ -0,0 +1,332 @@
1
+ // The bordered list used by top-level list pages (apps, teams, domains,
2
+ // admin lists): a muted heading row and one grid row per item, its key facts
3
+ // in columns. Secondary columns drop away on narrow screens.
4
+ //
5
+ // <DataList columns={[{ label: "Name", width: "2fr" }, …]}>
6
+ // {items.map((x) => <DataListRow key={x.id} to={`/x/${x.id}`} cells={[…]} />)}
7
+ // </DataList>
8
+ //
9
+ // A row with `to` is one link (keyboard, middle-click, new tab) and gets a
10
+ // chevron; it must not hold other controls. A row with controls passes
11
+ // `onClick` instead and keeps a real link in its first cell.
12
+
13
+ import {
14
+ makeStyles,
15
+ mergeClasses,
16
+ Skeleton,
17
+ SkeletonItem,
18
+ tokens,
19
+ } from "@fluentui/react-components";
20
+ import { ChevronRightRegular } from "@fluentui/react-icons";
21
+ import { createContext, useContext, type ReactNode } from "react";
22
+ import { UiLink } from "../provider/context.js";
23
+
24
+ const NARROW = "@media (max-width: 768px)";
25
+
26
+ export interface DataListColumn {
27
+ /** Heading text; empty for an unlabelled column (actions). */
28
+ label: ReactNode;
29
+ /** CSS grid track, e.g. "minmax(0, 2fr)" or "120px". */
30
+ width: string;
31
+ /** Hidden on narrow screens. */
32
+ secondary?: boolean;
33
+ /** Right-align the column (numbers, actions). */
34
+ end?: boolean;
35
+ }
36
+
37
+ const useStyles = makeStyles({
38
+ frame: {
39
+ borderRadius: tokens.borderRadiusXLarge,
40
+ border: `1px solid ${tokens.colorNeutralStroke1}`,
41
+ background: tokens.colorNeutralBackground1,
42
+ overflow: "hidden",
43
+ },
44
+ grid: {
45
+ display: "grid",
46
+ gridTemplateColumns: "var(--cols)",
47
+ gap: "16px",
48
+ alignItems: "center",
49
+ [NARROW]: { gridTemplateColumns: "var(--cols-narrow)" },
50
+ },
51
+ head: {
52
+ padding: "10px 16px",
53
+ fontSize: "12px",
54
+ color: tokens.colorNeutralForeground3,
55
+ minHeight: "40px",
56
+ boxSizing: "border-box",
57
+ },
58
+ row: {
59
+ minHeight: "56px",
60
+ padding: "10px 16px",
61
+ boxSizing: "border-box",
62
+ borderTop: `1px solid ${tokens.colorNeutralStroke2}`,
63
+ color: "inherit",
64
+ textDecorationLine: "none",
65
+ },
66
+ clickable: {
67
+ cursor: "pointer",
68
+ ":hover": { background: tokens.colorNeutralBackground1Hover },
69
+ ":focus-visible": {
70
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
71
+ outlineOffset: "-2px",
72
+ },
73
+ },
74
+ selected: { background: tokens.colorNeutralBackground1Selected },
75
+ cell: {
76
+ minWidth: 0,
77
+ fontSize: tokens.fontSizeBase300,
78
+ color: tokens.colorNeutralForeground2,
79
+ overflowWrap: "anywhere",
80
+ },
81
+ first: { color: tokens.colorNeutralForeground1 },
82
+ secondary: { [NARROW]: { display: "none" } },
83
+ // Flex alone: a text-align here would leak into controls in the cell
84
+ // (it shoved a Switch knob out of its track).
85
+ end: { display: "flex", justifyContent: "flex-end" },
86
+ chevron: { fontSize: "14px", color: tokens.colorNeutralForeground3 },
87
+ });
88
+
89
+ const ColumnsContext = createContext<DataListColumn[]>([]);
90
+
91
+ function tracks(columns: DataListColumn[], chevron: boolean, narrow: boolean) {
92
+ const list = columns.filter((c) => !narrow || !c.secondary).map((c) => c.width);
93
+ if (chevron) list.push("14px");
94
+ return list.join(" ");
95
+ }
96
+
97
+ interface DataListProps {
98
+ /** The columns, in order: `{ label, width, secondary?, end? }`. `width` is a
99
+ * CSS grid track, e.g. "minmax(0, 2fr)" or "120px". */
100
+ columns: DataListColumn[];
101
+ /** Rows link somewhere: keeps room for their chevron. */
102
+ linked?: boolean;
103
+ /** Replaces the column headings, e.g. a bulk-action bar. */
104
+ head?: ReactNode;
105
+ /** The rows, as `DataListRow`s. */
106
+ children: ReactNode;
107
+ /** Extra styles for the list's frame. */
108
+ className?: string;
109
+ }
110
+
111
+ /** A list with columns, lighter than a table. */
112
+ export function DataList({ columns, linked, head, children, className }: DataListProps) {
113
+ const styles = useStyles();
114
+ const vars = {
115
+ "--cols": tracks(columns, !!linked, false),
116
+ "--cols-narrow": tracks(columns, !!linked, true),
117
+ } as React.CSSProperties;
118
+ return (
119
+ <ColumnsContext.Provider value={columns}>
120
+ <div className={mergeClasses(styles.frame, className)} style={vars}>
121
+ {head ?? (
122
+ <div className={mergeClasses(styles.grid, styles.head)} aria-hidden>
123
+ {columns.map((c, i) => (
124
+ <span
125
+ key={i}
126
+ className={mergeClasses(c.secondary && styles.secondary, c.end && styles.end)}
127
+ >
128
+ {c.label}
129
+ </span>
130
+ ))}
131
+ {linked && <span />}
132
+ </div>
133
+ )}
134
+ {children}
135
+ </div>
136
+ </ColumnsContext.Provider>
137
+ );
138
+ }
139
+
140
+ interface DataListRowProps {
141
+ /** One node per column, in order. */
142
+ cells: ReactNode[];
143
+ /** The whole row links here and shows a chevron. A linked row mustn't hold
144
+ * other controls. */
145
+ to?: string;
146
+ /** Router state passed with `to`, e.g. where the page was opened from. */
147
+ state?: unknown;
148
+ /** Called on a click, in place of `to`, e.g. to select the row. A row with
149
+ * controls uses this and keeps a real link in a cell (`DataListLink`). */
150
+ onClick?: () => void;
151
+ /** Shows the row as selected. */
152
+ selected?: boolean;
153
+ }
154
+
155
+ /** One item in a `DataList`: a cell per column. */
156
+ export function DataListRow({ cells, to, state, onClick, selected }: DataListRowProps) {
157
+ const styles = useStyles();
158
+ const columns = useContext(ColumnsContext);
159
+ const className = mergeClasses(
160
+ styles.grid,
161
+ styles.row,
162
+ (to || onClick) && styles.clickable,
163
+ selected && styles.selected,
164
+ );
165
+ const content = (
166
+ <>
167
+ {cells.map((cell, i) => (
168
+ <div
169
+ key={i}
170
+ className={mergeClasses(
171
+ styles.cell,
172
+ i === 0 && styles.first,
173
+ columns[i]?.secondary && styles.secondary,
174
+ columns[i]?.end && styles.end,
175
+ )}
176
+ >
177
+ {cell}
178
+ </div>
179
+ ))}
180
+ {to && <ChevronRightRegular className={styles.chevron} />}
181
+ </>
182
+ );
183
+ if (to)
184
+ return (
185
+ <UiLink to={to} state={state} className={className}>
186
+ {content}
187
+ </UiLink>
188
+ );
189
+ return (
190
+ <div className={className} onClick={onClick}>
191
+ {content}
192
+ </div>
193
+ );
194
+ }
195
+
196
+ const useNameStyles = makeStyles({
197
+ root: { display: "flex", alignItems: "center", gap: "12px", minWidth: 0 },
198
+ text: { display: "flex", flexDirection: "column", gap: "2px", minWidth: 0 },
199
+ line: {
200
+ display: "flex",
201
+ alignItems: "center",
202
+ gap: "6px",
203
+ minWidth: 0,
204
+ flexWrap: "wrap",
205
+ },
206
+ name: {
207
+ fontWeight: tokens.fontWeightSemibold,
208
+ color: tokens.colorNeutralForeground1,
209
+ overflowWrap: "anywhere",
210
+ },
211
+ sub: {
212
+ fontSize: tokens.fontSizeBase200,
213
+ color: tokens.colorNeutralForeground3,
214
+ overflow: "hidden",
215
+ textOverflow: "ellipsis",
216
+ whiteSpace: "nowrap",
217
+ },
218
+ });
219
+
220
+ /** First-column content: an icon or avatar, the name, badges, a subtitle. */
221
+ export function DataListName({
222
+ icon,
223
+ name,
224
+ badges,
225
+ sub,
226
+ }: {
227
+ /** An icon or avatar before the name. */
228
+ icon?: ReactNode;
229
+ /** The item's name. */
230
+ name: ReactNode;
231
+ /** Shown after the name, e.g. a `Badge`. */
232
+ badges?: ReactNode;
233
+ /** A muted line under the name, e.g. an ID. */
234
+ sub?: ReactNode;
235
+ }) {
236
+ const styles = useNameStyles();
237
+ return (
238
+ <div className={styles.root}>
239
+ {icon}
240
+ <div className={styles.text}>
241
+ <div className={styles.line}>
242
+ <span className={styles.name}>{name}</span>
243
+ {badges}
244
+ </div>
245
+ {sub && <span className={styles.sub}>{sub}</span>}
246
+ </div>
247
+ </div>
248
+ );
249
+ }
250
+
251
+ /** Placeholder rows in the list's own frame, so nothing moves when the
252
+ * items arrive. `icon` reserves the first column's avatar. */
253
+ export function DataListSkeleton({
254
+ columns,
255
+ linked,
256
+ rows = 4,
257
+ icon,
258
+ }: {
259
+ /** The columns of the list it stands in for, headings included. */
260
+ columns: DataListColumn[];
261
+ /** Keeps room for the chevron, as on a linked `DataList`. */
262
+ linked?: boolean;
263
+ /** How many rows to show. */
264
+ rows?: number;
265
+ /** Reserves the first column's avatar, in this shape. */
266
+ icon?: "square" | "circle";
267
+ }) {
268
+ const nameStyles = useNameStyles();
269
+ return (
270
+ <Skeleton aria-busy>
271
+ <DataList columns={columns} linked={linked}>
272
+ {Array.from({ length: rows }).map((_, i) => (
273
+ <DataListRow
274
+ key={i}
275
+ cells={columns.map((_, c) => {
276
+ const bar = (
277
+ <SkeletonItem
278
+ key={c}
279
+ size={12}
280
+ style={{ width: c === 0 ? `${40 + (i % 3) * 12}%` : "60%" }}
281
+ />
282
+ );
283
+ return c === 0 && icon ? (
284
+ <div key={c} className={nameStyles.root}>
285
+ <SkeletonItem shape={icon} size={32} />
286
+ {bar}
287
+ </div>
288
+ ) : (
289
+ bar
290
+ );
291
+ })}
292
+ />
293
+ ))}
294
+ </DataList>
295
+ </Skeleton>
296
+ );
297
+ }
298
+
299
+ const useLinkStyles = makeStyles({
300
+ link: {
301
+ color: tokens.colorNeutralForeground1,
302
+ textDecorationLine: "none",
303
+ ":hover": { textDecorationLine: "underline" },
304
+ ":focus-visible": {
305
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
306
+ borderRadius: "2px",
307
+ },
308
+ },
309
+ });
310
+
311
+ /** The real link inside a row that passes `onClick` (because it holds other
312
+ * controls), so the row still works with the keyboard, middle-click and
313
+ * "open in new tab". */
314
+ export function DataListLink({
315
+ to,
316
+ state,
317
+ children,
318
+ }: {
319
+ /** Where the link goes. */
320
+ to: string;
321
+ /** Router state passed with `to`. */
322
+ state?: unknown;
323
+ /** The link's text. */
324
+ children: ReactNode;
325
+ }) {
326
+ const styles = useLinkStyles();
327
+ return (
328
+ <UiLink to={to} state={state} className={styles.link} onClick={(e) => e.stopPropagation()}>
329
+ {children}
330
+ </UiLink>
331
+ );
332
+ }
@@ -0,0 +1,108 @@
1
+ // The top of a detail page (an app, a team, a user, a notice…): the way back
2
+ // to its list, then its name with badges, a line under it, and an action.
3
+
4
+ import { Text, Title2, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
5
+ import { ArrowLeftRegular } from "@fluentui/react-icons";
6
+ import type { ReactNode } from "react";
7
+ import { useTabTitle } from "../provider/context.js";
8
+ import { ButtonLink } from "./ButtonLink.js";
9
+
10
+ const useStyles = makeStyles({
11
+ back: {
12
+ alignSelf: "flex-start",
13
+ marginLeft: "-8px",
14
+ color: tokens.colorNeutralForeground3,
15
+ },
16
+ header: {
17
+ display: "flex",
18
+ alignItems: "center",
19
+ flexWrap: "wrap",
20
+ gap: "16px",
21
+ },
22
+ titles: {
23
+ display: "flex",
24
+ flexDirection: "column",
25
+ gap: "4px",
26
+ flex: "1 1 240px",
27
+ minWidth: 0,
28
+ },
29
+ titleLine: {
30
+ display: "flex",
31
+ alignItems: "center",
32
+ flexWrap: "wrap",
33
+ gap: "8px",
34
+ },
35
+ title: { margin: 0, letterSpacing: "-0.015em", overflowWrap: "anywhere" },
36
+ subtitle: {
37
+ color: tokens.colorNeutralForeground3,
38
+ overflowWrap: "anywhere",
39
+ },
40
+ });
41
+
42
+ /** "← Apps": back to the list the page was opened from. */
43
+ export function BackButton({
44
+ to,
45
+ children,
46
+ }: {
47
+ /** The list's path, opened through the app's router. */
48
+ to: string;
49
+ /** The list's name. */
50
+ children: ReactNode;
51
+ }) {
52
+ const styles = useStyles();
53
+ return (
54
+ <ButtonLink
55
+ to={to}
56
+ appearance="subtle"
57
+ size="small"
58
+ icon={<ArrowLeftRegular />}
59
+ className={styles.back}
60
+ >
61
+ {children}
62
+ </ButtonLink>
63
+ );
64
+ }
65
+
66
+ export function DetailHeader({
67
+ icon,
68
+ title,
69
+ badges,
70
+ subtitle,
71
+ actions,
72
+ tabTitle,
73
+ className,
74
+ }: {
75
+ /** An avatar or icon before the name. */
76
+ icon?: ReactNode;
77
+ /** The item's name, the page's `h1`. */
78
+ title: ReactNode;
79
+ /** Badges after the name, such as "Verified". */
80
+ badges?: ReactNode;
81
+ /** A line under the name. */
82
+ subtitle?: ReactNode;
83
+ /** Buttons at the end of the row, e.g. "Edit" or "Visit website". */
84
+ actions?: ReactNode;
85
+ /** Browser tab title when the name isn't plain text, e.g. a link. Defaults
86
+ * to the title when it is a plain string. Goes to
87
+ * `<UiProvider onPageTitle>`. */
88
+ tabTitle?: string;
89
+ className?: string;
90
+ }) {
91
+ const styles = useStyles();
92
+ useTabTitle(title, tabTitle);
93
+ return (
94
+ <div className={mergeClasses(styles.header, className)}>
95
+ {icon}
96
+ <div className={styles.titles}>
97
+ <div className={styles.titleLine}>
98
+ <Title2 as="h1" className={styles.title}>
99
+ {title}
100
+ </Title2>
101
+ {badges}
102
+ </div>
103
+ {subtitle && <Text className={styles.subtitle}>{subtitle}</Text>}
104
+ </div>
105
+ {actions}
106
+ </div>
107
+ );
108
+ }