A component to display a navigation button in a sidebar.

Importing

The component can be imported via:

import { NavItem } from '@customerio/pluma-components/react';

For expandable nav items:

import {
  NavItemExpandable,
  NavItemExpandableTrigger,
  NavItemExpandableContent,
} from '@customerio/pluma-components/react';

For dropdown nav items:

import {
  NavItemDropdown,
  NavItemDropdownTrigger,
  NavItemDropdownContent,
} from '@customerio/pluma-components/react';

Usage

The NavItem component accepts a href prop, just like other components that extend from PlainLink.

Additionally, an icon can be provided to render an icon next to the label.

<Box display="flex">
  <NavItem icon="dashboard" href="#">Dashboard</NavItem>
</Box>

Selected

Use the isSelected prop to indicate the currently active nav item - for example, to indicate the currently active page.

<Box display="flex">
  <NavItem icon="segment" href="#" isSelected={true}>Segments</NavItem>
</Box>

Collapsed

Use the isCollapsed prop to hide the label and only show the icon. This can be used when collapsing a navigation sidebar for a condensed view.

<Box display="flex">
  <NavItem icon="dashboard" href="#" isCollapsed={true}>Dashboard</NavItem>
</Box>

Expandable content

NavItemExpandable, NavItemExpandableTrigger, and NavItemExpandableContent can be used to create a group of nav items that can be expanded and collapsed.

NavItemExpandable is a wrapper component that provides the context for the nested items. It doesn't render anything itself.

NavItemExpandableTrigger is a component that renders a NavItem which functions as an expand/collapse toggle button for the section.

NavItemExpandableContent is the container for the nested items. When the section's state is expanded, it will render the nested elements.

<Box display="flex" flexDirection="column" style={{ width: 200 }}>
  <NavItemExpandable>
    <NavItemExpandableTrigger icon="object">Objects</NavItemExpandableTrigger>
    <NavItemExpandableContent>
      <NavItem href="#" icon="company">Companies</NavItem>
      <NavItem href="#" icon="copy-to-clipboard">Appointments</NavItem>
      <NavItem href="#" icon="integrations">Courses</NavItem>
    </NavItemExpandableContent>
  </NavItemExpandable>
</Box>

Default open

Use the defaultIsOpen prop to have the expandable section open by default.

<Box display="flex" flexDirection="column" style={{ width: 200 }}>
  <NavItemExpandable defaultIsOpen={true}>
    <NavItemExpandableTrigger icon="object">Objects</NavItemExpandableTrigger>
    <NavItemExpandableContent>
      <NavItem href="#" icon="company">Companies</NavItem>
      <NavItem href="#" icon="copy-to-clipboard" isSelected={true}>Appointments</NavItem>
      <NavItem href="#" icon="integrations">Courses</NavItem>
    </NavItemExpandableContent>
  </NavItemExpandable>
</Box>

NavItemDropdown, NavItemDropdownTrigger, and NavItemDropdownContent can be used to create a group of nav items where a subset is shown inline (animated in/out based on selection), and the rest are accessible via a dropdown menu triggered by the trigger item.

NavItemDropdown wraps the entire group.

NavItemDropdownContent contains the nav items that animate in when selected and collapse when deselected.

NavItemDropdownTrigger renders a nav item that opens a dropdown menu containing all the items from NavItemDropdownContent.

import { useState } from 'react';

export default function Example() {
  const [activeItem, setActiveItem] = useState('broadcasts');
  const select = (id, e) => {
    e?.preventDefault();
    setActiveItem(id);
  };

  return (
    <Box display="flex" flexDirection="column" style={{ width: 200 }}>
      <NavItem icon="dashboard" href="#" isSelected={activeItem === 'dashboard'} onClick={(e) => select('dashboard', e)}>Dashboard</NavItem>
      <NavItem icon="workspace-settings" href="#" isSelected={activeItem === 'settings'} onClick={(e) => select('settings', e)}>Settings</NavItem>
      <NavItemDropdown>
        <NavItemDropdownContent>
          <NavItem icon="broadcast" href="#" isSelected={activeItem === 'broadcasts'} onClick={(e) => select('broadcasts', e)}>Broadcasts</NavItem>
          <NavItem icon="campaigns" href="#" isSelected={activeItem === 'campaigns'} onClick={(e) => select('campaigns', e)}>Campaigns</NavItem>
          <NavItem icon="transactional-api" href="#" isSelected={activeItem === 'transactional'} onClick={(e) => select('transactional', e)}>Transactional</NavItem>
        </NavItemDropdownContent>
        <NavItemDropdownTrigger icon="more">More</NavItemDropdownTrigger>
      </NavItemDropdown>
    </Box>
  );
}

API

Which direction the arrow should point, if withArrow is true.

If this item is the trigger for an expandable section, this indicates whether any of the child items are selected.

The URL passed into the link component (or a tag)

The name of an icon (from Pluma Icons) to render in the nav item

Whether the nav item should render in the "collapsed" state, which hides the text and only shows the icon.

Whether the link should be disabled (this prevents click handlers from firing)

When this flag is true, an a tag will be used instead of the provider's linkComponent, even if it exists. Additionally, target="_blank" rel="noopener noreferrer" will be added automatically

Whether this nav item is nested within another nav item.

Whether this nav item is currently active/selected, which changes the item's appearance.

If provided, the component will render as a button and call this function when clicked.

This is passed into the provider's linkComponent. It can be used by the link component implementation to handle replaceState instead of pushState

Whether an arrow icon should be rendered on the right side of the nav item, indicating that this is a parent item that can be expanded to show child items.

This allows turning off the automatic addition of target="_blank" rel="noopener noreferrer". This can be used for links to other protocols like mailto:

Whether the expandable section should be open by default.

Which direction the arrow should point, if withArrow is true.

If this item is the trigger for an expandable section, this indicates whether any of the child items are selected.

The URL passed into the link component (or a tag)

The name of an icon (from Pluma Icons) to render in the nav item

Whether the nav item should render in the "collapsed" state, which hides the text and only shows the icon.

Whether the link should be disabled (this prevents click handlers from firing)

When this flag is true, an a tag will be used instead of the provider's linkComponent, even if it exists. Additionally, target="_blank" rel="noopener noreferrer" will be added automatically

Whether this nav item is nested within another nav item.

Whether this nav item is currently active/selected, which changes the item's appearance.

If provided, the component will render as a button and call this function when clicked.

This is passed into the provider's linkComponent. It can be used by the link component implementation to handle replaceState instead of pushState

Whether an arrow icon should be rendered on the right side of the nav item, indicating that this is a parent item that can be expanded to show child items.

This allows turning off the automatic addition of target="_blank" rel="noopener noreferrer". This can be used for links to other protocols like mailto: