@patternfly/react-core#NavExpandable JavaScript Examples

The following examples show how to use @patternfly/react-core#NavExpandable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NavSidebar.js    From operate-first.github.io-old with GNU General Public License v3.0 6 votes vote down vote up
NavGroup = (props) => {
  const { id, label, links, location, href } = props;

  const isSubPath = (path) => location.pathname.split('/')[1] === path.split('/')[1];

  if (!links) {
    if (!isSubPath(href)) {
      return null;
    }
    return <NavItem {...props} location={location} />;
  }

  const navItems = links
    // only include navItems that start with the current top level navigation or are remote urls
    .filter(({ href }) => isSubPath(href))
    .map((node) => <NavItem key={node.id} {...node} location={location} />);
  const isActive = !!links.find((c) => {
    if (c.remote) {
      return false;
    }
    return location.pathname.startsWith(c.href);
  });

  if (navItems.filter(Boolean).length === 0) {
    return null;
  }
  return (
    <NavExpandable key={id} title={label} groupId={id} isActive={isActive} isExpanded={isActive}>
      {navItems}
    </NavExpandable>
  );
}