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

@bbc/psammead-navigation

v9.2.22

Published

A navigation bar to use on index pages

Downloads

132

Readme

psammead-navigation - Known Vulnerabilities Dependency Status peerDependencies Status Storybook GitHub license npm version PRs Welcome

Description

The @bbc/psammead-navigation package is a set of two components, NavigationUl and NavigationLi. They use ul and li HTML elements respectively. The package also includes a Hamburger Menu and a Dropdown Navigation which are visible for breakpoints under 600px.

Exports

/dropdown - Adds a dropdown navigation with hamburger menu which is visible for breakpoints under 600px /scrollable - Makes the navigation to be scrollable under 600px.

Installation

npm install @bbc/psammead-navigation

Props

Navigation

| Argument | Type | Required | Default | Example | | -------- | ---- | -------- | ------- | ------- | | children | node | Yes | N/A | <ScrollableNavigation dir={dir}><NavigationUl><NavigationLi url="/" script={latin} active="true">Home</NavigationLi><NavigationLi url="/sport" script={latin}>{Sport}</NavigationLi></NavigationUl><ScrollableNavigation/> | | dir | string | No | 'ltr' | 'rtl' | | isOpen | boolean | No | false | true | | ampOpenClass | string | No | null | 'open' | | brandBackgroundColour | string | Yes | N/A | '#B80000' | | brandForegroundColour | string | Yes | N/A | '#FDFDFD' | | brandBorderColour | string | Yes | N/A | '#EAB3B3' | | brandHighlightColour | string YesNo | N/A | '#FFFFFF' |

NavigationUl

| Argument | Type | Required | Default | Example | | -------- | ---- | -------- | ------- | ------- | | children | node | Yes | N/A | <NavigationLi url="/" script={latin} active="true">Home</NavigationLi><NavigationLi url="/sport" script={latin}>{Sport}</NavigationLi> |

NavigationLi

| Argument | Type | Required | Default | Example | | -------- | ------- | -------- | ------- | -------- | | url | string | Yes | N/A | /sport | | script | object | Yes | N/A | { canon: { groupA: { fontSize: '28', lineHeight: '32',}, groupB: { fontSize: '32', lineHeight: '36', }, groupD: { fontSize: '44', lineHeight: '48', }, }, trafalgar: { groupA: { fontSize: '20', lineHeight: '24', }, groupB: { fontSize: '24', lineHeight: '28', }, groupD: { fontSize: '32', lineHeight: '36', }, }, } | | active | boolean | No | false | true | | currentPageText | string | No | null | Current page | | service | string | Yes | N/A | 'news' | | dir | string | No | 'ltr' | 'rtl' | | brandForegroundColour | string | Yes | N/A | '#FDFDFD' | | brandBorderColour | string | Yes | N/A | '#EAB3B3' | | brandHighlightColour | string YesNo | N/A | '#FFFFFF' |

ScrollableNavigation

| Argument | Type | Required | Default | Example | | -------- | ---- | -------- | ------- | ------- | | children | node | Yes | N/A | <NavigationUl><NavigationLi url="/" script={latin} active="true">Home</NavigationLi><NavigationLi url="/sport" script={latin}>{Sport}</NavigationLi></NavigationUl> | | dir | string | No | 'ltr' | 'rtl' | | brandBackgroundColour | string | Yes | N/A | '#B80000' | | brandHighlightColour | string YesNo | N/A | '#FFFFFF' |

CanonicalDropdown

| Argument | Type | Required | Default | Example | | -------- | ---- | -------- | ------- | ------- | | children | node | Yes | N/A | <DropdownUl><DropdownLi script={latin} service='news' key='sport' url='/sport' active="false"> Sport </DropdownLi></DropdownUl> | | isOpen | bool | Yes | N/A | false |

AmpDropdown

| Argument | Type | Required | Default | Example | | -------- | ---- | -------- | ------- | ------- | | children | node | Yes | N/A | <DropdownUl><DropdownLi script={latin} service='news' key='sport' url='/sport' active="false"> Sport </DropdownLi></DropdownUl> |

DropdownLi

| Argument | Type | Required | Default | Example | | -------- | ------- | -------- | ------- | -------- | | children | string | Yes | N/A | 'Sport' | | url | string | Yes | N/A | /sport | | script | object | Yes | N/A | { canon: { groupA: { fontSize: '28', lineHeight: '32',}, groupB: { fontSize: '32', lineHeight: '36', }, groupD: { fontSize: '44', lineHeight: '48', }, }, trafalgar: { groupA: { fontSize: '20', lineHeight: '24', }, groupB: { fontSize: '24', lineHeight: '28', }, groupD: { fontSize: '32', lineHeight: '36', }, }, } | | service | string | Yes | N/A | 'news' | | active | boolean | No | false | true | | currentPageText | string | No | null | Current page | | dir | string | No | ltr | rtl |

CanonicalMenuButton

| Argument | Type | Required | Default | Example | | -------- | ---- | -------- | ------- | ------- | | announcedText | string | Yes | N/A | 'Menu' | | onClick | function | Yes | N/A | () => { console.log("Handle onClick action"); } | | isOpen | bool | Yes | N/A | false | | dir | string | no | 'ltr' | 'rtl' | | script | object | Yes | N/A | { canon: { groupA: { fontSize: '28', lineHeight: '32',}, groupB: { fontSize: '32', lineHeight: '36', }, groupD: { fontSize: '44', lineHeight: '48', }, }, trafalgar: { groupA: { fontSize: '20', lineHeight: '24', }, groupB: { fontSize: '24', lineHeight: '28', }, groupD: { fontSize: '32', lineHeight: '36', }, }, } |

