@siiway/ui-react 0.1.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 (108) hide show
  1. package/dist/components/AppShell.d.ts +29 -0
  2. package/dist/components/AppShell.d.ts.map +1 -0
  3. package/dist/components/AppShell.js +220 -0
  4. package/dist/components/AppShell.js.map +1 -0
  5. package/dist/components/AuthShell.d.ts +21 -0
  6. package/dist/components/AuthShell.d.ts.map +1 -0
  7. package/dist/components/AuthShell.js +53 -0
  8. package/dist/components/AuthShell.js.map +1 -0
  9. package/dist/components/ButtonLink.d.ts +11 -0
  10. package/dist/components/ButtonLink.d.ts.map +1 -0
  11. package/dist/components/ButtonLink.js +15 -0
  12. package/dist/components/ButtonLink.js.map +1 -0
  13. package/dist/components/CommandPalette.d.ts +23 -11
  14. package/dist/components/CommandPalette.d.ts.map +1 -1
  15. package/dist/components/CommandPalette.js +33 -3
  16. package/dist/components/CommandPalette.js.map +1 -1
  17. package/dist/components/CopyButton.d.ts +25 -6
  18. package/dist/components/CopyButton.d.ts.map +1 -1
  19. package/dist/components/CopyButton.js +11 -8
  20. package/dist/components/CopyButton.js.map +1 -1
  21. package/dist/components/DetailHeader.d.ts +5 -1
  22. package/dist/components/DetailHeader.d.ts.map +1 -1
  23. package/dist/components/DetailHeader.js +6 -5
  24. package/dist/components/DetailHeader.js.map +1 -1
  25. package/dist/components/FormPage.d.ts +1 -1
  26. package/dist/components/FormPage.d.ts.map +1 -1
  27. package/dist/components/LoadingPage.d.ts +6 -0
  28. package/dist/components/LoadingPage.d.ts.map +1 -0
  29. package/dist/components/LoadingPage.js +25 -0
  30. package/dist/components/LoadingPage.js.map +1 -0
  31. package/dist/components/MenuPanel.d.ts +34 -0
  32. package/dist/components/MenuPanel.d.ts.map +1 -0
  33. package/dist/components/MenuPanel.js +98 -0
  34. package/dist/components/MenuPanel.js.map +1 -0
  35. package/dist/components/PageHeader.d.ts +3 -3
  36. package/dist/components/PageHeader.d.ts.map +1 -1
  37. package/dist/components/PageHeader.js +5 -14
  38. package/dist/components/PageHeader.js.map +1 -1
  39. package/dist/components/PasswordInput.d.ts.map +1 -1
  40. package/dist/components/PasswordInput.js +15 -2
  41. package/dist/components/PasswordInput.js.map +1 -1
  42. package/dist/components/SideNav.d.ts +18 -5
  43. package/dist/components/SideNav.d.ts.map +1 -1
  44. package/dist/components/SideNav.js +30 -4
  45. package/dist/components/SideNav.js.map +1 -1
  46. package/dist/components/StatusPage.d.ts +17 -5
  47. package/dist/components/StatusPage.d.ts.map +1 -1
  48. package/dist/components/StatusPage.js +10 -6
  49. package/dist/components/StatusPage.js.map +1 -1
  50. package/dist/components/ThemeMenu.d.ts +6 -4
  51. package/dist/components/ThemeMenu.d.ts.map +1 -1
  52. package/dist/components/ThemeMenu.js +3 -27
  53. package/dist/components/ThemeMenu.js.map +1 -1
  54. package/dist/components/ThemeSwitch.d.ts +7 -4
  55. package/dist/components/ThemeSwitch.d.ts.map +1 -1
  56. package/dist/components/ThemeSwitch.js +12 -4
  57. package/dist/components/ThemeSwitch.js.map +1 -1
  58. package/dist/components/TopBar.d.ts +6 -2
  59. package/dist/components/TopBar.d.ts.map +1 -1
  60. package/dist/components/TopBar.js +10 -9
  61. package/dist/components/TopBar.js.map +1 -1
  62. package/dist/hooks/useCopy.d.ts +5 -2
  63. package/dist/hooks/useCopy.d.ts.map +1 -1
  64. package/dist/hooks/useCopy.js +29 -4
  65. package/dist/hooks/useCopy.js.map +1 -1
  66. package/dist/hooks/useThemeMode.d.ts +13 -1
  67. package/dist/hooks/useThemeMode.d.ts.map +1 -1
  68. package/dist/hooks/useThemeMode.js +59 -10
  69. package/dist/hooks/useThemeMode.js.map +1 -1
  70. package/dist/index.d.ts +8 -3
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +7 -2
  73. package/dist/index.js.map +1 -1
  74. package/dist/provider/UiProvider.d.ts +30 -7
  75. package/dist/provider/UiProvider.d.ts.map +1 -1
  76. package/dist/provider/UiProvider.js +116 -14
  77. package/dist/provider/UiProvider.js.map +1 -1
  78. package/dist/provider/canvas.d.ts +5 -0
  79. package/dist/provider/canvas.d.ts.map +1 -1
  80. package/dist/provider/canvas.js +21 -6
  81. package/dist/provider/canvas.js.map +1 -1
  82. package/dist/provider/context.d.ts +27 -3
  83. package/dist/provider/context.d.ts.map +1 -1
  84. package/dist/provider/context.js +48 -3
  85. package/dist/provider/context.js.map +1 -1
  86. package/package.json +2 -2
  87. package/src/components/AppShell.tsx +337 -0
  88. package/src/components/AuthShell.tsx +104 -0
  89. package/src/components/ButtonLink.tsx +40 -0
  90. package/src/components/CommandPalette.tsx +56 -14
  91. package/src/components/CopyButton.tsx +61 -33
  92. package/src/components/DetailHeader.tsx +12 -6
  93. package/src/components/FormPage.tsx +1 -1
  94. package/src/components/LoadingPage.tsx +41 -0
  95. package/src/components/MenuPanel.tsx +163 -0
  96. package/src/components/PageHeader.tsx +9 -20
  97. package/src/components/PasswordInput.tsx +16 -1
  98. package/src/components/SideNav.tsx +86 -16
  99. package/src/components/StatusPage.tsx +41 -17
  100. package/src/components/ThemeMenu.tsx +12 -44
  101. package/src/components/ThemeSwitch.tsx +20 -10
  102. package/src/components/TopBar.tsx +31 -18
  103. package/src/hooks/useCopy.ts +27 -8
  104. package/src/hooks/useThemeMode.ts +78 -8
  105. package/src/index.ts +17 -1
  106. package/src/provider/UiProvider.tsx +182 -21
  107. package/src/provider/canvas.ts +20 -6
  108. package/src/provider/context.tsx +65 -5
