@hitachivantara/uikit-react-lab 4.3.3 → 4.4.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.
@@ -1,77 +1,112 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
5
  var _Backwards, _Forwards;
6
+ var _excluded = ["onNavigationChange", "onToggleExpanded", "data", "selected", "expanded", "topPosition", "expandedPanelWidth", "collapsedPanelWidth", "position"],
7
+ _excluded2 = ["data"];
8
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
+ import "core-js/modules/es.array.map.js";
11
+ import "core-js/modules/es.array.concat.js";
12
+ import "core-js/modules/es.object.keys.js";
13
+ import "core-js/modules/es.symbol.js";
14
+ import "core-js/modules/es.array.filter.js";
15
+ import "core-js/modules/es.object.to-string.js";
16
+ import "core-js/modules/es.object.get-own-property-descriptor.js";
17
+ import "core-js/modules/web.dom-collections.for-each.js";
18
+ import "core-js/modules/es.object.get-own-property-descriptors.js";
3
19
  import React, { useState } from "react";
4
20
  import { withStyles } from "@mui/styles";
5
21
  import PropTypes from "prop-types";
6
22
  import clsx from "clsx";
7
- import { HvVerticalNavigation as HvVerticalNavigationCore, HvVerticalNavigationTree, HvVerticalNavigationActions, HvButton, setId } from "@hitachivantara/uikit-react-core";
23
+ import { HvVerticalNavigation as HvVerticalNavigationCore, HvVerticalNavigationTree, HvButton, HvContainer } from "@hitachivantara/uikit-react-core";
8
24
  import { Backwards, Forwards } from "@hitachivantara/uikit-react-icons";
9
25
  import useStyles from "./styles";
26
+ import { getAllParents, findRootParentById, findItemById } from "./utils";
10
27
  import { jsx as _jsx } from "react/jsx-runtime";
