@canonical/react-ds-app 0.38.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.
- package/dist/esm/lib/SideNavigation/SideNavigation.js +51 -9
- package/dist/esm/lib/SideNavigation/SideNavigation.js.map +1 -1
- package/dist/esm/lib/SideNavigation/common/CollapseToggle/CollapseToggle.js +14 -6
- package/dist/esm/lib/SideNavigation/common/CollapseToggle/CollapseToggle.js.map +1 -1
- package/dist/esm/lib/SideNavigation/common/CollapseToggle/styles.css +48 -2
- package/dist/esm/lib/SideNavigation/common/Content/Content.js +9 -5
- package/dist/esm/lib/SideNavigation/common/Content/Content.js.map +1 -1
- package/dist/esm/lib/SideNavigation/common/Content/styles.css +45 -21
- package/dist/esm/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.js +70 -0
- package/dist/esm/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/ContextSwitcher/index.js +2 -0
- package/dist/esm/lib/SideNavigation/common/ContextSwitcher/index.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/ContextSwitcher/styles.css +94 -0
- package/dist/esm/lib/SideNavigation/common/ContextSwitcher/types.js +2 -0
- package/dist/esm/lib/SideNavigation/common/ContextSwitcher/types.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/Footer/Footer.js +46 -6
- package/dist/esm/lib/SideNavigation/common/Footer/Footer.js.map +1 -1
- package/dist/esm/lib/SideNavigation/common/Footer/styles.css +13 -3
- package/dist/esm/lib/SideNavigation/common/Group/Group.js +14 -0
- package/dist/esm/lib/SideNavigation/common/Group/Group.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/Group/index.js +2 -0
- package/dist/esm/lib/SideNavigation/common/Group/index.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/Group/styles.css +18 -0
- package/dist/esm/lib/SideNavigation/common/Group/types.js +2 -0
- package/dist/esm/lib/SideNavigation/common/Group/types.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/GroupHeader/GroupHeader.js +17 -0
- package/dist/esm/lib/SideNavigation/common/GroupHeader/GroupHeader.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/GroupHeader/index.js +2 -0
- package/dist/esm/lib/SideNavigation/common/GroupHeader/index.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/GroupHeader/styles.css +31 -0
- package/dist/esm/lib/SideNavigation/common/GroupHeader/types.js +2 -0
- package/dist/esm/lib/SideNavigation/common/GroupHeader/types.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/Header/Header.js +4 -2
- package/dist/esm/lib/SideNavigation/common/Header/Header.js.map +1 -1
- package/dist/esm/lib/SideNavigation/common/Header/styles.css +66 -28
- package/dist/esm/lib/SideNavigation/common/Item/Item.js +9 -13
- package/dist/esm/lib/SideNavigation/common/Item/Item.js.map +1 -1
- package/dist/esm/lib/SideNavigation/common/Item/styles.css +71 -36
- package/dist/esm/lib/SideNavigation/common/ItemButton/ItemButton.js +18 -0
- package/dist/esm/lib/SideNavigation/common/ItemButton/ItemButton.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/ItemButton/index.js +2 -0
- package/dist/esm/lib/SideNavigation/common/ItemButton/index.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/ItemButton/styles.css +79 -0
- package/dist/esm/lib/SideNavigation/common/ItemButton/types.js +2 -0
- package/dist/esm/lib/SideNavigation/common/ItemButton/types.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/ItemExpandable/ItemExpandable.js +71 -0
- package/dist/esm/lib/SideNavigation/common/ItemExpandable/ItemExpandable.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/ItemExpandable/index.js +2 -0
- package/dist/esm/lib/SideNavigation/common/ItemExpandable/index.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/ItemExpandable/styles.css +121 -0
- package/dist/esm/lib/SideNavigation/common/ItemExpandable/types.js +2 -0
- package/dist/esm/lib/SideNavigation/common/ItemExpandable/types.js.map +1 -0
- package/dist/esm/lib/SideNavigation/common/NavTree/NavTree.js +63 -21
- package/dist/esm/lib/SideNavigation/common/NavTree/NavTree.js.map +1 -1
- package/dist/esm/lib/SideNavigation/common/NavTree/styles.css +7 -30
- package/dist/esm/lib/SideNavigation/common/index.js +5 -0
- package/dist/esm/lib/SideNavigation/common/index.js.map +1 -1
- package/dist/esm/lib/SideNavigation/helpItem.js +29 -0
- package/dist/esm/lib/SideNavigation/helpItem.js.map +1 -0
- package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/index.js +2 -0
- package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/index.js.map +1 -0
- package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/types.js +2 -0
- package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/types.js.map +1 -0
- package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.js +45 -0
- package/dist/esm/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.js.map +1 -0
- package/dist/esm/lib/SideNavigation/index.js +1 -0
- package/dist/esm/lib/SideNavigation/index.js.map +1 -1
- package/dist/esm/lib/SideNavigation/styles.css +272 -19
- package/dist/types/lib/SideNavigation/SideNavigation.d.ts +22 -1
- package/dist/types/lib/SideNavigation/SideNavigation.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/CollapseToggle/CollapseToggle.d.ts +9 -2
- package/dist/types/lib/SideNavigation/common/CollapseToggle/CollapseToggle.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/CollapseToggle/types.d.ts +6 -1
- package/dist/types/lib/SideNavigation/common/CollapseToggle/types.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/Content/Content.d.ts +8 -4
- package/dist/types/lib/SideNavigation/common/Content/Content.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/Content/types.d.ts +5 -8
- package/dist/types/lib/SideNavigation/common/Content/types.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.d.ts +20 -0
- package/dist/types/lib/SideNavigation/common/ContextSwitcher/ContextSwitcher.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/ContextSwitcher/index.d.ts +3 -0
- package/dist/types/lib/SideNavigation/common/ContextSwitcher/index.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/ContextSwitcher/types.d.ts +52 -0
- package/dist/types/lib/SideNavigation/common/ContextSwitcher/types.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/Footer/Footer.d.ts +8 -4
- package/dist/types/lib/SideNavigation/common/Footer/Footer.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/Footer/types.d.ts +5 -8
- package/dist/types/lib/SideNavigation/common/Footer/types.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/Group/Group.d.ts +13 -0
- package/dist/types/lib/SideNavigation/common/Group/Group.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/Group/index.d.ts +3 -0
- package/dist/types/lib/SideNavigation/common/Group/index.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/Group/types.d.ts +10 -0
- package/dist/types/lib/SideNavigation/common/Group/types.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/GroupHeader/GroupHeader.d.ts +13 -0
- package/dist/types/lib/SideNavigation/common/GroupHeader/GroupHeader.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/GroupHeader/index.d.ts +3 -0
- package/dist/types/lib/SideNavigation/common/GroupHeader/index.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/GroupHeader/types.d.ts +8 -0
- package/dist/types/lib/SideNavigation/common/GroupHeader/types.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/Header/Header.d.ts +3 -1
- package/dist/types/lib/SideNavigation/common/Header/Header.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/Item/Item.d.ts +8 -9
- package/dist/types/lib/SideNavigation/common/Item/Item.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/Item/types.d.ts +18 -7
- package/dist/types/lib/SideNavigation/common/Item/types.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/ItemButton/ItemButton.d.ts +17 -0
- package/dist/types/lib/SideNavigation/common/ItemButton/ItemButton.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/ItemButton/index.d.ts +3 -0
- package/dist/types/lib/SideNavigation/common/ItemButton/index.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/ItemButton/types.d.ts +17 -0
- package/dist/types/lib/SideNavigation/common/ItemButton/types.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/ItemExpandable/ItemExpandable.d.ts +26 -0
- package/dist/types/lib/SideNavigation/common/ItemExpandable/ItemExpandable.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/ItemExpandable/index.d.ts +3 -0
- package/dist/types/lib/SideNavigation/common/ItemExpandable/index.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/ItemExpandable/types.d.ts +32 -0
- package/dist/types/lib/SideNavigation/common/ItemExpandable/types.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/common/NavTree/NavTree.d.ts +12 -13
- package/dist/types/lib/SideNavigation/common/NavTree/NavTree.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/NavTree/types.d.ts +7 -5
- package/dist/types/lib/SideNavigation/common/NavTree/types.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/common/index.d.ts +5 -0
- package/dist/types/lib/SideNavigation/common/index.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/helpItem.d.ts +20 -0
- package/dist/types/lib/SideNavigation/helpItem.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/index.d.ts +3 -0
- package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/index.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/types.d.ts +14 -0
- package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/types.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.d.ts +14 -0
- package/dist/types/lib/SideNavigation/hooks/useCollapseShortcut/useCollapseShortcut.d.ts.map +1 -0
- package/dist/types/lib/SideNavigation/index.d.ts +1 -0
- package/dist/types/lib/SideNavigation/index.d.ts.map +1 -1
- package/dist/types/lib/SideNavigation/types.d.ts +168 -24
- package/dist/types/lib/SideNavigation/types.d.ts.map +1 -1
- package/package.json +17 -17
|
@@ -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 @@
|
|
|
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
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { getItemId } from "@canonical/ds-utils";
|
|
3
3
|
import { useNavigationTree } from "@canonical/react-hooks";
|
|
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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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
|
|
22
|
-
|
|
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
|
|
32
|
-
return (_jsx("div", { className: "
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
return (
|
|
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.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"NavTree.js","sourceRoot":"","sources":["../../../../../../src/lib/SideNavigation/common/NavTree/NavTree.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;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AK,EACd,eAAe,EACb,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,gBAAgB,YAG1C,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAClC,WAAW,CACT,KAAK,EACL,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,QAAQ,EACjC,aAAa,EACb,UAAU,CACX,CACF,IAdI,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAelB,CAClB,CAAC;wBACJ,CAAC;wBAED,OAAO,WAAW,CAChB,KAAK,EACL,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,QAAQ,EACjC,aAAa,EACb,UAAU,CACX,CAAC;oBACJ,CAAC,CAAC,GACI,CACT,IA/CY,SAAS,CAgDb,CACZ,CAAC;QACJ,CAAC,CAAC,GACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -1,36 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* SideNavigation NavTree —
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
|
|
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"). */
|
|
10
9
|
@layer ds.components.apps {
|
|
11
10
|
.ds.nav-tree {
|
|
12
11
|
display: contents;
|
|
13
|
-
|
|
14
|
-
& > .group {
|
|
15
|
-
> .header {
|
|
16
|
-
/* Group header sits on the baseline grid like a row: a fixed bU-multiple
|
|
17
|
-
height (4bU) with the .p label baseline-snapped, and inline padding that
|
|
18
|
-
aligns the header text with the item labels below (past the start column
|
|
19
|
-
+ its gap). */
|
|
20
|
-
display: flex;
|
|
21
|
-
align-items: baseline;
|
|
22
|
-
block-size: calc(var(--space-baseline) * 4); /* 32px — 4bU */
|
|
23
|
-
box-sizing: border-box;
|
|
24
|
-
padding-inline-start: calc(var(--sidenav-start) + var(--dimension-100));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
> .list {
|
|
28
|
-
display: flex;
|
|
29
|
-
flex-direction: column;
|
|
30
|
-
list-style: none;
|
|
31
|
-
margin: 0;
|
|
32
|
-
padding: 0;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
12
|
}
|
|
36
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 @@
|
|
|
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 @@
|
|
|
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 +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"}
|