@canonical/react-ds-app 0.37.0 → 0.40.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 (149) hide show
  1. package/README.md +30 -0
  2. package/dist/esm/lib/ApplicationLayout/styles.css +27 -24
  3. package/dist/esm/lib/ContentLayout/styles.css +13 -10
  4. package/dist/esm/lib/SideNavigation/SideNavigation.js +51 -9
  5. package/dist/esm/lib/SideNavigation/SideNavigation.js.map +1 -1
  6. package/dist/esm/lib/SideNavigation/common/CollapseToggle/CollapseToggle.js +14 -6
  7. package/dist/esm/lib/SideNavigation/common/CollapseToggle/CollapseToggle.js.map +1 -1
  8. package/dist/esm/lib/SideNavigation/common/CollapseToggle/styles.css +52 -3
  9. package/dist/esm/lib/SideNavigation/common/Content/Content.js +9 -5
  10. package/dist/esm/lib/SideNavigation/common/Content/Content.js.map +1 -1
  11. package/dist/esm/lib/SideNavigation/common/Content/styles.css +55 -28
  12. package/dist/esm/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.js +70 -0
  13. package/dist/esm/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.js.map +1 -0
  14. package/dist/esm/lib/SideNavigation/common/ContextSwitcher/index.js +2 -0
  15. package/dist/esm/lib/SideNavigation/common/ContextSwitcher/index.js.map +1 -0
  16. package/dist/esm/lib/SideNavigation/common/ContextSwitcher/styles.css +94 -0
  17. package/dist/esm/lib/SideNavigation/common/ContextSwitcher/types.js +2 -0
  18. package/dist/esm/lib/SideNavigation/common/ContextSwitcher/types.js.map +1 -0
  19. package/dist/esm/lib/SideNavigation/common/Footer/Footer.js +46 -6
  20. package/dist/esm/lib/SideNavigation/common/Footer/Footer.js.map +1 -1
  21. package/dist/esm/lib/SideNavigation/common/Footer/styles.css +17 -4
  22. package/dist/esm/lib/SideNavigation/common/Group/Group.js +14 -0
  23. package/dist/esm/lib/SideNavigation/common/Group/Group.js.map +1 -0
  24. package/dist/esm/lib/SideNavigation/common/Group/index.js +2 -0
  25. package/dist/esm/lib/SideNavigation/common/Group/index.js.map +1 -0
  26. package/dist/esm/lib/SideNavigation/common/Group/styles.css +18 -0
  27. package/dist/esm/lib/SideNavigation/common/Group/types.js +2 -0
  28. package/dist/esm/lib/SideNavigation/common/Group/types.js.map +1 -0
  29. package/dist/esm/lib/SideNavigation/common/GroupHeader/GroupHeader.js +17 -0
  30. package/dist/esm/lib/SideNavigation/common/GroupHeader/GroupHeader.js.map +1 -0
  31. package/dist/esm/lib/SideNavigation/common/GroupHeader/index.js +2 -0
  32. package/dist/esm/lib/SideNavigation/common/GroupHeader/index.js.map +1 -0
  33. package/dist/esm/lib/SideNavigation/common/GroupHeader/styles.css +31 -0
  34. package/dist/esm/lib/SideNavigation/common/GroupHeader/types.js +2 -0
  35. package/dist/esm/lib/SideNavigation/common/GroupHeader/types.js.map +1 -0
  36. package/dist/esm/lib/SideNavigation/common/Header/Header.js +4 -2
  37. package/dist/esm/lib/SideNavigation/common/Header/Header.js.map +1 -1
  38. package/dist/esm/lib/SideNavigation/common/Header/styles.css +73 -32
  39. package/dist/esm/lib/SideNavigation/common/Item/Item.js +9 -13
  40. package/dist/esm/lib/SideNavigation/common/Item/Item.js.map +1 -1
  41. package/dist/esm/lib/SideNavigation/common/Item/styles.css +86 -46
  42. package/dist/esm/lib/SideNavigation/common/ItemButton/ItemButton.js +18 -0
  43. package/dist/esm/lib/SideNavigation/common/ItemButton/ItemButton.js.map +1 -0
  44. package/dist/esm/lib/SideNavigation/common/ItemButton/index.js +2 -0
  45. package/dist/esm/lib/SideNavigation/common/ItemButton/index.js.map +1 -0
  46. package/dist/esm/lib/SideNavigation/common/ItemButton/styles.css +79 -0
  47. package/dist/esm/lib/SideNavigation/common/ItemButton/types.js +2 -0
  48. package/dist/esm/lib/SideNavigation/common/ItemButton/types.js.map +1 -0
  49. package/dist/esm/lib/SideNavigation/common/ItemExpandable/ItemExpandable.js +71 -0
  50. package/dist/esm/lib/SideNavigation/common/ItemExpandable/ItemExpandable.js.map +1 -0
  51. package/dist/esm/lib/SideNavigation/common/ItemExpandable/index.js +2 -0
  52. package/dist/esm/lib/SideNavigation/common/ItemExpandable/index.js.map +1 -0
  53. package/dist/esm/lib/SideNavigation/common/ItemExpandable/styles.css +121 -0
  54. package/dist/esm/lib/SideNavigation/common/ItemExpandable/types.js +2 -0
  55. package/dist/esm/lib/SideNavigation/common/ItemExpandable/types.js.map +1 -0
  56. package/dist/esm/lib/SideNavigation/common/NavTree/NavTree.js +64 -22
  57. package/dist/esm/lib/SideNavigation/common/NavTree/NavTree.js.map +1 -1
  58. package/dist/esm/lib/SideNavigation/common/NavTree/styles.css +10 -28
  59. package/dist/esm/lib/SideNavigation/common/index.js +5 -0
  60. package/dist/esm/lib/SideNavigation/common/index.js.map +1 -1
  61. package/dist/esm/lib/SideNavigation/helpItem.js +29 -0
  62. package/dist/esm/lib/SideNavigation/helpItem.js.map +1 -0
  63. package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/index.js +2 -0
  64. package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/index.js.map +1 -0
  65. package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/types.js +2 -0
  66. package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/types.js.map +1 -0
  67. package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.js +45 -0
  68. package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.js.map +1 -0
  69. package/dist/esm/lib/SideNavigation/index.js +1 -0
  70. package/dist/esm/lib/SideNavigation/index.js.map +1 -1
  71. package/dist/esm/lib/SideNavigation/styles.css +280 -24
  72. package/dist/esm/lib/ViewLayout/styles.css +25 -22
  73. package/dist/types/lib/ApplicationLayout/types.d.ts +5 -3
  74. package/dist/types/lib/ApplicationLayout/types.d.ts.map +1 -1
  75. package/dist/types/lib/ContentLayout/types.d.ts +5 -3
  76. package/dist/types/lib/ContentLayout/types.d.ts.map +1 -1
  77. package/dist/types/lib/SideNavigation/SideNavigation.d.ts +22 -1
  78. package/dist/types/lib/SideNavigation/SideNavigation.d.ts.map +1 -1
  79. package/dist/types/lib/SideNavigation/common/CollapseToggle/CollapseToggle.d.ts +9 -2
  80. package/dist/types/lib/SideNavigation/common/CollapseToggle/CollapseToggle.d.ts.map +1 -1
  81. package/dist/types/lib/SideNavigation/common/CollapseToggle/types.d.ts +10 -3
  82. package/dist/types/lib/SideNavigation/common/CollapseToggle/types.d.ts.map +1 -1
  83. package/dist/types/lib/SideNavigation/common/Content/Content.d.ts +8 -4
  84. package/dist/types/lib/SideNavigation/common/Content/Content.d.ts.map +1 -1
  85. package/dist/types/lib/SideNavigation/common/Content/types.d.ts +8 -9
  86. package/dist/types/lib/SideNavigation/common/Content/types.d.ts.map +1 -1
  87. package/dist/types/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.d.ts +20 -0
  88. package/dist/types/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.d.ts.map +1 -0
  89. package/dist/types/lib/SideNavigation/common/ContextSwitcher/index.d.ts +3 -0
  90. package/dist/types/lib/SideNavigation/common/ContextSwitcher/index.d.ts.map +1 -0
  91. package/dist/types/lib/SideNavigation/common/ContextSwitcher/types.d.ts +52 -0
  92. package/dist/types/lib/SideNavigation/common/ContextSwitcher/types.d.ts.map +1 -0
  93. package/dist/types/lib/SideNavigation/common/Footer/Footer.d.ts +8 -4
  94. package/dist/types/lib/SideNavigation/common/Footer/Footer.d.ts.map +1 -1
  95. package/dist/types/lib/SideNavigation/common/Footer/types.d.ts +9 -10
  96. package/dist/types/lib/SideNavigation/common/Footer/types.d.ts.map +1 -1
  97. package/dist/types/lib/SideNavigation/common/Group/Group.d.ts +13 -0
  98. package/dist/types/lib/SideNavigation/common/Group/Group.d.ts.map +1 -0
  99. package/dist/types/lib/SideNavigation/common/Group/index.d.ts +3 -0
  100. package/dist/types/lib/SideNavigation/common/Group/index.d.ts.map +1 -0
  101. package/dist/types/lib/SideNavigation/common/Group/types.d.ts +10 -0
  102. package/dist/types/lib/SideNavigation/common/Group/types.d.ts.map +1 -0
  103. package/dist/types/lib/SideNavigation/common/GroupHeader/GroupHeader.d.ts +13 -0
  104. package/dist/types/lib/SideNavigation/common/GroupHeader/GroupHeader.d.ts.map +1 -0
  105. package/dist/types/lib/SideNavigation/common/GroupHeader/index.d.ts +3 -0
  106. package/dist/types/lib/SideNavigation/common/GroupHeader/index.d.ts.map +1 -0
  107. package/dist/types/lib/SideNavigation/common/GroupHeader/types.d.ts +8 -0
  108. package/dist/types/lib/SideNavigation/common/GroupHeader/types.d.ts.map +1 -0
  109. package/dist/types/lib/SideNavigation/common/Header/Header.d.ts +3 -1
  110. package/dist/types/lib/SideNavigation/common/Header/Header.d.ts.map +1 -1
  111. package/dist/types/lib/SideNavigation/common/Header/types.d.ts +5 -3
  112. package/dist/types/lib/SideNavigation/common/Header/types.d.ts.map +1 -1
  113. package/dist/types/lib/SideNavigation/common/Item/Item.d.ts +8 -9
  114. package/dist/types/lib/SideNavigation/common/Item/Item.d.ts.map +1 -1
  115. package/dist/types/lib/SideNavigation/common/Item/types.d.ts +19 -8
  116. package/dist/types/lib/SideNavigation/common/Item/types.d.ts.map +1 -1
  117. package/dist/types/lib/SideNavigation/common/ItemButton/ItemButton.d.ts +17 -0
  118. package/dist/types/lib/SideNavigation/common/ItemButton/ItemButton.d.ts.map +1 -0
  119. package/dist/types/lib/SideNavigation/common/ItemButton/index.d.ts +3 -0
  120. package/dist/types/lib/SideNavigation/common/ItemButton/index.d.ts.map +1 -0
  121. package/dist/types/lib/SideNavigation/common/ItemButton/types.d.ts +17 -0
  122. package/dist/types/lib/SideNavigation/common/ItemButton/types.d.ts.map +1 -0
  123. package/dist/types/lib/SideNavigation/common/ItemExpandable/ItemExpandable.d.ts +26 -0
  124. package/dist/types/lib/SideNavigation/common/ItemExpandable/ItemExpandable.d.ts.map +1 -0
  125. package/dist/types/lib/SideNavigation/common/ItemExpandable/index.d.ts +3 -0
  126. package/dist/types/lib/SideNavigation/common/ItemExpandable/index.d.ts.map +1 -0
  127. package/dist/types/lib/SideNavigation/common/ItemExpandable/types.d.ts +32 -0
  128. package/dist/types/lib/SideNavigation/common/ItemExpandable/types.d.ts.map +1 -0
  129. package/dist/types/lib/SideNavigation/common/NavTree/NavTree.d.ts +12 -13
  130. package/dist/types/lib/SideNavigation/common/NavTree/NavTree.d.ts.map +1 -1
  131. package/dist/types/lib/SideNavigation/common/NavTree/types.d.ts +7 -5
  132. package/dist/types/lib/SideNavigation/common/NavTree/types.d.ts.map +1 -1
  133. package/dist/types/lib/SideNavigation/common/index.d.ts +5 -0
  134. package/dist/types/lib/SideNavigation/common/index.d.ts.map +1 -1
  135. package/dist/types/lib/SideNavigation/helpItem.d.ts +20 -0
  136. package/dist/types/lib/SideNavigation/helpItem.d.ts.map +1 -0
  137. package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/index.d.ts +3 -0
  138. package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/index.d.ts.map +1 -0
  139. package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/types.d.ts +14 -0
  140. package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/types.d.ts.map +1 -0
  141. package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.d.ts +14 -0
  142. package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.d.ts.map +1 -0
  143. package/dist/types/lib/SideNavigation/index.d.ts +1 -0
  144. package/dist/types/lib/SideNavigation/index.d.ts.map +1 -1
  145. package/dist/types/lib/SideNavigation/types.d.ts +172 -27
  146. package/dist/types/lib/SideNavigation/types.d.ts.map +1 -1
  147. package/dist/types/lib/ViewLayout/types.d.ts +5 -3
  148. package/dist/types/lib/ViewLayout/types.d.ts.map +1 -1
  149. package/package.json +20 -20
package/README.md CHANGED
@@ -28,6 +28,36 @@ function AppHeader() {
28
28
  }
29
29
  ```
30
30
 
31
+ ## Styling
32
+
33
+ ### Every component stylesheet is in `ds.components.apps`
34
+
35
+ Every component stylesheet under `src` is wrapped in one cascade layer:
36
+
37
+ ```css
38
+ @layer ds.components.apps {
39
+ .ds.side-navigation {
40
+ /* … */
41
+ }
42
+ }
43
+ ```
44
+
45
+ That includes the story-only components under `src/storybook`, which carry `.ds` rules of their own and render in the same page as the published ones. `.storybook/styles.css` is deliberately not wrapped: it is the Storybook harness rather than a component stylesheet, and it is not published.
46
+
47
+ One consequence is worth knowing before you read a story or a screenshot. The harness re-declares two SideNavigation row-grid custom properties, `--sidenav-start` and `--sidenav-row-columns`, because the subcomponent stories (Header, Item, NavTree, …) render inside a bare `.ds.side-navigation` shell without mounting the root, so the component's own sheet is not in those stories' chunk at all and the row grid would collapse without them — removing them moves 14 of the 26 stories. Where both are on the page, the harness copy is now the **authority** rather than merely the last one in: it is unlayered and the component's sheet is in `ds.components.apps`. The values are identical, so nothing computes differently, but the two must be kept in step until the story shell imports the component's sheet, after which the harness copy can go.
48
+
49
+ The component layers follow the design system's tier tree, flat, one name per tier: `ds.components.global` for the global packages, then the second level — `sites`, `documentation`, `stores` and `apps` — which `@canonical/styles` names in its order statement, and then a sub-tier, which names itself. This package is the **shared application tier**, so it is `ds.components.apps`. A product's own package (`@canonical/react-ds-app-lxd` and its siblings) is a sub-tier: it declares `@layer ds.components.apps-lxd;` as the first rule of its stylesheet entry and wraps its sheets in that, and because pragma's statement comes first, a name it does not contain is appended after the second level and sorts above it. Deeper wins, which is the tree's own rule — so a product tier overrides this package, this package overrides the global one, and none of it depends on the order a bundler emits them in. Three things follow.
50
+
51
+ **This release lands with, and after, the global tier's own wrap.** Taken alone it would invert the two packages: an unlayered author rule outranks every layered one, so wrapping this package while `@canonical/react-ds-global` is still unlayered hands the global tier every rule the two contend. Measured over this package's 26 Storybook stories, that is 80 of 810 elements — 74 icons in the side navigation lose `vertical-align: sub` to the global Icon's `middle`, and the application shell gains a third grid track from the global package's work-in-progress grid `ApplicationLayout`, which styles `.application-layout`, the same class this package's `ApplicationLayout` renders. With both packages layered, nothing moves at all: 0 of 810 elements, in every condition measured.
52
+
53
+ Once both are layered, no selector this package declares is also declared by `@canonical/react-ds-global`, so nothing changes hands. What the layer buys is the answer to the next collision, and that answer is fixed rather than emitted: today specificity settles the `.application-layout` near-miss, one seat apart; a global rule written at the same seat as this package's would have been settled by whichever bundle a loader emitted last, and is now settled by layer, in this package's favour, whatever the emit order and without a longer selector or an `!important`.
54
+
55
+ The guarantee needs `@canonical/styles` on the page, and needs its statement first. An order statement is what fixes the relative order of two sublayers; without it they fall back to the order they first appear in, and a bundle that emits this package before `@canonical/react-ds-global` hands the win back to the global tier. One nuance, measured: `ds.components.apps` is not a name the statement contains yet — it still names the retired `ds.components.app`, and gains the second level in full with the rework of the styles package — but a sublayer the statement does not name is appended after every name it fixed, so with the statement on the page this package already beats `@canonical/react-ds-global` in both emit orders. Nothing under `src/lib` imports `@canonical/styles` — an application imports it once, as the installation instructions above say.
56
+
57
+ An application's own **unlayered** CSS now beats every rule in this package, whatever the selectors on either side, because an unlayered author rule outranks every layered one. That is CSS working as designed, and it is the deliberate escape hatch: an application that needs to override a component writes a plain rule and it wins. An application that does *not* want to win by accident puts its CSS in `@layer app`.
58
+
59
+ **Rule for contributors:** every component stylesheet under `src` opens with that wrapper. `@keyframes` and a component's own `:root` token defaults go inside it; `@property` and `@font-face` registrations stay outside, above the block, because no layer sorts a registration. Never reach for `!important` to win a fight — an important declaration inverts the layer order, so it cannot be arbitrated by layers at all. The "Cascade Layers" section of the `@canonical/styles` README is the reference for the full order and for what is deliberately left unlayered.
60
+
31
61
  ## Storybook
32
62
 
33
63
  ```bash
