@bbc/psammead-navigation
v9.2.22
Published
A navigation bar to use on index pages
Downloads
630
Maintainers
Readme
psammead-navigation -
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.