Components

PrimaryNav

PrimaryNav provides the main, top-level navigation for an app, usually in the page header.

Examples #

Import Syntax #

import { PrimaryNav, NavItem } from 'mineral-ui/Navigation';

Basic Usage #

Use NavItem children to define the navigation options.

<PrimaryNav>
  <NavItem href="/malachite">Malachite</NavItem>
  <NavItem selected href="/fluorite">Fluorite</NavItem>
  <NavItem href="/magnetite">Magnetite</NavItem>
</PrimaryNav>

Data-Driven #

Instead of children, you can define your items and use the selectedIndex property to set which item is currently being viewed.

() => {
  const items = [
    {
      href: '/malachite',
      text: 'Malachite'
    },
    {
      href: '/fluorite',
      text: 'Fluorite'
    },
    {
      href: '/magnetite',
      text: 'Magnetite'
    }
  ];

  return <PrimaryNav items={items} selectedIndex={1} />;
}

Minimal #

Use the minimal property to display PrimaryNav in a more minimal appearance.

<PrimaryNav minimal>
  <NavItem href="/malachite">Malachite</NavItem>
  <NavItem selected href="/fluorite">Fluorite</NavItem>
  <NavItem href="/magnetite">Magnetite</NavItem>
</PrimaryNav>

Alignment #

Control the alignment of the list of NavItems with the align prop. Note that a value of 'justify' will force all NavItems to be equal width and maxItemWidth will not apply.

() => {
  const alignments = ['start', 'center', 'end', 'justify'];

  return (
    <DemoLayout>
      {alignments.map((alignment) => (
        <PrimaryNav align={alignment} key={alignment}>
          <NavItem href="/malachite">Malachite</NavItem>
          <NavItem href="/fluorite">Fluorite</NavItem>
          <NavItem href="/magnetite">Magnetite</NavItem>
        </PrimaryNav>
      ))}
    </DemoLayout>
  );
}

Maximum Item Width #

Use the maxItemWidth prop to constrain the width of each NavItem. Note that if the item's text is longer than the maximum width, it will be truncated but accessible via Tooltip. Also note that if the maxWidth property is set for an item, it will take precedence.

<PrimaryNav maxItemWidth="8em">
  <NavItem href="/malachite">Malachite</NavItem>
  <NavItem href="/fluorite">Fluorite will truncate</NavItem>
  <NavItem href="/magnetite">Magnetite</NavItem>
</PrimaryNav>

Overflow #

If there is not sufficient space to display all navigation items, e.g. when a media query dictates a narrow width, they can be overflowed into a Dropdown menu with the overflowAtIndex property.

() => {
  const items = [
    {
      href: '/malachite',
      text: 'Malachite'
    },
    {
      href: '/fluorite',
      text: 'Fluorite'
    },
    {
      href: '/magnetite',
      text: 'Magnetite'
    },
    {
      href: '/aragonite',
      text: 'Aragonite'
    }
  ];

  const onChange = (selectedIndex, event) => {
    event.preventDefault();
    console.log(selectedIndex + ' clicked')
  }

  return (
    <DemoLayout style={{ width: '23em' }}>
      <PrimaryNav overflowAtIndex={2}>
        {items.map((item) => {
          return <NavItem key={item.href} {...item}>{item.text}</NavItem>
        })}
      </PrimaryNav>

      <PrimaryNav items={items} overflowAtIndex={2} onChange={onChange} />
    </DemoLayout>
  );
}

Item As #

Any component that renders an <a /> element may be used for NavItem by specifying the itemAs prop, such as a React Router Link.

<PrimaryNav itemAs={ReactRouterLink}>
  <NavItem to="/malachite">Malachite</NavItem>
  <NavItem to="/fluorite">Fluorite</NavItem>
  <NavItem to="/magnetite">Magnetite</NavItem>
</PrimaryNav>

Bidirectionality #

PrimaryNav supports right-to-left (RTL) languages. The alignment is reversed when the direction theme variable is set to 'rtl'. The messages prop allows customization of various messages — both those that are displayed, and those that are announced by assistive technologies.

() => {
  const messages = {
    moreLabel: 'المزيد من عناصر الملاحة',
    moreText: 'أكثر من'
  };

  return (
    <div dir="rtl">
      <ThemeProvider theme={{direction: 'rtl'}}>
        <PrimaryNav messages={messages} align="start">
          <NavItem href="/page-1">علامة التبويب 1</NavItem>
          <NavItem href="/page-2">علامة التبويب 2</NavItem>
          <NavItem href="/page-3">علامة التبويب 3</NavItem>
        </PrimaryNav>
      </ThemeProvider>
    </div>
  );
}

