rift-ds 1.32.0 → 1.33.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 (96) hide show
  1. package/README.md +4 -4
  2. package/behaviors/clipboard.d.ts +7 -0
  3. package/behaviors/clipboard.js +35 -0
  4. package/behaviors/headingSlug.d.ts +8 -0
  5. package/behaviors/headingSlug.js +4 -0
  6. package/behaviors/shell.css +64 -0
  7. package/behaviors/syncedChoice.d.ts +2 -0
  8. package/behaviors/syncedChoice.js +48 -0
  9. package/behaviors/useLayer.d.ts +15 -2
  10. package/behaviors/useLayer.js +3 -2
  11. package/bin/templates/blocks/app/guide/PageFeedback.tsx +55 -0
  12. package/bin/templates/blocks/app/guide/page.module.css +94 -0
  13. package/bin/templates/blocks/app/guide/page.tsx +168 -0
  14. package/bin/templates/blocks/components/blocks/AppShell.module.css +3 -1
  15. package/bin/templates/blocks/components/blocks/AppShell.tsx +8 -0
  16. package/bin/templates/blocks/components/blocks/DocsShell.module.css +18 -0
  17. package/bin/templates/blocks/components/blocks/DocsShell.tsx +179 -0
  18. package/bin/templates/blocks/registry.json +13 -0
  19. package/code/highlight.d.ts +4 -0
  20. package/code/highlight.js +34 -0
  21. package/code/index.d.ts +16 -0
  22. package/code/index.js +23 -0
  23. package/components/AnchorNav/AnchorNav.d.ts +29 -3
  24. package/components/AnchorNav/AnchorNav.js +69 -5
  25. package/components/AppLayout/AppLayout.css +8 -4
  26. package/components/AppLayout/AppLayout.d.ts +13 -3
  27. package/components/AppLayout/AppLayout.js +2 -0
  28. package/components/ArtifactPanel/ArtifactPanel.css +46 -0
  29. package/components/ArtifactPanel/ArtifactPanel.d.ts +14 -4
  30. package/components/ArtifactPanel/ArtifactPanel.js +8 -5
  31. package/components/BackToTop/BackToTop.css +28 -0
  32. package/components/BackToTop/BackToTop.d.ts +28 -0
  33. package/components/BackToTop/BackToTop.js +47 -0
  34. package/components/BentoTile/BentoTile.css +3 -0
  35. package/components/CodeBlock/CodeBlock.css +63 -24
  36. package/components/CodeBlock/CodeBlock.d.ts +62 -6
  37. package/components/CodeBlock/CodeBlock.js +90 -48
  38. package/components/CopyButton/CopyButton.d.ts +42 -0
  39. package/components/CopyButton/CopyButton.js +72 -0
  40. package/components/DescriptionList/DescriptionListCopy.d.ts +2 -2
  41. package/components/DescriptionList/DescriptionListCopy.js +7 -35
  42. package/components/Figure/Figure.css +26 -0
  43. package/components/Figure/Figure.d.ts +10 -1
  44. package/components/Figure/Figure.js +15 -3
  45. package/components/Heading/Heading.css +43 -0
  46. package/components/Heading/Heading.d.ts +14 -3
  47. package/components/Heading/Heading.js +22 -4
  48. package/components/HoverCard/HoverCard.js +1 -0
  49. package/components/Link/Link.css +38 -0
  50. package/components/Link/Link.d.ts +3 -3
  51. package/components/Link/Link.js +1 -1
  52. package/components/Menubar/Menubar.css +82 -0
  53. package/components/Menubar/Menubar.d.ts +40 -0
  54. package/components/Menubar/Menubar.js +97 -0
  55. package/components/NavList/NavList.css +197 -0
  56. package/components/NavList/NavList.d.ts +54 -6
  57. package/components/NavList/NavList.js +136 -8
  58. package/components/Pagination/Pagination.css +80 -0
  59. package/components/Pagination/Pagination.d.ts +29 -3
  60. package/components/Pagination/Pagination.js +49 -5
  61. package/components/Rating/Rating.css +26 -0
  62. package/components/Rating/Rating.d.ts +18 -5
  63. package/components/Rating/Rating.js +16 -7
  64. package/components/SectionTitle/SectionTitle.css +36 -0
  65. package/components/SectionTitle/SectionTitle.d.ts +10 -1
  66. package/components/SectionTitle/SectionTitle.js +7 -2
  67. package/components/ShaderScene/ShaderScene.d.ts +2 -1
  68. package/components/ShaderScene/ShaderScene.js +20 -2
  69. package/components/SiteFooter/SiteFooter.css +157 -0
  70. package/components/SiteFooter/SiteFooter.d.ts +53 -0
  71. package/components/SiteFooter/SiteFooter.js +61 -0
  72. package/components/SiteHeader/SiteHeader.css +106 -4
  73. package/components/SiteHeader/SiteHeader.d.ts +25 -2
  74. package/components/SiteHeader/SiteHeader.js +46 -8
  75. package/components/SiteLayout/SiteLayout.css +361 -0
  76. package/components/SiteLayout/SiteLayout.d.ts +103 -0
  77. package/components/SiteLayout/SiteLayout.js +68 -0
  78. package/components/Table/Table.css +14 -0
  79. package/components/Table/Table.d.ts +2 -0
  80. package/components/Table/Table.js +1 -1
  81. package/components/Tooltip/Tooltip.js +1 -0
  82. package/components/keyboard-patterns.json.d.ts +57 -0
  83. package/components/keyboard-patterns.json.js +1 -1
  84. package/components/registry.json +89 -19
  85. package/components/registry.json.d.ts +89 -19
  86. package/components/registry.json.js +1 -1
  87. package/index.d.ts +5 -0
  88. package/index.js +14 -1
  89. package/package.json +14 -2
  90. package/tokens/breakpoints.js +3 -3
  91. package/tokens/registry.json +5 -0
  92. package/tokens/registry.json.d.ts +5 -0
  93. package/tokens/registry.json.js +1 -1
  94. package/tokens/tokens-dark.css +12 -0
  95. package/tokens/tokens-light.css +12 -0
  96. package/tokens/values.json.js +1 -1