AmpMenuButton

| Argument | Type | Required | Default | Example | | -------- | ---- | -------- | ------- | ------- | | announcedText | string | Yes | N/A | 'Menu' | | onToggle | string | Yes | N/A | "menu.toggleVisibility" - must be an action on a valid AMP target| | dir | string | no | 'ltr' | 'rtl' | | script | object | Yes | N/A | { canon: { groupA: { fontSize: '28', lineHeight: '32',}, groupB: { fontSize: '32', lineHeight: '36', }, groupD: { fontSize: '44', lineHeight: '48', }, }, trafalgar: { groupA: { fontSize: '20', lineHeight: '24', }, groupB: { fontSize: '24', lineHeight: '28', }, groupD: { fontSize: '32', lineHeight: '36', }, }, } |

Navigation Usage

import React from 'react';
import { ScrollableNavigation } from '@bbc/psammead-navigation/scrollable';
import Navigation, {
  NavigationUl,
  NavigationLi,
} from '@bbc/psammead-navigation';
import { latin } from '@bbc/gel-foundations/scripts';

<Navigation
  brandBackgroundColour='#B80000'
  brandForegroundColour='#FDFDFD'
  brandBorderColour='#EAB3B3'
  brandHighlightColour='#FFFFFF'
>
  <ScrollableNavigation
    brandBackgroundColour='#B80000'
    brandHighlightColour='#FFFFFF'
  >
    <NavigationUl>
      <NavigationLi
        url="/"
        script={latin}
        active
        currentPageText="Current Page"
        service="news"
        brandForegroundColour='#FDFDFD'
        brandBorderColour='#EAB3B3'
        brandHighlightColour='#FFFFFF'
      >
        Home
      </NavigationLi>
      <NavigationLi
        url="/sport"
        script={latin}
        service="news"
        brandForegroundColour='#FDFDFD'
        brandBorderColour='#EAB3B3'
        brandHighlightColour='#FFFFFF'
      >
        {Sport}
      </NavigationLi>
      <NavigationLi
        url="/weather"
        script={latin}
        service="news"
        brandForegroundColour='#FDFDFD'
        brandBorderColour='#EAB3B3'
        brandHighlightColour='#FFFFFF'
      >
        {Weather}
      </NavigationLi>
    </NavigationUl>
  </ScrollableNavigation>
</Navigation>;

Dropdown Navigation Usage

import React from 'react';
import {
  Dropdown,
  DropdownUl,
  DropdownLi,
} from '@bbc/psammead-navigation/dropdown';
import { latin } from '@bbc/gel-foundations/scripts';

<CanonicalDropdown isOpen={isOpen}>
  <DropdownUl>
    <DropdownLi
      script={latin}
      service="news"
      key="Home"
      url="/"
      active
      currentPageText="Current page"
    >
      Home
    </DropdownLi>
    <DropdownLi script={latin} service="news" key="Sport" url="/sport">
      Sport
    </DropdownLi>
  </DropdownUl>
</CanonicalDropdown>

Canonical Menu Button Usage

import React from 'react';
import { CanonicalMenuButton } from '@bbc/psammead-navigation/dropdown';
import { latin } from '@bbc/gel-foundations/scripts';

<CanonicalMenuButton
  announcedText="Menu"
  isOpen
  dir={dir}
  onClick={() => {
    console.log('Handle onClick action');
  }}
  script={latin}
/>

Amp Menu Button Usage

import React from 'react';
import { AmpMenuButton } from '@bbc/psammead-navigation/dropdown';
import { latin } from '@bbc/gel-foundations/scripts';

<AmpMenuButton
  announcedText="Menu"
  onToggle="menu.toggleVisibility"
  script={latin}
  dir={dir}
/>

Note that in order for the AmpMenuButton toggling to work correctly, an id should be added to the Navigation component. This id can be passed in as a prop to the component. Similarly, ScrollableNavigation also requires an id to be added to it.

When to use this component

The Navigation is designed to show a navigation bar on all pages, which will show all sections on a site. If there are too many items to fit on one line, the items will wrap to the next lines.

On the other hand, with ScrollableNavigation we can make the list to remain on one line and to be horizontally scrollable to allow access to further links, under 600px.

Accessibility notes

The Navigation has a navigation landmark to provide a way to identify links that are intended to be used for navigation.

We have added the role list and listitem to the NavigationUl and NavigationList respectively, due to a VoiceOver bug to reinstate the list semantics.

We have also added visually hidden text to let the user know which item in both regular and dropdown Navigation is the current page. Note the use of visually hidden text here is due to lack of support at this time for the aria-current page attribute. Also note the use of role="text" to stop text splitting in VoiceOver.

We have added an aria-expanded attribute to the menu button to indicate whether the menu is collapsed or expanded.

Contributing

Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at the root of the Psammead respository.

Code of Conduct

We welcome feedback and help on this work. By participating in this project, you agree to abide by the code of conduct. Please take a moment to read it.

License

Psammead is Apache 2.0 licensed.