@common-origin/design-system 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +2622 -830
- package/dist/client.js.map +1 -1
- package/dist/components/atoms/Badge/Badge.d.mts +2 -2
- package/dist/components/atoms/Badge/Badge.d.ts +2 -2
- package/dist/components/atoms/Badge/Badge.mjs +15 -9
- package/dist/components/atoms/Box/Box.d.mts +3 -2
- package/dist/components/atoms/Box/Box.d.ts +3 -2
- package/dist/components/atoms/Button/Button.mjs +1 -1
- package/dist/components/atoms/Chip/shared/ChipBase.mjs +1 -1
- package/dist/components/atoms/IconButton/IconButton.mjs +1 -1
- package/dist/components/atoms/ProgressBar/ProgressBar.d.mts +1 -1
- package/dist/components/atoms/ProgressBar/ProgressBar.d.ts +1 -1
- package/dist/components/atoms/Tag/Tag.d.mts +1 -1
- package/dist/components/atoms/Tag/Tag.d.ts +1 -1
- package/dist/components/atoms/Tooltip/Tooltip.d.mts +47 -0
- package/dist/components/atoms/Tooltip/Tooltip.d.ts +47 -0
- package/dist/components/atoms/Tooltip/Tooltip.mjs +214 -0
- package/dist/components/atoms/Tooltip/Tooltip.mjs.map +1 -0
- package/dist/components/atoms/Tooltip/index.d.mts +2 -0
- package/dist/components/atoms/Tooltip/index.d.ts +2 -0
- package/dist/components/atoms/index.d.mts +1 -0
- package/dist/components/atoms/index.d.ts +1 -0
- package/dist/components/index.d.mts +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/molecules/ActionSheet/ActionSheet.mjs +3 -2
- package/dist/components/molecules/Alert/Alert.mjs +2 -2
- package/dist/components/molecules/Checkbox/SelectableInputBase.mjs +1 -1
- package/dist/components/molecules/ChipGroup/ChipGroup.mjs +1 -0
- package/dist/components/molecules/Dropdown/Dropdown.mjs +1 -1
- package/dist/components/molecules/List/List.d.mts +2 -0
- package/dist/components/molecules/List/List.d.ts +2 -0
- package/dist/components/molecules/List/ListItem.d.mts +2 -0
- package/dist/components/molecules/List/ListItem.d.ts +2 -0
- package/dist/components/molecules/List/ListItem.mjs +7 -7
- package/dist/components/molecules/Menu/Menu.d.mts +124 -0
- package/dist/components/molecules/Menu/Menu.d.ts +124 -0
- package/dist/components/molecules/Menu/Menu.mjs +476 -0
- package/dist/components/molecules/Menu/Menu.mjs.map +1 -0
- package/dist/components/molecules/Menu/index.d.mts +2 -0
- package/dist/components/molecules/Menu/index.d.ts +2 -0
- package/dist/components/molecules/Modal/Modal.mjs +1 -1
- package/dist/components/molecules/NumberInput/NumberInput.mjs +2 -1
- package/dist/components/molecules/PasswordField/PasswordField.mjs +3 -2
- package/dist/components/molecules/SearchField/SearchField.mjs +5 -3
- package/dist/components/molecules/Sheet/Sheet.mjs +3 -3
- package/dist/components/molecules/SidebarNavItem/SidebarNavContext.d.mts +13 -0
- package/dist/components/molecules/SidebarNavItem/SidebarNavContext.d.ts +13 -0
- package/dist/components/molecules/SidebarNavItem/SidebarNavContext.mjs +13 -0
- package/dist/components/molecules/SidebarNavItem/SidebarNavContext.mjs.map +1 -0
- package/dist/components/molecules/SidebarNavItem/SidebarNavItem.d.mts +44 -0
- package/dist/components/molecules/SidebarNavItem/SidebarNavItem.d.ts +44 -0
- package/dist/components/molecules/SidebarNavItem/SidebarNavItem.mjs +235 -0
- package/dist/components/molecules/SidebarNavItem/SidebarNavItem.mjs.map +1 -0
- package/dist/components/molecules/SidebarNavItem/index.d.mts +2 -0
- package/dist/components/molecules/SidebarNavItem/index.d.ts +2 -0
- package/dist/components/molecules/SidebarNavItem/sidebarNavMotion.d.mts +30 -0
- package/dist/components/molecules/SidebarNavItem/sidebarNavMotion.d.ts +30 -0
- package/dist/components/molecules/SidebarNavItem/sidebarNavMotion.mjs +69 -0
- package/dist/components/molecules/SidebarNavItem/sidebarNavMotion.mjs.map +1 -0
- package/dist/components/molecules/SidebarNavSection/SidebarNavSection.d.mts +36 -0
- package/dist/components/molecules/SidebarNavSection/SidebarNavSection.d.ts +36 -0
- package/dist/components/molecules/SidebarNavSection/SidebarNavSection.mjs +202 -0
- package/dist/components/molecules/SidebarNavSection/SidebarNavSection.mjs.map +1 -0
- package/dist/components/molecules/SidebarNavSection/index.d.mts +2 -0
- package/dist/components/molecules/SidebarNavSection/index.d.ts +2 -0
- package/dist/components/molecules/TabBar/TabBar.mjs +3 -3
- package/dist/components/molecules/TransactionListItem/TransactionListItem.mjs +1 -1
- package/dist/components/molecules/WorkspaceSwitcher/WorkspaceSwitcher.d.mts +39 -0
- package/dist/components/molecules/WorkspaceSwitcher/WorkspaceSwitcher.d.ts +39 -0
- package/dist/components/molecules/WorkspaceSwitcher/WorkspaceSwitcher.mjs +133 -0
- package/dist/components/molecules/WorkspaceSwitcher/WorkspaceSwitcher.mjs.map +1 -0
- package/dist/components/molecules/WorkspaceSwitcher/index.d.mts +2 -0
- package/dist/components/molecules/WorkspaceSwitcher/index.d.ts +2 -0
- package/dist/components/molecules/index.d.mts +4 -0
- package/dist/components/molecules/index.d.ts +4 -0
- package/dist/components/organisms/SidebarNav/SidebarNav.d.mts +52 -0
- package/dist/components/organisms/SidebarNav/SidebarNav.d.ts +52 -0
- package/dist/components/organisms/SidebarNav/SidebarNav.mjs +346 -0
- package/dist/components/organisms/SidebarNav/SidebarNav.mjs.map +1 -0
- package/dist/components/organisms/SidebarNav/index.d.mts +2 -0
- package/dist/components/organisms/SidebarNav/index.d.ts +2 -0
- package/dist/components/organisms/index.d.mts +1 -0
- package/dist/components/organisms/index.d.ts +1 -0
- package/dist/data.js +155 -68
- package/dist/data.js.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -1
- package/dist/lib/floatingPosition.d.mts +43 -0
- package/dist/lib/floatingPosition.d.ts +43 -0
- package/dist/lib/floatingPosition.mjs +86 -0
- package/dist/lib/floatingPosition.mjs.map +1 -0
- package/dist/lib/keyboardFocus.d.mts +6 -0
- package/dist/lib/keyboardFocus.d.ts +6 -0
- package/dist/lib/keyboardFocus.mjs +17 -0
- package/dist/lib/keyboardFocus.mjs.map +1 -0
- package/dist/lib/styleUtils.d.mts +4 -0
- package/dist/lib/styleUtils.d.ts +4 -0
- package/dist/lib/styleUtils.mjs +5 -1
- package/dist/lib/styleUtils.mjs.map +1 -1
- package/dist/lib/tokenAliases.mjs +1 -0
- package/dist/lib/tokenAliases.mjs.map +1 -1
- package/dist/lib/useFloatingLayer.d.mts +32 -0
- package/dist/lib/useFloatingLayer.d.ts +32 -0
- package/dist/lib/useFloatingLayer.mjs +95 -0
- package/dist/lib/useFloatingLayer.mjs.map +1 -0
- package/dist/styles/icons.json +30 -1
- package/dist/styles/icons.json.mjs +34 -3
- package/dist/styles/icons.json.mjs.map +1 -1
- package/dist/styles/tokens.d.mts +139 -32
- package/dist/styles/tokens.d.ts +139 -32
- package/dist/styles/tokens.json +122 -66
- package/dist/styles/tokens.json.mjs +122 -66
- package/dist/styles/tokens.json.mjs.map +1 -1
- package/dist/tokens/index.js +122 -66
- package/dist/tokens/index.js.map +1 -1
- package/dist/tokens/index.mjs +122 -66
- package/dist/tokens/index.mjs.map +1 -1
- package/dist/tokens/styles/tokens.d.mts +139 -32
- package/dist/tokens/styles/tokens.d.ts +139 -32
- package/dist/tokens.css +1137 -86
- package/dist/types/icons.d.mts +1 -1
- package/dist/types/icons.d.ts +1 -1
- package/dist/types/icons.mjs.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { __makeTemplateObject, __assign } from '../../../vendor/tslib/tslib.es6.mjs';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
import { useState, useRef, useEffect } from 'react';
|
|
5
|
+
import styled$module from 'styled-components';
|
|
6
|
+
const styled = styled$module.default || styled$module;
|
|
7
|
+
import tokens from '../../../lib/cssTokens.mjs';
|
|
8
|
+
import { reducedMotion, rowRadius, forcedColors } from '../../../lib/styleUtils.mjs';
|
|
9
|
+
import { IconButton } from '../../atoms/IconButton/IconButton.mjs';
|
|
10
|
+
import { Tooltip } from '../../atoms/Tooltip/Tooltip.mjs';
|
|
11
|
+
import { isKeyboardFocus } from '../../../lib/keyboardFocus.mjs';
|
|
12
|
+
import { SidebarNavContext } from '../../molecules/SidebarNavItem/SidebarNavContext.mjs';
|
|
13
|
+
import { fade, EXPANDED_WIDTH_VAR, NAV_PADDING, SCROLLBAR_VAR } from '../../molecules/SidebarNavItem/sidebarNavMotion.mjs';
|
|
14
|
+
|
|
15
|
+
var semantic = tokens.semantic,
|
|
16
|
+
component = tokens.component;
|
|
17
|
+
var space = semantic.space,
|
|
18
|
+
motion = semantic.motion,
|
|
19
|
+
color = semantic.color,
|
|
20
|
+
size = semantic.size;
|
|
21
|
+
var widths = component.sidebarNav.width;
|
|
22
|
+
var Nav = /*#__PURE__*/styled.nav.withConfig({
|
|
23
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
24
|
+
return !prop.startsWith('$');
|
|
25
|
+
},
|
|
26
|
+
displayName: "SidebarNav__Nav",
|
|
27
|
+
componentId: "sc-1as46tp-0"
|
|
28
|
+
})(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n gap: ", ";\n box-sizing: border-box;\n /* Its width is set; in a flex app shell it mustn't shrink to make room */\n flex-shrink: 0;\n width: ", ";\n height: 100%;\n padding: ", ";\n overflow: hidden;\n /* Quiet chrome (P1): the page's own background, with no edge of its own (issue 348). The width\n moves with everything inside it, decelerating (0037) */\n transition: width ", " ", ";\n\n ", " {\n transition: none;\n }\n"], ["\n display: flex;\n flex-direction: column;\n gap: ", ";\n box-sizing: border-box;\n /* Its width is set; in a flex app shell it mustn't shrink to make room */\n flex-shrink: 0;\n width: ", ";\n height: 100%;\n padding: ", ";\n overflow: hidden;\n /* Quiet chrome (P1): the page's own background, with no edge of its own (issue 348). The width\n moves with everything inside it, decelerating (0037) */\n transition: width ", " ", ";\n\n ", " {\n transition: none;\n }\n"
|
|
29
|
+
// The header holds two toggles in fixed places that cross-fade (issue 348): collapse beside the
|
|
30
|
+
// header content, and expand in the content's place, where the rail shows it. Nothing moves.
|
|
31
|
+
])), space[200], function (_a) {
|
|
32
|
+
var $width = _a.$width;
|
|
33
|
+
return $width;
|
|
34
|
+
}, space[200], motion.duration.moderate, motion.easing.decelerate, reducedMotion);
|
|
35
|
+
// The header holds two toggles in fixed places that cross-fade (issue 348): collapse beside the
|
|
36
|
+
// header content, and expand in the content's place, where the rail shows it. Nothing moves.
|
|
37
|
+
var Header = /*#__PURE__*/styled.div.withConfig({
|
|
38
|
+
displayName: "SidebarNav__Header",
|
|
39
|
+
componentId: "sc-1as46tp-1"
|
|
40
|
+
})(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: relative;\n display: flex;\n align-items: center;\n gap: ", ";\n min-height: ", ";\n"], ["\n position: relative;\n display: flex;\n align-items: center;\n gap: ", ";\n min-height: ", ";\n"])), space[100], size.control.sm);
|
|
41
|
+
var HeaderContent = /*#__PURE__*/styled.div.withConfig({
|
|
42
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
43
|
+
return !prop.startsWith('$');
|
|
44
|
+
},
|
|
45
|
+
displayName: "SidebarNav__HeaderContent",
|
|
46
|
+
componentId: "sc-1as46tp-2"
|
|
47
|
+
})(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n flex: 1;\n min-width: 0;\n overflow: hidden;\n ", "\n\n /* Keeps its expanded width, so the nav's edge clips it rather than it reflowing mid-move */\n & > div {\n width: calc(var(", ") - 2 * ", " - ", " - ", ");\n }\n"], ["\n flex: 1;\n min-width: 0;\n overflow: hidden;\n ", "\n\n /* Keeps its expanded width, so the nav's edge clips it rather than it reflowing mid-move */\n & > div {\n width: calc(var(", ") - 2 * ", " - ", " - ", ");\n }\n"])), function (_a) {
|
|
48
|
+
var $hidden = _a.$hidden;
|
|
49
|
+
return fade($hidden);
|
|
50
|
+
}, EXPANDED_WIDTH_VAR, NAV_PADDING, size.control.sm, space[100]);
|
|
51
|
+
var CollapseSlot = /*#__PURE__*/styled.span.withConfig({
|
|
52
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
53
|
+
return !prop.startsWith('$');
|
|
54
|
+
},
|
|
55
|
+
displayName: "SidebarNav__CollapseSlot",
|
|
56
|
+
componentId: "sc-1as46tp-3"
|
|
57
|
+
})(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: inline-flex;\n flex-shrink: 0;\n margin-left: auto;\n ", "\n"], ["\n display: inline-flex;\n flex-shrink: 0;\n margin-left: auto;\n ", "\n"
|
|
58
|
+
// Centred in the rail, where the header content starts
|
|
59
|
+
])), function (_a) {
|
|
60
|
+
var $hidden = _a.$hidden;
|
|
61
|
+
return fade($hidden);
|
|
62
|
+
});
|
|
63
|
+
// Centred in the rail, where the header content starts
|
|
64
|
+
var ExpandSlot = /*#__PURE__*/styled.span.withConfig({
|
|
65
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
66
|
+
return !prop.startsWith('$');
|
|
67
|
+
},
|
|
68
|
+
displayName: "SidebarNav__ExpandSlot",
|
|
69
|
+
componentId: "sc-1as46tp-4"
|
|
70
|
+
})(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n position: absolute;\n top: 0;\n bottom: 0;\n left: calc((", " - 2 * ", " - ", ") / 2);\n display: flex;\n align-items: center;\n ", "\n"], ["\n position: absolute;\n top: 0;\n bottom: 0;\n left: calc((", " - 2 * ", " - ", ") / 2);\n display: flex;\n align-items: center;\n ", "\n"])), component.sidebarNav.width.rail, NAV_PADDING, size.control.sm, function (_a) {
|
|
71
|
+
var $hidden = _a.$hidden;
|
|
72
|
+
return fade($hidden);
|
|
73
|
+
});
|
|
74
|
+
var Body = /*#__PURE__*/styled.div.withConfig({
|
|
75
|
+
displayName: "SidebarNav__Body",
|
|
76
|
+
componentId: "sc-1as46tp-5"
|
|
77
|
+
})(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n flex: 1;\n min-height: 0;\n overflow-x: hidden;\n overflow-y: auto;\n"], ["\n flex: 1;\n min-height: 0;\n overflow-x: hidden;\n overflow-y: auto;\n"
|
|
78
|
+
// The rows and the highlight share this box, so the highlight scrolls with the rows
|
|
79
|
+
])));
|
|
80
|
+
// The rows and the highlight share this box, so the highlight scrolls with the rows
|
|
81
|
+
var Content = /*#__PURE__*/styled.div.withConfig({
|
|
82
|
+
displayName: "SidebarNav__Content",
|
|
83
|
+
componentId: "sc-1as46tp-6"
|
|
84
|
+
})(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n position: relative;\n isolation: isolate;\n display: flex;\n flex-direction: column;\n\n & [data-sidebar-row] {\n position: relative;\n z-index: 1;\n }\n"], ["\n position: relative;\n isolation: isolate;\n display: flex;\n flex-direction: column;\n\n & [data-sidebar-row] {\n position: relative;\n z-index: 1;\n }\n"])));
|
|
85
|
+
var List = /*#__PURE__*/styled.ul.withConfig({
|
|
86
|
+
displayName: "SidebarNav__List",
|
|
87
|
+
componentId: "sc-1as46tp-7"
|
|
88
|
+
})(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n margin: 0;\n padding: 0;\n list-style: none;\n display: flex;\n flex-direction: column;\n"], ["\n margin: 0;\n padding: 0;\n list-style: none;\n display: flex;\n flex-direction: column;\n"])));
|
|
89
|
+
// One highlight glides to the hovered or keyboard-focused row (0053): the row hover colour,
|
|
90
|
+
// moving over duration.fast. It jumps under reduced motion and hides in forced colours, where
|
|
91
|
+
// rows outline themselves instead.
|
|
92
|
+
var Highlight = /*#__PURE__*/styled.div.withConfig({
|
|
93
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
94
|
+
return !prop.startsWith('$');
|
|
95
|
+
},
|
|
96
|
+
displayName: "SidebarNav__Highlight",
|
|
97
|
+
componentId: "sc-1as46tp-8"
|
|
98
|
+
})(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n position: absolute;\n top: 0;\n left: 0;\n z-index: 0;\n border-radius: ", ";\n background-color: ", ";\n pointer-events: none;\n opacity: ", ";\n transition: ", ";\n\n ", " {\n transition: opacity ", " ", ";\n }\n\n ", " {\n display: none;\n }\n"], ["\n position: absolute;\n top: 0;\n left: 0;\n z-index: 0;\n border-radius: ", ";\n background-color: ", ";\n pointer-events: none;\n opacity: ", ";\n transition: ", ";\n\n ", " {\n transition: opacity ", " ", ";\n }\n\n ", " {\n display: none;\n }\n"
|
|
99
|
+
// The footer fades out in the rail, keeping its expanded width so it doesn't reflow mid-move
|
|
100
|
+
])), rowRadius, color.fill.muted, function (_a) {
|
|
101
|
+
var $visible = _a.$visible;
|
|
102
|
+
return $visible ? 1 : 0;
|
|
103
|
+
}, function (_a) {
|
|
104
|
+
var $instant = _a.$instant;
|
|
105
|
+
return $instant ? "opacity ".concat(motion.duration.fast, " ").concat(motion.easing.decelerate) : "transform ".concat(motion.duration.fast, " ").concat(motion.easing.decelerate, ",\n height ").concat(motion.duration.fast, " ").concat(motion.easing.decelerate, ",\n width ").concat(motion.duration.fast, " ").concat(motion.easing.decelerate, ",\n opacity ").concat(motion.duration.fast, " ").concat(motion.easing.decelerate);
|
|
106
|
+
}, reducedMotion, motion.duration.fast, motion.easing.decelerate, forcedColors);
|
|
107
|
+
// The footer fades out in the rail, keeping its expanded width so it doesn't reflow mid-move
|
|
108
|
+
var Footer = /*#__PURE__*/styled.div.withConfig({
|
|
109
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
110
|
+
return !prop.startsWith('$');
|
|
111
|
+
},
|
|
112
|
+
displayName: "SidebarNav__Footer",
|
|
113
|
+
componentId: "sc-1as46tp-9"
|
|
114
|
+
})(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n flex-shrink: 0;\n overflow: hidden;\n ", "\n\n & > div {\n width: calc(var(", ") - 2 * ", ");\n }\n"], ["\n flex-shrink: 0;\n overflow: hidden;\n ", "\n\n & > div {\n width: calc(var(", ") - 2 * ", ");\n }\n"
|
|
115
|
+
/**
|
|
116
|
+
* A product's sidebar navigation (#331): a header, a scrolling body of items and sections, and a
|
|
117
|
+
* footer, that collapses to an icon rail. Row heights follow density (0051); the width is a prop.
|
|
118
|
+
* On small screens, place it in a Sheet with `collapsible={false}`.
|
|
119
|
+
*/])), function (_a) {
|
|
120
|
+
var $hidden = _a.$hidden;
|
|
121
|
+
return fade($hidden);
|
|
122
|
+
}, EXPANDED_WIDTH_VAR, NAV_PADDING);
|
|
123
|
+
/**
|
|
124
|
+
* A product's sidebar navigation (#331): a header, a scrolling body of items and sections, and a
|
|
125
|
+
* footer, that collapses to an icon rail. Row heights follow density (0051); the width is a prop.
|
|
126
|
+
* On small screens, place it in a Sheet with `collapsible={false}`.
|
|
127
|
+
*/
|
|
128
|
+
var SidebarNav = function SidebarNav(_a) {
|
|
129
|
+
var _b;
|
|
130
|
+
var label = _a.label,
|
|
131
|
+
children = _a.children,
|
|
132
|
+
header = _a.header,
|
|
133
|
+
footer = _a.footer,
|
|
134
|
+
_c = _a.width,
|
|
135
|
+
width = _c === void 0 ? 'default' : _c,
|
|
136
|
+
collapsedProp = _a.collapsed,
|
|
137
|
+
_d = _a.defaultCollapsed,
|
|
138
|
+
defaultCollapsed = _d === void 0 ? false : _d,
|
|
139
|
+
onCollapsedChange = _a.onCollapsedChange,
|
|
140
|
+
_e = _a.collapsible,
|
|
141
|
+
collapsible = _e === void 0 ? true : _e,
|
|
142
|
+
linkComponent = _a.linkComponent,
|
|
143
|
+
dataTestId = _a["data-testid"];
|
|
144
|
+
var _f = useState(defaultCollapsed),
|
|
145
|
+
uncontrolledCollapsed = _f[0],
|
|
146
|
+
setUncontrolledCollapsed = _f[1];
|
|
147
|
+
var isControlled = collapsedProp !== undefined;
|
|
148
|
+
var collapsed = collapsible && (isControlled ? collapsedProp : uncontrolledCollapsed);
|
|
149
|
+
var contentRef = useRef(null);
|
|
150
|
+
var navRef = useRef(null);
|
|
151
|
+
var bodyRef = useRef(null);
|
|
152
|
+
// A classic scrollbar narrows every row, so rows need its width. Measured while expanded (the rail
|
|
153
|
+
// only clips what rows hold) and written straight to a CSS variable, so it re-renders nothing.
|
|
154
|
+
useEffect(function () {
|
|
155
|
+
var nav = navRef.current;
|
|
156
|
+
var body = bodyRef.current;
|
|
157
|
+
if (!nav || !body || collapsed) return;
|
|
158
|
+
var measure = function measure() {
|
|
159
|
+
return nav.style.setProperty(SCROLLBAR_VAR, "".concat(body.offsetWidth - body.clientWidth, "px"));
|
|
160
|
+
};
|
|
161
|
+
measure();
|
|
162
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
163
|
+
var observer = new ResizeObserver(measure);
|
|
164
|
+
observer.observe(body);
|
|
165
|
+
if (contentRef.current) observer.observe(contentRef.current);
|
|
166
|
+
return function () {
|
|
167
|
+
return observer.disconnect();
|
|
168
|
+
};
|
|
169
|
+
}, [collapsed]);
|
|
170
|
+
var _g = useState({
|
|
171
|
+
box: null,
|
|
172
|
+
visible: false,
|
|
173
|
+
instant: true
|
|
174
|
+
}),
|
|
175
|
+
highlight = _g[0],
|
|
176
|
+
setHighlight = _g[1];
|
|
177
|
+
// Focus follows the toggle: the one pressed fades away, so focus moves to the one now shown
|
|
178
|
+
var collapseSlot = useRef(null);
|
|
179
|
+
var expandSlot = useRef(null);
|
|
180
|
+
// Which state a toggle asked for, and when: focus moves only if that state arrives promptly, so a
|
|
181
|
+
// controlled parent that declined the change can't have focus jump on some later change
|
|
182
|
+
var focusToggle = useRef(null);
|
|
183
|
+
var toggle = function toggle() {
|
|
184
|
+
var next = !collapsed;
|
|
185
|
+
focusToggle.current = {
|
|
186
|
+
to: next,
|
|
187
|
+
at: Date.now()
|
|
188
|
+
};
|
|
189
|
+
if (!isControlled) setUncontrolledCollapsed(next);
|
|
190
|
+
onCollapsedChange === null || onCollapsedChange === void 0 ? void 0 : onCollapsedChange(next);
|
|
191
|
+
};
|
|
192
|
+
useEffect(function () {
|
|
193
|
+
var _a;
|
|
194
|
+
var request = focusToggle.current;
|
|
195
|
+
focusToggle.current = null;
|
|
196
|
+
if (!request || request.to !== collapsed || Date.now() - request.at > 1000) return;
|
|
197
|
+
var slot = collapsed ? expandSlot.current : collapseSlot.current;
|
|
198
|
+
(_a = slot === null || slot === void 0 ? void 0 : slot.querySelector('button')) === null || _a === void 0 ? void 0 : _a.focus();
|
|
199
|
+
}, [collapsed]);
|
|
200
|
+
var hide = function hide() {
|
|
201
|
+
return setHighlight(function (state) {
|
|
202
|
+
return __assign(__assign({}, state), {
|
|
203
|
+
visible: false
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
// Collapsing or expanding moves every row, so the highlight's box is stale: hide it until the
|
|
208
|
+
// pointer or focus finds a row again (adjusted during render, React's pattern for a prop change)
|
|
209
|
+
var _h = useState(collapsed),
|
|
210
|
+
layout = _h[0],
|
|
211
|
+
setLayout = _h[1];
|
|
212
|
+
if (layout !== collapsed) {
|
|
213
|
+
setLayout(collapsed);
|
|
214
|
+
setHighlight(function (state) {
|
|
215
|
+
return __assign(__assign({}, state), {
|
|
216
|
+
visible: false,
|
|
217
|
+
instant: true
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
// Move the highlight to a row, or step aside for the current page's row, which has its own fill
|
|
222
|
+
var highlightRow = function highlightRow(target) {
|
|
223
|
+
var content = contentRef.current;
|
|
224
|
+
var row = target instanceof Element ? target.closest('[data-sidebar-row]') : null;
|
|
225
|
+
if (!content || !row || !content.contains(row) || row.getAttribute('aria-current') === 'page') return hide();
|
|
226
|
+
var outer = content.getBoundingClientRect();
|
|
227
|
+
var box = row.getBoundingClientRect();
|
|
228
|
+
setHighlight(function (state) {
|
|
229
|
+
return {
|
|
230
|
+
box: {
|
|
231
|
+
top: box.top - outer.top,
|
|
232
|
+
left: box.left - outer.left,
|
|
233
|
+
width: box.width,
|
|
234
|
+
height: box.height
|
|
235
|
+
},
|
|
236
|
+
visible: true,
|
|
237
|
+
// Appearing, it starts at the row rather than sliding from where it last was
|
|
238
|
+
instant: !state.visible
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
var context = {
|
|
243
|
+
collapsed: collapsed,
|
|
244
|
+
linkComponent: linkComponent,
|
|
245
|
+
glide: true,
|
|
246
|
+
inNav: true
|
|
247
|
+
};
|
|
248
|
+
// The header content keeps its expanded layout: it fades out in the rail rather than turning into
|
|
249
|
+
// a rail version of itself mid-move
|
|
250
|
+
var headerContext = __assign(__assign({}, context), {
|
|
251
|
+
collapsed: false
|
|
252
|
+
});
|
|
253
|
+
return jsx(SidebarNavContext.Provider, {
|
|
254
|
+
value: context,
|
|
255
|
+
children: jsxs(Nav, {
|
|
256
|
+
ref: navRef,
|
|
257
|
+
"aria-label": label,
|
|
258
|
+
"$width": collapsed ? widths.rail : widths[width],
|
|
259
|
+
"data-collapsed": collapsed || undefined,
|
|
260
|
+
"data-testid": dataTestId,
|
|
261
|
+
style: (_b = {}, _b[EXPANDED_WIDTH_VAR] = widths[width], _b),
|
|
262
|
+
children: [(header || collapsible) && jsxs(Header, {
|
|
263
|
+
children: [header && jsx(HeaderContent, {
|
|
264
|
+
"$hidden": collapsed,
|
|
265
|
+
children: jsx("div", {
|
|
266
|
+
children: jsx(SidebarNavContext.Provider, {
|
|
267
|
+
value: headerContext,
|
|
268
|
+
children: header
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
}), collapsible && jsxs(Fragment, {
|
|
272
|
+
children: [jsx(CollapseSlot, {
|
|
273
|
+
ref: collapseSlot,
|
|
274
|
+
"$hidden": collapsed,
|
|
275
|
+
children: jsx(Tooltip, {
|
|
276
|
+
text: "Collapse sidebar",
|
|
277
|
+
side: "bottom",
|
|
278
|
+
children: jsx(IconButton, {
|
|
279
|
+
variant: "naked",
|
|
280
|
+
size: "small",
|
|
281
|
+
iconName: "sidebar",
|
|
282
|
+
"aria-label": "Collapse sidebar",
|
|
283
|
+
"aria-expanded": true,
|
|
284
|
+
onClick: toggle
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
}), jsx(ExpandSlot, {
|
|
288
|
+
ref: expandSlot,
|
|
289
|
+
"$hidden": !collapsed,
|
|
290
|
+
children: jsx(Tooltip, {
|
|
291
|
+
text: "Expand sidebar",
|
|
292
|
+
side: "right",
|
|
293
|
+
children: jsx(IconButton, {
|
|
294
|
+
variant: "naked",
|
|
295
|
+
size: "small",
|
|
296
|
+
iconName: "sidebar",
|
|
297
|
+
"aria-label": "Expand sidebar",
|
|
298
|
+
"aria-expanded": false,
|
|
299
|
+
onClick: toggle
|
|
300
|
+
})
|
|
301
|
+
})
|
|
302
|
+
})]
|
|
303
|
+
})]
|
|
304
|
+
}), jsx(Body, {
|
|
305
|
+
ref: bodyRef,
|
|
306
|
+
children: jsxs(Content, {
|
|
307
|
+
ref: contentRef,
|
|
308
|
+
onPointerOver: function onPointerOver(event) {
|
|
309
|
+
return event.pointerType !== 'touch' && highlightRow(event.target);
|
|
310
|
+
},
|
|
311
|
+
onPointerLeave: hide,
|
|
312
|
+
onFocus: function onFocus(event) {
|
|
313
|
+
return isKeyboardFocus(event.target) && highlightRow(event.target);
|
|
314
|
+
},
|
|
315
|
+
onBlur: function onBlur(event) {
|
|
316
|
+
var _a;
|
|
317
|
+
if (!((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.relatedTarget))) hide();
|
|
318
|
+
},
|
|
319
|
+
children: [jsx(Highlight, {
|
|
320
|
+
"aria-hidden": "true",
|
|
321
|
+
"data-sidebar-highlight": "",
|
|
322
|
+
"$visible": highlight.visible,
|
|
323
|
+
"$instant": highlight.instant,
|
|
324
|
+
style: highlight.box ? {
|
|
325
|
+
transform: "translate(".concat(highlight.box.left, "px, ").concat(highlight.box.top, "px)"),
|
|
326
|
+
width: highlight.box.width,
|
|
327
|
+
height: highlight.box.height
|
|
328
|
+
} : undefined
|
|
329
|
+
}), jsx(List, {
|
|
330
|
+
children: children
|
|
331
|
+
})]
|
|
332
|
+
})
|
|
333
|
+
}), footer && jsx(Footer, {
|
|
334
|
+
"$hidden": collapsed,
|
|
335
|
+
children: jsx("div", {
|
|
336
|
+
children: footer
|
|
337
|
+
})
|
|
338
|
+
})]
|
|
339
|
+
})
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
SidebarNav.displayName = 'SidebarNav';
|
|
343
|
+
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10;
|
|
344
|
+
|
|
345
|
+
export { SidebarNav };
|
|
346
|
+
//# sourceMappingURL=SidebarNav.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidebarNav.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SidebarNav/index.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SidebarNav';
|