@@ -12,7 +12,7 @@ export interface DescriptionListCopyProps {
12
12
  /**
13
13
  * The copy button beside a description list value. Internal: DescriptionList
14
14
  * renders it for a `copyable` item, so the list itself stays
15
- * server-renderable. A compact tertiary IconButton whose glyph and name
16
- * turn to "Copied" for a moment after a press.
15
+ * server-renderable. An icon-only CopyButton whose glyph and name turn to
16
+ * "Copied" for a moment after a press.
17
17
  */
18
18
  export declare function DescriptionListCopy({ value, label, copiedLabel, onCopied }: DescriptionListCopyProps): import("react").JSX.Element;
@@ -1,44 +1,16 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
- import { useState, useRef, useEffect } from "react";
4
- import { IconButton } from "../IconButton/IconButton.js";
5
- import { MOTION_FEEDBACK_RESET_MS } from "../../tokens/motion.js";
6
- function writeClipboard(text) {
7
- const fallback = () => {
8
- const focused = document.activeElement instanceof HTMLElement ? document.activeElement : null;
9
- const textarea = document.createElement("textarea");
10
- textarea.value = text;
11
- textarea.setAttribute("readonly", "");
12
- textarea.className = "ds-visually-hidden";
13
- document.body.appendChild(textarea);
14
- textarea.select();
15
- document.execCommand("copy");
16
- document.body.removeChild(textarea);
17
- focused?.focus({ preventScroll: true });
18
- };
19
- if (navigator.clipboard?.writeText) navigator.clipboard.writeText(text).catch(fallback);
20
- else fallback();
21
- }
3
+ import { CopyButton } from "../CopyButton/CopyButton.js";
22
4
  function DescriptionListCopy({ value, label, copiedLabel, onCopied }) {
23
- const [copied, setCopied] = useState(false);
24
- const timer = useRef(void 0);
25
- useEffect(() => () => window.clearTimeout(timer.current), []);
26
- const copy = () => {
27
- writeClipboard(value);
28
- onCopied?.(value);
29
- setCopied(true);
30
- window.clearTimeout(timer.current);
31
- timer.current = window.setTimeout(() => setCopied(false), MOTION_FEEDBACK_RESET_MS);
32
- };
33
5
  return /* @__PURE__ */ jsx(
34
- IconButton,
6
+ CopyButton,
35
7
  {
36
8
  className: "ds-description-list__copy",
37
- icon: copied ? "check" : "content_copy",
38
- variant: "tertiary",
39
- size: "compact",
40
- label: copied ? copiedLabel : label,
41
- onClick: copy
9
+ value,
10
+ iconOnly: true,
11
+ copyLabel: label,
12
+ copiedLabel,
13
+ onCopied
42
14
  }
43
15
  );
44
16
  }
@@ -69,3 +69,29 @@
69
69
  outline: 2px solid var(--color-action-primary-bg);
70
70
  outline-offset: -2px;
71
71
  }