@@ -1,29 +1,32 @@
1
- /* Generated by @canonical/summon-component:react v0.1.0 */
1
+ /* Generated by @canonical/summon-component:react v0.1.0
2
+ * Layer: ds.components.apps (@canonical/styles README, "Cascade layers"). */
2
3
 
3
- .ds.application-layout {
4
- /* Application shell: navigation rail (min-content) + content (1fr), per
5
- the ontology instance apps.layout.application_layout. The rail/content
6
- gutter follows the design reference (#421: 1rem) via the container gap
7
- token; --application-layout-gap overrides (0 for a flush shell). */
8
- display: grid;
9
- grid-template-columns: min-content 1fr;
10
- gap: var(--application-layout-gap, var(--container-gap-default, 1rem));
11
- block-size: 100%;
12
- }
4
+ @layer ds.components.apps {
5
+ .ds.application-layout {
6
+ /* Application shell: navigation rail (min-content) + content (1fr), per
7
+ the ontology instance apps.layout.application_layout. The rail/content
8
+ gutter follows the design reference (#421: 1rem) via the container gap
9
+ token; --application-layout-gap overrides (0 for a flush shell). */
10
+ display: grid;
11
+ grid-template-columns: min-content 1fr;
12
+ gap: var(--application-layout-gap, var(--container-gap-default, 1rem));
13
+ block-size: 100%;
14
+ }
13
15
 
14
- /* Without a navigation slot, drop the rail column entirely so neither the
15
- empty track nor the gap offsets the content. */
16
- .ds.application-layout:not(:has(> .navigation)) {
17
- grid-template-columns: 1fr;
18
- }
16
+ /* Without a navigation slot, drop the rail column entirely so neither the
17
+ empty track nor the gap offsets the content. */
18
+ .ds.application-layout:not(:has(> .navigation)) {
19
+ grid-template-columns: 1fr;
20
+ }
19
21
 
20
- /* min-size 0 lets each region scroll internally instead of stretching the
21
- shell beyond the viewport. The navigation slot owns its inline size. */
22
- .ds.application-layout > .navigation {
23
- min-block-size: 0;
24
- }
22
+ /* min-size 0 lets each region scroll internally instead of stretching the
23
+ shell beyond the viewport. The navigation slot owns its inline size. */
24
+ .ds.application-layout > .navigation {
25
+ min-block-size: 0;
26
+ }
25
27
 
26
- .ds.application-layout > .content {
27
- min-block-size: 0;
28
- min-inline-size: 0;
28
+ .ds.application-layout > .content {
29
+ min-block-size: 0;
30
+ min-inline-size: 0;
31
+ }
29
32
  }
@@ -1,13 +1,16 @@
1
- /* Generated by @canonical/summon-component:react v0.1.0 */
1
+ /* Generated by @canonical/summon-component:react v0.1.0
2
+ * Layer: ds.components.apps (@canonical/styles README, "Cascade layers"). */
2
3
 
3
- .ds.content-layout {
4
- /* Column templates and gaps come from the .grid presets in
5
- @canonical/styles (.responsive: breakpoint-driven 4/8/12 columns;
6
- .intrinsic: fluid auto-fill groups of four minmax(--grid-col-min, 1fr)
7
- columns). Knobs: --grid-gap (or per-axis --grid-row-gap /
8
- --grid-column-gap), --grid-col-min for the intrinsic mode. */
4
+ @layer ds.components.apps {
5
+ .ds.content-layout {
6
+ /* Column templates and gaps come from the .grid presets in
7
+ @canonical/styles (.responsive: breakpoint-driven 4/8/12 columns;
8
+ .intrinsic: fluid auto-fill groups of four minmax(--grid-col-min, 1fr)
9
+ columns). Knobs: --grid-gap (or per-axis --grid-row-gap /
10
+ --grid-column-gap), --grid-col-min for the intrinsic mode. */
9
11
 
10
- /* Rows size to content; the grid grows downwards and scrolls in whatever
11
- region contains it (e.g. ViewLayout's content slot). */
12
- align-content: start;
12
+ /* Rows size to content; the grid grows downwards and scrolls in whatever
13
+ region contains it (e.g. ViewLayout's content slot). */
14
+ align-content: start;
15
+ }
13
16
  }
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useId, useState } from "react";
3
- import { Content, Footer, Header } from "./common/index.js";
2
+ import { useCallback, useEffect, useId, useState } from "react";
3
+ import { Content, ContextSwitcher, Footer, Header } from "./common/index.js";
4
+ import { useCollapseShortcut } from "./hooks/useCollapseShortcut/index.js";
4
5
  import "./styles.css";
5
6
  const componentCssClassName = "ds side-navigation";
6
7
  /**
@@ -9,23 +10,60 @@ const componentCssClassName = "ds side-navigation";
9
10
  * `defaultExpanded` — and wires the header's collapse toggle to the content
10
11
  * region it controls.
11
12
  *
13
+ * Four regions: Header (branding, collapse toggle), the optional
14
+ * ContextSwitcher region (a `role="menu"` select-like widget — not
15
+ * navigation, so it sits outside the landmark in a plain `<div>` between
16
+ * Header and Content; hidden when collapsed, where labels are unviable),
17
+ * Content (the main `<nav>` landmark) and Footer (user profile, settings
18
+ * and non-navigational actions). The root element is a plain `<div>` and
19
+ * the component's single *navigation* landmark is Content's `<nav>`, so
20
+ * screen readers announce exactly one navigation region; the regions
21
+ * themselves are `<header>`/`<footer>` elements, which additionally
22
+ * expose banner/contentinfo landmarks. `aria-label` is forwarded to the
23
+ * `<nav>` and defaults to `"Main navigation"`.
24
+ *
25
+ * A visually hidden "Skip to main content" link is the first element in the
26
+ * component's DOM order, so keyboard users can bypass the navigation block;
27
+ * target it with `skipTo` (default `"#main-content"`).
28
+ *
12
29
  * Routing-agnostic: navigable items render via `LinkComponent` (default `"a"`);
13
30
  * pass a router `Link` to integrate client-side navigation. The active item is
14
31
  * resolved from `currentUrl`.
15
32
  *
33
+ * Consumption pattern: data-driven only. Pass props and all four regions
34
+ * build; row-level and region components are private
35
+ * (`cs:react.component.subcomponent_export_api` — no dot-static exports),
36
+ * and render exclusively from data.
37
+ *
16
38
  * @implements ds:apps.pattern.side-navigation
17
39
  */
18
- const SideNavigation = ({ className, brand, applicationName, root, footerRoot, LinkComponent = "a", currentUrl,
40
+ const SideNavigation = ({ className, brand, applicationName, root, contextSwitcher, footerRoot, LinkComponent = "a", currentUrl, skipTo = "#main-content",
19
41
  // Controlled circuit — not official yet.
20
42
  // expanded: expandedProp,
21
- defaultExpanded = true,
43
+ defaultExpanded: defaultExpandedProp,
22
44
  // onExpandedChange,
23
- ...props }) => {
45
+ keyboardShortcut = true, "aria-label": ariaLabel, ...props }) => {
24
46
  const contentId = useId();
25
- const [expanded, setExpanded] = useState(defaultExpanded);
47
+ const [expanded, setExpanded] = useState(defaultExpandedProp ?? true);
48
+ // Mobile seed: below the small breakpoint, the
49
+ // expanded state renders as a fullscreen fixed overlay — a takeover, not a
50
+ // rail — so with `defaultExpanded` left unset (desktop default `true`), a
51
+ // small viewport collapses the rail after mount instead. An explicit
52
+ // `defaultExpanded` always wins, on every viewport. Post-mount on purpose:
53
+ // the server cannot know the viewport, so SSR/hydration stay pure — the
54
+ // cost is one frame of the expanded rail on a phone before the flip.
55
+ useEffect(() => {
56
+ if (defaultExpandedProp !== undefined)
57
+ return;
58
+ if (window.matchMedia("(width < 620px)").matches)
59
+ setExpanded(false);
60
+ }, [defaultExpandedProp]);
26
61
  const handleToggle = useCallback(() => {
27
62
  setExpanded((current) => !current);
28
63
  }, []);
64
+ // Ctrl+B rail-collapse shortcut — on unless
65
+ // `keyboardShortcut` opts out. See hooks/useCollapseShortcut.
66
+ useCollapseShortcut({ condition: keyboardShortcut, onTrigger: handleToggle });
29
67
  // --- Controlled circuit (not official yet) -------------------------------
30
68
  // const [uncontrolledExpanded, setUncontrolledExpanded] =
31
69
  // useState(defaultExpanded);
@@ -38,9 +76,13 @@ defaultExpanded = true,
38
76
  // onExpandedChange?.(next);
39
77
  // }, [expanded, isControlled, onExpandedChange]);
40
78
  // -------------------------------------------------------------------------
41
- return (_jsxs("div", { className: [componentCssClassName, !expanded && "collapsed", className]
42
- .filter(Boolean)
43
- .join(" "), "data-expanded": expanded, ...props, children: [_jsx(Header, { brand: brand, applicationName: applicationName, expanded: expanded, onToggle: handleToggle, collapseControls: contentId }), _jsx(Content, { id: contentId, root: root, LinkComponent: LinkComponent, currentUrl: currentUrl }), footerRoot && (_jsx(Footer, { root: footerRoot, LinkComponent: LinkComponent, currentUrl: currentUrl }))] }));
79
+ return (_jsxs("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), "data-expanded": expanded, ...props, children: [_jsx("a", { className: "skip-link", href: skipTo, children: "Skip to main content" }), _jsx(Header, { brand: brand, applicationName: applicationName, expanded: expanded, onToggle: handleToggle, collapseControls: contentId }), contextSwitcher ? (
80
+ // Own plain <div> region — a select-like widget is not navigation,
81
+ // so it sits outside the <nav> landmark. Hidden when collapsed:
82
+ // its rows are label-driven, unviable icon-only (the collapsed CSS
83
+ // hides the region via the root's data-expanded, so the region
84
+ // carries no state of its own).
85
+ _jsx("div", { className: "ds side-navigation-context-switcher-region", children: _jsx(ContextSwitcher, { ...contextSwitcher }) })) : null, _jsx(Content, { id: contentId, root: root, LinkComponent: LinkComponent, currentUrl: currentUrl, "aria-label": ariaLabel ?? "Main navigation" }), footerRoot ? (_jsx(Footer, { root: footerRoot, LinkComponent: LinkComponent, currentUrl: currentUrl })) : null] }));
44
86
  };
