@pingux/astro 2.81.0-alpha.0 → 2.81.0-alpha.1
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/lib/cjs/components/NavBar/NavBar.styles.d.ts +30 -0
- package/lib/cjs/components/NavBar/NavBar.styles.js +34 -1
- package/lib/cjs/components/NavBarSection/NavBarItemLink.js +1 -4
- package/lib/cjs/components/NavSideBar/Icon.test.d.ts +1 -0
- package/lib/cjs/components/NavSideBar/Icon.test.js +67 -0
- package/lib/cjs/components/NavSideBar/NavSideBar.d.ts +4 -0
- package/lib/cjs/components/NavSideBar/NavSideBar.js +115 -0
- package/lib/cjs/components/NavSideBar/NavSideBar.mdx +42 -0
- package/lib/cjs/components/NavSideBar/NavSideBar.stories.d.ts +8 -0
- package/lib/cjs/components/NavSideBar/NavSideBar.stories.js +1344 -0
- package/lib/cjs/components/NavSideBar/NavSideBar.test.d.ts +1 -0
- package/lib/cjs/components/NavSideBar/NavSideBar.test.js +311 -0
- package/lib/cjs/components/NavSideBar/NavSideBarHeader.d.ts +4 -0
- package/lib/cjs/components/NavSideBar/NavSideBarHeader.js +33 -0
- package/lib/cjs/components/NavSideBar/NavSideBarItem.d.ts +4 -0
- package/lib/cjs/components/NavSideBar/NavSideBarItem.js +112 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSection.d.ts +4 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSection.js +122 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSectionHeader.d.ts +4 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSectionHeader.js +98 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSectionItem.d.ts +4 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSectionItem.js +81 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSubTitle.d.ts +4 -0
- package/lib/cjs/components/NavSideBar/NavSideBarSubTitle.js +25 -0
- package/lib/cjs/components/NavSideBar/icons.d.ts +15 -0
- package/lib/cjs/components/NavSideBar/icons.js +174 -0
- package/lib/cjs/components/NavSideBar/index.d.ts +5 -0
- package/lib/cjs/components/NavSideBar/index.js +42 -0
- package/lib/cjs/hooks/useNavBarStyling/useNavBarStyling.d.ts +1 -0
- package/lib/cjs/hooks/useNavBarStyling/useNavBarStyling.js +14 -3
- package/lib/cjs/hooks/useNavBarStyling/useNavBarStyling.test.js +1 -1
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +54 -35
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +28 -17
- package/lib/cjs/types/link.d.ts +1 -0
- package/lib/cjs/types/navSideBar.d.ts +75 -0
- package/lib/cjs/types/navSideBar.js +6 -0
- package/lib/components/NavBar/NavBar.styles.js +34 -1
- package/lib/components/NavBarSection/NavBarItemLink.js +1 -4
- package/lib/components/NavSideBar/Icon.test.js +58 -0
- package/lib/components/NavSideBar/NavSideBar.js +101 -0
- package/lib/components/NavSideBar/NavSideBar.mdx +42 -0
- package/lib/components/NavSideBar/NavSideBar.stories.js +1326 -0
- package/lib/components/NavSideBar/NavSideBar.test.js +308 -0
- package/lib/components/NavSideBar/NavSideBarHeader.js +19 -0
- package/lib/components/NavSideBar/NavSideBarItem.js +98 -0
- package/lib/components/NavSideBar/NavSideBarSection.js +108 -0
- package/lib/components/NavSideBar/NavSideBarSectionHeader.js +84 -0
- package/lib/components/NavSideBar/NavSideBarSectionItem.js +69 -0
- package/lib/components/NavSideBar/NavSideBarSubTitle.js +16 -0
- package/lib/components/NavSideBar/icons.js +102 -0
- package/lib/components/NavSideBar/index.js +5 -0
- package/lib/hooks/useNavBarStyling/useNavBarStyling.js +14 -3
- package/lib/hooks/useNavBarStyling/useNavBarStyling.test.js +1 -1
- package/lib/index.js +2 -0
- package/lib/types/index.js +1 -0
- package/lib/types/navSideBar.js +1 -0
- package/package.json +1 -1
@@ -0,0 +1,308 @@
|
|
1
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
2
|
+
import React from 'react';
|
3
|
+
import userEvent from '@testing-library/user-event';
|
4
|
+
import { Box, NavSideBarHeader, NavSideBarItem, NavSideBarSection, NavSideBarSectionItem, Separator } from '../../index';
|
5
|
+
import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
6
|
+
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
7
|
+
import { Earth, EmoticonHappy, Fingerprint, GlobeIcon, Logo, OpenInNew, ViewDashboard, ViewGridPlusOutline } from './icons';
|
8
|
+
import NavSideBar from './NavSideBar';
|
9
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
10
|
+
var onKeyDownProp = jest.fn();
|
11
|
+
var getComponent = function getComponent() {
|
12
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
13
|
+
return render(___EmotionJSX(NavSideBar, props, ___EmotionJSX(NavSideBarHeader, {
|
14
|
+
linkProps: {
|
15
|
+
href: 'https://pingidentity.com/',
|
16
|
+
target: '_blank'
|
17
|
+
},
|
18
|
+
logo: Logo
|
19
|
+
}), ___EmotionJSX(Separator, {
|
20
|
+
m: "0",
|
21
|
+
backgroundColor: "neutral.60",
|
22
|
+
key: "top-separator"
|
23
|
+
}), ___EmotionJSX(Box, {
|
24
|
+
variant: "navBar.sectionContainer",
|
25
|
+
paddingBottom: "xl",
|
26
|
+
key: "first-section-container"
|
27
|
+
}, ___EmotionJSX(NavSideBarItem, {
|
28
|
+
key: "Overview",
|
29
|
+
icon: GlobeIcon,
|
30
|
+
id: "Overview",
|
31
|
+
"data-testid": "navItem"
|
32
|
+
}, "Overview"), ___EmotionJSX(NavSideBarSection, {
|
33
|
+
title: "Dashboard",
|
34
|
+
key: "Dashboard",
|
35
|
+
id: "Dashboard",
|
36
|
+
icon: ViewDashboard
|
37
|
+
}, ___EmotionJSX(NavSideBarSectionItem, {
|
38
|
+
key: "Dashboard Link Group",
|
39
|
+
linkProps: {
|
40
|
+
href: 'https://pingidentity.com/'
|
41
|
+
},
|
42
|
+
"data-testid": "navItemLink"
|
43
|
+
}, "Group"), ___EmotionJSX(NavSideBarSectionItem, {
|
44
|
+
key: "Dashboard Link Populations",
|
45
|
+
"data-testid": "navItemButton"
|
46
|
+
}, "Populations")), ___EmotionJSX(NavSideBarSection, {
|
47
|
+
title: "MFA",
|
48
|
+
key: "MFA",
|
49
|
+
id: "MFA",
|
50
|
+
icon: Fingerprint
|
51
|
+
}, ___EmotionJSX(NavSideBarSectionItem, {
|
52
|
+
key: "MFA Button Users"
|
53
|
+
}, "Users"), ___EmotionJSX(NavSideBarSectionItem, {
|
54
|
+
key: "PingOne Services"
|
55
|
+
}), ___EmotionJSX(NavSideBarSectionItem, {
|
56
|
+
key: "MFA Button Group"
|
57
|
+
}, "Group Test")), ___EmotionJSX(NavSideBarItem, {
|
58
|
+
key: "DaVinci",
|
59
|
+
id: "DaVinci",
|
60
|
+
"data-testid": "navBarItemLink",
|
61
|
+
icon: ViewGridPlusOutline,
|
62
|
+
customIcon: OpenInNew,
|
63
|
+
linkProps: {
|
64
|
+
href: 'https://pingidentity.com/'
|
65
|
+
}
|
66
|
+
}, "DaVinci"), ___EmotionJSX(NavSideBarSection, {
|
67
|
+
title: "Environment title that is so long, it wraps",
|
68
|
+
key: "Environment",
|
69
|
+
id: "Environment",
|
70
|
+
icon: Earth
|
71
|
+
}, ___EmotionJSX(NavSideBarSectionItem, {
|
72
|
+
key: "Earth Button Users"
|
73
|
+
}, "Users"), ___EmotionJSX(NavSideBarSectionItem, {
|
74
|
+
key: "Earth Button Group"
|
75
|
+
}, "Group")), ___EmotionJSX(NavSideBarSection, {
|
76
|
+
title: "Credentials",
|
77
|
+
key: "Credentials",
|
78
|
+
id: "Credentials",
|
79
|
+
"data-testid": "Credentials",
|
80
|
+
icon: EmoticonHappy,
|
81
|
+
onKeyDown: onKeyDownProp
|
82
|
+
}, ___EmotionJSX(NavSideBarSectionItem, {
|
83
|
+
key: "Credentials Button Users"
|
84
|
+
}, "Users"), ___EmotionJSX(NavSideBarSectionItem, {
|
85
|
+
key: "Credentials Button Group"
|
86
|
+
}, "Group")))));
|
87
|
+
};
|
88
|
+
|
89
|
+
// Needs to be added to each components test file
|
90
|
+
universalComponentTests({
|
91
|
+
renderComponent: function renderComponent(props) {
|
92
|
+
return ___EmotionJSX(NavSideBar, props, ___EmotionJSX(NavSideBarItem, {
|
93
|
+
key: "Overview",
|
94
|
+
icon: GlobeIcon,
|
95
|
+
id: "Overview"
|
96
|
+
}, "Overview"));
|
97
|
+
}
|
98
|
+
});
|
99
|
+
var clickHeaderButtons = function clickHeaderButtons() {
|
100
|
+
var headerButtons = screen.getAllByRole('button');
|
101
|
+
_forEachInstanceProperty(headerButtons).call(headerButtons, function (button) {
|
102
|
+
return userEvent.click(button);
|
103
|
+
});
|
104
|
+
};
|
105
|
+
test('should render basic nav with children', function () {
|
106
|
+
getComponent();
|
107
|
+
expect(screen.queryByRole('navigation')).toBeInTheDocument();
|
108
|
+
});
|
109
|
+
test('should render title for sections that have titles', function () {
|
110
|
+
getComponent();
|
111
|
+
expect(screen.getByText('Dashboard')).toBeInTheDocument();
|
112
|
+
});
|
113
|
+
test('should select NavItemLink', function () {
|
114
|
+
getComponent();
|
115
|
+
clickHeaderButtons();
|
116
|
+
var link = screen.getByTestId('navItemLink');
|
117
|
+
expect(link).toBeInTheDocument();
|
118
|
+
userEvent.click(link);
|
119
|
+
expect(link).toHaveClass('is-selected');
|
120
|
+
});
|
121
|
+
test('should select NavItemLink on space key press', function () {
|
122
|
+
getComponent();
|
123
|
+
clickHeaderButtons();
|
124
|
+
var link = screen.getByTestId('navItemLink');
|
125
|
+
expect(link).toBeInTheDocument();
|
126
|
+
fireEvent.keyDown(link, {
|
127
|
+
key: 'Space',
|
128
|
+
keyCode: 32
|
129
|
+
});
|
130
|
+
expect(link).toHaveClass('is-selected');
|
131
|
+
});
|
132
|
+
test('should select NavItem', function () {
|
133
|
+
getComponent();
|
134
|
+
var item;
|
135
|
+
item = screen.queryByTestId('navItem');
|
136
|
+
expect(item).toBeInTheDocument();
|
137
|
+
userEvent.click(item);
|
138
|
+
item = screen.queryByTestId('navItem');
|
139
|
+
expect(item).toHaveClass('is-selected');
|
140
|
+
});
|
141
|
+
test('should select NavItemButton', function () {
|
142
|
+
getComponent();
|
143
|
+
clickHeaderButtons();
|
144
|
+
var button = screen.getByTestId('navItemButton');
|
145
|
+
expect(button).toBeInTheDocument();
|
146
|
+
userEvent.click(button);
|
147
|
+
expect(button).toHaveClass('is-selected');
|
148
|
+
});
|
149
|
+
test('should collapse NavItemBody', function () {
|
150
|
+
getComponent();
|
151
|
+
expect(screen.queryByText('Users')).not.toBeInTheDocument();
|
152
|
+
clickHeaderButtons();
|
153
|
+
expect(screen.getByTestId('navItemButton')).toBeInTheDocument();
|
154
|
+
clickHeaderButtons();
|
155
|
+
expect(screen.queryByText('Users')).not.toBeInTheDocument();
|
156
|
+
});
|
157
|
+
test('should collapse NavItemBody on Escape key press', function () {
|
158
|
+
getComponent();
|
159
|
+
clickHeaderButtons();
|
160
|
+
expect(screen.getByTestId('navItemButton')).toBeInTheDocument();
|
161
|
+
var headerButtons = screen.getAllByRole('button');
|
162
|
+
_forEachInstanceProperty(headerButtons).call(headerButtons, function (headerButton) {
|
163
|
+
return fireEvent.keyDown(headerButton, {
|
164
|
+
key: 'Escape',
|
165
|
+
keyCode: 27
|
166
|
+
});
|
167
|
+
});
|
168
|
+
expect(screen.queryByText('Users')).not.toBeInTheDocument();
|
169
|
+
});
|
170
|
+
test('should change focus between NavBarItemHeader on arrow key press', function () {
|
171
|
+
getComponent();
|
172
|
+
var headerButtons = screen.getAllByRole('button');
|
173
|
+
expect(headerButtons[0]).toBeInTheDocument();
|
174
|
+
headerButtons[0].focus();
|
175
|
+
expect(headerButtons[0]).toHaveClass('is-focused');
|
176
|
+
fireEvent.keyDown(headerButtons[0], {
|
177
|
+
key: 'ArrowDown',
|
178
|
+
keyCode: 40
|
179
|
+
});
|
180
|
+
expect(headerButtons[1]).toHaveClass('is-focused');
|
181
|
+
fireEvent.keyDown(headerButtons[0], {
|
182
|
+
key: 'ArrowRight',
|
183
|
+
keyCode: 39
|
184
|
+
});
|
185
|
+
expect(headerButtons[2]).toHaveClass('is-focused');
|
186
|
+
fireEvent.keyDown(headerButtons[0], {
|
187
|
+
key: 'ArrowLeft',
|
188
|
+
keyCode: 37
|
189
|
+
});
|
190
|
+
expect(headerButtons[1]).toHaveClass('is-focused');
|
191
|
+
fireEvent.keyDown(headerButtons[0], {
|
192
|
+
key: 'ArrowUp',
|
193
|
+
keyCode: 38
|
194
|
+
});
|
195
|
+
expect(headerButtons[0]).toHaveClass('is-focused');
|
196
|
+
fireEvent.keyDown(headerButtons[0], {
|
197
|
+
key: 'Shift',
|
198
|
+
keyCode: 16
|
199
|
+
});
|
200
|
+
expect(headerButtons[0]).toHaveClass('is-focused');
|
201
|
+
});
|
202
|
+
test('should not change focus from NavItemBody to NavBarItemHeader on up/down arrow key press', function () {
|
203
|
+
getComponent();
|
204
|
+
var headerButtons = screen.getAllByRole('button');
|
205
|
+
expect(headerButtons[1]).toBeInTheDocument();
|
206
|
+
headerButtons[1].click();
|
207
|
+
fireEvent.keyDown(headerButtons[0], {
|
208
|
+
key: 'ArrowDown',
|
209
|
+
keyCode: 40
|
210
|
+
});
|
211
|
+
expect(screen.getByTestId('navItemLink')).toHaveClass('is-focused');
|
212
|
+
expect(document.activeElement).toHaveTextContent('Group');
|
213
|
+
fireEvent.keyDown(screen.getByTestId('navItemLink'), {
|
214
|
+
key: 'ArrowUp',
|
215
|
+
keyCode: 38
|
216
|
+
});
|
217
|
+
expect(screen.getByTestId('navItemLink')).toHaveClass('is-focused');
|
218
|
+
expect(document.activeElement).toHaveTextContent('Group');
|
219
|
+
fireEvent.keyDown(screen.getByTestId('navItemLink'), {
|
220
|
+
key: 'ArrowDown',
|
221
|
+
keyCode: 40
|
222
|
+
});
|
223
|
+
expect(screen.getByTestId('navItemButton')).toHaveClass('is-focused');
|
224
|
+
expect(document.activeElement).toHaveTextContent('Populations');
|
225
|
+
fireEvent.keyDown(screen.getByTestId('navItemButton'), {
|
226
|
+
key: 'ArrowDown',
|
227
|
+
keyCode: 40
|
228
|
+
});
|
229
|
+
expect(screen.getByTestId('navItemButton')).toHaveClass('is-focused');
|
230
|
+
expect(document.activeElement).toHaveTextContent('Populations');
|
231
|
+
});
|
232
|
+
test('should not change focus from NavItemBody to NavBarItemHeader on left/right arrow key press', function () {
|
233
|
+
getComponent();
|
234
|
+
var headerButtons = screen.getAllByRole('button');
|
235
|
+
expect(headerButtons[1]).toBeInTheDocument();
|
236
|
+
headerButtons[1].click();
|
237
|
+
fireEvent.keyDown(headerButtons[0], {
|
238
|
+
key: 'ArrowRight',
|
239
|
+
keyCode: 39
|
240
|
+
});
|
241
|
+
expect(screen.getByTestId('navItemLink')).toHaveClass('is-focused');
|
242
|
+
fireEvent.keyDown(screen.getByTestId('navItemLink'), {
|
243
|
+
key: 'ArrowLeft',
|
244
|
+
keyCode: 37
|
245
|
+
});
|
246
|
+
expect(screen.getByTestId('navItemLink')).toHaveClass('is-focused');
|
247
|
+
fireEvent.keyDown(screen.getByTestId('navItemLink'), {
|
248
|
+
key: 'ArrowRight',
|
249
|
+
keyCode: 39
|
250
|
+
});
|
251
|
+
expect(screen.getByTestId('navItemButton')).toHaveClass('is-focused');
|
252
|
+
fireEvent.keyDown(screen.getByTestId('navItemButton'), {
|
253
|
+
key: 'ArrowRight',
|
254
|
+
keyCode: 39
|
255
|
+
});
|
256
|
+
expect(screen.getByTestId('navItemButton')).toHaveClass('is-focused');
|
257
|
+
});
|
258
|
+
test('passing in a string into defaultSelectedKeys makes the key selected by default, and the parent expanded by default ', function () {
|
259
|
+
getComponent({
|
260
|
+
defaultSelectedKey: 'Dashboard Link Populations'
|
261
|
+
});
|
262
|
+
var child = screen.getByTestId('navItemButton');
|
263
|
+
expect(child).toBeInTheDocument();
|
264
|
+
expect(child).toHaveClass('is-selected');
|
265
|
+
});
|
266
|
+
test('expand only one item', function () {
|
267
|
+
getComponent({
|
268
|
+
isAutoСollapsible: true
|
269
|
+
});
|
270
|
+
expect(screen.queryByText('Group')).not.toBeInTheDocument();
|
271
|
+
expect(screen.queryByText('Users')).not.toBeInTheDocument();
|
272
|
+
var headerButtons = screen.getAllByRole('button');
|
273
|
+
userEvent.click(headerButtons[1]);
|
274
|
+
expect(screen.queryByText('Group')).toBeInTheDocument();
|
275
|
+
expect(screen.queryByText('Users')).not.toBeInTheDocument();
|
276
|
+
userEvent.click(headerButtons[2]);
|
277
|
+
expect(screen.queryByText('Group')).not.toBeInTheDocument();
|
278
|
+
expect(screen.queryByText('Users')).toBeInTheDocument();
|
279
|
+
});
|
280
|
+
test('default expended keys', function () {
|
281
|
+
getComponent({
|
282
|
+
isAutoСollapsible: true,
|
283
|
+
defaultExpandedKeys: ['Dashboard']
|
284
|
+
});
|
285
|
+
expect(screen.getByTestId('navItemLink')).toBeInTheDocument();
|
286
|
+
expect(screen.getByTestId('navItemButton')).toBeInTheDocument();
|
287
|
+
});
|
288
|
+
test('when a child is selected, and the parent is collapsed, the parent has the is-selected class', function () {
|
289
|
+
getComponent({
|
290
|
+
defaultSelectedKey: 'Dashboard Link Populations'
|
291
|
+
});
|
292
|
+
var child = screen.getByTestId('navItemButton');
|
293
|
+
expect(child).toBeInTheDocument();
|
294
|
+
expect(child).toHaveClass('is-selected');
|
295
|
+
var parent = screen.getByTestId('Dashboard');
|
296
|
+
expect(parent).not.toHaveClass('is-selected');
|
297
|
+
userEvent.click(parent);
|
298
|
+
var parentDiv = screen.getByTestId('Dashboard').firstElementChild;
|
299
|
+
expect(parentDiv).toHaveClass('is-selected');
|
300
|
+
});
|
301
|
+
test('calls onKeyDownProp when a key is pressed', function () {
|
302
|
+
getComponent();
|
303
|
+
var header = screen.getByText('Credentials');
|
304
|
+
fireEvent.keyDown(header, {
|
305
|
+
key: 'Enter'
|
306
|
+
});
|
307
|
+
expect(onKeyDownProp).toHaveBeenCalled();
|
308
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["linkProps", "logo"];
|
4
|
+
import React, { forwardRef } from 'react';
|
5
|
+
import { useLocalOrForwardRef } from '../../hooks';
|
6
|
+
import { Box, Link } from '../../index';
|
7
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
|
+
var NavSideBarHeader = /*#__PURE__*/forwardRef(function (props, ref) {
|
9
|
+
var linkProps = props.linkProps,
|
10
|
+
logo = props.logo,
|
11
|
+
others = _objectWithoutProperties(props, _excluded);
|
12
|
+
var NavSideBarHeaderRef = useLocalOrForwardRef(ref);
|
13
|
+
return ___EmotionJSX(Box, _extends({
|
14
|
+
p: "md"
|
15
|
+
}, others, {
|
16
|
+
ref: NavSideBarHeaderRef
|
17
|
+
}), ___EmotionJSX(Link, linkProps, logo));
|
18
|
+
});
|
19
|
+
export default NavSideBarHeader;
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["children", "icon", "className", "id", "onPress", "customIcon", "iconProps", "customIconProps"];
|
4
|
+
import React, { forwardRef } from 'react';
|
5
|
+
import { mergeProps, useFocusRing } from 'react-aria';
|
6
|
+
import { useHover, usePress } from '@react-aria/interactions';
|
7
|
+
import { useNavBarContext } from '../../context/NavBarContext';
|
8
|
+
import { useLocalOrForwardRef, useNavBarPress, useStatusClasses } from '../../hooks';
|
9
|
+
import { Box, Button, Icon, Link, Text } from '../../index';
|
10
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
11
|
+
var NavSideBarItem = function NavSideBarItem(props) {
|
12
|
+
var children = props.children,
|
13
|
+
linkProps = props.linkProps;
|
14
|
+
if (linkProps && linkProps !== null && linkProps !== void 0 && linkProps.href) {
|
15
|
+
return ___EmotionJSX(Link, linkProps, ___EmotionJSX(ChildWrapper, props, children));
|
16
|
+
}
|
17
|
+
return ___EmotionJSX(Button, {
|
18
|
+
variant: "link",
|
19
|
+
sx: {
|
20
|
+
width: '100%',
|
21
|
+
display: 'block'
|
22
|
+
}
|
23
|
+
}, ___EmotionJSX(ChildWrapper, props, children));
|
24
|
+
};
|
25
|
+
var ChildWrapper = /*#__PURE__*/forwardRef(function (props, ref) {
|
26
|
+
var children = props.children,
|
27
|
+
icon = props.icon,
|
28
|
+
className = props.className,
|
29
|
+
key = props.id,
|
30
|
+
onPressCallback = props.onPress,
|
31
|
+
customIcon = props.customIcon,
|
32
|
+
iconProps = props.iconProps,
|
33
|
+
customIconProps = props.customIconProps,
|
34
|
+
others = _objectWithoutProperties(props, _excluded);
|
35
|
+
var navItemRef = useLocalOrForwardRef(ref);
|
36
|
+
var _useHover = useHover({}),
|
37
|
+
hoverProps = _useHover.hoverProps,
|
38
|
+
isHovered = _useHover.isHovered;
|
39
|
+
var _useFocusRing = useFocusRing({
|
40
|
+
within: true
|
41
|
+
}),
|
42
|
+
focusWithinProps = _useFocusRing.focusProps;
|
43
|
+
var _useFocusRing2 = useFocusRing(),
|
44
|
+
focusProps = _useFocusRing2.focusProps,
|
45
|
+
isFocusVisible = _useFocusRing2.isFocusVisible;
|
46
|
+
var state = useNavBarContext();
|
47
|
+
var isSelected = state.selectedKey === key;
|
48
|
+
var _useNavBarPress = useNavBarPress({
|
49
|
+
key: key,
|
50
|
+
onPressCallback: onPressCallback
|
51
|
+
}, state),
|
52
|
+
onNavPress = _useNavBarPress.onNavPress;
|
53
|
+
var _usePress = usePress({
|
54
|
+
ref: navItemRef,
|
55
|
+
onPress: onNavPress
|
56
|
+
}),
|
57
|
+
pressProps = _usePress.pressProps,
|
58
|
+
isPressed = _usePress.isPressed;
|
59
|
+
var mergedProps = mergeProps(pressProps, hoverProps, focusWithinProps, focusProps, others);
|
60
|
+
var _useStatusClasses = useStatusClasses(className, {
|
61
|
+
isPressed: isPressed,
|
62
|
+
isHovered: isHovered,
|
63
|
+
isSelected: isSelected,
|
64
|
+
isFocused: isFocusVisible
|
65
|
+
}),
|
66
|
+
classNames = _useStatusClasses.classNames;
|
67
|
+
return ___EmotionJSX(Box, _extends({
|
68
|
+
id: key,
|
69
|
+
variant: state.navStyles.navBarItem,
|
70
|
+
isRow: true,
|
71
|
+
alignItems: "center",
|
72
|
+
className: classNames,
|
73
|
+
ref: navItemRef
|
74
|
+
}, mergedProps, {
|
75
|
+
sx: {
|
76
|
+
flexGrow: 0
|
77
|
+
},
|
78
|
+
role: "none"
|
79
|
+
}), icon && ___EmotionJSX(Icon, _extends({
|
80
|
+
icon: icon,
|
81
|
+
title: {
|
82
|
+
name: children
|
83
|
+
},
|
84
|
+
size: state.navStyles.navBarItemHeaderIconSize,
|
85
|
+
variant: isSelected ? state.navStyles.navBarItemIconSelected : state.navStyles.navBarItemIcon
|
86
|
+
}, iconProps)), ___EmotionJSX(Text, {
|
87
|
+
variant: state.navStyles.navBarItemText
|
88
|
+
}, children), customIcon && ___EmotionJSX(Icon, _extends({
|
89
|
+
icon: customIcon,
|
90
|
+
size: state.navStyles.navBarItemHeaderIconSize,
|
91
|
+
variant: isSelected ? state.navStyles.navBarItemCustomIconSelected : state.navStyles.navBarItemCustomIcon
|
92
|
+
}, customIconProps, {
|
93
|
+
title: {
|
94
|
+
name: 'Action Icon'
|
95
|
+
}
|
96
|
+
})));
|
97
|
+
});
|
98
|
+
export default NavSideBarItem;
|
@@ -0,0 +1,108 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["children", "title", "icon", "id", "onKeyDown", "headerProps"];
|
4
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
5
|
+
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
6
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
7
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
8
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
9
|
+
import React, { Children, forwardRef } from 'react';
|
10
|
+
import { useFocusManager } from '@react-aria/focus';
|
11
|
+
import { useKeyboard } from '@react-aria/interactions';
|
12
|
+
import { useNavBarContext } from '../../context/NavBarContext';
|
13
|
+
import { Box } from '../../index';
|
14
|
+
import NavSideBarSectionHeader from './NavSideBarSectionHeader';
|
15
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
16
|
+
var NavSideBarSection = /*#__PURE__*/forwardRef(function (props, ref) {
|
17
|
+
var children = props.children,
|
18
|
+
title = props.title,
|
19
|
+
icon = props.icon,
|
20
|
+
id = props.id,
|
21
|
+
onKeyDownProp = props.onKeyDown,
|
22
|
+
headerProps = props.headerProps,
|
23
|
+
others = _objectWithoutProperties(props, _excluded);
|
24
|
+
var navBarState = useNavBarContext();
|
25
|
+
var isAutoСollapsible = navBarState.isAutoСollapsible,
|
26
|
+
expandedKeys = navBarState.expandedKeys,
|
27
|
+
setExpandedKeys = navBarState.setExpandedKeys;
|
28
|
+
var isExpanded = _includesInstanceProperty(expandedKeys).call(expandedKeys, id);
|
29
|
+
var firstChildKey = _Array$isArray(children) && children.length && children[0].key !== undefined ? children[0].key : null;
|
30
|
+
var lastChildKey = _Array$isArray(children) && children.length && children[children.length - 1].key !== undefined ? children[children.length - 1].key : null;
|
31
|
+
var onExpandedChange = function onExpandedChange(isOpen) {
|
32
|
+
var newArray;
|
33
|
+
if (isOpen) {
|
34
|
+
var _context;
|
35
|
+
newArray = isAutoСollapsible ? [id] : _concatInstanceProperty(_context = []).call(_context, expandedKeys, [id]);
|
36
|
+
} else {
|
37
|
+
newArray = _filterInstanceProperty(expandedKeys).call(expandedKeys, function (thisKey) {
|
38
|
+
return thisKey !== id;
|
39
|
+
});
|
40
|
+
}
|
41
|
+
setExpandedKeys(newArray);
|
42
|
+
};
|
43
|
+
var focusManager = useFocusManager();
|
44
|
+
var _onKeyDown = function onKeyDown(e, childKey) {
|
45
|
+
var _e$target;
|
46
|
+
switch (e.which) {
|
47
|
+
case 37:
|
48
|
+
case 38:
|
49
|
+
if (firstChildKey && childKey !== firstChildKey) {
|
50
|
+
focusManager.focusPrevious();
|
51
|
+
}
|
52
|
+
e.preventDefault();
|
53
|
+
break;
|
54
|
+
case 39:
|
55
|
+
case 40:
|
56
|
+
if (lastChildKey && childKey !== lastChildKey) {
|
57
|
+
focusManager.focusNext();
|
58
|
+
}
|
59
|
+
e.preventDefault();
|
60
|
+
break;
|
61
|
+
case 27:
|
62
|
+
onExpandedChange(false);
|
63
|
+
break;
|
64
|
+
case 32:
|
65
|
+
if (childKey && (_e$target = e.target) !== null && _e$target !== void 0 && _e$target.href) {
|
66
|
+
e.target.click();
|
67
|
+
}
|
68
|
+
break;
|
69
|
+
default:
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
if (onKeyDownProp) {
|
73
|
+
onKeyDownProp(e);
|
74
|
+
}
|
75
|
+
};
|
76
|
+
var _useKeyboard = useKeyboard({
|
77
|
+
onKeyDown: function onKeyDown(e) {
|
78
|
+
_onKeyDown(e, undefined);
|
79
|
+
e.continuePropagation();
|
80
|
+
}
|
81
|
+
}),
|
82
|
+
keyboardProps = _useKeyboard.keyboardProps;
|
83
|
+
var expendedBoxId = "expanded-container-".concat(id);
|
84
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(NavSideBarSectionHeader, _extends({
|
85
|
+
items: children,
|
86
|
+
id: id,
|
87
|
+
"aria-controls": isExpanded ? expendedBoxId : undefined,
|
88
|
+
icon: icon
|
89
|
+
}, keyboardProps, {
|
90
|
+
onExpandedChange: onExpandedChange
|
91
|
+
}, headerProps), title), isExpanded && ___EmotionJSX(Box, {
|
92
|
+
id: expendedBoxId,
|
93
|
+
role: "region"
|
94
|
+
}, ___EmotionJSX(Box, _extends({
|
95
|
+
as: "ul",
|
96
|
+
ref: ref,
|
97
|
+
variant: navBarState.navStyles.navBarSectionList
|
98
|
+
}, others), _mapInstanceProperty(Children).call(Children, children, function (child) {
|
99
|
+
return ___EmotionJSX(Box, {
|
100
|
+
as: "li",
|
101
|
+
variant: navBarState.navStyles.navBarItemHeaderListItem
|
102
|
+
}, /*#__PURE__*/React.isValidElement(child) ? /*#__PURE__*/React.cloneElement(child, {
|
103
|
+
onKeyDown: _onKeyDown,
|
104
|
+
id: child.key
|
105
|
+
}) : child);
|
106
|
+
}))));
|
107
|
+
});
|
108
|
+
export default NavSideBarSection;
|
@@ -0,0 +1,84 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["children", "icon", "items", "id", "className", "onExpandedChange"];
|
4
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
5
|
+
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
6
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
7
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
8
|
+
import React, { useEffect } from 'react';
|
9
|
+
import MenuDown from '@pingux/mdi-react/MenuDownIcon';
|
10
|
+
import MenuUp from '@pingux/mdi-react/MenuUpIcon';
|
11
|
+
import { useNavBarContext } from '../../context/NavBarContext';
|
12
|
+
import { useStatusClasses } from '../../hooks';
|
13
|
+
import { Box, Button, Icon, Text } from '../../index';
|
14
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
15
|
+
var NavSideBarSectionHeader = function NavSideBarSectionHeader(props) {
|
16
|
+
var _context;
|
17
|
+
var children = props.children,
|
18
|
+
icon = props.icon,
|
19
|
+
items = props.items,
|
20
|
+
id = props.id,
|
21
|
+
className = props.className,
|
22
|
+
onExpandedChange = props.onExpandedChange,
|
23
|
+
others = _objectWithoutProperties(props, _excluded);
|
24
|
+
var navBarState = useNavBarContext();
|
25
|
+
var expandedKeys = navBarState.expandedKeys,
|
26
|
+
setExpandedKeys = navBarState.setExpandedKeys,
|
27
|
+
navStyles = navBarState.navStyles,
|
28
|
+
selectedKey = navBarState.selectedKey;
|
29
|
+
var isExpanded = _includesInstanceProperty(expandedKeys).call(expandedKeys, id);
|
30
|
+
var childSelected = _Array$isArray(items) && _includesInstanceProperty(_context = _mapInstanceProperty(items).call(items, function (i) {
|
31
|
+
return i.key;
|
32
|
+
})).call(_context, selectedKey);
|
33
|
+
useEffect(function () {
|
34
|
+
if (childSelected && isExpanded === false) {
|
35
|
+
var _context2;
|
36
|
+
setExpandedKeys(_concatInstanceProperty(_context2 = []).call(_context2, expandedKeys, [id]));
|
37
|
+
}
|
38
|
+
}, []);
|
39
|
+
var _useStatusClasses = useStatusClasses(className, {
|
40
|
+
isSelected: childSelected && !isExpanded
|
41
|
+
}),
|
42
|
+
classNames = _useStatusClasses.classNames;
|
43
|
+
var variant = childSelected && !isExpanded ? navStyles.navBarItemIcon : navStyles.navBarItemIconSelected;
|
44
|
+
var handleButtonPress = function handleButtonPress() {
|
45
|
+
onExpandedChange(!isExpanded);
|
46
|
+
if (childSelected && isExpanded === false) {
|
47
|
+
var _context3;
|
48
|
+
setExpandedKeys(_concatInstanceProperty(_context3 = []).call(_context3, expandedKeys, [id]));
|
49
|
+
}
|
50
|
+
};
|
51
|
+
return ___EmotionJSX(Button, _extends({
|
52
|
+
variant: navStyles.sectionItem,
|
53
|
+
onPress: handleButtonPress,
|
54
|
+
"data-testid": children,
|
55
|
+
"aria-expanded": isExpanded
|
56
|
+
}, others), ___EmotionJSX(Box, {
|
57
|
+
variant: navStyles.navBarItemHeader,
|
58
|
+
className: classNames,
|
59
|
+
isRow: true
|
60
|
+
}, icon && ___EmotionJSX(Icon, {
|
61
|
+
icon: icon,
|
62
|
+
size: navStyles.navBarItemHeaderIconSize,
|
63
|
+
variant: variant,
|
64
|
+
"aria-hidden": "true"
|
65
|
+
}), ___EmotionJSX(Text, {
|
66
|
+
variant: navStyles.navBarItemHeaderText
|
67
|
+
}, children), ___EmotionJSX(Box, {
|
68
|
+
isRow: true,
|
69
|
+
alignItems: "center",
|
70
|
+
sx: {
|
71
|
+
ml: 'auto'
|
72
|
+
}
|
73
|
+
}, ___EmotionJSX(Icon, {
|
74
|
+
icon: isExpanded ? MenuUp : MenuDown,
|
75
|
+
size: navStyles.navBarItemHeaderIconSize,
|
76
|
+
variant: variant,
|
77
|
+
mr: "0",
|
78
|
+
title: {
|
79
|
+
name: isExpanded ? 'Menu up' : 'Menu down'
|
80
|
+
},
|
81
|
+
"aria-label": isExpanded ? 'menu up' : 'menu down'
|
82
|
+
}))));
|
83
|
+
};
|
84
|
+
export default NavSideBarSectionHeader;
|