72
+
73
+ /* ============================================
74
+ VERDICT (variant="positive" | "error")
75
+ A guideline's Do or Don't: a status Badge leading the
76
+ caption, saying the verdict in words and in its status
77
+ colour, on the crisp container fill behind a hairline (a
78
+ verdict frames a live specimen more often than a photo, and
79
+ the photo mat's grey reads as a dark slab on a white page).
80
+ ============================================ */
81
+
82
+ .ds-figure--positive,
83
+ .ds-figure--error {
84
+ background-color: var(--color-bg-container-primary);
85
+ border: var(--border-025) solid var(--color-bg-container-border);
86
+ }
87
+
88
+ .ds-figure--positive .ds-figure__caption,
89
+ .ds-figure--error .ds-figure__caption {
90
+ display: flex;
91
+ align-items: baseline;
92
+ gap: var(--gap-200);
93
+ }
94
+
95
+ .ds-figure__verdict {
96
+ flex: none;
97
+ }
@@ -11,6 +11,15 @@ type FigureOwnProps = {
11
11
  * `<figure>`, so it replaces the native `onClick` on the root.
12
12
  */
13
13
  onClick?: React.MouseEventHandler<HTMLButtonElement>;
14
+ /**
15
+ * A verdict on what the figure shows, for a guideline's Do and Don't pair:
16
+ * `positive` leads the caption with a positive "Do" badge, `error` with an
17
+ * error "Don't" badge, on the crisp container fill. `default` is a plain
18
+ * figure. Set two side by side in a Grid.
19
+ */
20
+ variant?: 'default' | 'positive' | 'error';
21
+ /** The verdict mark's text. Defaults to "Do" for `positive` and "Don't" for `error`. */
22
+ verdictLabel?: string;
14
23
  /** Additional CSS classes */
15
24
  className?: string;
16
25
  };
@@ -18,7 +27,7 @@ export interface FigureProps extends FigureOwnProps, Omit<React.ComponentPropsWi
18
27
  }
19
28
  /**
20
29
  * Figure component — an image with an optional caption in a bordered,
21
- * rounded container. Pass onClick to make it zoomable (adds the
30
+ * rounded container. `variant` adds a Do or Don't verdict for guidelines. Pass onClick to make it zoomable (adds the
22
31
  * zoom cursor, hover dim, and keyboard activation). Forwards a ref to the
23
32
  * root `<figure>` and spreads native attributes onto it.
24
33
  */
