9.2.22 • Published 2 years ago

@bbc/psammead-navigation v9.2.22

Weekly downloads
1,344
License
Apache-2.0
Repository
github
Last release
2 years ago

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

ArgumentTypeRequiredDefaultExample
childrennodeYesN/A<ScrollableNavigation dir={dir}><NavigationUl><NavigationLi url="/" script={latin} active="true">Home</NavigationLi><NavigationLi url="/sport" script={latin}>{Sport}</NavigationLi></NavigationUl><ScrollableNavigation/>
dirstringNo'ltr''rtl'
isOpenbooleanNofalsetrue
ampOpenClassstringNonull'open'
brandBackgroundColourstringYesN/A'#B80000'
brandForegroundColourstringYesN/A'#FDFDFD'
brandBorderColourstringYesN/A'#EAB3B3'
brandHighlightColourstring YesNoN/A'#FFFFFF'

NavigationUl

ArgumentTypeRequiredDefaultExample
childrennodeYesN/A<NavigationLi url="/" script={latin} active="true">Home</NavigationLi><NavigationLi url="/sport" script={latin}>{Sport}</NavigationLi>

NavigationLi

ArgumentTypeRequiredDefaultExample
urlstringYesN/A/sport
scriptobjectYesN/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', }, }, }
activebooleanNofalsetrue
currentPageTextstringNonullCurrent page
servicestringYesN/A'news'
dirstringNo'ltr''rtl'
brandForegroundColourstringYesN/A'#FDFDFD'
brandBorderColourstringYesN/A'#EAB3B3'
brandHighlightColourstring YesNoN/A'#FFFFFF'

ScrollableNavigation

ArgumentTypeRequiredDefaultExample
childrennodeYesN/A<NavigationUl><NavigationLi url="/" script={latin} active="true">Home</NavigationLi><NavigationLi url="/sport" script={latin}>{Sport}</NavigationLi></NavigationUl>
dirstringNo'ltr''rtl'
brandBackgroundColourstringYesN/A'#B80000'
brandHighlightColourstring YesNoN/A'#FFFFFF'

CanonicalDropdown

ArgumentTypeRequiredDefaultExample
childrennodeYesN/A<DropdownUl><DropdownLi script={latin} service='news' key='sport' url='/sport' active="false"> Sport </DropdownLi></DropdownUl>
isOpenboolYesN/Afalse

AmpDropdown

ArgumentTypeRequiredDefaultExample
childrennodeYesN/A<DropdownUl><DropdownLi script={latin} service='news' key='sport' url='/sport' active="false"> Sport </DropdownLi></DropdownUl>

DropdownLi

ArgumentTypeRequiredDefaultExample
childrenstringYesN/A'Sport'
urlstringYesN/A/sport
scriptobjectYesN/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', }, }, }
servicestringYesN/A'news'
activebooleanNofalsetrue
currentPageTextstringNonullCurrent page
dirstringNoltrrtl

CanonicalMenuButton

ArgumentTypeRequiredDefaultExample
announcedTextstringYesN/A'Menu'
onClickfunctionYesN/A() => { console.log("Handle onClick action"); }
isOpenboolYesN/Afalse
dirstringno'ltr''rtl'
scriptobjectYesN/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

ArgumentTypeRequiredDefaultExample
announcedTextstringYesN/A'Menu'
onTogglestringYesN/A"menu.toggleVisibility" - must be an action on a valid AMP target
dirstringno'ltr''rtl'
scriptobjectYesN/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.

9.2.21

2 years ago

9.2.22

2 years ago

9.2.20

2 years ago

9.2.18

2 years ago

9.2.19

2 years ago

9.2.16

2 years ago

9.2.17

2 years ago

9.2.14

2 years ago

9.2.15

2 years ago

9.2.13

3 years ago

9.2.12

3 years ago

9.2.11

3 years ago

9.2.8

3 years ago

9.2.9

3 years ago

9.2.10

3 years ago

9.2.7

3 years ago

9.2.6

3 years ago

9.2.5

3 years ago

9.2.4

3 years ago

9.2.3

3 years ago

9.2.2

3 years ago

9.2.1

3 years ago

9.2.0

3 years ago

9.1.1

3 years ago

9.1.0

3 years ago

9.0.12

3 years ago

9.0.11

3 years ago

9.0.10

3 years ago

9.0.9

3 years ago

9.0.8

3 years ago

9.0.7

3 years ago

9.0.6

3 years ago

9.0.5

3 years ago

9.0.4

3 years ago

9.0.3

3 years ago

9.0.2

3 years ago

9.0.1

3 years ago

9.0.0

3 years ago

8.0.9

3 years ago

8.0.8

3 years ago

8.0.7

3 years ago

8.0.6

3 years ago

8.0.5

3 years ago

8.0.4

3 years ago

8.0.3

4 years ago

8.0.1

4 years ago

8.0.2

4 years ago

8.0.0

4 years ago

7.0.3

4 years ago

7.0.2

4 years ago

7.0.1

4 years ago

7.0.0-alpha.0

4 years ago

6.0.23

4 years ago

6.0.22

4 years ago

6.0.21

4 years ago

6.0.20

4 years ago

6.0.19

4 years ago

6.0.18

4 years ago

6.0.16

4 years ago

6.0.17

4 years ago

6.0.15

4 years ago

6.0.14

4 years ago

6.0.13

4 years ago

6.0.12

4 years ago

6.0.11

4 years ago

6.0.10

4 years ago

6.0.9

4 years ago

6.0.8

4 years ago

6.0.7

4 years ago

6.0.6

4 years ago

6.0.5

4 years ago

6.0.4

4 years ago

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

6.0.0-alpha.27

4 years ago

6.0.0-alpha.26

4 years ago

6.0.0-alpha.25

4 years ago

6.0.0-alpha.23

4 years ago

6.0.0-alpha.24

4 years ago

6.0.0-alpha.22

4 years ago

6.0.0-alpha.21

4 years ago

6.0.0-alpha.20

4 years ago

6.0.0-alpha.19

4 years ago

6.0.0-alpha.18

4 years ago

6.0.0-alpha.17

4 years ago

6.0.0-alpha.16

4 years ago

6.0.0-alpha.15

4 years ago

6.0.0-alpha.14

4 years ago

6.0.0-alpha.13

4 years ago

6.0.0-alpha.12

4 years ago

6.0.0-alpha.11

4 years ago

6.0.0-alpha.10

4 years ago

6.0.0-alpha.9

4 years ago

6.0.0-alpha.8

4 years ago

6.0.0-alpha.7

4 years ago

6.0.0-alpha.6

4 years ago

6.0.0-alpha.5

4 years ago

6.0.0-alpha.4

4 years ago

6.0.0-alpha.3

4 years ago

6.0.0-alpha.2

4 years ago

6.0.0-alpha.1

4 years ago

5.0.0-alpha.2

4 years ago

5.0.0-alpha.1

4 years ago

4.0.0-alpha.2

4 years ago

4.0.0-alpha.1

4 years ago

3.1.0-alpha.1

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.12

5 years ago

2.2.11

5 years ago

2.2.10

5 years ago

2.2.9

5 years ago

2.2.8

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago