@e-group/material-module
Version:
EGroup Team react component modules.
137 lines (118 loc) • 5.85 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/esm/extends";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import React, { forwardRef } from 'react';
import { List, ListSubheader } from '@material-ui/core';
import { NavLink } from 'react-router-dom';
import NestedListItem from '@e-group/material/NestedListItem';
const NavLinkWrapper = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/React.createElement(NavLink, _extends({
innerRef: ref
}, props)));
const NestedSideMenu = props => {
const classes = props.classes,
className = props.className,
pathname = props.pathname,
routes = props.routes,
NestedListItemProps = props.NestedListItemProps,
NestedListItemItemsProps = props.NestedListItemItemsProps,
style = props.style,
other = _objectWithoutProperties(props, ["classes", "className", "pathname", "routes", "NestedListItemProps", "NestedListItemItemsProps", "style"]);
const _ref = NestedListItemProps || {},
MuiListItemProps = _ref.MuiListItemProps,
MuiListItemTextProps = _ref.MuiListItemTextProps,
otherNestedListItemProps = _objectWithoutProperties(_ref, ["MuiListItemProps", "MuiListItemTextProps"]);
return /*#__PURE__*/React.createElement(List, _extends({
style: _objectSpread({
width: 240
}, style)
}, other), routes.map(route => {
if (route.routes && route.routes.length > 0) {
var _route$key2;
let items = route.routes.filter(el => Boolean(el.breadcrumbName)); // If routes do not exist any breadcrumbName means it doesn't need openable NestedListItem.
// Therefore we can simply return a `NestedListItem` wrapped by `Link`.
if (items.length === 0) {
var _route$key;
return /*#__PURE__*/React.createElement(NestedListItem, _extends({
key: (_route$key = route.key) !== null && _route$key !== void 0 ? _route$key : route.path,
icon: route.icon,
MuiListItemProps: _objectSpread({
button: true,
selected: route.path === pathname,
// TODO: Need fixed ts-ignore
// @ts-ignore
to: route.path,
component: NavLinkWrapper
}, MuiListItemProps),
MuiListItemTextProps: _objectSpread({
primary: route.breadcrumbName
}, MuiListItemTextProps)
}, otherNestedListItemProps));
}
const _ref2 = NestedListItemItemsProps || {},
NestedMuiListItemProps = _ref2.MuiListItemProps,
NestedMuiListItemTextProps = _ref2.MuiListItemTextProps,
otherNestedListItemItemsProps = _objectWithoutProperties(_ref2, ["MuiListItemProps", "MuiListItemTextProps"]);
let defaultIsOpen = false;
items = items.map(el => {
var _el$key;
const selected = el.path === pathname;
if (selected) {
defaultIsOpen = true;
}
return _objectSpread({
key: (_el$key = el.key) !== null && _el$key !== void 0 ? _el$key : el.path,
icon: el.icon,
path: el.path,
MuiListItemProps: _objectSpread({
button: true,
selected,
to: el.path,
component: NavLinkWrapper
}, NestedMuiListItemProps),
MuiListItemTextProps: _objectSpread({
primary: el.breadcrumbName
}, NestedMuiListItemTextProps)
}, otherNestedListItemItemsProps);
});
return /*#__PURE__*/React.createElement(NestedListItem, _extends({
key: (_route$key2 = route.key) !== null && _route$key2 !== void 0 ? _route$key2 : route.path,
icon: route.icon,
MuiListItemProps: _objectSpread({
button: true
}, MuiListItemProps),
MuiListItemTextProps: _objectSpread({
primary: route.breadcrumbName
}, MuiListItemTextProps),
items: items,
defaultIsOpen: defaultIsOpen
}, otherNestedListItemProps));
}
if (route.breadcrumbName) {
var _route$key3;
return /*#__PURE__*/React.createElement(NestedListItem, _extends({
key: (_route$key3 = route.key) !== null && _route$key3 !== void 0 ? _route$key3 : route.path,
icon: route.icon,
MuiListItemProps: _objectSpread({
button: true,
selected: route.path === pathname,
// TODO: Need fixed ts-ignore
// @ts-ignore
to: route.path,
component: NavLinkWrapper
}, MuiListItemProps),
MuiListItemTextProps: _objectSpread({
primary: route.breadcrumbName
}, MuiListItemTextProps)
}, otherNestedListItemProps));
}
if (route.subheader) {
return /*#__PURE__*/React.createElement(ListSubheader, {
key: route.key
}, route.subheader);
}
return null;
}));
};
export default NestedSideMenu;