From 6ed2fb1a2d4259c7571a6c81112167034a2b9feb Mon Sep 17 00:00:00 2001 From: "Jingwei.Zhang" Date: Wed, 9 Nov 2022 14:55:04 +0800 Subject: [PATCH] feat: support search in the global navigation Support search menu in the global navagition Change-Id: I4c12e5d57650f6ef2641ed8680e98d6919432124 --- ...rt-Global-Navigation-45412aa3603c4f14.yaml | 10 +++ .../Layout/GlobalNav/Right/index.jsx | 80 +++++++++++++++++-- .../Layout/GlobalNav/Right/index.less | 7 ++ src/locales/en.json | 1 + src/locales/zh.json | 1 + 5 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/Support-Global-Navigation-45412aa3603c4f14.yaml 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 ( -