@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
@@ -0,0 +1,79 @@
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-item-button {
5
+ display: flex;
6
+ align-items: center;
7
+ justify-content: center;
8
+ list-style: none;
9
+ height: var(--dimension-400);
10
+
11
+ /* The row: identical geometry to SideNavigation.Item's row (shares the
12
+ insets/gap/icon-column tokens so icons line up down the rail), but a
13
+ real <button> — native `:disabled`/`:hover`/`:active` apply directly,
14
+ no `data-disabled` attribute needed (cs:css.component.states: native
15
+ states via attribute/pseudo-class selectors). */
16
+ & > .row {
17
+ display: grid;
18
+ grid-template-columns: var(--sidenav-icon-column-inline-size) 1fr auto;
19
+ align-items: center;
20
+ gap: var(--sidenav-icon-gap); /* 0.5rem */
21
+ width: 100%;
22
+ height: 100%;
23
+ padding-inline: var(--sidenav-inset-inline); /* 0.5rem */
24
+ box-sizing: border-box;
25
+ border: none;
26
+ background: var(--sidenav-row-background);
27
+ color: var(--color-text);
28
+ font: inherit;
29
+ text-align: start;
30
+ cursor: pointer;
31
+
32
+ &:hover {
33
+ background: var(--sidenav-row-background-hover);
34
+ }
35
+
36
+ &:active {
37
+ background: var(--sidenav-row-background-active);
38
+ }
39
+
40
+ &:focus-visible {
41
+ outline: 2px solid currentColor;
42
+ outline-offset: -2px;
43
+ }
44
+
45
+ &:disabled {
46
+ color: var(--color-text-disabled);
47
+ background: var(--sidenav-row-background-disabled);
48
+ cursor: default;
49
+ }
50
+ }
51
+
52
+ & .start {
53
+ display: flex;
54
+ align-items: center;
55
+ justify-content: center;
56
+ color: var(--color-icon);
57
+ width: var(--dimension-250);
58
+ height: var(--dimension-250);
59
+ }
60
+
61
+ & > .row:disabled .start {
62
+ color: var(--color-icon-disabled);
63
+ }
64
+
65
+ /* Item labels are single-line and truncate. */
66
+ & .label {
67
+ min-width: 0;
68
+ overflow: hidden;
69
+ text-overflow: ellipsis;
70
+ white-space: nowrap;
71
+ }
72
+
73
+ & .end {
74
+ display: flex;
75
+ align-items: center;
76
+ justify-content: center;
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/ItemButton/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Icon } from "@canonical/react-ds-global";
3
+ import { useCallback, useEffect, useId, useRef } from "react";
4
+ import "./styles.css";
5
+ const componentCssClassName = "ds side-navigation-item-expandable";
6
+ /**
7
+ * SideNavigation.ItemExpandable — a collapsible row that discloses its own
8
+ * (always-leaf) children instead of navigating. Native
9
+ * `<details>`/`<summary>` — no `role`/`aria-expanded` authored, per
10
+ * `cs:ui_blocks.nojs.disclosure`; the element owns its own open state.
11
+ * `heading` and `children` are composed, not string props — matching
12
+ * `Accordion.Item`'s own split.
13
+ *
14
+ * `defaultExpanded` seeds the initial state (NavTree supplies it from the
15
+ * tree's own state: whether this node's branch is the selected one) and is
16
+ * live in one direction only: when it turns `true` on navigation the
17
+ * disclosure re-opens — a manual collapse stays collapsed and the
18
+ * disclosure never auto-closes.
19
+ *
20
+ * `collapseOnChildClick` is the Footer's opt-in: activating a leaf row
21
+ * among the `children` collapses the disclosure. The content tree does not
22
+ * opt in: its branch stays open so the active row remains visible.
23
+ *
24
+ * @implements ds:apps.subcomponent.side-navigation-item-expandable
25
+ */
26
+ const ItemExpandable = ({ heading, icon, disabled = false, defaultExpanded = false, collapseOnChildClick = false, children, className, ...props }) => {
27
+ // Uncontrolled: the <details> owns its open state and React never
28
+ // re-asserts it. The attribute is seeded from a mount-only snapshot of
29
+ // `defaultExpanded` — not the live prop, so a seed flipping back to false
30
+ // never force-closes an open disclosure — and the two imperative
31
+ // behaviours below reach the DOM through the ref.
32
+ const detailsRef = useRef(null);
33
+ const initialExpanded = useRef(defaultExpanded).current;
34
+ // One-way re-open: navigation making this branch the selected one flips
35
+ // the seed true, and the disclosure re-opens. Manual collapses stay
36
+ // collapsed; the disclosure never auto-closes.
37
+ useEffect(() => {
38
+ const details = detailsRef.current;
39
+ if (defaultExpanded && details && !details.open) {
40
+ details.open = true;
41
+ }
42
+ }, [defaultExpanded]);
43
+ // Guards the CLICK, not the toggle: the native `toggle` event isn't
44
+ // cancelable, and preventing the summary's default stops the disclosure
45
+ // toggling at all.
46
+ const handleSummaryClick = useCallback((event) => {
47
+ if (disabled)
48
+ event.preventDefault();
49
+ }, [disabled]);
50
+ // Footer opt-in (`collapseOnChildClick`): activating a child link or
51
+ // button row collapses the disclosure (the summary has neither, so it is
52
+ // excluded by the closest() check). Delegated on the list so the row
53
+ // components stay unaware of their disclosure parent.
54
+ const handleChildrenClick = useCallback((event) => {
55
+ const details = detailsRef.current;
56
+ if (collapseOnChildClick &&
57
+ details &&
58
+ event.target.closest("a, button")) {
59
+ details.open = false;
60
+ }
61
+ }, [collapseOnChildClick]);
62
+ // Unique per instance and ident-safe (useId may contain ":" on older
63
+ // React). Wires the collapsed-rail popover's CSS anchor positioning: the
64
+ // summary anchors, the panel positions against it, and the browser flips
65
+ // it on overflow (`position-try-fallbacks` in styles.css) — no
66
+ // measurement JS.
67
+ const anchorName = `--sidenav-expandable-${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
68
+ return (_jsx("li", { className: [componentCssClassName, className].filter(Boolean).join(" "), "data-disabled": disabled || undefined, ...props, children: _jsxs("details", { className: "details", ref: detailsRef, open: initialExpanded || undefined, children: [_jsxs("summary", { className: "row", onClick: handleSummaryClick, style: { anchorName }, children: [_jsx("span", { className: "start", children: icon ? _jsx(Icon, { width: 16, height: 16, icon: icon }) : null }), _jsx("span", { className: "label", title: typeof heading === "string" ? heading : undefined, children: heading }), _jsx(Icon, { icon: "chevron-down", className: "end caret" })] }), _jsx("ul", { className: "children", onClick: handleChildrenClick, style: { positionAnchor: anchorName }, children: children })] }) }));
69
+ };
70
+ export default ItemExpandable;
71
+ //# sourceMappingURL=ItemExpandable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ItemExpandable.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/ItemExpandable/ItemExpandable.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,oCAAoC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,cAAc,GAAG,CAAC,EACtB,OAAO,EACP,IAAI,EACJ,QAAQ,GAAG,KAAK,EAChB,eAAe,GAAG,KAAK,EACvB,oBAAoB,GAAG,KAAK,EAC5B,QAAQ,EACR,SAAS,EACT,GAAG,KAAK,EACY,EAAsB,EAAE;IAC5C,kEAAkE;IAClE,uEAAuE;IACvE,0EAA0E;IAC1E,iEAAiE;IACjE,kDAAkD;IAClD,MAAM,UAAU,GAAG,MAAM,CAAqB,IAAI,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC;IAExD,wEAAwE;IACxE,oEAAoE;IACpE,+CAA+C;IAC/C,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QACnC,IAAI,eAAe,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAChD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAEtB,oEAAoE;IACpE,wEAAwE;IACxE,mBAAmB;IACnB,MAAM,kBAAkB,GAAG,WAAW,CACpC,CAAC,KAAoC,EAAE,EAAE;QACvC,IAAI,QAAQ;YAAE,KAAK,CAAC,cAAc,EAAE,CAAC;IACvC,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAA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,IAAI,EAAC,cAAc,EAAC,SAAS,EAAC,WAAW,GAAG,IAC1C,EAIV,aACE,SAAS,EAAC,UAAU,EACpB,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,YAEpC,QAAQ,GACN,IACG,GACP,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as ItemExpandable } from "./ItemExpandable.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/ItemExpandable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,121 @@
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-item-expandable {
5
+ list-style: none;
6
+
7
+ & > .details {
8
+ /* Reset the native disclosure marker — the row supplies its own chevron. */
9
+ & > summary {
10
+ list-style: none;
11
+
12
+ &::-webkit-details-marker {
13
+ display: none;
14
+ }
15
+ }
16
+ }
17
+
18
+ /* The row: identical geometry to SideNavigation.Item's row (shares the
19
+ insets/gap/icon-column tokens so icons line up down the rail), but a
20
+ <summary> instead of a link/label. Its height is set directly here
21
+ (`--dimension-400`, matching the other row variants) rather than via
22
+ an outer wrapper's fixed height + `height: 100%`, the way those rows
23
+ do it — `.details`/the root `<li>` must stay auto-height here, to make
24
+ room for the disclosed `.children` list when open. */
25
+ & > .details > .row {
26
+ display: grid;
27
+ grid-template-columns: var(--sidenav-icon-column-inline-size) 1fr auto;
28
+ align-items: center;
29
+ gap: var(--sidenav-icon-gap); /* 0.5rem */
30
+ width: 100%;
31
+ height: var(--dimension-400);
32
+ padding-inline: var(--sidenav-inset-inline); /* 0.5rem */
33
+ box-sizing: border-box;
34
+ color: var(--color-text);
35
+ background: var(--sidenav-row-background);
36
+ cursor: pointer;
37
+ }
38
+
39
+ &:not([data-disabled]) > .details > .row {
40
+ &:hover {
41
+ background: var(--sidenav-row-background-hover);
42
+ }
43
+
44
+ &:active {
45
+ background: var(--sidenav-row-background-active);
46
+ }
47
+
48
+ &:focus-visible {
49
+ outline: 2px solid currentColor;
50
+ outline-offset: -2px;
51
+ }
52
+ }
53
+
54
+ &[data-disabled] > .details > .row {
55
+ color: var(--color-text-disabled);
56
+ background: var(--sidenav-row-background-disabled);
57
+ cursor: default;
58
+ }
59
+
60
+ & .start {
61
+ display: flex;
62
+ align-items: center;
63
+ justify-content: center;
64
+ color: var(--color-icon);
65
+ width: var(--dimension-250);
66
+ height: var(--dimension-250);
67
+ }
68
+
69
+ &[data-disabled] .start {
70
+ color: var(--color-icon-disabled);
71
+ }
72
+
73
+ /* Item labels are single-line and truncate. */
74
+ & .label {
75
+ min-width: 0;
76
+ overflow: hidden;
77
+ text-overflow: ellipsis;
78
+ white-space: nowrap;
79
+ }
80
+
81
+ /* Disclosure caret — rotates open. The rotation is animated;
82
+ it respects reduced motion — and the
83
+ motion tokens are zeroed under prefers-reduced-motion anyway
84
+ (@canonical/styles/motion.css), as is the rail's own width transition. */
85
+ & .end.caret {
86
+ display: flex;
87
+ align-items: center;
88
+ justify-content: center;
89
+ color: var(--color-icon);
90
+ }
91
+
92
+ &[data-disabled] .end.caret {
93
+ color: var(--color-icon-disabled);
94
+ }
95
+
96
+ & > .details[open] > .row > .end.caret {
97
+ transform: rotate(180deg);
98
+ }
99
+
100
+ @media (prefers-reduced-motion: no-preference) {
101
+ & .end.caret {
102
+ transition: transform var(--motion-duration-fast)
103
+ var(--motion-easing-standard);
104
+ }
105
+ }
106
+
107
+ /* Children — always leaves, indented past the parent's icon column so
108
+ they read as nested. */
109
+ & > .details > .children {
110
+ display: flex;
111
+ flex-direction: column;
112
+ list-style: none;
113
+ margin: 0;
114
+ padding: 0;
115
+
116
+ & .row {
117
+ margin-inline-start: var(--sidenav-icon-column-inline-size);
118
+ }
119
+ }
120
+ }
121
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/ItemExpandable/types.ts"],"names":[],"mappings":""}
@@ -1,25 +1,60 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { getItemId } from "@canonical/ds-utils";
2
3
  import { useNavigationTree } from "@canonical/react-hooks";
3
- import { getItemId } from "@canonical/utils";
4
- import { useEffect } from "react";
4
+ import { Fragment, useEffect } from "react";
5
+ import { Group } from "../Group/index.js";
5
6
  import { Item } from "../Item/index.js";
7
+ import { ItemExpandable } from "../ItemExpandable/index.js";
6
8
  import "./styles.css";
9
+ const componentCssClassName = "ds nav-tree";
7
10
  /**
8
- * Internal: renders a navigation tree with two explicit loops (no recursion),
9
- * deriving active state from useNavigationTree. Shared by Content and Footer —
10
- * each region drives its own hook instance over its own root.
11
- *
12
- * Loop 1 — level-1 groups: each direct child of the root is a group; its
13
- * label renders as a header (omitted when absent), wrapping its items.
14
- * Loop 2 — level-2 items: each child of a group maps to a (flat) Item.
15
- *
16
- * The hook is generic over NavItem, so `icon`/`slot` survive typed onto the
17
- * annotated nodes. `currentUrl` seeds initial selection and re-syncs it on
18
- * navigation (the hook's `initialUrl` is mount-only), so the active item stays
19
- * in sync with the consumer's router.
11
+ * A stable React key for a tree node. `getItemId` resolves `url` or `key`;
12
+ * the public `LeafNavItem` leaves both optional (one flat optional shape
13
+ * per row, not a discriminated identity union), so a label-only entry
14
+ * falls back to its `label`, then to its list index — a missing `key`
15
+ * must never surface as a missing React key.
20
16
  */
21
- const NavTree = ({ root, currentUrl, LinkComponent = "a", }) => {
22
- const nav = useNavigationTree({ root, initialUrl: currentUrl });
17
+ const stableKey = (node, index) => getItemId(node) ?? node.label ?? String(index);
18
+ /**
19
+ * Renders a single content-tree entry (never an expandable's own row — the
20
+ * caller renders that): a link (via `Item`) when `url` is set, otherwise a
21
+ * plain label — the content tree accepts nothing else; action buttons are
22
+ * Footer-only. Strips the tree-annotation fields (`_Item<T>`: `parentUrl`,
23
+ * `depth`) and the authored `key` — tree identity, applied as the element
24
+ * key (`stableKey`) above; React 19 rejects a `key` inside a spread —
25
+ * then spreads the rest onto `Item`, which consumes
26
+ * `url`/`slot`/`icon`/`disabled` itself. `label` is passed as `children`
27
+ * (Item composes via `children`, not a same-named prop).
28
+ */
29
+ const renderEntry = (entry, active, LinkComponent, index) => {
30
+ const { parentUrl: _parentUrl, depth: _depth, items: _items, key: _key, label, ...rest } = entry;
31
+ return (_jsx(Item, { ...rest, active: active, LinkComponent: LinkComponent, children: label }, stableKey(entry, index)));
32
+ };
33
+ /**
34
+ * Internal: renders the content tree with two explicit loops (no recursion)
35
+ * — loop 1 over root's `Group` children, loop 2 over a group's entries
36
+ * (leaf rows via `renderEntry`, or `ItemExpandable` for entries with
37
+ * `items`, whose always-leaf children render through the same
38
+ * `renderEntry`). Active/expanded state derives from `useNavigationTree`,
39
+ * generic over `_AnyNavNode` so every field stays typed on annotated nodes
40
+ * regardless of tier. `currentUrl` seeds initial
41
+ * selection and re-syncs it on navigation (the hook's `initialUrl` is
42
+ * mount-only), keeping the active item — and its `ItemExpandable`
43
+ * ancestors' open state (`inSelectedBranch`) — in sync with the consumer's
44
+ * router.
45
+ */
46
+ const NavTree = ({ root, currentUrl, LinkComponent = "a", className, ...props }) => {
47
+ // `LeafNavItem` keeps `key`/`url` both optional (one flat shape per row,
48
+ // no discriminated union) — looser than `_AnyNavNode`'s WD405 identity
49
+ // requirement, which the hook's `T extends Item` bound needs. The cast
50
+ // trusts that contract rather than tightening the public shape; a
51
+ // label-only entry with neither is safe at render level (element keys
52
+ // fall back via `stableKey`), and identity-bearing data is the
53
+ // documented contract (see `NavGroup.key`).
54
+ const nav = useNavigationTree({
55
+ root: root,
56
+ initialUrl: currentUrl,
57
+ });
23
58
  const { index, selectItem } = nav;
24
59
  useEffect(() => {
25
60
  if (currentUrl === undefined)
@@ -28,11 +63,18 @@ const NavTree = ({ root, currentUrl, LinkComponent = "a", }) => {
28
63
  if (match)
29
64
  selectItem(match);
30
65
  }, [currentUrl, index, selectItem]);
31
- const groups = nav.annotatedRoot.items ?? [];
32
- return (_jsx("div", { className: "ds nav-tree", children: groups.map((group) => {
33
- const groupId = getItemId(group);
34
- const items = group.items ?? [];
35
- return (_jsxs("section", { className: "group", "data-depth": group.depth, children: [group.label ? (_jsx("span", { className: "header p", children: group.label })) : null, _jsx("ul", { className: "list", children: items.map((item) => (_jsx(Item, { ...item, active: nav.getNodeStatus(item).selected, LinkComponent: LinkComponent }, getItemId(item)))) })] }, groupId));
66
+ const sections = nav.annotatedRoot.items ?? [];
67
+ return (_jsx("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), ...props, children: sections.map((section) => {
68
+ const sectionId = getItemId(section);
69
+ const entries = section.items ?? [];
70
+ return (_jsx(Fragment, { children: entries.length > 0 && (_jsx(Group, { label: section.label, children: entries.map((entry, entryIndex) => {
71
+ const children = entry.items ?? [];
72
+ if (children.length > 0) {
73
+ const { parentUrl: _parentUrl, depth: _depth, items: _items, key: _key, slot: _slot, url: _url, label, ...expandableFields } = entry;
74
+ return (_jsx(ItemExpandable, { ...expandableFields, heading: label, defaultExpanded: nav.getNodeStatus(entry).inSelectedBranch, children: children.map((child, childIndex) => renderEntry(child, nav.getNodeStatus(child).selected, LinkComponent, childIndex)) }, stableKey(entry, entryIndex)));
75
+ }
76
+ return renderEntry(entry, nav.getNodeStatus(entry).selected, LinkComponent, entryIndex);
77
+ }) })) }, sectionId));
36
78
  }) }));
37
79
  };
38
80
  export default NavTree;
@@ -1 +1 @@
1
- {"version":3,"file":"NavTree.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/NavTree/NavTree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AAO,CAAC"}
@@ -1,31 +1,13 @@
1
1
  /*
2
- * SideNavigation NavTree — domain styles for the rendered tree structure
3
- * (level-1 groups → header + level-2 item list). Owned here so Content and
4
- * Footer can compose NavTree without re-declaring its internals. Structural
5
- * only; colour/visual tokens are deferred to PR2.
6
- */
7
- .ds.nav-tree {
8
- display: contents;
9
-
10
- & > .group {
11
- > .header {
12
- /* Group header sits on the baseline grid like a row: a fixed bU-multiple
13
- height (4bU) with the .p label baseline-snapped, and inline padding that
14
- aligns the header text with the item labels below (past the start column
15
- + its gap). */
16
- display: flex;
17
- align-items: baseline;
18
- block-size: calc(var(--space-baseline) * 4); /* 32px — 4bU */
19
- box-sizing: border-box;
20
- padding-inline-start: calc(var(--sidenav-start) + var(--dimension-100));
21
- }
22
-
23
- > .list {
24
- display: flex;
25
- flex-direction: column;
26
- list-style: none;
27
- margin: 0;
28
- padding: 0;
29
- }
2
+ * SideNavigation NavTree — internal wrapper for the rendered tree structure.
3
+ * `display: contents` makes it invisible in the box tree so Content's
4
+ * own flex/scroll layout applies directly to the rendered Group
5
+ * children. Group/GroupHeader/Item/ItemExpandable each own their
6
+ * own styles.
7
+ *
8
+ * Layer: ds.components.apps (@canonical/styles README, "Cascade layers"). */
9
+ @layer ds.components.apps {
10
+ .ds.nav-tree {
11
+ display: contents;
30
12
  }
31
13
  }
@@ -1,7 +1,12 @@
1
1
  // Generated by @canonical/summon-component:react v0.1.0
2
2
  export * from "./CollapseToggle/index.js";
3
3
  export * from "./Content/index.js";
4
+ export * from "./ContextSwitcher/index.js";
4
5
  export * from "./Footer/index.js";
6
+ export * from "./Group/index.js";
7
+ export * from "./GroupHeader/index.js";
5
8
  export * from "./Header/index.js";
6
9
  export * from "./Item/index.js";
10
+ export * from "./ItemButton/index.js";
11
+ export * from "./ItemExpandable/index.js";
7
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/SideNavigation/common/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/SideNavigation/common/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Builds the content's one mandatory item: a collapsible "Help" item
3
+ * containing at least one external link to legal information.
4
+ *
5
+ * A thin data-construction helper, not a component — the mandatory item is
6
+ * an ordinary `ExpandableNavItem`; this removes the
7
+ * chance of authoring it slightly wrong every time a consumer wires it
8
+ * into their `root`.
9
+ *
10
+ * @param legalUrl The external URL to legal information.
11
+ * @param options.legalLabel Label for the legal link. Defaults to `"Legal information"`.
12
+ * @param options.additionalItems Further leaf items under "Help", after the
13
+ * legal link (e.g. a documentation or support link).
14
+ */
15
+ export const createHelpItem = (legalUrl, options = {}) => ({
16
+ key: "help",
17
+ label: "Help",
18
+ icon: "help",
19
+ items: [
20
+ {
21
+ key: "help-legal",
22
+ url: legalUrl,
23
+ label: options.legalLabel ?? "Legal information",
24
+ icon: "external-link",
25
+ },
26
+ ...(options.additionalItems ?? []),
27
+ ],
28
+ });
29
+ //# sourceMappingURL=helpItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpItem.js","sourceRoot":"","sources":["../../../../src/lib/SideNavigation/helpItem.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,QAAgB,EAChB,UAGI,EAAE,EACa,EAAE,CAAC,CAAC;IACvB,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE;QACL;YACE,GAAG,EAAE,YAAY;YACjB,GAAG,EAAE,QAAQ;YACb,KAAK,EAAE,OAAO,CAAC,UAAU,IAAI,mBAAmB;YAChD,IAAI,EAAE,eAAe;SACtB;QACD,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;KACnC;CACF,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as useCollapseShortcut } from "./useCollapseShortcut.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/hooks/useCollapseShortcut/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/hooks/useCollapseShortcut/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ import { useEffect } from "react";
2
+ /**
3
+ * The rail-collapse shortcut: Ctrl+B. A single module-level constant so
4
+ * the key can change in one place if a consumer needs a different
5
+ * binding.
6
+ */
7
+ const COLLAPSE_SHORTCUT = { key: "b", ctrlKey: true };
8
+ /**
9
+ * Binds `COLLAPSE_SHORTCUT` to `onTrigger` while `condition` holds.
10
+ * `SideNavigation` calls this with its `keyboardShortcut` prop
11
+ * (default `true`).
12
+ *
13
+ * The match is exact: the Ctrl+B chord with no other modifiers held, and
14
+ * only when the event's target is not an editable element (an input,
15
+ * textarea, select, or contenteditable host) — Ctrl+B is bold in editors,
16
+ * and the shortcut must never steal it.
17
+ */
18
+ const useCollapseShortcut = ({ condition = false, onTrigger, }) => {
19
+ useEffect(() => {
20
+ if (!condition)
21
+ return;
22
+ const isEditableTarget = (target) => {
23
+ if (!(target instanceof HTMLElement))
24
+ return false;
25
+ // Selector-based (not `target.isContentEditable`) so jsdom, which does
26
+ // not implement that property, resolves the same answer in tests.
27
+ return (target.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])') !== null);
28
+ };
29
+ const handleKeyDown = (event) => {
30
+ if (event.ctrlKey === COLLAPSE_SHORTCUT.ctrlKey &&
31
+ !event.shiftKey &&
32
+ !event.altKey &&
33
+ !event.metaKey &&
34
+ event.key.toLowerCase() === COLLAPSE_SHORTCUT.key &&
35
+ !isEditableTarget(event.target)) {
36
+ event.preventDefault();
37
+ onTrigger();
38
+ }
39
+ };
40
+ window.addEventListener("keydown", handleKeyDown);
41
+ return () => window.removeEventListener("keydown", handleKeyDown);
42
+ }, [condition, onTrigger]);
43
+ };
44
+ export default useCollapseShortcut;
45
+ //# sourceMappingURL=useCollapseShortcut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCollapseShortcut.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMlC;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAW,CAAC;AAE/D;;;;;;;;;GASG;AACH,MAAM,mBAAmB,GAAG,CAAC,EAC3B,SAAS,GAAG,KAAK,EACjB,SAAS,GACgB,EAA6B,EAAE;IACxD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,SAAS;YAAE,OAAO;QAEvB,MAAM,gBAAgB,GAAG,CAAC,MAA0B,EAAW,EAAE;YAC/D,IAAI,CAAC,CAAC,MAAM,YAAY,WAAW,CAAC;gBAAE,OAAO,KAAK,CAAC;YACnD,uEAAuE;YACvE,kEAAkE;YAClE,OAAO,CACL,MAAM,CAAC,OAAO,CACZ,2EAA2E,CAC5E,KAAK,IAAI,CACX,CAAC;QACJ,CAAC,CAAC;QAEF,MAAM,aAAa,GAAG,CAAC,KAAoB,EAAQ,EAAE;YACnD,IACE,KAAK,CAAC,OAAO,KAAK,iBAAiB,CAAC,OAAO;gBAC3C,CAAC,KAAK,CAAC,QAAQ;gBACf,CAAC,KAAK,CAAC,MAAM;gBACb,CAAC,KAAK,CAAC,OAAO;gBACd,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,iBAAiB,CAAC,GAAG;gBACjD,CAAC,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,EAC/B,CAAC;gBACD,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,SAAS,EAAE,CAAC;YACd,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAClD,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IACpE,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  // Generated by @canonical/summon-component:react v0.1.0
2
+ export { createHelpItem } from "./helpItem.js";
2
3
  export { default as SideNavigation } from "./SideNavigation.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/SideNavigation/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/SideNavigation/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC"}