45
87
  export default SideNavigation;
46
88
  //# sourceMappingURL=SideNavigation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SideNavigation.js","sourceRoot":"","sources":["../../../../src/lib/SideNavigation/SideNavigation.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,KAAK,EACL,eAAe,EACf,IAAI,EACJ,UAAU,EACV,aAAa,GAAG,GAAG,EACnB,UAAU;AACV,yCAAyC;AACzC,0BAA0B;AAC1B,eAAe,GAAG,IAAI;AACtB,oBAAoB;AACpB,GAAG,KAAK,EACY,EAAsB,EAAE;IAC5C,MAAM,SAAS,GAAG,KAAK,EAAE,CAAC;IAE1B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,CAAC;IAE1D,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;QACpC,WAAW,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,4EAA4E;IAC5E,0DAA0D;IAC1D,+BAA+B;IAC/B,mDAAmD;IACnD,uEAAuE;IACvE,EAAE;IACF,2CAA2C;IAC3C,4BAA4B;IAC5B,sDAAsD;IACtD,8BAA8B;IAC9B,kDAAkD;IAClD,4EAA4E;IAE5E,OAAO,CACL,eACE,SAAS,EAAE,CAAC,qBAAqB,EAAE,CAAC,QAAQ,IAAI,WAAW,EAAE,SAAS,CAAC;aACpE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,mBACG,QAAQ,KACnB,KAAK,aAET,KAAC,MAAM,IACL,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,SAAS,GAC3B,EACF,KAAC,OAAO,IACN,EAAE,EAAE,SAAS,EACb,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,GACtB,EACD,UAAU,IAAI,CACb,KAAC,MAAM,IACL,IAAI,EAAE,UAAU,EAChB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,GACtB,CACH,IACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"SideNavigation.js","sourceRoot":"","sources":["../../../../src/lib/SideNavigation/SideNavigation.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAE3E,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,KAAK,EACL,eAAe,EACf,IAAI,EACJ,eAAe,EACf,UAAU,EACV,aAAa,GAAG,GAAG,EACnB,UAAU,EACV,MAAM,GAAG,eAAe;AACxB,yCAAyC;AACzC,0BAA0B;AAC1B,eAAe,EAAE,mBAAmB;AACpC,oBAAoB;AACpB,gBAAgB,GAAG,IAA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K,EAAE,KAAK,EACZ,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,YAAY,EACtB,gBAAgB,EAAE,SAAS,GAC3B,EACD,eAAe,CAAC,CAAC,CAAC;YACjB,mEAAmE;YACnE,gEAAgE;YAChE,mEAAmE;YACnE,+DAA+D;YAC/D,gCAAgC;YAChC,cAAK,SAAS,EAAC,4CAA4C,YACzD,KAAC,eAAe,OAAK,eAAe,GAAI,GACpC,CACP,CAAC,CAAC,CAAC,IAAI,EACR,KAAC,OAAO,IACN,EAAE,EAAE,SAAS,EACb,IAAI,EAAE,IAAI,EACV,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,gBACV,SAAS,IAAI,iBAAiB,GAC1C,EACD,UAAU,CAAC,CAAC,CAAC,CACZ,KAAC,MAAM,IACL,IAAI,EAAE,UAAU,EAChB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,GACtB,CACH,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,17 +1,25 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Icon } from "@canonical/react-ds-global";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Icon, TooltipEngine } from "@canonical/react-ds-global";
