diff --git a/releasenotes/notes/Support-Global-Navigation-45412aa3603c4f14.yaml b/releasenotes/notes/Support-Global-Navigation-45412aa3603c4f14.yaml new file mode 100644 index 00000000..8b537f62 --- /dev/null +++ b/releasenotes/notes/Support-Global-Navigation-45412aa3603c4f14.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + Support the global navigation at the top-left position of the page: + + * The global navigation displays all the expanded menu items. + + * The global navigation supports the search of the menu items. + + * Update the UI and UE of the menu items. diff --git a/src/components/Layout/GlobalNav/Right/index.jsx b/src/components/Layout/GlobalNav/Right/index.jsx index 05153421..2d40533b 100644 --- a/src/components/Layout/GlobalNav/Right/index.jsx +++ b/src/components/Layout/GlobalNav/Right/index.jsx @@ -14,11 +14,14 @@ import React from 'react'; import { Link } from 'react-router-dom'; +import { Input } from 'antd'; import PropTypes from 'prop-types'; import { navItemPropType } from '../common'; import styles from './index.less'; +const { Search } = Input; + export default class Right extends React.Component { static propTypes = { items: PropTypes.arrayOf(navItemPropType), @@ -29,6 +32,51 @@ export default class Right extends React.Component { items: [], }; + constructor(props) { + super(props); + this.state = { + currentItems: props.items || [], + }; + } + + onInputChange = (e) => { + const { value } = e.target; + this.getNavItemsBySearch(value); + }; + + onSearch = (value) => { + this.getNavItemsBySearch(value); + }; + + getNavItemsBySearch = (search) => { + const checkWords = (search || '').toLowerCase().trim(); + const { items } = this.props; + const currentItems = []; + items.forEach((first) => { + if (!checkWords) { + currentItems.push(first); + } else { + const { name, children = [] } = first; + if (name.toLowerCase().includes(checkWords)) { + currentItems.push(first); + } else { + const cItems = children.filter((c) => { + return c.name.toLowerCase().includes(checkWords); + }); + if (cItems.length) { + currentItems.push({ + ...first, + children: cItems, + }); + } + } + } + }); + this.setState({ + currentItems, + }); + }; + renderNavItemChildren = (item) => { const { children = [] } = item; const currentChildren = children.length ? children : [item]; @@ -59,15 +107,31 @@ export default class Right extends React.Component { ); }; - render() { - const { items } = this.props; - if (!items.length) { - return null; - } - + renderSearch() { return ( -