@pingux/astro 2.21.0-alpha.1 → 2.21.0-alpha.2

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.
@@ -23,11 +23,12 @@ var _useProgressiveState3 = _interopRequireDefault(require("../../hooks/useProgr
23
23
  var _isIterable = require("../../utils/devUtils/props/isIterable");
24
24
  var _Box = _interopRequireDefault(require("../Box/Box"));
25
25
  var _react2 = require("@emotion/react");
26
- var _excluded = ["defaultSelectedKey", "selectedKey", "setSelectedKey", "hasRestoreFocus", "defaultExpandedKeys", "children", "variant"];
26
+ var _excluded = ["isAuto\u0421ollapsible", "defaultSelectedKey", "selectedKey", "setSelectedKey", "hasRestoreFocus", "defaultExpandedKeys", "children", "variant"];
27
27
  function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
28
28
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
29
  var NavBar = function NavBar(props) {
30
- var defaultSelectedKey = props.defaultSelectedKey,
30
+ var isAutoСollapsible = props.isAutoСollapsible,
31
+ defaultSelectedKey = props.defaultSelectedKey,
31
32
  selectedKeyProp = props.selectedKey,
32
33
  setSelectedKeyProp = props.setSelectedKey,
33
34
  hasRestoreFocus = props.hasRestoreFocus,
@@ -35,7 +36,8 @@ var NavBar = function NavBar(props) {
35
36
  children = props.children,
36
37
  variant = props.variant,
37
38
  others = (0, _objectWithoutProperties2["default"])(props, _excluded);
38
- var _useState = (0, _react.useState)(defaultExpandedKeys),
39
+ var initialExpandedKeys = isAutoСollapsible && defaultExpandedKeys.length ? defaultExpandedKeys[0] : defaultExpandedKeys;
40
+ var _useState = (0, _react.useState)(initialExpandedKeys),
39
41
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
40
42
  expandedKeys = _useState2[0],
41
43
  setExpandedKeys = _useState2[1];
@@ -53,13 +55,16 @@ var NavBar = function NavBar(props) {
53
55
  item: children,
54
56
  key: children.key
55
57
  }];
56
- var contextValue = {
57
- selectedKey: selectedKey,
58
- setSelectedKey: setSelectedKeyProp || setSelectedKey,
59
- expandedKeys: expandedKeys,
60
- setExpandedKeys: setExpandedKeys,
61
- navStyles: navStyles
62
- };
58
+ var contextValue = (0, _react.useMemo)(function () {
59
+ return {
60
+ isAutoСollapsible: isAutoСollapsible,
61
+ selectedKey: selectedKey,
62
+ setSelectedKey: setSelectedKeyProp || setSelectedKey,
63
+ expandedKeys: expandedKeys,
64
+ setExpandedKeys: setExpandedKeys,
65
+ navStyles: navStyles
66
+ };
67
+ }, [isAutoСollapsible, selectedKey, setSelectedKeyProp, setSelectedKey, expandedKeys, setExpandedKeys, navStyles]);
63
68
  return (0, _react2.jsx)(_NavBarContext.NavBarContext.Provider, {
64
69
  value: contextValue
65
70
  }, (0, _react2.jsx)(_Box["default"], (0, _extends2["default"])({
@@ -100,6 +105,8 @@ var FocusableItem = function FocusableItem(props) {
100
105
  return childWithFocusHandle;
101
106
  };
102
107
  NavBar.propTypes = {
108
+ /** Allows only one item to be expanded. */
109
+ isAutoСollapsible: _propTypes["default"].bool,
103
110
  /** This applies a style to the entire nav tree. the options are default and popup. */
104
111
  variant: _propTypes["default"].oneOf(['default', 'popupNav']),
105
112
  /** Whether or not the focus will return to the previously focused element upon unmount. */
@@ -118,6 +125,7 @@ NavBar.propTypes = {
118
125
  setSelectedKey: _propTypes["default"].func
119
126
  };
120
127
  NavBar.defaultProps = {
128
+ isAutoСollapsible: false,
121
129
  defaultSelectedKey: '',
122
130
  defaultExpandedKeys: [],
123
131
  variant: 'default',
@@ -8,7 +8,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
8
8
  _Object$defineProperty(exports, "__esModule", {
9
9
  value: true
10
10
  });
11
- exports["default"] = exports.Default = exports.Controlled = void 0;
11
+ exports["default"] = exports.Default = exports.Controlled = exports.AutoCollapse = void 0;
12
12
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
13
13
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
14
14
  var _react = _interopRequireWildcard(require("react"));
@@ -474,4 +474,42 @@ var Controlled = function Controlled() {
474
474
  "data-id": "third-nav-bar-section"
475
475
  })));
476
476
  };
477
- exports.Controlled = Controlled;
477
+ exports.Controlled = Controlled;
478
+ var AutoCollapse = function AutoCollapse() {
479
+ return (0, _react2.jsx)(_index.NavBar, {
480
+ isAutoСollapsible: true
481
+ }, (0, _react2.jsx)(_index.Box, {
482
+ padding: "md",
483
+ key: "top-logo-parent"
484
+ }, (0, _react2.jsx)(_index.Link, {
485
+ "aria-label": "home link",
486
+ href: "https://pingidentity.com",
487
+ target: "_blank"
488
+ }, logo)), (0, _react2.jsx)(_index.Separator, {
489
+ m: 0,
490
+ backgroundColor: "neutral.60"
491
+ }), (0, _react2.jsx)(_index.Box, {
492
+ variant: "navBar.sectionContainer",
493
+ paddingBottom: "xl",
494
+ key: "first-section-container"
495
+ }, (0, _react2.jsx)(_index.NavBarItem, {
496
+ "data-id": "nav-bar-item",
497
+ icon: _GlobeIcon["default"],
498
+ id: "Overview",
499
+ key: "Overview",
500
+ text: "Overview"
501
+ }), (0, _react2.jsx)(_index.NavBarSection, {
502
+ items: data,
503
+ "data-id": "nav-bar-section"
504
+ }), (0, _react2.jsx)(_index.NavBarSection, {
505
+ items: secondData,
506
+ hasSeparator: true,
507
+ title: "PingOne Services",
508
+ "data-id": "second-nav-bar-section"
509
+ }), (0, _react2.jsx)(_index.NavBarSection, {
510
+ items: thirdData,
511
+ hasSeparator: true,
512
+ "data-id": "third-nav-bar-section"
513
+ })));
514
+ };
515
+ exports.AutoCollapse = AutoCollapse;
@@ -49,12 +49,12 @@ var data = [{
49
49
  icon: _ViewDashboardIcon["default"],
50
50
  key: 'Dashboard',
51
51
  heading: 'Dashboard',
52
- children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles']
52
+ children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles', 'Dashboard Unique']
53
53
  }, {
54
54
  icon: _AccountMultipleIcon["default"],
55
55
  key: 'Identities',
56
56
  heading: 'Identities',
57
- children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles']
57
+ children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles', 'Identities Unique']
58
58
  }, {
59
59
  icon: _TransitConnectionVariantIcon["default"],
60
60
  key: 'Connections',
@@ -468,4 +468,18 @@ test('controlled version: items can be updated.', function () {
468
468
  expect(thisitem).toBeInTheDocument();
469
469
  _userEvent["default"].click(button);
470
470
  expect(_testWrapper.screen.queryByTestId('Environment title that is so long, it wraps')).not.toBeInTheDocument();
471
+ });
472
+ test('expand only one item', function () {
473
+ getComponent({
474
+ isAutoСollapsible: true
475
+ });
476
+ expect(_testWrapper.screen.queryByText('Dashboard Unique')).not.toBeInTheDocument();
477
+ expect(_testWrapper.screen.queryByText('Identities Unique')).not.toBeInTheDocument();
478
+ var headerButtons = _testWrapper.screen.getAllByRole('button');
479
+ _userEvent["default"].click(headerButtons[1]);
480
+ expect(_testWrapper.screen.queryByText('Dashboard Unique')).toBeInTheDocument();
481
+ expect(_testWrapper.screen.queryByText('Identities Unique')).not.toBeInTheDocument();
482
+ _userEvent["default"].click(headerButtons[2]);
483
+ expect(_testWrapper.screen.queryByText('Dashboard Unique')).not.toBeInTheDocument();
484
+ expect(_testWrapper.screen.queryByText('Identities Unique')).toBeInTheDocument();
471
485
  });
@@ -78,7 +78,8 @@ var SectionItem = function SectionItem(_ref2) {
78
78
  children = item.children,
79
79
  others = (0, _objectWithoutProperties2["default"])(item, _excluded2);
80
80
  var navBarState = (0, _NavBarContext.useNavBarContext)();
81
- var expandedKeys = navBarState.expandedKeys,
81
+ var isAutoСollapsible = navBarState.isAutoСollapsible,
82
+ expandedKeys = navBarState.expandedKeys,
82
83
  setExpandedKeys = navBarState.setExpandedKeys;
83
84
  var isExpanded = (0, _includes["default"])(expandedKeys).call(expandedKeys, key);
84
85
  var firstChildKey = children.length ? children[0].key : null;
@@ -87,7 +88,7 @@ var SectionItem = function SectionItem(_ref2) {
87
88
  var newArray;
88
89
  if (isOpen) {
89
90
  var _context;
90
- newArray = (0, _concat["default"])(_context = []).call(_context, expandedKeys, [key]);
91
+ newArray = isAutoСollapsible ? [key] : (0, _concat["default"])(_context = []).call(_context, expandedKeys, [key]);
91
92
  } else {
92
93
  newArray = (0, _filter["default"])(expandedKeys).call(expandedKeys, function (thiskey) {
93
94
  return thiskey !== key;
@@ -1,10 +1,10 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
2
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
4
- var _excluded = ["defaultSelectedKey", "selectedKey", "setSelectedKey", "hasRestoreFocus", "defaultExpandedKeys", "children", "variant"];
4
+ var _excluded = ["isAuto\u0421ollapsible", "defaultSelectedKey", "selectedKey", "setSelectedKey", "hasRestoreFocus", "defaultExpandedKeys", "children", "variant"];
5
5
  import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
6
6
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
7
- import React, { useState } from 'react';
7
+ import React, { useMemo, useState } from 'react';
8
8
  import { FocusScope, useFocusManager } from '@react-aria/focus';
9
9
  import PropTypes from 'prop-types';
10
10
  import { NavBarContext } from '../../context/NavBarContext';
@@ -14,7 +14,8 @@ import { isIterableProp } from '../../utils/devUtils/props/isIterable';
14
14
  import Box from '../Box/Box';
15
15
  import { jsx as ___EmotionJSX } from "@emotion/react";
16
16
  var NavBar = function NavBar(props) {
17
- var defaultSelectedKey = props.defaultSelectedKey,
17
+ var isAutoСollapsible = props.isAutoСollapsible,
18
+ defaultSelectedKey = props.defaultSelectedKey,
18
19
  selectedKeyProp = props.selectedKey,
19
20
  setSelectedKeyProp = props.setSelectedKey,
20
21
  hasRestoreFocus = props.hasRestoreFocus,
@@ -22,7 +23,8 @@ var NavBar = function NavBar(props) {
22
23
  children = props.children,
23
24
  variant = props.variant,
24
25
  others = _objectWithoutProperties(props, _excluded);
25
- var _useState = useState(defaultExpandedKeys),
26
+ var initialExpandedKeys = isAutoСollapsible && defaultExpandedKeys.length ? defaultExpandedKeys[0] : defaultExpandedKeys;
27
+ var _useState = useState(initialExpandedKeys),
26
28
  _useState2 = _slicedToArray(_useState, 2),
27
29
  expandedKeys = _useState2[0],
28
30
  setExpandedKeys = _useState2[1];
@@ -40,13 +42,16 @@ var NavBar = function NavBar(props) {
40
42
  item: children,
41
43
  key: children.key
42
44
  }];
43
- var contextValue = {
44
- selectedKey: selectedKey,
45
- setSelectedKey: setSelectedKeyProp || setSelectedKey,
46
- expandedKeys: expandedKeys,
47
- setExpandedKeys: setExpandedKeys,
48
- navStyles: navStyles
49
- };
45
+ var contextValue = useMemo(function () {
46
+ return {
47
+ isAutoСollapsible: isAutoСollapsible,
48
+ selectedKey: selectedKey,
49
+ setSelectedKey: setSelectedKeyProp || setSelectedKey,
50
+ expandedKeys: expandedKeys,
51
+ setExpandedKeys: setExpandedKeys,
52
+ navStyles: navStyles
53
+ };
54
+ }, [isAutoСollapsible, selectedKey, setSelectedKeyProp, setSelectedKey, expandedKeys, setExpandedKeys, navStyles]);
50
55
  return ___EmotionJSX(NavBarContext.Provider, {
51
56
  value: contextValue
52
57
  }, ___EmotionJSX(Box, _extends({
@@ -87,6 +92,8 @@ var FocusableItem = function FocusableItem(props) {
87
92
  return childWithFocusHandle;
88
93
  };
89
94
  NavBar.propTypes = {
95
+ /** Allows only one item to be expanded. */
96
+ isAutoСollapsible: PropTypes.bool,
90
97
  /** This applies a style to the entire nav tree. the options are default and popup. */
91
98
  variant: PropTypes.oneOf(['default', 'popupNav']),
92
99
  /** Whether or not the focus will return to the previously focused element upon unmount. */
@@ -105,6 +112,7 @@ NavBar.propTypes = {
105
112
  setSelectedKey: PropTypes.func
106
113
  };
107
114
  NavBar.defaultProps = {
115
+ isAutoСollapsible: false,
108
116
  defaultSelectedKey: '',
109
117
  defaultExpandedKeys: [],
110
118
  variant: 'default',
@@ -458,4 +458,41 @@ export var Controlled = function Controlled() {
458
458
  items: customData,
459
459
  "data-id": "third-nav-bar-section"
460
460
  })));
461
+ };
462
+ export var AutoCollapse = function AutoCollapse() {
463
+ return ___EmotionJSX(NavBar, {
464
+ isAutoСollapsible: true
465
+ }, ___EmotionJSX(Box, {
466
+ padding: "md",
467
+ key: "top-logo-parent"
468
+ }, ___EmotionJSX(Link, {
469
+ "aria-label": "home link",
470
+ href: "https://pingidentity.com",
471
+ target: "_blank"
472
+ }, logo)), ___EmotionJSX(Separator, {
473
+ m: 0,
474
+ backgroundColor: "neutral.60"
475
+ }), ___EmotionJSX(Box, {
476
+ variant: "navBar.sectionContainer",
477
+ paddingBottom: "xl",
478
+ key: "first-section-container"
479
+ }, ___EmotionJSX(NavBarItem, {
480
+ "data-id": "nav-bar-item",
481
+ icon: GlobeIcon,
482
+ id: "Overview",
483
+ key: "Overview",
484
+ text: "Overview"
485
+ }), ___EmotionJSX(NavBarSection, {
486
+ items: data,
487
+ "data-id": "nav-bar-section"
488
+ }), ___EmotionJSX(NavBarSection, {
489
+ items: secondData,
490
+ hasSeparator: true,
491
+ title: "PingOne Services",
492
+ "data-id": "second-nav-bar-section"
493
+ }), ___EmotionJSX(NavBarSection, {
494
+ items: thirdData,
495
+ hasSeparator: true,
496
+ "data-id": "third-nav-bar-section"
497
+ })));
461
498
  };
@@ -40,12 +40,12 @@ var data = [{
40
40
  icon: ViewDashboard,
41
41
  key: 'Dashboard',
42
42
  heading: 'Dashboard',
43
- children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles']
43
+ children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles', 'Dashboard Unique']
44
44
  }, {
45
45
  icon: AccountMultiple,
46
46
  key: 'Identities',
47
47
  heading: 'Identities',
48
- children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles']
48
+ children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles', 'Identities Unique']
49
49
  }, {
50
50
  icon: TransitConnection,
51
51
  key: 'Connections',
@@ -459,4 +459,18 @@ test('controlled version: items can be updated.', function () {
459
459
  expect(thisitem).toBeInTheDocument();
460
460
  userEvent.click(button);
461
461
  expect(screen.queryByTestId('Environment title that is so long, it wraps')).not.toBeInTheDocument();
462
+ });
463
+ test('expand only one item', function () {
464
+ getComponent({
465
+ isAutoСollapsible: true
466
+ });
467
+ expect(screen.queryByText('Dashboard Unique')).not.toBeInTheDocument();
468
+ expect(screen.queryByText('Identities Unique')).not.toBeInTheDocument();
469
+ var headerButtons = screen.getAllByRole('button');
470
+ userEvent.click(headerButtons[1]);
471
+ expect(screen.queryByText('Dashboard Unique')).toBeInTheDocument();
472
+ expect(screen.queryByText('Identities Unique')).not.toBeInTheDocument();
473
+ userEvent.click(headerButtons[2]);
474
+ expect(screen.queryByText('Dashboard Unique')).not.toBeInTheDocument();
475
+ expect(screen.queryByText('Identities Unique')).toBeInTheDocument();
462
476
  });
@@ -66,7 +66,8 @@ var SectionItem = function SectionItem(_ref2) {
66
66
  children = item.children,
67
67
  others = _objectWithoutProperties(item, _excluded2);
68
68
  var navBarState = useNavBarContext();
69
- var expandedKeys = navBarState.expandedKeys,
69
+ var isAutoСollapsible = navBarState.isAutoСollapsible,
70
+ expandedKeys = navBarState.expandedKeys,
70
71
  setExpandedKeys = navBarState.setExpandedKeys;
71
72
  var isExpanded = _includesInstanceProperty(expandedKeys).call(expandedKeys, key);
72
73
  var firstChildKey = children.length ? children[0].key : null;
@@ -75,7 +76,7 @@ var SectionItem = function SectionItem(_ref2) {
75
76
  var newArray;
76
77
  if (isOpen) {
77
78
  var _context;
78
- newArray = _concatInstanceProperty(_context = []).call(_context, expandedKeys, [key]);
79
+ newArray = isAutoСollapsible ? [key] : _concatInstanceProperty(_context = []).call(_context, expandedKeys, [key]);
79
80
  } else {
80
81
  newArray = _filterInstanceProperty(expandedKeys).call(expandedKeys, function (thiskey) {
81
82
  return thiskey !== key;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "2.21.0-alpha.1",
3
+ "version": "2.21.0-alpha.2",
4
4
  "description": "React component library for Ping Identity's design system",
5
5
  "repository": {
6
6
  "type": "git",