npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@volvo-cars/react-local-submenu

v2.1.2

Published

A React Local Submenu component to be used as a secondary navigation

Downloads

2,147

Readme

Local Submenu

Questions? Ask in Slack #vcc-ui

@volvo-cars/react-local-submenu

A secondary navigation menu, typically displayed under the global navigation. It takes any number of links, shown horizontally on large breakpoints and transforms into a dropdown on small and medium breakpoints.

Installation

💡 This package includes Typescript definitions

📝 This package has built-in translations

LocalSubmenu sticks to the top of the page and follows the user when scrolling. When integrating with the global navigation, the global navigation is expected to stay in place (relative) while the LocalSubmenu sticks.

An example integration with the global navigation can be found in the kitchen-sink example.

Horizontal Navigation

LocalSubmenu behaves as a horizontal navigation on large breakpoints rendering all links in order and scrolls horizontally when links overflow the current viewport width. The current page is highlighted with an active prop on a LocalSubmenuLink.

() => {
  const links = [
    { text: 'Our story', href: '##', active: false },
    { text: 'Our heritage', href: '##', active: true },
    { text: 'Sustainability', href: '##', active: false },
    { text: 'Discover', href: '##', active: false },
  ];
  return (
    <Block
      extend={{
        height: 250,
        width: '95%',
        position: 'relative',
      }}
    >
      <LocalSubmenu header={links[1].text}>
        {links.map(({ href, text, active }, index) => (
          <LocalSubmenuLink href={href} key={index} active={active}>
            {text}
          </LocalSubmenuLink>
        ))}
      </LocalSubmenu>
    </Block>
  );
};

Dropdown Navigation

LocalSubmenu behaves as a dropdown on small and medium breakpoints, highlighting the current page with a header prop and active prop on the current page LocalSubmenuLink.

() => {
  const links = [
    { text: 'Our story', href: '##', active: false },
    { text: 'Our heritage', href: '##', active: true },
    { text: 'Sustainability', href: '##', active: false },
    { text: 'Discover', href: '##', active: false },
  ];
  return (
    <Block
      extend={{
        height: 260,
        position: 'relative',
      }}
    >
      <LocalSubmenu header={links[1].text}>
        {links.map(({ href, text, active }, index) => (
          <LocalSubmenuLink href={href} key={index} active={active}>
            {text}
          </LocalSubmenuLink>
        ))}
      </LocalSubmenu>
    </Block>
  );
};

Accessibility

The LocalSubmenu component is built with accessibility in mind following WAI:ARIA best practices:

  • The LocalSubmenu component is contained within a navigation landmark region.
  • The active element of the current page has aria-current set to page.

The LocalSubmenu component ships with built-in translations for aria-label when toggling the dropdown on small and medium breakpoints if used in conjunction with the Shared translations library.

Tracking

This component integrates with @volvo-cars/tracking, allowing us to dispatch tracking events to GTM. Each LocalSubmenuLink will send an interaction event with click eventAction when trackEventLabel prop is provided.

() => {
  const links = [
    { text: 'Our story', href: '##', active: false },
    { text: 'Our heritage', href: '/our-heritage', active: true },
    { text: 'Sustainability', href: '##', active: false },
    { text: 'Discover', href: '##', active: false },
  ];
  return (
    <Block
      extend={{
        height: 80,
        width: '95%',
        position: 'relative',
      }}
    >
      <TrackingProvider eventCategory="local submenu">
        <LocalSubmenu header={links[1].text}>
          {links.map(({ href, text, active }, index) => (
            <LocalSubmenuLink
              href={href}
              key={index}
              active={active}
              trackEventLabel={`${text} | ${href} | ${index}`}
            >
              {text}
            </LocalSubmenuLink>
          ))}
        </LocalSubmenu>
      </TrackingProvider>
    </Block>
  );
};

Clicking on "Our heritage" would send the following event for example

{
  "eventCategory": "local submenu",
  "eventAction": "click",
  "eventLabel": "our heritage | /our-heritage | 1",
  "event": "interaction"
}

API

Props - LocalSubmenu

| Name | Description | Type | Default Value | | ---------- | ----------------------------------------------------------- | -------------------------------------- | ------------------------------------------- | | children | A single or an array of ReactNodes of type LocalSubmenuLink | React.ReactNode | React.ReactNode[] | n/a | | header | Header to be shown on mobile breakpoints | string | n/a | | onChange | onChange called when mobile dropdown is toggled | ((isOpen: boolean) => void) | n/a | | zIndex | | string | number | calc(var(--sitenav-z-index-min, 990) - 1) |

Props - LocalSubmenuLink

| Name | Description | Type | Default Value | | ----------------- | --------------------------------------------------------------------------------------------------------- | --------- | ------------- | | active | Highlights link when true | boolean | false | | aria-label | An optional aria-label to add to the link | string | n/a | | children | Link text | string | n/a | | href | The URL that the link points to | string | n/a | | target | Anchor target | string | _self | | trackEventLabel | eventLabel to dispatch with the dataLayer event, event will not be dispatched if this is not provided | string | `` |