@@ -1,10 +1,12 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import "./Figure.css";
4
+ import { Badge } from "../Badge/Badge.js";
4
5
  const Figure = React.forwardRef(
5
- ({ children, caption, onClick, className = "", ...rest }, ref) => {
6
+ ({ children, caption, onClick, variant = "default", verdictLabel, className = "", ...rest }, ref) => {
6
7
  const baseClass = "ds-figure";
7
- const classes = [baseClass, onClick && `${baseClass}--zoomable`, className].filter(Boolean).join(" ");
8
+ const verdict = variant === "default" ? null : verdictLabel ?? (variant === "positive" ? "Do" : "Don't");
9
+ const classes = [baseClass, onClick && `${baseClass}--zoomable`, verdict && `${baseClass}--${variant}`, className].filter(Boolean).join(" ");
8
10
  const media = /* @__PURE__ */ jsx("div", { className: `${baseClass}__media`, children });
9
11
  return /* @__PURE__ */ jsxs("figure", { ...rest, ref, className: classes, children: [
10
12
  onClick ? (
@@ -14,7 +16,17 @@ const Figure = React.forwardRef(
14
16
  // child image's alt text.
15
17
  /* @__PURE__ */ jsx("button", { type: "button", className: `${baseClass}__zoom`, onClick, children: media })
16
18
  ) : media,
17
- caption && /* @__PURE__ */ jsx("figcaption", { className: `${baseClass}__caption`, children: caption })
19
+ (caption || verdict) && /* @__PURE__ */ jsxs("figcaption", { className: `${baseClass}__caption`, children: [
20
+ verdict && /* @__PURE__ */ jsx(
21
+ Badge,
22
+ {
23
+ className: `${baseClass}__verdict`,
24
+ label: verdict,
25
+ variant: variant === "positive" ? "positive" : "error"
26
+ }
27
+ ),
28
+ caption
29
+ ] })
18
30
  ] });
19
31
  }
20
32
  );
@@ -127,3 +127,46 @@
127
127
  .ds-heading--align-end {
128
128
  text-align: end;
129
129
  }
130
+
131
+ /* ============================================
132
+ ANCHOR
133
+ A quiet "#" after the text that links to the heading itself.
134
+ Hidden until the heading is hovered or the link is focused, so a
135
+ page of headings reads clean; a focused link always shows. The
136
+ heading keeps a scroll margin so a jump lands it clear of a sticky
137
+ header (a page sets --ds-heading-scroll-margin to its header's height).
138
+ ============================================ */
139
+
140
+ .ds-heading--anchored {
141
+ scroll-margin-block-start: var(--ds-heading-scroll-margin, var(--gap-500));
142
+ }
143
+
144
+ .ds-heading__anchor {
145
+ margin-inline-start: 0.3em; /* ds-allow(typography): the gap follows the heading's own size, so every tier sets the mark a word-space away */
146
+ color: var(--color-text-tertiary);
147
+ font-weight: inherit;
148
+ text-decoration: none;
149
+ opacity: 0;
150
+ transition: opacity var(--motion-duration-base) var(--motion-ease-standard), color var(--motion-duration-base) var(--motion-ease-standard);
151
+ }
152
+
153
+ .ds-heading:hover .ds-heading__anchor,
154
+ .ds-heading__anchor:focus-visible {
155
+ opacity: 1;
156
+ }
157
+
158
+ .ds-heading__anchor:hover {
159
+ color: var(--color-text-secondary);
160
+ }
161
+
162
+ .ds-heading__anchor:focus-visible {
163
+ outline: 2px solid var(--color-action-primary-bg);
164
+ outline-offset: 2px;
165
+ border-radius: var(--radius-100);
166
+ }
167
+
168
+ @media (hover: none) {
169
+ .ds-heading__anchor {
170
+ opacity: 1;
171
+ }
172
+ }
@@ -1,3 +1,4 @@
1
+ import { headingSlug } from '../../behaviors/headingSlug';
1
2
  import { default as React } from 'react';
2
3
  /** A heading type style, named as the type scale names it, from the largest. */
3
4
  export type HeadingTier = 'mega-1' | 'mega-2' | 'display-1' | 'display-2' | 'sub-display' | 'heading-1' | 'heading-2' | 'heading-3' | 'title-body';
@@ -15,6 +16,15 @@ type HeadingOwnProps = {
15
16
  balance?: boolean;
16
17
  /** Where the text sits on the line, along the reading direction. */
17
18
  align?: 'start' | 'center' | 'end';
19
+ /**
20
+ * Give the heading an id and a "#" link to itself, shown on hover and
21
+ * focus, so a reader can link straight to the section. `true` makes the
22
+ * id from the heading's text ("Getting started" becomes
23
+ * `getting-started`); a string sets it. An `id` passed directly wins.
24
+ */
25
+ anchor?: boolean | string;
26
+ /** Accessible name of the anchor link, given the heading's text. Defaults to "Link to <text>". */
27
+ anchorLabel?: (text: string) => string;
18
28
  /** The heading's text. */
19
29
  children?: React.ReactNode;
20
30
  /** Additional CSS classes. */
@@ -25,7 +35,8 @@ export interface HeadingProps extends HeadingOwnProps, Omit<React.ComponentProps
25
35
  /**
26
36
  * A heading in the type scale. `level` sets the element and `tier` the
27
37
  * look, chosen apart, so the outline stays correct whatever size a design
28
- * calls for. Server-renderable.
38
+ * calls for. `anchor` adds an id and a "#" link to the section.
39
+ * Server-renderable.
29
40
  */
30
- export declare function Heading({ level, tier, tone, truncate, balance, align, className, children, ref, ...rest }: HeadingProps): React.JSX.Element;
31
- export {};
41
+ export declare function Heading({ level, tier, tone, truncate, balance, align, anchor, anchorLabel, className, children, id: idProp, ref, ...rest }: HeadingProps): React.JSX.Element;
42
+ export { headingSlug };
@@ -1,5 +1,6 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import "react";
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { headingSlug } from "../../behaviors/headingSlug.js";
3
+ import React from "react";
3
4
  import "./Heading.css";
4
5
  const LEVEL_TIER = {
5
6
  1: "heading-1",
@@ -9,6 +10,13 @@ const LEVEL_TIER = {
9
10
  5: "title-body",
10
11
  6: "title-body"
11
12
  };
13
+ const textOf = (node) => {
14
+ if (node === null || node === void 0 || typeof node === "boolean") return "";
15
+ if (typeof node === "string" || typeof node === "number") return String(node);
16
+ if (Array.isArray(node)) return node.map(textOf).join("");
17
+ if (React.isValidElement(node)) return textOf(node.props.children);
18
+ return "";
19
+ };
12
20
  function Heading({
13
21
  level = 2,
14
22
  tier,
@@ -16,11 +24,16 @@ function Heading({
16
24
  truncate = false,
17
25
  balance = false,
18
26
  align,
27
+ anchor,
28
+ anchorLabel = (text) => `Link to ${text}`,
19
29
  className = "",
20
30
  children,
31
+ id: idProp,
21
32
  ref,
22
33
  ...rest
23
34
  }) {
35
+ const text = anchor ? textOf(children) : "";
36
+ const id = idProp ?? (typeof anchor === "string" ? anchor : anchor ? headingSlug(text) || void 0 : void 0);
24
37
  const Tag = `h${level}`;
25
38
  const resolvedTier = tier ?? LEVEL_TIER[level];
26
39
  const classes = [
@@ -30,10 +43,15 @@ function Heading({
30
43
  truncate && "ds-heading--truncate",
31
44
  balance && "ds-heading--balance",
32
45
  align && `ds-heading--align-${align}`,
46
+ anchor && "ds-heading--anchored",
33
47
  className
34
48
  ].filter(Boolean).join(" ");
35
- return /* @__PURE__ */ jsx(Tag, { ...rest, ref, className: classes, children });
49
+ return /* @__PURE__ */ jsxs(Tag, { ...rest, id, ref, className: classes, children: [
50
+ children,
51
+ anchor && id && /* @__PURE__ */ jsx("a", { className: "ds-heading__anchor", href: `#${id}`, "aria-label": anchorLabel(text), children: "#" })
52
+ ] });
36
53
  }
37
54
  export {
38
- Heading
55
+ Heading,
56
+ headingSlug
39
57
  };
@@ -55,6 +55,7 @@ const HoverCard = React.forwardRef(
55
55
  }, []);
56
56
  useLayer({
57
57
  open: visible,
58
+ passive: true,
58
59
  onDismiss: () => {
59
60
  clearTimeout(showTimeoutRef.current);
60
61
  clearTimeout(hideTimeoutRef.current);
@@ -82,3 +82,41 @@
82
82
  .ds-link--disabled:hover {
83
83
  text-decoration-thickness: from-font;
84
84
  }
85
+
86
+ /* ============================================
87
+ SKIP (variant="skip")
88
+ "Skip to content": parked above the top of the viewport
89
+ until it holds focus, then a pill sliding down into the top
90
+ start corner above every layer but the chat. Moved out of
91
+ view rather than display:none, so it stays in the tab order.
92
+ ============================================ */
93
+
94
+ .ds-link--skip {
95
+ position: fixed;
96
+ inset-block-start: var(--gap-300);
97
+ inset-inline-start: var(--gap-300);
98
+ z-index: var(--layer-toast);
99
+ display: inline-flex;
100
+ align-items: center;
101
+ box-sizing: border-box;
102
+ height: var(--control-height-default);
103
+ padding-inline: var(--padding-500);
104
+ border-radius: var(--radius-pill);
105
+ background-color: var(--color-bg-container-primary);
106
+ box-shadow: var(--shadow-floating);
107
+ font-family: var(--font-paragraph-emphasis-family);
108
+ font-size: var(--font-paragraph-emphasis-size);
109
+ font-weight: var(--font-paragraph-emphasis-weight);
110
+ line-height: var(--font-paragraph-emphasis-line-height);
111
+ color: var(--color-text-primary);
112
+ text-decoration: none;
113
+ transform: translateY(calc(-100% - 2 * var(--gap-300)));
114
+ transition: transform var(--motion-duration-base) var(--motion-ease-standard);
115
+ }
116
+
117
+ .ds-link--skip:focus-visible,
118
+ .ds-link--skip:focus {
119
+ transform: none;
120
+ outline: 2px solid var(--color-action-primary-bg);
121
+ outline-offset: 2px;
122
+ }
@@ -6,9 +6,9 @@ type LinkOwnProps = {
6
6
  href: string;
7
7
  /** The link text. */
8
8
  children: React.ReactNode;
9
- /** `inline` sits inside a sentence, underlined and in the sentence's colour; `standalone` stands on its own line or beside a control, in the tertiary action text colour and its own type face. Both are underlined. */
10
- variant?: 'inline' | 'standalone';
11
- /** The standalone link's type size: `default` the paragraph face, `compact` the small paragraph face. An inline link always takes the size of the text around it. Distinct from no native attribute of an anchor. */
9
+ /** `inline` sits inside a sentence, underlined and in the sentence's colour; `standalone` stands on its own line or beside a control, in the tertiary action text colour and its own type face. Both are underlined. `skip` is a page's first link, "Skip to content": hidden until it takes focus from the keyboard, then shown pinned to the top of the page above everything, so a keyboard reader can pass the header and the navigation in one press. Point it at the main region's id. */
10
+ variant?: 'inline' | 'standalone' | 'skip';
11
+ /** The type size of a standalone or skip link: `default` the paragraph face, `compact` the small paragraph face. An inline link always takes the size of the text around it. Distinct from no native attribute of an anchor. */
12
12
  size?: 'default' | 'compact';
13
13
  /** The link leaves the app: it opens in a new tab with `rel="noopener noreferrer"`, carries an outward mark, and tells a screen reader it opens a new tab. */
14
14
  external?: boolean;
@@ -29,7 +29,7 @@ function Link({
29
29
  const classes = [
30
30
  "ds-link",
31
31
  `ds-link--${variant}`,
32
- variant === "standalone" && `ds-link--${size}`,
32
+ variant !== "inline" && `ds-link--${size}`,
33
33
  disabled && "ds-link--disabled",
34
34
  className
35
35
  ].filter(Boolean).join(" ");
@@ -0,0 +1,82 @@
1
+ /* ============================================
2
+ MENUBAR COMPONENT
3
+ A persistent row of menus. The bar is Toolbar's
4
+ shell (container fill, hairline, pill); each
5
+ menu is a DropdownMenu, whose panel is unchanged.
6
+ ============================================ */
7
+
8
+ /* Base: Toolbar's pill shell, so a menu bar and a toolbar sitting in the
9
+ same chrome read as one family. Padding clears the focus ring's reach. */
10
+
11
+ .ds-menubar {
12
+ display: inline-flex;
13
+ align-items: center;
14
+ gap: var(--gap-050);
15
+ padding: var(--padding-100);
16
+ background-color: var(--color-bg-container-primary);
17
+ border: var(--border-025) solid var(--color-bg-container-border);
18
+ border-radius: var(--radius-pill);
19
+ }
20
+
21
+ /* ============================================
22
+ TRIGGER
23
+ A quiet text button on the control row: the tertiary
24
+ button's hover, and the same wash held while its menu is open.
25
+ ============================================ */
26
+
27
+ .ds-menubar__trigger {
28
+ display: inline-flex;
29
+ align-items: center;
30
+ box-sizing: border-box;
31
+ height: var(--control-height-compact);
32
+ margin: 0;
33
+ padding-inline: var(--padding-300);
34
+ border: none;
35
+ border-radius: var(--radius-pill);
36
+ background: none;
37
+ font-family: var(--font-paragraph-sm-emphasis-family);
38
+ font-size: var(--font-paragraph-sm-emphasis-size);
39
+ font-weight: var(--font-paragraph-sm-emphasis-weight);
40
+ line-height: var(--font-paragraph-sm-emphasis-line-height);
41
+ color: var(--color-text-primary);
42
+ white-space: nowrap;
43
+ cursor: pointer;
44
+ transition: background-color var(--motion-duration-base) var(--motion-ease-standard);
45
+ }
46
+
47
+ .ds-menubar__trigger:hover,
48
+ .ds-menubar__trigger[aria-expanded='true'] {
49
+ background-color: var(--color-action-passive-bg-hover);
50
+ }
51
+
52
+ .ds-menubar__trigger:focus-visible {
53
+ outline: 2px solid var(--color-action-primary-bg);
54
+ outline-offset: 2px;
55
+ }
56
+
57
+ .ds-menubar__trigger[aria-disabled='true'] {
58
+ opacity: 0.4;
59
+ cursor: not-allowed;
60
+ }
61
+
62
+ .ds-menubar__trigger[aria-disabled='true']:hover {
63
+ background: none;
64
+ }
65
+
66
+ /* The trigger draws its own ring; the menu's wrapper ring would double it. */
67
+ .ds-menubar__menu .ds-dropdown-menu__trigger:focus-visible {
68
+ outline: none;
69
+ }
70
+
71
+ /* Compact: a smaller trigger on the same shell. */
72
+
73
+ .ds-menubar--compact {
74
+ padding: var(--padding-050);
75
+ }
76
+
77
+ .ds-menubar--compact .ds-menubar__trigger {
78
+ /* One step under the compact row, so the compact bar's outer height
79
+ (with its padding) lands near the compact control height. */
80
+ height: calc(var(--control-height-compact) - var(--padding-200));
81
+ padding-inline: var(--padding-200);
82
+ }
@@ -0,0 +1,40 @@
1
+ import { default as React } from 'react';
2
+ import { DropdownMenuEntry } from '../DropdownMenu/DropdownMenu';
3
+ import { ShortcutKeyLabels } from '../../behaviors/shortcut-keys';
4
+ /** One menu in the bar: its trigger's label and the entries it opens. */
5
+ export interface MenubarMenu {
6
+ /** The trigger's text, e.g. "File". Also the open menu's accessible name. */
7
+ label: string;
8
+ /** The menu's entries, in DropdownMenu's shape: items, groups, separators, checkbox and radio items, sub-menus and shortcuts. */
9
+ items: DropdownMenuEntry[];
10
+ /** Show the trigger but do not let it open. */
11
+ disabled?: boolean;
12
+ /** Stable identity for the menu, when two menus share a label. Defaults to the label. */
13
+ id?: string;
14
+ }
15
+ /** Props owned by Menubar itself. */
16
+ type MenubarOwnProps = {
17
+ /** The menus, in order along the bar. */
18
+ menus: MenubarMenu[];
19
+ /** Accessible name for the bar. */
20
+ label?: string;
21
+ /** Trigger and menu size. */
22
+ size?: 'default' | 'compact';
23
+ /** Key names for the shortcut hints in every menu, for a keyboard other than English (passed to each DropdownMenu). */
24
+ keyLabels?: ShortcutKeyLabels;
25
+ /** Additional CSS classes */
26
+ className?: string;
27
+ };
28
+ export interface MenubarProps extends MenubarOwnProps, Omit<React.ComponentPropsWithRef<'div'>, keyof MenubarOwnProps | 'children' | 'role'> {
29
+ }
30
+ /**
31
+ * Menubar: a persistent row of menus, the way a desktop app's File, Edit
32
+ * and View sit along the top of its window. Each menu is a DropdownMenu, so
33
+ * its panel, items, sub-menus, shortcuts and keys are DropdownMenu's own;
34
+ * the bar adds the WAI-ARIA menubar behaviour around them. The bar is one
35
+ * tab stop, the inline arrows move along it (and, while a menu is open,
36
+ * open the next one instead), Home and End jump to its ends, and with a
37
+ * menu open, pointing at another trigger opens that one.
38
+ */
39
+ export declare function Menubar({ menus, label, size, keyLabels, className, ref, ...rest }: MenubarProps): React.JSX.Element;
40
+ export {};
@@ -0,0 +1,97 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useState, useRef } from "react";
4
+ import { DropdownMenu } from "../DropdownMenu/DropdownMenu.js";
5
+ import { logicalArrowKey } from "../../behaviors/direction.js";
6
+ import "./Menubar.css";
7
+ function Menubar({
8
+ menus,
9
+ label = "Menu bar",
10
+ size = "default",
11
+ keyLabels,
12
+ className = "",
13
+ ref,
14
+ ...rest
15
+ }) {
16
+ const [openIndex, setOpenIndex] = useState(null);
17
+ const [focusIndex, setFocusIndex] = useState(0);
18
+ const triggers = useRef([]);
19
+ const baseClass = "ds-menubar";
20
+ const classes = [baseClass, size === "compact" ? `${baseClass}--compact` : "", className].filter(Boolean).join(" ");
21
+ const enabled = menus.map((menu, i) => menu.disabled ? -1 : i).filter((i) => i >= 0);
22
+ const move = (to) => {
23
+ setFocusIndex(to);
24
+ triggers.current[to]?.focus();
25
+ if (openIndex !== null) setOpenIndex(to);
26
+ };
27
+ const step = (from, by) => {
28
+ const at = enabled.indexOf(from);
29
+ return enabled[(at + by + enabled.length) % enabled.length];
30
+ };
31
+ const handleKeyDown = (index) => (event) => {
32
+ switch (logicalArrowKey(event.key, event.currentTarget)) {
33
+ case "ArrowRight":
34
+ event.preventDefault();
35
+ move(step(index, 1));
36
+ break;
37
+ case "ArrowLeft":
38
+ event.preventDefault();
39
+ move(step(index, -1));
40
+ break;
41
+ case "Home":
42
+ if (openIndex === null) {
43
+ event.preventDefault();
44
+ move(enabled[0]);
45
+ }
46
+ break;
47
+ case "End":
48
+ if (openIndex === null) {
49
+ event.preventDefault();
50
+ move(enabled[enabled.length - 1]);
51
+ }
52
+ break;
53
+ }
54
+ };
55
+ return /* @__PURE__ */ jsx("div", { "aria-label": label, ...rest, ref, className: classes, role: "menubar", children: menus.map((menu, index) => /* @__PURE__ */ jsx(
56
+ DropdownMenu,
57
+ {
58
+ className: `${baseClass}__menu`,
59
+ items: menu.items,
60
+ size,
61
+ keyLabels,
62
+ open: openIndex === index,
63
+ onOpenChange: (open) => {
64
+ if (menu.disabled) return;
65
+ setOpenIndex((current) => open ? index : current === index ? null : current);
66
+ if (open) setFocusIndex(index);
67
+ },
68
+ trigger: /* @__PURE__ */ jsx(
69
+ "button",
70
+ {
71
+ ref: (node) => {
72
+ triggers.current[index] = node;
73
+ },
74
+ type: "button",
75
+ role: "menuitem",
76
+ className: `${baseClass}__trigger`,
77
+ tabIndex: index === focusIndex ? 0 : -1,
78
+ "aria-disabled": menu.disabled || void 0,
79
+ onKeyDown: handleKeyDown(index),
80
+ onFocus: () => setFocusIndex(index),
81
+ onMouseEnter: () => {
82
+ if (openIndex !== null && openIndex !== index && !menu.disabled) {
83
+ setOpenIndex(index);
84
+ setFocusIndex(index);
85
+ triggers.current[index]?.focus();
86
+ }
87
+ },
88
+ children: menu.label
89
+ }
90
+ )
91
+ },
92
+ menu.id ?? menu.label
93
+ )) });
94
+ }
95
+ export {
96
+ Menubar
97
+ };