3
3
  import "./styles.css";
4
4
  const componentCssClassName = "ds collapse-toggle";
5
+ const CollapseToggleButton = ({ className, expanded = true, "aria-label": ariaLabel, ...props }) => {
6
+ return (_jsxs("button", { className: [componentCssClassName, className].filter(Boolean).join(" "), "aria-expanded": expanded, "aria-label": ariaLabel ?? (expanded ? "Collapse navigation" : "Expand navigation"), ...props, type: "button", children: [_jsx(Icon, { icon: expanded ? "collapse-side-nav" : "expand-side-nav" }), _jsx("span", { className: "p", children: expanded ? "Close menu" : "Menu" })] }));
7
+ };
5
8
  /**
6
9
  * SideNavigation.CollapseToggle — icon-only button that expands or collapses
7
10
  * the navigation rail. Carries the disclosure ARIA contract: `aria-expanded`
8
11
  * reflects the current state and `aria-controls` should point at the id of the
9
- * navigation region it toggles.
12
+ * navigation region it toggles. Hovering for 1s shows a tooltip naming the
13
+ * action ("Collapse"/"Expand"); the `<button>`'s own
14
+ * `aria-label` carries the fuller "Collapse/Expand navigation" text.
15
+ *
16
+ * Rendered through `TooltipEngine` (not `withTooltip`) so the tooltip's
17
+ * message follows the `expanded` prop as a live prop: one stable element
18
+ * type across state changes, so the button — and with it keyboard focus
19
+ * and hover state — survives every toggle instead of remounting.
10
20
  *
11
21
  * @implements ds:apps.subcomponent.side-navigation-collapse-toggle
12
22
  */