API & Theme #

PrimaryNav Props #

The PrimaryNav component takes the following React props.

NameTypeDefaultDescription
align'start' | 'center' | 'end' | 'justify''center'

Horizontal alignment of items

childrenReact$Node
itemAsReact$Element<*> | string'a'

React element used for items (see example)

itemsItems

Navigational items (see example)

maxItemWidthnumber | string'8.5em'

Maximum width of each item

messages

Various messages and labels used by PrimaryNav (see example for more details)

minimalboolean

Display PrimaryNav with 'minimal' styles

onChange

Called when an item is selected

overflowAtIndexnumber

Index at which NavItems overflow into a "More" Dropdown menu

selectedIndexnumber

Index of the selected item

Undocumented properties, including as and css, will be applied to the root element.

PrimaryNav Theme Variables #

These variables can be used as hooks to override this component's style at either a local or global level. The theme referenced below is whatever theme is available from props to the instance of this component.

VariableValue
PrimaryNav_backgroundColortheme.backgroundColor_themePrimary
PrimaryNav_backgroundColor_minimaltheme.backgroundColor
PrimaryNav_guttertheme.space_inline_xs
PrimaryNav_paddingHorizontaltheme.space_inline_xl
PrimaryNav_paddingVerticaltheme.space_stack_sm
PrimaryNavItem_backgroundColortransparent
PrimaryNavItem_backgroundColor_activetheme.color_theme_80
PrimaryNavItem_backgroundColor_focustransparent
PrimaryNavItem_backgroundColor_hovertheme.color_theme_70
PrimaryNavItem_backgroundColor_selectedtheme.color_theme_80
PrimaryNavItem_backgroundColor_minimaltransparent
PrimaryNavItem_backgroundColor_minimal_activetheme.color_gray_10
PrimaryNavItem_backgroundColor_minimal_focustransparent
PrimaryNavItem_backgroundColor_minimal_hovertransparent
PrimaryNavItem_backgroundColor_minimal_selectedtheme.color_gray_10
PrimaryNavItem_borderColortransparent
PrimaryNavItem_borderColor_activetransparent
PrimaryNavItem_borderColor_focustheme.color_theme_20
PrimaryNavItem_borderColor_hovertransparent
PrimaryNavItem_borderColor_selectedtheme.color_theme_80
PrimaryNavItem_borderColor_minimaltransparent
PrimaryNavItem_borderColor_minimal_activetransparent
PrimaryNavItem_borderColor_minimal_focustheme.color_theme_40
PrimaryNavItem_borderColor_minimal_hovertransparent
PrimaryNavItem_borderColor_minimal_selectedtheme.color_theme_40
PrimaryNavItem_colortheme.color_themePrimary
PrimaryNavItem_color_disabledtheme.color_theme_40
PrimaryNavItem_color_hovertheme.color_themePrimary
PrimaryNavItem_color_selectedtheme.color_themePrimary
PrimaryNavItem_color_minimaltheme.color_gray_80
PrimaryNavItem_color_minimal_hovertheme.color_theme_60
PrimaryNavItem_color_minimal_selectedtheme.color_theme_70
PrimaryNavItem_paddingHorizontaltheme.space_inset_sm
PrimaryNavItemIcon_colorinherit

Usage #

When/How to Use #

Mineral supports several different types of navigation. The correct navigation component should be selected based on your application's information architecture.

PrimaryNav is for top-level lateral navigation, where the user would be moving between two or more destinations at the top level of the application hierarchy. This component should allow the user to navigate to all of the main sections within the application. It can be used in conjunction with all other navigation types.

PrimaryNav can also be used to navigate between suites of products, if another in-app navigation method is also present in each of the individual products.

Best Practices #

Use PrimaryNav in conjunction with SecondaryNav for applications that have two or more levels of hierarchy.

PrimaryNav items should be immediately recognizable. Use short words or phrases for text labels, which consistently start with nouns or verbs. Include icons if they assist the user in quick recognition of the functionality.

Avoid long titles which would force truncation.

Don't mix content types for NavItem titles. Be consistent with icon usage; either all or no NavItems should contain an icon.

Don't use PrimaryNav when there is only one NavItem.