11
28
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
29
  var HvVerticalNavigation = function HvVerticalNavigation(_ref) {
13
- var id = _ref.id,
14
- onNavigationChange = _ref.onNavigationChange,
30
+ var _findRootParentById;
31
+ var onNavigationChange = _ref.onNavigationChange,
32
+ onToggleExpanded = _ref.onToggleExpanded,
15
33
  data = _ref.data,
16
34
  selected = _ref.selected,
17
- collapseLabel = _ref.collapseLabel,
35
+ expanded = _ref.expanded,
18
36
  topPosition = _ref.topPosition,
19
37
  expandedPanelWidth = _ref.expandedPanelWidth,
20
38
  collapsedPanelWidth = _ref.collapsedPanelWidth,
21
- position = _ref.position;
39
+ position = _ref.position,
40
+ others = _objectWithoutProperties(_ref, _excluded);
22
41
  var classes = useStyles({
23
42
  topPosition: topPosition,
24
43
  expandedPanelWidth: expandedPanelWidth,
25
44
  collapsedPanelWidth: collapsedPanelWidth,
26
45
  position: position
27
46
  })();
28
- var _useState = useState(true),
47
+ var noSubData = data.map(function (_ref2) {
48
+ var dataToRemove = _ref2.data,
49
+ rest = _objectWithoutProperties(_ref2, _excluded2);
50
+ return rest;
51
+ });
52
+ var _useState = useState(getAllParents(data).map(function (item) {
53
+ return item.id;
54
+ })),
29
55
  _useState2 = _slicedToArray(_useState, 2),
30
- isExpanded = _useState2[0],
31
- setIsExpanded = _useState2[1];
56
+ expandedItems = _useState2[0],
57
+ setExpandedItems = _useState2[1];
58
+ var selectedTopParent = (_findRootParentById = findRootParentById(data, selected)) === null || _findRootParentById === void 0 ? void 0 : _findRootParentById.id;
32
59
  var handleVerticalNavigationChange = function handleVerticalNavigationChange(event, item) {
33
- onNavigationChange === null || onNavigationChange === void 0 ? void 0 : onNavigationChange(event, item);
60
+ // This need to be done because the item recieved on the callback is missing the original data object
61
+ var fullItem = findItemById(data, item.id);
62
+ if (!expanded && fullItem.data && fullItem.data.length > 0) {
63
+ setExpandedItems(function (prevState) {
64
+ return [].concat(_toConsumableArray(prevState), [item.id]);
65
+ });
66
+ onToggleExpanded(true);
67
+ } else {
68
+ onNavigationChange === null || onNavigationChange === void 0 ? void 0 : onNavigationChange(event, item);
69
+ }
70
+ };
71
+ var handleVerticalNavigationToggle = function handleVerticalNavigationToggle(event, currentExpandedItems) {
72
+ setExpandedItems(currentExpandedItems);
34
73
  };
35
74
  var handleExpandToggle = function handleExpandToggle() {
36
- setIsExpanded(function (prevState) {
37
- return !prevState;
38
- });
75
+ onToggleExpanded(!expanded);
39
76
  };
40
- return /*#__PURE__*/_jsxs(HvVerticalNavigationCore, {
41
- className: clsx(classes.panel, isExpanded ? classes.panelExpanded : classes.panelCollapsed),
42
- children: [/*#__PURE__*/_jsx(HvVerticalNavigationTree, {
43
- collapsible: true,
44
- data: data,
45
- selected: selected,
46
- onChange: handleVerticalNavigationChange
47
- }), /*#__PURE__*/_jsx(HvVerticalNavigationActions, {
77
+ return /*#__PURE__*/_jsxs(HvVerticalNavigationCore, _objectSpread(_objectSpread({
78
+ className: clsx(classes.panel, expanded ? classes.panelExpanded : classes.panelCollapsed)
79
+ }, others), {}, {
80
+ children: [/*#__PURE__*/_jsx(HvContainer, {
81
+ className: "".concat(classes.toggleCollapsePanel),
48
82
  children: /*#__PURE__*/_jsx(HvButton, {
49
- id: setId(id, "button-toggle"),
50
- className: clsx(isExpanded ? classes.collapseButton : classes.expandButton),
51
- category: "ghost",
52
- startIcon: isExpanded ? _Backwards || (_Backwards = /*#__PURE__*/_jsx(Backwards, {
83
+ icon: true,
84
+ onClick: handleExpandToggle,
85
+ children: expanded ? _Backwards || (_Backwards = /*#__PURE__*/_jsx(Backwards, {
53
86
  iconSize: "XS"
54
87
  })) : _Forwards || (_Forwards = /*#__PURE__*/_jsx(Forwards, {
55
88
  iconSize: "XS"
56
- })),
57
- onClick: handleExpandToggle,
58
- children: isExpanded && /*#__PURE__*/_jsx("span", {
59
- className: classes.collapseTextContainer,
60
- children: collapseLabel
61
- })
89
+ }))
62
90
  })
91
+ }), /*#__PURE__*/_jsx(HvVerticalNavigationTree, {
92
+ collapsible: true,
93
+ expanded: expandedItems,
94
+ data: expanded ? data : noSubData,
95
+ selected: expanded ? selected : selectedTopParent,
96
+ onChange: handleVerticalNavigationChange,
97
+ onToggle: handleVerticalNavigationToggle
63
98
  })]
64
- });
99
+ }));
65
100
  };
66
101
  process.env.NODE_ENV !== "production" ? HvVerticalNavigation.propTypes = {
67
- /**
68
- * Id to be applied to the root node of the panel.
69
- */
70
- id: PropTypes.string,
71
102
  /**
72
103
  * Called when a menu item is clicked.
73
104
  */
74
105
  onNavigationChange: PropTypes.func,
106
+ /**
107
+ * Called when the collapse / expand button is clicked.
108
+ */
109
+ onToggleExpanded: PropTypes.func,
75
110
  /**
76
111
  * An array containing the data for each menu item.
77
112
  *
@@ -90,14 +125,14 @@ process.env.NODE_ENV !== "production" ? HvVerticalNavigation.propTypes = {
90
125
  href: PropTypes.string,
91
126
  target: PropTypes.string
92
127
  })).isRequired,
93
- /**
94
- * Text to be displayed in the collpase area when the panel is expanded.
95
- */
96
- collapseLabel: PropTypes.string,
97
128
  /**
98
129
  * The ID of the selected page.
99
130
  */
100
131
  selected: PropTypes.string,
132
+ /**
133
+ * Boolean value stating if the panel should be collapsed or expanded.
134
+ */
135
+ expanded: PropTypes.bool,
101
136
  /**
102
137
  * The top value where the panel will be rendered. Default is 44 as it is the height of the Header component.
103
138
  */
@@ -116,7 +151,6 @@ process.env.NODE_ENV !== "production" ? HvVerticalNavigation.propTypes = {
116
151
  position: PropTypes.oneOf(["static", "relative", "fixed", "absolute", "sticky"])
117
152
  } : void 0;
118
153
  HvVerticalNavigation.defaultProps = {
119
- collapseLabel: "Collapse",
120
154
  topPosition: 44,
121
155
  expandedPanelWidth: 300,
122
156
  collapsedPanelWidth: 52,
@@ -1 +1 @@
1
- {"version":3,"file":"VerticalNavigation.js","names":["React","useState","withStyles","PropTypes","clsx","HvVerticalNavigation","HvVerticalNavigationCore","HvVerticalNavigationTree","HvVerticalNavigationActions","HvButton","setId","Backwards","Forwards","useStyles","id","onNavigationChange","data","selected","collapseLabel","topPosition","expandedPanelWidth","collapsedPanelWidth","position","classes","isExpanded","setIsExpanded","handleVerticalNavigationChange","event","item","handleExpandToggle","prevState","panel","panelExpanded","panelCollapsed","collapseButton","expandButton","collapseTextContainer","propTypes","string","func","arrayOf","shape","isRequired","label","icon","node","array","href","target","number","oneOf","defaultProps","name"],"sources":["../../../src/VerticalNavigation/VerticalNavigation.js"],"sourcesContent":["import React, { useState } from \"react\";\nimport { withStyles } from \"@mui/styles\";\nimport PropTypes from \"prop-types\";\nimport clsx from \"clsx\";\n\nimport {\n HvVerticalNavigation as HvVerticalNavigationCore,\n HvVerticalNavigationTree,\n HvVerticalNavigationActions,\n HvButton,\n setId,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Backwards, Forwards } from \"@hitachivantara/uikit-react-icons\";\n\nimport useStyles from \"./styles\";\n\nconst HvVerticalNavigation = ({\n id,\n onNavigationChange,\n data,\n selected,\n collapseLabel,\n\n topPosition,\n expandedPanelWidth,\n collapsedPanelWidth,\n position,\n}) => {\n const classes = useStyles({ topPosition, expandedPanelWidth, collapsedPanelWidth, position })();\n\n const [isExpanded, setIsExpanded] = useState(true);\n\n const handleVerticalNavigationChange = (event, item) => {\n onNavigationChange?.(event, item);\n };\n\n const handleExpandToggle = () => {\n setIsExpanded((prevState) => !prevState);\n };\n\n return (\n <HvVerticalNavigationCore\n className={clsx(classes.panel, {\n [classes.panelExpanded]: isExpanded,\n [classes.panelCollapsed]: !isExpanded,\n })}\n >\n <HvVerticalNavigationTree\n collapsible\n data={data}\n selected={selected}\n onChange={handleVerticalNavigationChange}\n />\n\n <HvVerticalNavigationActions>\n <HvButton\n id={setId(id, \"button-toggle\")}\n className={clsx({\n [classes.collapseButton]: isExpanded,\n [classes.expandButton]: !isExpanded,\n })}\n category=\"ghost\"\n startIcon={isExpanded ? <Backwards iconSize=\"XS\" /> : <Forwards iconSize=\"XS\" />}\n onClick={handleExpandToggle}\n >\n {isExpanded && <span className={classes.collapseTextContainer}>{collapseLabel}</span>}\n </HvButton>\n </HvVerticalNavigationActions>\n </HvVerticalNavigationCore>\n );\n};\n\nHvVerticalNavigation.propTypes = {\n /**\n * Id to be applied to the root node of the panel.\n */\n id: PropTypes.string,\n /**\n * Called when a menu item is clicked.\n */\n onNavigationChange: PropTypes.func,\n /**\n * An array containing the data for each menu item.\n *\n * id - the id to be applied to the root element.\n * label - the label to be rendered on the menu item.\n * icon - the icon component.\n * data - sub-menu items\n * href - the url used for navigation.\n * target - the behavior when opening an url.\n */\n data: PropTypes.arrayOf(\n PropTypes.shape({\n id: PropTypes.string.isRequired,\n label: PropTypes.string.isRequired,\n icon: PropTypes.node,\n data: PropTypes.array,\n href: PropTypes.string,\n target: PropTypes.string,\n })\n ).isRequired,\n /**\n * Text to be displayed in the collpase area when the panel is expanded.\n */\n collapseLabel: PropTypes.string,\n /**\n * The ID of the selected page.\n */\n selected: PropTypes.string,\n /**\n * The top value where the panel will be rendered. Default is 44 as it is the height of the Header component.\n */\n topPosition: PropTypes.number,\n /**\n * The width of the panel when expanded. Default value is 300.\n */\n expandedPanelWidth: PropTypes.number,\n /**\n * The width of the panel when collapsed. Default vlaue is 52.\n */\n collapsedPanelWidth: PropTypes.number,\n /**\n * Position of the component.\n */\n position: PropTypes.oneOf([\"static\", \"relative\", \"fixed\", \"absolute\", \"sticky\"]),\n};\n\nHvVerticalNavigation.defaultProps = {\n collapseLabel: \"Collapse\",\n topPosition: 44,\n expandedPanelWidth: 300,\n collapsedPanelWidth: 52,\n position: \"fixed\",\n};\n\nexport default withStyles(useStyles, { name: \"HvVerticalNavigation\" })(HvVerticalNavigation);\n"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,SAASC,UAAU,QAAQ,aAAa;AACxC,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,IAAI,MAAM,MAAM;AAEvB,SACEC,oBAAoB,IAAIC,wBAAwB,EAChDC,wBAAwB,EACxBC,2BAA2B,EAC3BC,QAAQ,EACRC,KAAK,QACA,kCAAkC;AACzC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,mCAAmC;AAEvE,OAAOC,SAAS,MAAM,UAAU;AAAC;AAAA;AAEjC,IAAMR,oBAAoB,GAAG,SAAvBA,oBAAoB,OAWpB;EAAA,IAVJS,EAAE,QAAFA,EAAE;IACFC,kBAAkB,QAAlBA,kBAAkB;IAClBC,IAAI,QAAJA,IAAI;IACJC,QAAQ,QAARA,QAAQ;IACRC,aAAa,QAAbA,aAAa;IAEbC,WAAW,QAAXA,WAAW;IACXC,kBAAkB,QAAlBA,kBAAkB;IAClBC,mBAAmB,QAAnBA,mBAAmB;IACnBC,QAAQ,QAARA,QAAQ;EAER,IAAMC,OAAO,GAAGV,SAAS,CAAC;IAAEM,WAAW,EAAXA,WAAW;IAAEC,kBAAkB,EAAlBA,kBAAkB;IAAEC,mBAAmB,EAAnBA,mBAAmB;IAAEC,QAAQ,EAARA;EAAS,CAAC,CAAC,EAAE;EAE/F,gBAAoCrB,QAAQ,CAAC,IAAI,CAAC;IAAA;IAA3CuB,UAAU;IAAEC,aAAa;EAEhC,IAAMC,8BAA8B,GAAG,SAAjCA,8BAA8B,CAAIC,KAAK,EAAEC,IAAI,EAAK;IACtDb,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAGY,KAAK,EAAEC,IAAI,CAAC;EACnC,CAAC;E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AM,CAACI,UAAU;IAC/BC,KAAK,EAAExC,SAAS,CAACmC,MAAM,CAACI,UAAU;IAClCE,IAAI,EAAEzC,SAAS,CAAC0C,IAAI;IACpB7B,IAAI,EAAEb,SAAS,CAAC2C,KAAK;IACrBC,IAAI,EAAE5C,SAAS,CAACmC,MAAM;IACtBU,MAAM,EAAE7C,SAAS,CAACmC;EACpB,CAAC,CAAC,CACH,CAACI,UAAU;EACZ;AACF;AACA;EACExB,aAAa,EAAEf,SAAS,CAACmC,MAAM;EAC/B;AACF;AACA;EACErB,QAAQ,EAAEd,SAAS,CAACmC,MAAM;EAC1B;AACF;AACA;EACEnB,WAAW,EAAEhB,SAAS,CAAC8C,MAAM;EAC7B;AACF;AACA;EACE7B,kBAAkB,EAAEjB,SAAS,CAAC8C,MAAM;EACpC;AACF;AACA;EACE5B,mBAAmB,EAAElB,SAAS,CAAC8C,MAAM;EACrC;AACF;AACA;EACE3B,QAAQ,EAAEnB,SAAS,CAAC+C,KAAK,CAAC,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC;AACjF,CAAC;AAED7C,oBAAoB,CAAC8C,YAAY,GAAG;EAClCjC,aAAa,EAAE,UAAU;EACzBC,WAAW,EAAE,EAAE;EACfC,kBAAkB,EAAE,GAAG;EACvBC,mBAAmB,EAAE,EAAE;EACvBC,QAAQ,EAAE;AACZ,CAAC;AAED,eAAepB,UAAU,CAACW,SAAS,EAAE;EAAEuC,IAAI,EAAE;AAAuB,CAAC,CAAC,CAAC/C,oBAAoB,CAAC"}
1
+ {"version":3,"file":"VerticalNavigation.js","names":["React","useState","withStyles","PropTypes","clsx","HvVerticalNavigation","HvVerticalNavigationCore","HvVerticalNavigationTree","HvButton","HvContainer","Backwards","Forwards","useStyles","getAllParents","findRootParentById","findItemById","onNavigationChange","onToggleExpanded","data","selected","expanded","topPosition","expandedPanelWidth","collapsedPanelWidth","position","others","classes","noSubData","map","dataToRemove","rest","item","id","expandedItems","setExpandedItems","selectedTopParent","handleVerticalNavigationChange","event","fullItem","length","prevState","handleVerticalNavigationToggle","currentExpandedItems","handleExpandToggle","panel","panelExpanded","panelCollapsed","toggleCollapsePanel","propTypes","func","arrayOf","shape","string","isRequired","label","icon","node","array","href","target","bool","number","oneOf","defaultProps","name"],"sources":["../../../src/VerticalNavigation/VerticalNavigation.js"],"sourcesContent":["import React, { useState } from \"react\";\nimport { withStyles } from \"@mui/styles\";\nimport PropTypes from \"prop-types\";\nimport clsx from \"clsx\";\n\nimport {\n HvVerticalNavigation as HvVerticalNavigationCore,\n HvVerticalNavigationTree,\n HvButton,\n HvContainer,\n} from \"@hitachivantara/uikit-react-core\";\nimport { Backwards, Forwards } from \"@hitachivantara/uikit-react-icons\";\n\nimport useStyles from \"./styles\";\nimport { getAllParents, findRootParentById, findItemById } from \"./utils\";\n\nconst HvVerticalNavigation = ({\n onNavigationChange,\n onToggleExpanded,\n data,\n selected,\n expanded,\n topPosition,\n expandedPanelWidth,\n collapsedPanelWidth,\n position,\n\n ...others\n}) => {\n const classes = useStyles({ topPosition, expandedPanelWidth, collapsedPanelWidth, position })();\n\n const noSubData = data.map(({ data: dataToRemove, ...rest }) => rest);\n\n const [expandedItems, setExpandedItems] = useState(getAllParents(data).map((item) => item.id));\n\n const selectedTopParent = findRootParentById(data, selected)?.id;\n\n const handleVerticalNavigationChange = (event, item) => {\n // This need to be done because the item recieved on the callback is missing the original data object\n const fullItem = findItemById(data, item.id);\n\n if (!expanded && fullItem.data && fullItem.data.length > 0) {\n setExpandedItems((prevState) => [...prevState, item.id]);\n onToggleExpanded(true);\n } else {\n onNavigationChange?.(event, item);\n }\n };\n\n const handleVerticalNavigationToggle = (event, currentExpandedItems) => {\n setExpandedItems(currentExpandedItems);\n };\n\n const handleExpandToggle = () => {\n onToggleExpanded(!expanded);\n };\n\n return (\n <HvVerticalNavigationCore\n className={clsx(classes.panel, {\n [classes.panelExpanded]: expanded,\n [classes.panelCollapsed]: !expanded,\n })}\n {...others}\n >\n <HvContainer className={`${classes.toggleCollapsePanel}`}>\n <HvButton icon onClick={handleExpandToggle}>\n {expanded ? <Backwards iconSize=\"XS\" /> : <Forwards iconSize=\"XS\" />}\n </HvButton>\n </HvContainer>\n\n <HvVerticalNavigationTree\n collapsible\n expanded={expandedItems}\n data={expanded ? data : noSubData}\n selected={expanded ? selected : selectedTopParent}\n onChange={handleVerticalNavigationChange}\n onToggle={handleVerticalNavigationToggle}\n />\n </HvVerticalNavigationCore>\n );\n};\n\nHvVerticalNavigation.propTypes = {\n /**\n * Called when a menu item is clicked.\n */\n onNavigationChange: PropTypes.func,\n /**\n * Called when the collapse / expand button is clicked.\n */\n onToggleExpanded: PropTypes.func,\n /**\n * An array containing the data for each menu item.\n *\n * id - the id to be applied to the root element.\n * label - the label to be rendered on the menu item.\n * icon - the icon component.\n * data - sub-menu items\n * href - the url used for navigation.\n * target - the behavior when opening an url.\n */\n data: PropTypes.arrayOf(\n PropTypes.shape({\n id: PropTypes.string.isRequired,\n label: PropTypes.string.isRequired,\n icon: PropTypes.node,\n data: PropTypes.array,\n href: PropTypes.string,\n target: PropTypes.string,\n })\n ).isRequired,\n /**\n * The ID of the selected page.\n */\n selected: PropTypes.string,\n /**\n * Boolean value stating if the panel should be collapsed or expanded.\n */\n expanded: PropTypes.bool,\n /**\n * The top value where the panel will be rendered. Default is 44 as it is the height of the Header component.\n */\n topPosition: PropTypes.number,\n /**\n * The width of the panel when expanded. Default value is 300.\n */\n expandedPanelWidth: PropTypes.number,\n /**\n * The width of the panel when collapsed. Default vlaue is 52.\n */\n collapsedPanelWidth: PropTypes.number,\n /**\n * Position of the component.\n */\n position: PropTypes.oneOf([\"static\", \"relative\", \"fixed\", \"absolute\", \"sticky\"]),\n};\n\nHvVerticalNavigation.defaultProps = {\n topPosition: 44,\n expandedPanelWidth: 300,\n collapsedPanelWidth: 52,\n position: \"fixed\",\n};\n\nexport default withStyles(useStyles, { name: \"HvVerticalNavigation\" })(HvVerticalNavigation);\n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AErB,SAAS,CAAC2D,KAAK,CAAC,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC;AACjF,CAAC;AAEDzD,oBAAoB,CAAC0D,YAAY,GAAG;EAClC1C,WAAW,EAAE,EAAE;EACfC,kBAAkB,EAAE,GAAG;EACvBC,mBAAmB,EAAE,EAAE;EACvBC,QAAQ,EAAE;AACZ,CAAC;AAED,eAAetB,UAAU,CAACU,SAAS,EAAE;EAAEoD,IAAI,EAAE;AAAuB,CAAC,CAAC,CAAC3D,oBAAoB,CAAC"}
@@ -1,18 +1,9 @@
1
- import "core-js/modules/es.object.keys.js";
2
- import "core-js/modules/es.symbol.js";
3
- import "core-js/modules/es.array.filter.js";
4
- import "core-js/modules/es.object.to-string.js";
5
- import "core-js/modules/es.object.get-own-property-descriptor.js";
6
- import "core-js/modules/web.dom-collections.for-each.js";
7
- import "core-js/modules/es.object.get-own-property-descriptors.js";
8
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
1
  import { makeStyles } from "@mui/styles";
12
2
  var styles = function styles(props) {
13
3
  return makeStyles(function (theme) {
14
4
  return {
15
5
  panel: {
6
+ justifyContent: "flex-start",
16
7
  position: props.position,
17
8
  top: props.topPosition,
18
9
  left: 0,
@@ -21,22 +12,20 @@ var styles = function styles(props) {
21
12
  panelExpanded: {
22
13
  width: props.expandedPanelWidth,
23
14
  height: "calc(100vh - ".concat(props.topPosition, "px)"),
24
- // This is for the bottom actions
25
- "& > :not(:first-child) > button > span": {
26
- marginBottom: 0
15
+ // To remove the top border of the navigation section
16
+ "& > :not(:first-child)": {
17
+ borderTop: "none"
27
18
  }
28
19
  },
29
20
  panelCollapsed: {
30
21
  width: props.collapsedPanelWidth,
31
22
  height: "calc(100vh - ".concat(props.topPosition, "px)"),
32
- // This is for the bottom actions
23
+ // Customize the navigation section
33
24
  "& > :not(:first-child)": {
34
- padding: theme.hvSpacing("xs", "xs", "sm", "xs"),
35
- "& > button > span": {
36
- marginLeft: 0
37
- }
25
+ borderTop: "none",
26
+ padding: theme.hvSpacing("xs", "xs", "sm", "xs")
38
27
  },
39
- // This is for the top menu items
28
+ // Customize the collapse / expand
40
29
  "& > :first-child:not(:last-child)": {
41
30
  padding: theme.hvSpacing("sm", "xs", "xs", "xs")
42
31
  },
@@ -44,22 +33,9 @@ var styles = function styles(props) {
44
33
  marginLeft: "6px"
45
34
  }
46
35
  },
47
- collapseButton: _objectSpread(_objectSpread({}, theme.hv.typography.normalText), {}, {
48
- width: "100%",
49
- "& > span": {
50
- justifyContent: "flex-start"
51
- }
52
- }),
53
- expandButton: {
54
- width: "100%",
55
- minWidth: "unset",
56
- "& > span > span": {
57
- marginLeft: "unset"
58
- }
59
- },
60
- collapseTextContainer: {
61
- width: "100%",
62
- textAlign: "left"
36
+ toggleCollapsePanel: {
37
+ display: "flex",
38
+ justifyContent: "flex-end"
63
39
  }
64
40
  };
65
41
  });
@@ -1 +1 @@
1
- {"version":3,"file":"styles.js","names":["makeStyles","styles","props","theme","panel","position","top","topPosition","left","zIndex","panelExpanded","width","expandedPanelWidth","height","marginBottom","panelCollapsed","collapsedPanelWidth","padding","hvSpacing","marginLeft","collapseButton","hv","typography","normalText","justifyContent","expandButton","minWidth","collapseTextContainer","textAlign"],"sources":["../../../src/VerticalNavigation/styles.js"],"sourcesContent":["import { makeStyles } from \"@mui/styles\";\n\nconst styles = (props) =>\n makeStyles((theme) => ({\n panel: {\n position: props.position,\n top: props.topPosition,\n left: 0,\n zIndex: 1100,\n },\n panelExpanded: {\n width: props.expandedPanelWidth,\n height: `calc(100vh - ${props.topPosition}px)`,\n\n // This is for the bottom actions\n \"& > :not(:first-child) > button > span\": {\n marginBottom: 0,\n },\n },\n panelCollapsed: {\n width: props.collapsedPanelWidth,\n height: `calc(100vh - ${props.topPosition}px)`,\n\n // This is for the bottom actions\n \"& > :not(:first-child)\": {\n padding: theme.hvSpacing(\"xs\", \"xs\", \"sm\", \"xs\"),\n\n \"& > button > span\": {\n marginLeft: 0,\n },\n },\n // This is for the top menu items\n \"& > :first-child:not(:last-child)\": {\n padding: theme.hvSpacing(\"sm\", \"xs\", \"xs\", \"xs\"),\n },\n\n \"& > nav > ul > li > div > div\": {\n marginLeft: \"6px\",\n },\n },\n collapseButton: {\n ...theme.hv.typography.normalText,\n width: \"100%\",\n\n \"& > span\": {\n justifyContent: \"flex-start\",\n },\n },\n expandButton: {\n width: \"100%\",\n minWidth: \"unset\",\n\n \"& > span > span\": {\n marginLeft: \"unset\",\n },\n },\n collapseTextContainer: {\n width: \"100%\",\n textAlign: \"left\",\n },\n }));\n\nexport default styles;\n"],"mappings":";;;;;;;;;;AAAA,SAASA,UAAU,QAAQ,aAAa;AAExC,IAAMC,MAAM,GAAG,SAATA,MAAM,CAAIC,KAAK;EAAA,OACnBF,UAAU,CAAC,UAACG,KAAK;IAAA,OAAM;MACrBC,KAAK,EAAE;QACLC,QAAQ,EAAEH,KAAK,CAACG,QAAQ;QACxBC,GAAG,EAAEJ,KAAK,CAACK,WAAW;QACtBC,IAAI,EAAE,CAAC;QACPC,MAAM,EAAE;MACV,CAAC;MACDC,aAAa,EAAE;QACbC,KAAK,EAAET,KAAK,CAACU,kBAAkB;QAC/BC,MAAM,yBAAkBX,KAAK,CAACK,WAAW,QAAK;QAE9C;QACA,wCAAwC,EAAE;UACxCO,YAAY,EAAE;QAChB;MACF,CAAC;MACDC,cAAc,EAAE;QACdJ,KAAK,EAAET,KAAK,CAACc,mBAAmB;QAChCH,MAAM,yBAAkBX,KAAK,CAACK,WAAW,QAAK;QAE9C;QACA,wBAAwB,EAAE;UACxBU,OAAO,EAAEd,KAAK,CAACe,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;UAEhD,mBAAmB,EAAE;YACnBC,UAAU,EAAE;UACd;QACF,CAAC;QACD;QACA,mCAAmC,EAAE;UACnCF,OAAO,EAAEd,KAAK,CAACe,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;QACjD,CAAC;QAED,+BAA+B,EAAE;UAC/BC,UAAU,EAAE;QACd;MACF,CAAC;MACDC,cAAc,kCACTjB,KAAK,CAACkB,EAAE,CAACC,UAAU,CAACC,UAAU;QACjCZ,KAAK,EAAE,MAAM;QAEb,UAAU,EAAE;UACVa,cAAc,EAAE;QAClB;MAAC,EACF;MACDC,YAAY,EAAE;QACZd,KAAK,EAAE,MAAM;QACbe,QAAQ,EAAE,OAAO;QAEjB,iBAAiB,EAAE;UACjBP,UAAU,EAAE;QACd;MACF,CAAC;MACDQ,qBAAqB,EAAE;QACrBhB,KAAK,EAAE,MAAM;QACbiB,SAAS,EAAE;MACb;IACF,CAAC;EAAA,CAAC,CAAC;AAAA;AAEL,eAAe3B,MAAM"}
1
+ {"version":3,"file":"styles.js","names":["makeStyles","styles","props","theme","panel","justifyContent","position","top","topPosition","left","zIndex","panelExpanded","width","expandedPanelWidth","height","borderTop","panelCollapsed","collapsedPanelWidth","padding","hvSpacing","marginLeft","toggleCollapsePanel","display"],"sources":["../../../src/VerticalNavigation/styles.js"],"sourcesContent":["import { makeStyles } from \"@mui/styles\";\n\nconst styles = (props) =>\n makeStyles((theme) => ({\n panel: {\n justifyContent: \"flex-start\",\n position: props.position,\n top: props.topPosition,\n left: 0,\n zIndex: 1100,\n },\n panelExpanded: {\n width: props.expandedPanelWidth,\n height: `calc(100vh - ${props.topPosition}px)`,\n\n // To remove the top border of the navigation section\n \"& > :not(:first-child)\": {\n borderTop: \"none\",\n },\n },\n panelCollapsed: {\n width: props.collapsedPanelWidth,\n height: `calc(100vh - ${props.topPosition}px)`,\n\n // Customize the navigation section\n \"& > :not(:first-child)\": {\n borderTop: \"none\",\n padding: theme.hvSpacing(\"xs\", \"xs\", \"sm\", \"xs\"),\n },\n\n // Customize the collapse / expand\n \"& > :first-child:not(:last-child)\": {\n padding: theme.hvSpacing(\"sm\", \"xs\", \"xs\", \"xs\"),\n },\n\n \"& > nav > ul > li > div > div\": {\n marginLeft: \"6px\",\n },\n },\n\n toggleCollapsePanel: {\n display: \"flex\",\n justifyContent: \"flex-end\",\n },\n }));\n\nexport default styles;\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,aAAa;AAExC,IAAMC,MAAM,GAAG,SAATA,MAAM,CAAIC,KAAK;EAAA,OACnBF,UAAU,CAAC,UAACG,KAAK;IAAA,OAAM;MACrBC,KAAK,EAAE;QACLC,cAAc,EAAE,YAAY;QAC5BC,QAAQ,EAAEJ,KAAK,CAACI,QAAQ;QACxBC,GAAG,EAAEL,KAAK,CAACM,WAAW;QACtBC,IAAI,EAAE,CAAC;QACPC,MAAM,EAAE;MACV,CAAC;MACDC,aAAa,EAAE;QACbC,KAAK,EAAEV,KAAK,CAACW,kBAAkB;QAC/BC,MAAM,yBAAkBZ,KAAK,CAACM,WAAW,QAAK;QAE9C;QACA,wBAAwB,EAAE;UACxBO,SAAS,EAAE;QACb;MACF,CAAC;MACDC,cAAc,EAAE;QACdJ,KAAK,EAAEV,KAAK,CAACe,mBAAmB;QAChCH,MAAM,yBAAkBZ,KAAK,CAACM,WAAW,QAAK;QAE9C;QACA,wBAAwB,EAAE;UACxBO,SAAS,EAAE,MAAM;UACjBG,OAAO,EAAEf,KAAK,CAACgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;QACjD,CAAC;QAED;QACA,mCAAmC,EAAE;UACnCD,OAAO,EAAEf,KAAK,CAACgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;QACjD,CAAC;QAED,+BAA+B,EAAE;UAC/BC,UAAU,EAAE;QACd;MACF,CAAC;MAEDC,mBAAmB,EAAE;QACnBC,OAAO,EAAE,MAAM;QACfjB,cAAc,EAAE;MAClB;IACF,CAAC;EAAA,CAAC,CAAC;AAAA;AAEL,eAAeJ,MAAM"}
@@ -0,0 +1,71 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import "core-js/modules/es.object.to-string.js";
3
+ import "core-js/modules/es.array.find.js";
4
+ import "core-js/modules/es.array.filter.js";
5
+ import "core-js/modules/es.array.flat-map.js";
6
+ import "core-js/modules/es.array.unscopables.flat-map.js";
7
+ import "core-js/modules/es.array.concat.js";
8
+ /**
9
+ * Receives the navigation data and the id of the item from which we want to get the root parent.
10
+ *
11
+ * @param {NavigationItem[]} data - The navigation data structure.
12
+ * @param {string} itemId - The item id.
13
+ * @returns The item that is the root parent of the received item.
14
+ */
15
+ var findRootParentById = function findRootParentById(data, itemId) {
16
+ return data.reduce(function (parent, item) {
17
+ if (parent) {
18
+ return parent;
19
+ }
20
+ if (item.id === itemId) {
21
+ return item;
22
+ }
23
+ if (item.data) {
24
+ var found = findRootParentById(item.data, itemId);
25
+ if (found) {
26
+ return item;
27
+ }
28
+ }
29
+ return null;
30
+ }, null);
31
+ };
32
+
33
+ /**
34
+ * Returns the complete item object from the data structure using the item id.
35
+ *
36
+ * @param {NavigationItem[]} data - The navigation data structure.
37
+ * @param {string} itemId - The item id.
38
+ * @returns The complete item object matching the received id.
39
+ */
40
+ var findItemById = function findItemById(data, itemId) {
41
+ return data.find(function (item) {
42
+ if (item.id === itemId) {
43
+ return true;
44
+ }
45
+ if (item.data && item.data.length > 0) {
46
+ var foundItem = findItemById(item.data, itemId);
47
+ if (foundItem) {
48
+ return true;
49
+ }
50
+ }
51
+ return false;
52
+ });
53
+ };
54
+
55
+ /**
56
+ * Returns all the items that have chilren associated.
57
+ *
58
+ * @param {NavigationItem[]} data - The navigation data structure.
59
+ * @returns All the items that have chilren associated.
60
+ */
61
+ var getAllParents = function getAllParents(items) {
62
+ var parents = items.filter(function (item) {
63
+ return item.data != null && item.data.length > 0;
64
+ });
65
+ var childParents = parents.flatMap(function (item) {
66
+ return getAllParents(item.data);
67
+ });
68
+ return [].concat(_toConsumableArray(parents), _toConsumableArray(childParents));
69
+ };
70
+ export { findRootParentById, findItemById, getAllParents };
71
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["findRootParentById","data","itemId","reduce","parent","item","id","found","findItemById","find","length","foundItem","getAllParents","items","parents","filter","childParents","flatMap"],"sources":["../../../src/VerticalNavigation/utils.js"],"sourcesContent":["/**\n * Receives the navigation data and the id of the item from which we want to get the root parent.\n *\n * @param {NavigationItem[]} data - The navigation data structure.\n * @param {string} itemId - The item id.\n * @returns The item that is the root parent of the received item.\n */\nconst findRootParentById = (data, itemId) => {\n return data.reduce((parent, item) => {\n if (parent) {\n return parent;\n }\n\n if (item.id === itemId) {\n return item;\n }\n\n if (item.data) {\n const found = findRootParentById(item.data, itemId);\n if (found) {\n return item;\n }\n }\n return null;\n }, null);\n};\n\n/**\n * Returns the complete item object from the data structure using the item id.\n *\n * @param {NavigationItem[]} data - The navigation data structure.\n * @param {string} itemId - The item id.\n * @returns The complete item object matching the received id.\n */\nconst findItemById = (data, itemId) => {\n return data.find((item) => {\n if (item.id === itemId) {\n return true;\n }\n\n if (item.data && item.data.length > 0) {\n const foundItem = findItemById(item.data, itemId);\n if (foundItem) {\n return true;\n }\n }\n return false;\n });\n};\n\n/**\n * Returns all the items that have chilren associated.\n *\n * @param {NavigationItem[]} data - The navigation data structure.\n * @returns All the items that have chilren associated.\n */\nconst getAllParents = (items) => {\n const parents = items.filter((item) => item.data != null && item.data.length > 0);\n const childParents = parents.flatMap((item) => getAllParents(item.data));\n\n return [...parents, ...childParents];\n};\n\nexport { findRootParentById, findItemById, getAllParents };\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,kBAAkB,GAAG,SAArBA,kBAAkB,CAAIC,IAAI,EAAEC,MAAM,EAAK;EAC3C,OAAOD,IAAI,CAACE,MAAM,CAAC,UAACC,MAAM,EAAEC,IAAI,EAAK;IACnC,IAAID,MAAM,EAAE;MACV,OAAOA,MAAM;IACf;IAEA,IAAIC,IAAI,CAACC,EAAE,KAAKJ,MAAM,EAAE;MACtB,OAAOG,IAAI;IACb;IAEA,IAAIA,IAAI,CAACJ,IAAI,EAAE;MACb,IAAMM,KAAK,GAAGP,kBAAkB,CAACK,IAAI,CAACJ,IAAI,EAAEC,MAAM,CAAC;MACnD,IAAIK,KAAK,EAAE;QACT,OAAOF,IAAI;MACb;IACF;IACA,OAAO,IAAI;EACb,CAAC,EAAE,IAAI,CAAC;AACV,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMG,YAAY,GAAG,SAAfA,YAAY,CAAIP,IAAI,EAAEC,MAAM,EAAK;EACrC,OAAOD,IAAI,CAACQ,IAAI,CAAC,UAACJ,IAAI,EAAK;IACzB,IAAIA,IAAI,CAACC,EAAE,KAAKJ,MAAM,EAAE;MACtB,OAAO,IAAI;IACb;IAEA,IAAIG,IAAI,CAACJ,IAAI,IAAII,IAAI,CAACJ,IAAI,CAACS,MAAM,GAAG,CAAC,EAAE;MACrC,IAAMC,SAAS,GAAGH,YAAY,CAACH,IAAI,CAACJ,IAAI,EAAEC,MAAM,CAAC;MACjD,IAAIS,SAAS,EAAE;QACb,OAAO,IAAI;MACb;IACF;IACA,OAAO,KAAK;EACd,CAAC,CAAC;AACJ,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,aAAa,GAAG,SAAhBA,aAAa,CAAIC,KAAK,EAAK;EAC/B,IAAMC,OAAO,GAAGD,KAAK,CAACE,MAAM,CAAC,UAACV,IAAI;IAAA,OAAKA,IAAI,CAACJ,IAAI,IAAI,IAAI,IAAII,IAAI,CAACJ,IAAI,CAACS,MAAM,GAAG,CAAC;EAAA,EAAC;EACjF,IAAMM,YAAY,GAAGF,OAAO,CAACG,OAAO,CAAC,UAACZ,IAAI;IAAA,OAAKO,aAAa,CAACP,IAAI,CAACJ,IAAI,CAAC;EAAA,EAAC;EAExE,oCAAWa,OAAO,sBAAKE,YAAY;AACrC,CAAC;AAED,SAAShB,kBAAkB,EAAEQ,YAAY,EAAEI,aAAa"}
@@ -1,26 +1,26 @@
1
1
  import { NavigationData } from "@hitachivantara/uikit-react-core";
2
2
 
3
3
  export interface HvVerticalNavigationProps {
4
- /**
5
- * Id to be applied to the root node of the panel.
6
- */
7
- id?: string;
8
4
  /**
9
5
  * Called when a menu item is clicked.
10
6
  */
11
7
  onNavigationChange?: Function;
12
8
  /**
13
- * An array containing the data for each menu item.
9
+ * Called the collpase / expand button is clicked.
14
10
  */
15
- data: NavigationData[];
11
+ onToggleExpanded?: Function;
16
12
  /**
17
- * Text to be displayed in the collpase area when the panel is expanded.
13
+ * An array containing the data for each menu item.
18
14
  */
19
- collapseLabel?: string;
15
+ data: NavigationData[];
20
16
  /**
21
17
  * The ID of the selected page.
22
18
  */
23
19
  selected?: string;
20
+ /**
21
+ * Flag that sets the panel to expanded / collapsed.
22
+ */
23
+ expanded: boolean;
24
24
  /**
25
25
  * The top value where the panel will be rendered. Default is 44 as it is the height of the Header component.
26
26
  */
@@ -33,6 +33,10 @@ export interface HvVerticalNavigationProps {
33
33
  * The width of the panel when collapsed. Default vlaue is 52.
34
34
  */
35
35
  collapsedPanelWidth?: number;
36
+ /**
37
+ * Sets the Css position of the panel. Default value is `sticked`
38
+ */
39
+ position?: "static" | "relative" | "fixed" | "absolute" | "sticky";
36
40
  }
37
41
 
38
42
  export default function HvVerticalNavigation(props: HvVerticalNavigationProps): JSX.Element | null;
@@ -1,72 +1,98 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
1
3
  var _Backwards, _Forwards;
4
+ const _excluded = ["onNavigationChange", "onToggleExpanded", "data", "selected", "expanded", "topPosition", "expandedPanelWidth", "collapsedPanelWidth", "position"],
5
+ _excluded2 = ["data"];
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2
8
  import React, { useState } from "react";
3
9
  import { withStyles } from "@mui/styles";
4
10
  import PropTypes from "prop-types";
5
11
  import clsx from "clsx";
6
- import { HvVerticalNavigation as HvVerticalNavigationCore, HvVerticalNavigationTree, HvVerticalNavigationActions, HvButton, setId } from "@hitachivantara/uikit-react-core";
12
+ import { HvVerticalNavigation as HvVerticalNavigationCore, HvVerticalNavigationTree, HvButton, HvContainer } from "@hitachivantara/uikit-react-core";
7
13
  import { Backwards, Forwards } from "@hitachivantara/uikit-react-icons";
8
14
  import useStyles from "./styles";
15
+ import { getAllParents, findRootParentById, findItemById } from "./utils";
9
16
  import { jsx as _jsx } from "react/jsx-runtime";
10
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
11
- const HvVerticalNavigation = ({
12
- id,
13
- onNavigationChange,
14
- data,
15
- selected,
16
- collapseLabel,
17
- topPosition,
18
- expandedPanelWidth,
19
- collapsedPanelWidth,
20
- position
21
- }) => {
18
+ const HvVerticalNavigation = _ref => {
19
+ var _findRootParentById;
20
+ let {
21
+ onNavigationChange,
22
+ onToggleExpanded,
23
+ data,
24
+ selected,
25
+ expanded,
26
+ topPosition,
27
+ expandedPanelWidth,
28
+ collapsedPanelWidth,
29
+ position
30
+ } = _ref,
31
+ others = _objectWithoutProperties(_ref, _excluded);
22
32
  const classes = useStyles({
23
33
  topPosition,
24
34
  expandedPanelWidth,
25
35
  collapsedPanelWidth,
26
36
  position
27
37
  })();
28
- const [isExpanded, setIsExpanded] = useState(true);
38
+ const noSubData = data.map(_ref2 => {
39
+ let {
40
+ data: dataToRemove
41
+ } = _ref2,
42
+ rest = _objectWithoutProperties(_ref2, _excluded2);
43
+ return rest;
44
+ });
45
+ const [expandedItems, setExpandedItems] = useState(getAllParents(data).map(item => item.id));
46
+ const selectedTopParent = (_findRootParentById = findRootParentById(data, selected)) === null || _findRootParentById === void 0 ? void 0 : _findRootParentById.id;
29
47
  const handleVerticalNavigationChange = (event, item) => {
30
- onNavigationChange === null || onNavigationChange === void 0 ? void 0 : onNavigationChange(event, item);
48
+ // This need to be done because the item recieved on the callback is missing the original data object
49
+ const fullItem = findItemById(data, item.id);
50
+ if (!expanded && fullItem.data && fullItem.data.length > 0) {
51
+ setExpandedItems(prevState => [...prevState, item.id]);
52
+ onToggleExpanded(true);
53
+ } else {
54
+ onNavigationChange === null || onNavigationChange === void 0 ? void 0 : onNavigationChange(event, item);
55
+ }
56
+ };
57
+ const handleVerticalNavigationToggle = (event, currentExpandedItems) => {
58
+ setExpandedItems(currentExpandedItems);
31
59
  };
32
60
  const handleExpandToggle = () => {
33
- setIsExpanded(prevState => !prevState);
61
+ onToggleExpanded(!expanded);
34
62
  };
35
- return /*#__PURE__*/_jsxs(HvVerticalNavigationCore, {
36
- className: clsx(classes.panel, isExpanded ? classes.panelExpanded : classes.panelCollapsed),
37
- children: [/*#__PURE__*/_jsx(HvVerticalNavigationTree, {
38
- collapsible: true,
39
- data: data,
40
- selected: selected,
41
- onChange: handleVerticalNavigationChange
42
- }), /*#__PURE__*/_jsx(HvVerticalNavigationActions, {
63
+ return /*#__PURE__*/_jsxs(HvVerticalNavigationCore, _objectSpread(_objectSpread({
64
+ className: clsx(classes.panel, expanded ? classes.panelExpanded : classes.panelCollapsed)
65
+ }, others), {}, {
66
+ children: [/*#__PURE__*/_jsx(HvContainer, {
67
+ className: `${classes.toggleCollapsePanel}`,
43
68
  children: /*#__PURE__*/_jsx(HvButton, {
44
- id: setId(id, "button-toggle"),
45
- className: clsx(isExpanded ? classes.collapseButton : classes.expandButton),
46
- category: "ghost",
47
- startIcon: isExpanded ? _Backwards || (_Backwards = /*#__PURE__*/_jsx(Backwards, {
69
+ icon: true,
70
+ onClick: handleExpandToggle,
71
+ children: expanded ? _Backwards || (_Backwards = /*#__PURE__*/_jsx(Backwards, {
48
72
  iconSize: "XS"
49
73
  })) : _Forwards || (_Forwards = /*#__PURE__*/_jsx(Forwards, {
50
74
  iconSize: "XS"
51
- })),
52
- onClick: handleExpandToggle,
53
- children: isExpanded && /*#__PURE__*/_jsx("span", {
54
- className: classes.collapseTextContainer,
55
- children: collapseLabel
56
- })
75
+ }))
57
76
  })
77
+ }), /*#__PURE__*/_jsx(HvVerticalNavigationTree, {
78
+ collapsible: true,
79
+ expanded: expandedItems,
80
+ data: expanded ? data : noSubData,
81
+ selected: expanded ? selected : selectedTopParent,
82
+ onChange: handleVerticalNavigationChange,
83
+ onToggle: handleVerticalNavigationToggle
58
84
  })]
59
- });
85
+ }));
60
86
  };
61
87
  process.env.NODE_ENV !== "production" ? HvVerticalNavigation.propTypes = {
62
- /**
63
- * Id to be applied to the root node of the panel.
64
- */
65
- id: PropTypes.string,
66
88
  /**
67
89
  * Called when a menu item is clicked.
68
90
  */
69
91
  onNavigationChange: PropTypes.func,
92
+ /**
93
+ * Called when the collapse / expand button is clicked.
94
+ */
95
+ onToggleExpanded: PropTypes.func,
70
96
  /**
71
97
  * An array containing the data for each menu item.
72
98
  *
@@ -85,14 +111,14 @@ process.env.NODE_ENV !== "production" ? HvVerticalNavigation.propTypes = {
85
111
  href: PropTypes.string,
86
112
  target: PropTypes.string
87
113
  })).isRequired,
88
- /**
89
- * Text to be displayed in the collpase area when the panel is expanded.
90
- */
91
- collapseLabel: PropTypes.string,
92
114
  /**
93
115
  * The ID of the selected page.
94
116
  */
95
117
  selected: PropTypes.string,
118
+ /**
119
+ * Boolean value stating if the panel should be collapsed or expanded.
120
+ */
121
+ expanded: PropTypes.bool,
96
122
  /**
97
123
  * The top value where the panel will be rendered. Default is 44 as it is the height of the Header component.
98
124
  */
@@ -111,7 +137,6 @@ process.env.NODE_ENV !== "production" ? HvVerticalNavigation.propTypes = {
111
137
  position: PropTypes.oneOf(["static", "relative", "fixed", "absolute", "sticky"])
112
138
  } : void 0;
113
139
  HvVerticalNavigation.defaultProps = {
114
- collapseLabel: "Collapse",
115
140
  topPosition: 44,
116
141
  expandedPanelWidth: 300,
117
142
  collapsedPanelWidth: 52,