13
- const CollapseToggle = ({ className, expanded = true, "aria-label": ariaLabel, ...props }) => {
14
- return (_jsx("button", { type: "button", className: [componentCssClassName, className].filter(Boolean).join(" "), "aria-expanded": expanded, "aria-label": ariaLabel ?? (expanded ? "Collapse navigation" : "Expand navigation"), ...props, children: _jsx(Icon, { icon: expanded ? "collapse-side-nav" : "expand-side-nav" }) }));
15
- };
23
+ const CollapseToggle = ({ expanded = true, ...props }) => (_jsx(TooltipEngine, { Message: expanded ? "Collapse" : "Expand", activateDelay: 1000, children: _jsx(CollapseToggleButton, { expanded: expanded, ...props }) }));
16
24
  export default CollapseToggle;
17
25
  //# sourceMappingURL=CollapseToggle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CollapseToggle.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/CollapseToggle/CollapseToggle.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGlD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,QAAQ,GAAG,IAAI,EACf,YAAY,EAAE,SAAS,EACvB,GAAG,KAAK,EACY,EAAsB,EAAE;IAC5C,OAAO,CAC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C,CAAC,CAAC,MAAM,GAAQ,IACtD,CACV,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,cAAc,GAAG,CAAC,EACtB,QAAQ,GAAG,IAAI,EACf,GAAG,KAAK,EACY,EAAsB,EAAE,CAAC,CAC7C,KAAC,aAAa,IACZ,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,EACzC,aAAa,EAAE,IAAI,YAEnB,KAAC,oBAAoB,IAAC,QAAQ,EAAE,QAAQ,KAAM,KAAK,GAAI,GACzC,CACjB,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,5 +1,54 @@