@@ -1,48 +1,76 @@
1
- // An icon button that copies a value and briefly shows how it went.
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.
2
3
 
3
- import { Button, Tooltip } from "@fluentui/react-components";
4
+ import { Button, Tooltip, type ButtonProps } from "@fluentui/react-components";
4
5
  import { CheckmarkRegular, CopyRegular, DismissRegular } from "@fluentui/react-icons";
6
+ import type { ReactElement, ReactNode } from "react";
5
7
  import { useUiStrings } from "../provider/context.js";
6
8
  import { useCopy } from "../hooks/useCopy.js";
7
9
 
8
- /** An icon button that copies `text`. */
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`. */
9
34
  export function CopyButton({
10
35
  text,
11
36
  label,
12
- }: {
13
- /** The value to copy. */
14
- text: string;
15
- /** The button's tooltip and accessible name. Defaults to the library's "Copy". */
16
- label?: string;
17
- }) {
37
+ children,
38
+ icon,
39
+ appearance = "subtle",
40
+ size = "small",
41
+ disabled,
42
+ className,
43
+ }: CopyButtonProps) {
18
44
  const strings = useUiStrings();
19
45
  const { state, copy } = useCopy();
20
- return (
21
- <Tooltip
22
- content={
23
- state === "copied"
24
- ? strings.copied
25
- : state === "failed"
26
- ? strings.copyFailed
27
- : (label ?? strings.copy)
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
+ )
28
64
  }
29
- relationship="label"
30
- withArrow
65
+ onClick={() => void copy(text)}
31
66
  >
32
- <Button
33
- size="small"
34
- appearance="subtle"
35
- icon={
36
- state === "copied" ? (
37
- <CheckmarkRegular />
38
- ) : state === "failed" ? (
39
- <DismissRegular />
40
- ) : (
41
- <CopyRegular />
42
- )
43
- }
44
- onClick={() => void copy(text)}
45
- />
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}
46
74
  </Tooltip>
47
75
  );
48
76
  }
@@ -1,10 +1,11 @@
1
1
  // The top of a detail page (an app, a team, a user, a notice…): the way back
2
2
  // to its list, then its name with badges, a line under it, and an action.
3
3
 
4
- import { Button, Text, Title2, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
4
+ import { Text, Title2, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
5
5
  import { ArrowLeftRegular } from "@fluentui/react-icons";
6
6
  import type { ReactNode } from "react";
7
- import { useUiNavigate } from "../provider/context.js";
7
+ import { useTabTitle } from "../provider/context.js";
8
+ import { ButtonLink } from "./ButtonLink.js";
8
9
 
9
10
  const useStyles = makeStyles({
10
11
  back: {
@@ -49,17 +50,16 @@ export function BackButton({
49
50
  children: ReactNode;
50
51
  }) {
51
52
  const styles = useStyles();
52
- const navigate = useUiNavigate();
53
53
  return (
54
- <Button
54
+ <ButtonLink
55
+ to={to}
55
56
  appearance="subtle"
56
57
  size="small"
57
58
  icon={<ArrowLeftRegular />}
58
59
  className={styles.back}
59
- onClick={() => navigate(to)}
60
60
  >
61
61
  {children}
62
- </Button>
62
+ </ButtonLink>
63
63
  );
64
64
  }
65
65
 
@@ -69,6 +69,7 @@ export function DetailHeader({
69
69
  badges,
70
70
  subtitle,
71
71
  actions,
72
+ tabTitle,
72
73
  className,
73
74
  }: {
74
75
  /** An avatar or icon before the name. */
@@ -81,9 +82,14 @@ export function DetailHeader({
81
82
  subtitle?: ReactNode;
82
83
  /** Buttons at the end of the row, e.g. "Edit" or "Visit website". */
83
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;
84
89
  className?: string;
85
90
  }) {
86
91
  const styles = useStyles();
92
+ useTabTitle(title, tabTitle);
87
93
  return (
88
94
  <div className={mergeClasses(styles.header, className)}>
89
95
  {icon}
@@ -63,7 +63,7 @@ interface FormPageProps {
63
63
  backTo: string;
64
64
  /** The back link's text, such as the list's name. */
65
65
  backLabel: string;
66
- /** The page's heading. */
66
+ /** The page's heading, its `h1`. */
67
67
  title: ReactNode;
68
68
  /** A line under the title. */
69
69
  subtitle?: ReactNode;
@@ -0,0 +1,41 @@
1
+ // A whole page that is still loading: a large spinner centred on the canvas,
2
+ // with what's happening when it's known. Prism's sign-in steps and public
3
+ // pages, and Glint's start and sign-in callback, before the page they lead
4
+ // to can show.
5
+
6
+ import { Spinner, makeStyles, mergeClasses } from "@fluentui/react-components";
7
+ import { useCanvasClass } from "../provider/canvas.js";
8
+ import { useUiStrings } from "../provider/context.js";
9
+
10
+ const useStyles = makeStyles({
11
+ page: {
12
+ minHeight: "100vh",
13
+ display: "flex",
14
+ alignItems: "center",
15
+ justifyContent: "center",
16
+ padding: "16px",
17
+ boxSizing: "border-box",
18
+ },
19
+ });
20
+
21
+ export function LoadingPage({
22
+ label,
23
+ }: {
24
+ /** What's happening, under the spinner, such as "Signing you in…". Without
25
+ * it, the spinner is named with the library's "Loading". */
26
+ label?: string;
27
+ }) {
28
+ const styles = useStyles();
29
+ const strings = useUiStrings();
30
+ const canvas = useCanvasClass();
31
+ return (
32
+ <div className={mergeClasses(styles.page, canvas)}>
33
+ <Spinner
34
+ size="large"
35
+ label={label}
36
+ labelPosition="below"
37
+ aria-label={label ? undefined : strings.loading}
38
+ />
39
+ </div>
40
+ );
41
+ }
@@ -0,0 +1,163 @@
1
+ // The panel of an account or preferences menu: Prism's account menu (name and
2
+ // email, the theme and language switches, sign out) and the theme menus of
3
+ // Vellum and ThemeMenu. A popover, not a Fluent Menu, since its rows hold
4
+ // controls such as a segmented switch.
5
+
6
+ import {
7
+ PopoverSurface,
8
+ Text,
9
+ makeStyles,
10
+ mergeClasses,
11
+ tokens,
12
+ type PopoverSurfaceProps,
13
+ } from "@fluentui/react-components";
14
+ import type { MouseEventHandler, ReactElement, ReactNode } from "react";
15
+
16
+ const useStyles = makeStyles({
17
+ // PopoverSurface brings a drop-shadow filter (sized for an arrow this
18
+ // panel doesn't have) and a transparent border; this has one soft shadow
19
+ // and a hairline edge instead, like the rest of the floating surfaces.
20
+ panel: {
21
+ padding: "4px",
22
+ minWidth: "220px",
23
+ boxSizing: "border-box",
24
+ borderRadius: tokens.borderRadiusLarge,
25
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
26
+ filter: "none",
27
+ boxShadow: tokens.shadow8,
28
+ background: tokens.colorNeutralBackground1,
29
+ fontSize: "13px",
30
+ },
31
+ header: {
32
+ display: "flex",
33
+ flexDirection: "column",
34
+ padding: "8px 8px 10px",
35
+ minWidth: 0,
36
+ },
37
+ subtitle: { color: tokens.colorNeutralForeground3 },
38
+ divider: {
39
+ height: "1px",
40
+ margin: "4px -4px",
41
+ background: tokens.colorNeutralStroke2,
42
+ },
43
+ row: {
44
+ display: "flex",
45
+ alignItems: "center",
46
+ justifyContent: "space-between",
47
+ gap: "12px",
48
+ minHeight: "36px",
49
+ padding: "0 4px 0 8px",
50
+ color: tokens.colorNeutralForeground2,
51
+ },
52
+ button: {
53
+ display: "flex",
54
+ alignItems: "center",
55
+ justifyContent: "space-between",
56
+ gap: "12px",
57
+ width: "100%",
58
+ minHeight: "34px",
59
+ padding: "0 8px",
60
+ border: "none",
61
+ borderRadius: tokens.borderRadiusMedium,
62
+ background: "transparent",
63
+ color: tokens.colorNeutralForeground2,
64
+ fontFamily: "inherit",
65
+ fontSize: "13px",
66
+ textAlign: "start",
67
+ cursor: "pointer",
68
+ "& svg": { fontSize: "16px", flexShrink: 0, color: tokens.colorNeutralForeground3 },
69
+ ":hover": {
70
+ background: tokens.colorNeutralBackground3,
71
+ color: tokens.colorNeutralForeground1,
72
+ },
73
+ ":focus-visible": {
74
+ outline: `2px solid ${tokens.colorStrokeFocus2}`,
75
+ outlineOffset: "-2px",
76
+ },
77
+ ":disabled": { cursor: "default", opacity: 0.6 },
78
+ ":disabled:hover": { background: "transparent", color: tokens.colorNeutralForeground2 },
79
+ },
80
+ });
81
+
82
+ /** The panel, in place of Fluent's `PopoverSurface` inside a `Popover`. It
83
+ * takes `PopoverSurface`'s props. */
84
+ export function MenuPanel({ className, ...rest }: PopoverSurfaceProps) {
85
+ const styles = useStyles();
86
+ return <PopoverSurface {...rest} className={mergeClasses(styles.panel, className)} />;
87
+ }
88
+
89
+ /** The panel's top, such as the person's name and email. */
90
+ export function MenuPanelHeader({
91
+ title,
92
+ subtitle,
93
+ }: {
94
+ /** In semibold, such as the person's name. */
95
+ title: ReactNode;
96
+ /** A line under it, such as their email. */
97
+ subtitle?: ReactNode;
98
+ }) {
99
+ const styles = useStyles();
100
+ return (
101
+ <div className={styles.header}>
102
+ <Text weight="semibold" size={200} truncate wrap={false}>
103
+ {title}
104
+ </Text>
105
+ {subtitle != null && (
106
+ <Text size={200} truncate wrap={false} className={styles.subtitle}>
107
+ {subtitle}
108
+ </Text>
109
+ )}
110
+ </div>
111
+ );
112
+ }
113
+
114
+ /** A line across the panel, between groups of rows. */
115
+ export function MenuPanelDivider() {
116
+ const styles = useStyles();
117
+ return <div role="separator" className={styles.divider} />;
118
+ }
119
+
120
+ /** A label with a control at the end, such as the theme switch. */
121
+ export function MenuPanelRow({
122
+ label,
123
+ children,
124
+ }: {
125
+ /** What the control sets, such as "Theme". */
126
+ label: ReactNode;
127
+ /** The control, named on its own, as ThemeSwitch's and Segmented's `label`
128
+ * name them: the row's label is only shown, not tied to it. */
129
+ children: ReactNode;
130
+ }) {
131
+ const styles = useStyles();
132
+ return (
133
+ <div className={styles.row}>
134
+ <span>{label}</span>
135
+ {children}
136
+ </div>
137
+ );
138
+ }
139
+
140
+ /** A row that does something when clicked, such as signing out. */
141
+ export function MenuPanelButton({
142
+ icon,
143
+ onClick,
144
+ disabled,
145
+ children,
146
+ }: {
147
+ /** At the end of the row. */
148
+ icon?: ReactElement;
149
+ /** What the row does when clicked. */
150
+ onClick: MouseEventHandler<HTMLButtonElement>;
151
+ /** Greys the row out and ignores clicks, such as while signing out. */
152
+ disabled?: boolean;
153
+ /** The row's text. */
154
+ children: ReactNode;
155
+ }) {
156
+ const styles = useStyles();
157
+ return (
158
+ <button type="button" className={styles.button} onClick={onClick} disabled={disabled}>
159
+ <span>{children}</span>
160
+ {icon}
161
+ </button>
162
+ );
163
+ }
@@ -3,8 +3,8 @@
3
3
  // across pages instead of each one rolling its own header row.
4
4
 
5
5
  import { Text, Title2, makeStyles, tokens } from "@fluentui/react-components";
6
- import { useEffect, type CSSProperties, type ReactNode } from "react";
7
- import { useUiPageTitle } from "../provider/context.js";
6
+ import type { CSSProperties, ReactNode } from "react";
7
+ import { useTabTitle } from "../provider/context.js";
8
8
 
9
9
  const useStyles = makeStyles({
10
10
  root: {
@@ -22,6 +22,7 @@ const useStyles = makeStyles({
22
22
  minWidth: 0,
23
23
  },
24
24
  title: {
25
+ margin: 0,
25
26
  letterSpacing: "-0.015em",
26
27
  },
27
28
  subtitle: {
@@ -36,7 +37,7 @@ const useStyles = makeStyles({
36
37
  });
37
38
 
38
39
  interface PageHeaderProps {
39
- /** The page's heading. */
40
+ /** The page's heading, its `h1`. */
40
41
  title: ReactNode;
41
42
  /** A line under the title. */
42
43
  subtitle?: ReactNode;
@@ -51,27 +52,15 @@ interface PageHeaderProps {
51
52
  style?: CSSProperties;
52
53
  }
53
54
 
54
- export function PageHeader({
55
- title,
56
- subtitle,
57
- actions,
58
- tabTitle: tabTitleProp,
59
- style,
60
- }: PageHeaderProps) {
55
+ export function PageHeader({ title, subtitle, actions, tabTitle, style }: PageHeaderProps) {
61
56
  const styles = useStyles();
62
- const onPageTitle = useUiPageTitle();
63
- // Name the browser tab after the page ("Security · Prism"). Only plain
64
- // string titles; a rich title (with badges, say) leaves the site name.
65
- const tabTitle = tabTitleProp ?? (typeof title === "string" ? title : null);
66
- useEffect(() => {
67
- if (!tabTitle || !onPageTitle) return;
68
- onPageTitle(tabTitle);
69
- return () => onPageTitle(null);
70
- }, [tabTitle, onPageTitle]);
57
+ useTabTitle(title, tabTitle);
71
58
  return (
72
59
  <div className={styles.root} style={style}>
73
60
  <div className={styles.titles}>
74
- <Title2 className={styles.title}>{title}</Title2>
61
+ <Title2 as="h1" className={styles.title}>
62
+ {title}
63
+ </Title2>
75
64
  {subtitle && <Text className={styles.subtitle}>{subtitle}</Text>}
76
65
  </div>
77
66
  {actions && <div className={styles.actions}>{actions}</div>}
@@ -1,18 +1,33 @@
1
1
  // Password field with a show/hide toggle. Drop-in replacement for
2
2
  // <Input type="password">; all other InputProps pass through.
3
3
 
4
- import { Button, Input, Tooltip } from "@fluentui/react-components";
4
+ import { Button, Input, Tooltip, makeStyles, mergeClasses } from "@fluentui/react-components";
5
5
  import type { InputProps } from "@fluentui/react-components";
6
6
  import { EyeOffRegular, EyeRegular } from "@fluentui/react-icons";
7
7
  import { useState } from "react";
8
8
  import { useUiStrings } from "../provider/context.js";
9
9
 
10
+ const useStyles = makeStyles({
11
+ // Edge draws its own reveal button in a password field, and a clear button
12
+ // once the text shows, beside the toggle here. Other browsers reject these
13
+ // selectors, and Griffel logs each rejected rule in development: @supports
14
+ // keeps the rules from them.
15
+ root: {
16
+ "@supports selector(::-ms-reveal)": {
17
+ "& input::-ms-reveal": { display: "none" },
18
+ "& input::-ms-clear": { display: "none" },
19
+ },
20
+ },
21
+ });
22
+
10
23
  export function PasswordInput(props: Omit<InputProps, "type">) {
24
+ const styles = useStyles();
11
25
  const strings = useUiStrings();
12
26
  const [visible, setVisible] = useState(false);
13
27
  return (
14
28
  <Input
15
29
  {...props}
30
+ className={mergeClasses(styles.root, props.className)}
16
31
  type={visible ? "text" : "password"}
17
32
  contentAfter={
18
33
  <Tooltip
@@ -1,11 +1,12 @@
1
1
  // A navigation column, as Prism's sidebar and Vellum's docs sidebar draw it:
2
2
  // flat on the canvas, 13px items with a grey (not brand) highlight on the
3
3
  // current page, quiet 12px group labels, and nested items under a hairline.
4
- // Where it sits (sticky, its width, a drawer on a phone) is the app's layout.
4
+ // The router tells it the current page. Where it sits (sticky, its width, a
5
+ // drawer on a phone) is the app's layout.
5
6
 
6
7
  import { Text, makeStyles, mergeClasses, tokens } from "@fluentui/react-components";
7
- import type { ReactNode } from "react";
8
- import { UiLink } from "../provider/context.js";
8
+ import { useContext, type ReactNode } from "react";
9
+ import { UiContext, UiLink, useUiMatch } from "../provider/context.js";
9
10
 
10
11
  const useStyles = makeStyles({
11
12
  root: {
@@ -15,6 +16,8 @@ const useStyles = makeStyles({
15
16
  boxSizing: "border-box",
16
17
  },
17
18
  group: { marginBottom: "6px" },
19
+ // Pushed to the bottom by the space the nav has to spare.
20
+ groupEnd: { marginTop: "auto" },
18
21
  label: {
19
22
  display: "block",
20
23
  margin: 0,
@@ -59,6 +62,10 @@ const useStyles = makeStyles({
59
62
  fontWeight: tokens.fontWeightMedium,
60
63
  color: tokens.colorNeutralForeground1,
61
64
  },
65
+ muted: {
66
+ color: tokens.colorNeutralForeground3,
67
+ fontWeight: tokens.fontWeightRegular,
68
+ },
62
69
  // A branch without a link of its own.
63
70
  heading: {
64
71
  display: "flex",
@@ -95,10 +102,18 @@ export interface SideNavItem {
95
102
  /** Shown before the label. */
96
103
  icon?: ReactNode;
97
104
  /**
98
- * The page the reader is on. The app decides from its router, e.g.
99
- * `!!useMatch(to)` in React Router. The item gets `aria-current="page"`.
105
+ * The page the reader is on; the item gets `aria-current="page"`. Leave it
106
+ * out and the router's `useMatch` decides; set, the router isn't asked.
100
107
  */
101
108
  active?: boolean;
109
+ /**
110
+ * Current on its own path only, not on the pages below it: for `/`, say.
111
+ * An item with `items` has it unless set to false: its pages are listed
112
+ * under it, and show themselves.
113
+ */
114
+ end?: boolean;
115
+ /** Drawn quieter: grey, at regular weight. For a way out of a section, say. */
116
+ muted?: boolean;
102
117
  /** Items under this one, indented. */
103
118
  items?: SideNavItem[];
104
119
  }
@@ -106,12 +121,17 @@ export interface SideNavItem {
106
121
  export interface SideNavGroup {
107
122
  /** A quiet label above the group's items. */
108
123
  label?: ReactNode;
109
- /** The group's items: `{ label, to?, icon?, active?, items? }`. */
124
+ /**
125
+ * `"end"` puts the group at the bottom, when the nav is taller than its
126
+ * groups (give it a height). Make it the last group.
127
+ */
128
+ placement?: "end";
129
+ /** The group's items: `{ label, to?, icon?, active?, end?, muted?, items? }`. */
110
130
  items: SideNavItem[];
111
131
  }
112
132
 
113
133
  export interface SideNavProps {
114
- /** The groups, in order: `{ label?, items }`. */
134
+ /** The groups, in order: `{ label?, placement?, items }`. */
115
135
  groups: SideNavGroup[];
116
136
  /** Names the navigation for screen readers, e.g. "Documentation". */
117
137
  label: string;
@@ -128,7 +148,10 @@ export function SideNav({ groups, label, onNavigate, className }: SideNavProps)
128
148
  return (
129
149
  <nav aria-label={label} className={mergeClasses(styles.root, className)}>
130
150
  {groups.map((group, g) => (
131
- <section key={g} className={styles.group}>
151
+ <section
152
+ key={g}
153
+ className={mergeClasses(styles.group, group.placement === "end" && styles.groupEnd)}
154
+ >
132
155
  {group.label != null && (
133
156
  <Text as="h2" className={mergeClasses(styles.label, g === 0 && styles.labelFirst)}>
134
157
  {group.label}
@@ -163,16 +186,13 @@ function Item({
163
186
  );
164
187
  const head =
165
188
  item.to != null ? (
166
- <UiLink
167
- to={item.to}
168
- onClick={onNavigate}
169
- aria-current={item.active ? "page" : undefined}
170
- className={mergeClasses(styles.item, branch && styles.branch, item.active && styles.active)}
171
- >
189
+ <ItemLink item={item} to={item.to} branch={branch} onNavigate={onNavigate} styles={styles}>
172
190
  {content}
173
- </UiLink>
191
+ </ItemLink>
174
192
  ) : (
175
- <div className={mergeClasses(styles.heading, styles.branch)}>{content}</div>
193
+ <div className={mergeClasses(styles.heading, styles.branch, item.muted && styles.muted)}>
194
+ {content}
195
+ </div>
176
196
  );
177
197
  if (!branch) return head;
178
198
  return (
@@ -186,3 +206,53 @@ function Item({
186
206
  </div>
187
207
  );
188
208
  }
209
+
210
+ interface ItemLinkProps {
211
+ item: SideNavItem;
212
+ to: string;
213
+ branch: boolean;
214
+ onNavigate?: () => void;
215
+ styles: Styles;
216
+ children: ReactNode;
217
+ }
218
+
219
+ // Only a link without `active` asks the router, from a component of its own:
220
+ // when `active` or the router's `useMatch` comes or goes, the link is another
221
+ // component, so React mounts it afresh rather than calling other hooks.
222
+ function ItemLink(props: ItemLinkProps) {
223
+ const { router } = useContext(UiContext);
224
+ if (props.item.active !== undefined) return <LinkRow {...props} active={props.item.active} />;
225
+ if (!router.useMatch) return <LinkRow {...props} active={false} />;
226
+ return <MatchedLink {...props} />;
227
+ }
228
+
229
+ function MatchedLink(props: ItemLinkProps) {
230
+ const active = useUiMatch(props.to, props.item.end ?? props.branch);
231
+ return <LinkRow {...props} active={active} />;
232
+ }
233
+
234
+ function LinkRow({
235
+ item,
236
+ to,
237
+ branch,
238
+ onNavigate,
239
+ styles,
240
+ children,
241
+ active,
242
+ }: ItemLinkProps & { active: boolean }) {
243
+ return (
244
+ <UiLink
245
+ to={to}
246
+ onClick={onNavigate}
247
+ aria-current={active ? "page" : undefined}
248
+ className={mergeClasses(
249
+ styles.item,
250
+ branch && styles.branch,
251
+ item.muted && styles.muted,
252
+ active && styles.active,
253
+ )}
254
+ >
255
+ {children}
256
+ </UiLink>
257
+ );
258
+ }