1
- /* Generated by @canonical/summon-component:react v0.1.0 */
1
+ /* Generated by @canonical/summon-component:react v0.1.0
2
+ * Layer: ds.components.apps (@canonical/styles README, "Cascade layers"). */
3
+ @layer ds.components.apps {
4
+ .ds.collapse-toggle {
5
+ display: flex;
6
+ align-items: center;
7
+ justify-content: center;
2
8
 
3
- .ds.collapse-toggle {
4
- /* Component styles */
9
+ /* size matches collapse icons */
10
+ inline-size: calc(var(--dimension-400) + var(--dimension-050));
11
+ block-size: var(--dimension-400);
12
+
13
+ border: none;
14
+ border-radius: var(--dimension-radius-small);
15
+ background: transparent;
16
+ color: var(--color-icon);
17
+ cursor: pointer;
18
+
19
+ /* The hover/press background swap is instant by design — no
20
+ `transition` property here. */
21
+ &:hover {
22
+ background: var(--sidenav-row-background-hover);
23
+ }
24
+
25
+ &:active {
26
+ background: var(--sidenav-row-background-active);
27
+ }
28
+
29
+ /* Icon (desktop) vs "Menu"/"Close menu" text (mobile) — plain CSS-toggled
30
+ siblings, not a JS media-query read, so the choice needs no client-only
31
+ branch and stays SSR-identical. The button's only two children are the
32
+ icon svg and the label span, so the two select directly. */
33
+ & span {
34
+ display: none;
35
+ }
36
+
37
+ /* Vanilla's "small" breakpoint — $breakpoint-small, 620px. */
38
+ @media (width < 620px) {
39
+ & svg {
40
+ display: none;
41
+ }
42
+
43
+ & span {
44
+ display: inline;
45
+ }
46
+
47
+ /* No longer an icon-only square — a text button sized to its content. */
48
+ inline-size: auto;
49
+ block-size: auto;
50
+ padding-block: var(--sidenav-icon-gap); /* 0.5rem */
51
+ padding-inline: var(--sidenav-inset-inline); /* 0.5rem */
52
+ }
53
+ }
5
54
  }
@@ -3,14 +3,18 @@ import { NavTree } from "../NavTree/index.js";
3
3
  import "./styles.css";
4
4
  const componentCssClassName = "ds content";
5
5
  /**
6
- * SideNavigation.Content — main navigation region. Renders the direct children
7
- * of its `root` Item via useNavigationTree (selection, active state, keyboard
8
- * traversal). Falls back to `children` when no `root` is given.
6
+ * SideNavigation.Content — the component's main `<nav>` landmark, and the
7
+ * only one: navigation rows are links and expandable items exclusively
8
+ * (actions are Footer's job). Data-only — rows render exclusively from the
9
+ * `root` tree (row components are private; there is no children escape
10
+ * hatch into the landmark). `aria-label` defaults to `"Main navigation"`
11
+ * and may be overridden by the consumer; with no `root`, the landmark
12
+ * renders empty (the landmark contract stays stable).
9
13
  *
10
14
  * @implements ds:apps.subcomponent.side-navigation-content
11
15
  */
12
- const Content = ({ className, root, LinkComponent = "a", currentUrl, children, ...props }) => {
13
- return (_jsx("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), ...props, children: root ? (_jsx(NavTree, { root: root, currentUrl: currentUrl, LinkComponent: LinkComponent })) : (children) }));
16
+ const Content = ({ className, root, LinkComponent = "a", currentUrl, ...props }) => {
17
+ return (_jsx("nav", { className: [componentCssClassName, className].filter(Boolean).join(" "), ...props, children: root ? (_jsx(NavTree, { root: root, currentUrl: currentUrl, LinkComponent: LinkComponent })) : null }));
14
18
  };
15
19
  export default Content;
16
20
  //# sourceMappingURL=Content.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Content.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/Content/Content.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,OAAO,GAAG,CAAC,EACf,SAAS,EACT,IAAI,EACJ,aAAa,GAAG,GAAG,EACnB,UAAU,EACV,QAAQ,EACR,GAAG,KAAK,EACK,EAAsB,EAAE;IACrC,OAAO,CACL,cACE,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KACnE,KAAK,YAER,IAAI,CAAC,CAAC,CAAC,CACN,KAAC,OAAO,IACN,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,GAC5B,CACH,CAAC,CAAC,CAAC,CACF,QAAQ,CACT,GACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"Content.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/Content/Content.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,GAAG,CAAC,EACf,SAAS,EACT,IAAI,EACJ,aAAa,GAAG,GAAG,EACnB,UAAU,EACV,GAAG,KAAK,EACK,EAAsB,EAAE;IACrC,OAAO,CACL,cACE,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KACnE,KAAK,YAER,IAAI,CAAC,CAAC,CAAC,CACN,KAAC,OAAO,IACN,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,GAC5B,CACH,CAAC,CAAC,CAAC,IAAI,GACJ,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -1,33 +1,60 @@
1
- /* Generated by @canonical/summon-component:react v0.1.0 */
1
+ /* Generated by @canonical/summon-component:react v0.1.0
2
+ * Layer: ds.components.apps (@canonical/styles README, "Cascade layers"). */
3
+ @layer ds.components.apps {
4
+ .ds.content {
5
+ position: relative;
6
+ flex: 1;
7
+ display: flex;
8
+ flex-direction: column;
9
+ gap: var(--dimension-100);
10
+ min-height: 0;
11
+ overflow: hidden auto;
12
+ container-type: scroll-state;
2
13
 
3
- .ds.content {
4
- position: relative;
5
- flex: 1;
6
- /* min-height:0 lets this flex item shrink below its content height so it can
7
- scroll internally (flex items default to min-height:auto, which refuses to
8
- shrink and would push the whole nav taller instead). Vertical scroll only;
9
- never horizontal (long labels must not cause sideways scroll). */
10
- min-height: 0;
11
- overflow: hidden auto;
14
+ scrollbar-width: none;
15
+ &::-webkit-scrollbar {
16
+ display: none;
17
+ }
12
18
 
13
- /* Tree structure (.group/.header/.list) is owned by NavTree's own styles.
14
- Content only reserves room for the overflow fade so the last item of the
15
- last group is never permanently hidden behind it. */
16
- & .nav-tree > .group:last-child > .list {
17
- padding-block-end: var(--overflow-gradient-height);
18
- }
19
+ &::before,
20
+ &::after {
21
+ content: none;
22
+ }
23
+
24
+ @container scroll-state(scrollable: top) {
25
+ &::before {
26
+ content: "";
27
+ position: sticky;
28
+ top: 0;
29
+ display: block;
30
+ block-size: var(--overflow-gradient-height);
31
+ margin-block-end: calc(-1 * var(--overflow-gradient-height));
32
+ background: linear-gradient(
33
+ to bottom,
34
+ var(--color-foreground-navigation-primary),
35
+ transparent
36
+ );
37
+ pointer-events: none;
38
+ flex: 0 0 auto;
39
+ }
40
+ }
19
41
 
20
- /* Overflow fade: a sticky bar pinned to the bottom of the scroll viewport,
21
- painting the surface-aware gradient over content scrolling underneath. */
22
- &::after {
23
- content: "";
24
- position: sticky;
25
- bottom: 0;
26
- display: block;
27
- block-size: var(--overflow-gradient-height);
28
- /* Pull the bar back over the reserved padding so it overlays content. */
29
- margin-block-start: calc(-1 * var(--overflow-gradient-height));
30
- background: var(--surface-overflow-gradient);
31
- pointer-events: none;
42
+ @container scroll-state(scrollable: bottom) {
43
+ &::after {
44
+ content: "";
45
+ position: sticky;
46
+ bottom: 0;
47
+ display: block;
48
+ block-size: var(--overflow-gradient-height);
49
+ margin-block-start: calc(-1 * var(--overflow-gradient-height));
50
+ background: linear-gradient(
51
+ to bottom,
52
+ transparent,
53
+ var(--color-foreground-navigation-primary)
54
+ );
55
+ pointer-events: none;
56
+ flex: 0 0 auto;
57
+ }
58
+ }
32
59
  }
33
60
  }
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ContextualMenu, Icon } from "@canonical/react-ds-global";
3
+ import { GroupHeader } from "../GroupHeader/index.js";
4
+ import "./styles.css";
5
+ const componentCssClassName = "ds side-navigation-context-switcher";
6
+ /**
7
+ * A context or "create context" entry — see {@link ContextMenuItem}.
8
+ */
9
+ const ContextItemContent = ({ item, }) => {
10
+ const { description, badge, isCurrent, renderLabel } = item;
11
+ // The "create context" action: a plain icon + label row.
12
+ if (renderLabel != null) {
13
+ return (_jsxs("span", { className: "create-context", children: [_jsx(Icon, { icon: "plus" }), _jsx("span", { className: "label", children: renderLabel })] }));
14
+ }
15
+ return (_jsxs("span", { className: ["content", isCurrent && "current"].filter(Boolean).join(" "), children: [_jsx("span", { className: "name", children: item.label }), description ? _jsx("span", { className: "description", children: description }) : null, badge ? _jsx("span", { className: "badge", children: badge }) : null] }));
16
+ };
17
+ /**
18
+ * SideNavigation.ContextSwitcher — a dropdown for products that divide
19
+ * into contexts, projects, users, or similar. Renders via
20
+ * `ContextualMenu`: a real `<button>` trigger
21
+ * (`aria-haspopup="menu"`/`aria-expanded`) and a `role="menu"` popup with
22
+ * full roving-focus keyboard navigation. `title`, when given, renders via
23
+ * `SideNavigation.GroupHeader` as a sibling above the dropdown field.
24
+ *
25
+ * Not part of the `NavRoot`/`NavGroup` content-tree data model — its
26
+ * position is content-defined: compose this component directly where
27
+ * the consumer wants it. See SPEC.md's known issues.
28
+ *
29
+ * @implements ds:apps.subcomponent.side-navigation-context-switcher
30
+ */
31
+ const ContextSwitcher = ({ title, currentContext, contexts, onContextChange, onCreateContext, createContextLabel = "Create context", className, open, onOpenChange, preferredDirections, distance, gutter, maxWidth, autoFit, ...props }) => {
32
+ const contextItems = contexts.map((context) => ({
33
+ key: context.key,
34
+ label: context.name,
35
+ description: context.description,
36
+ badge: context.badge,
37
+ isCurrent: context.key === currentContext.key,
38
+ displayItemsType: "custom",
39
+ Component: ContextItemContent,
40
+ }));
41
+ const items = contextItems;
42
+ if (onCreateContext) {
43
+ const createContextItem = {
44
+ key: "create-context",
45
+ // A plain string for type-ahead bookkeeping — the visible (possibly
46
+ // rich) content renders via `renderLabel` in ContextItemContent.
47
+ label: typeof createContextLabel === "string"
48
+ ? createContextLabel
49
+ : "Create context",
50
+ renderLabel: createContextLabel,
51
+ displayItemsType: "custom",
52
+ Component: ContextItemContent,
53
+ };
54
+ items.push({ type: "separator", key: "create-context-separator" });
55
+ items.push(createContextItem);
56
+ }
57
+ const handleSelect = (item) => {
58
+ if (item.key === "create-context") {
59
+ onCreateContext?.();
60
+ return;
61
+ }
62
+ const context = contexts.find((candidate) => candidate.key === item.key);
63
+ if (context)
64
+ onContextChange?.(context);
65
+ };
66
+ return (_jsxs("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), ...props, children: [title != null && _jsx(GroupHeader, { children: title }), _jsx(ContextualMenu, { open: open, onOpenChange: onOpenChange, preferredDirections: preferredDirections, distance: distance, gutter: gutter, maxWidth: maxWidth ??
67
+ "calc(var(--sidenav-rail-inline-size) - 2 * var(--sidenav-inset-inline))", autoFit: autoFit, items: items, onSelect: handleSelect, children: _jsxs("span", { className: "row", children: [_jsx("span", { className: "label", children: currentContext.name }), _jsx(Icon, { icon: "chevron-down", className: "end caret" })] }) })] }));
68
+ };
69
+ export default ContextSwitcher;
70
+ //# sourceMappingURL=ContextSwitcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextSwitcher.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,qCAAqC,CAAC;AAiBpE;;GAEG;AACH,MAAM,kBAAkB,GAAG,CAAC,EAC1B,IAAI,GAGL,EAAsB,EAAE;IACvB,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,GAClD,IAAuB,CAAC;IAE1B,yDAAyD;IACzD,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,OAAO,CACL,gBAAM,SAAS,EAAC,gBAAgB,aAC9B,KAAC,IAAI,IAAC,IAAI,EAAC,MAAM,GAAG,EACpB,eAAM,SAAS,EAAC,OAAO,YAAE,WAAW,GAAQ,IACvC,CACR,CAAC;IACJ,CAAC;IAED,OAAO,CACL,gBACE,SAAS,EAAE,CAAC,SAAS,EAAE,SAAS,IAAI,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aAExE,eAAM,SAAS,EAAC,MAAM,YAAE,IAAI,CAAC,KAAK,GAAQ,EACzC,WAAW,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,aAAa,YAAE,WAAW,GAAQ,CAAC,CAAC,CAAC,IAAI,EACvE,KAAK,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,OAAO,YAAE,KAAK,GAAQ,CAAC,CAAC,CAAC,IAAI,IACjD,CACR,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,eAAe,GAA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,CAAC;YACpB,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC;QACzE,IAAI,OAAO;YAAE,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC;IAEF,OAAO,CACL,eACE,SAAS,EAAE,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KACnE,KAAK,aAER,KAAK,IAAI,IAAI,IAAI,KAAC,WAAW,cAAE,KAAK,GAAe,EACpD,KAAC,cAAc,IACb,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,mBAAmB,EAAE,mBAAmB,EACxC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EACN,QAAQ;oBACR,yEAAyE,EAE3E,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,YAEtB,gBAAM,SAAS,EAAC,KAAK,aACnB,eAAM,SAAS,EAAC,OAAO,YAAE,cAAc,CAAC,IAAI,GAAQ,EACpD,KAAC,IAAI,IAAC,IAAI,EAAC,cAAc,EAAC,SAAS,EAAC,WAAW,GAAG,IAC7C,GACQ,IACb,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as ContextSwitcher } from "./ContextSwitcher.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/ContextSwitcher/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,94 @@
1
+ /* Generated by @canonical/summon-component:react v0.1.0
2
+ * Layer: ds.components.apps (@canonical/styles README, "Cascade layers"). */
3
+ @layer ds.components.apps {
4
+ .ds.side-navigation-context-switcher {
5
+ display: block;
6
+
7
+ /* ContextualMenu's own root — the dropdown field fills the wrapper
8
+ (its inline-block default is for inline placements; the rail is a
9
+ block column). */
10
+ & > .ds.contextual-menu {
11
+ display: block;
12
+ height: var(--dimension-400);
13
+
14
+ & > .trigger {
15
+ height: 100%;
16
+ display: grid;
17
+ grid-template-columns: 1fr auto;
18
+ align-items: center;
19
+ width: 100%;
20
+ padding-block: var(--sidenav-icon-gap);
21
+ padding-inline: var(--sidenav-icon-gap);
22
+ box-sizing: border-box;
23
+ color: var(--color-text);
24
+ background: var(--color-foreground-input);
25
+ border: none;
26
+ border-block-end: var(--dimension-stroke-thickness-medium) solid
27
+ var(--color-border);
28
+ cursor: pointer;
29
+
30
+ &:hover {
31
+ background: var(--color-foreground-input-hover);
32
+ }
33
+
34
+ & > .row {
35
+ display: flex;
36
+ align-items: center;
37
+ justify-content: space-between;
38
+ gap: var(--sidenav-icon-gap);
39
+ width: 100%;
40
+ }
41
+ }
42
+ }
43
+
44
+ & .label {
45
+ min-width: 0;
46
+ overflow: hidden;
47
+ text-overflow: ellipsis;
48
+ white-space: nowrap;
49
+ }
50
+
51
+ & .end.caret {
52
+ display: flex;
53
+ align-items: center;
54
+ color: var(--color-icon);
55
+ flex-shrink: 0;
56
+ }
57
+ }
58
+
59
+ .ds.contextual-menu-item {
60
+ /* The portaled menu items are styled structurally — this sheet's layer
61
+ (ds.components.apps) outranks the item's own (ds.components.global)
62
+ at equal specificity. Both classes are emitted only by this
63
+ component's renderer, so no other ContextualMenu on the page is
64
+ affected. */
65
+ /* A context: name + optional description + optional badge. */
66
+ & .content {
67
+ display: flex;
68
+ flex-direction: column;
69
+ align-items: flex-start;
70
+ width: 100%;
71
+ gap: var(--dimension-025);
72
+
73
+ & .description {
74
+ color: var(--color-text-muted);
75
+ font-size: var(--typography-text-secondary-font-size);
76
+ }
77
+
78
+ & .badge {
79
+ position: absolute;
80
+ align-self: flex-end;
81
+ }
82
+ &.current .name {
83
+ font-weight: var(--typography-weight-medium);
84
+ }
85
+ }
86
+
87
+ /* The "create context" action: an icon + label row. */
88
+ & .create-context {
89
+ display: flex;
90
+ align-items: center;
91
+ gap: var(--dimension-100);
92
+ }
93
+ }
94
+ }