7.1.13 • Published 3 years ago

@bbc/psammead-section-label v7.1.13

Weekly downloads
1,341
License
Apache-2.0
Repository
github
Last release
3 years ago

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

Description

The @bbc/psammead-section-label package exports one component - a Section Label.

For colours and font family it uses @bbc/psammead-styles and @bbc/gel-foundations for spacing and GEL Typography implemented in Styled Components.

The only provided child should be the title for the section, provided as a string, which will be wrapped in an <h2> element by the component – (see the Accessibility notes).

Installation

npm install @bbc/psammead-section-label

Props

ArgumentTypeRequiredDefaultExample
barbooleannotruefalse
mobileDividerbooleannotruefalse
visuallyHiddenbooleannofalsetrue
childrenstringyesN/A'Most Read'
dirstringno'ltr''rtl'
hrefstringnonull'https://www.bbc/com/igbo/egwuregwu'
idstringnoN/Atop-stories-id
labelIdstringnoN/Atop-stories-label
linkTextstringnonull'See More'
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'
backgroundColorstringnoC_GHOSTC_LUNAR
overrideHeadingAsstringnonullstrong

Usage

import SectionLabel from '@bbc/psammead-section-label';
import { latin } from '@bbc/gel-foundations/scripts';

const WrappingComponent = () => (
  <div aria-labelledby="example-section-label">
    <SectionLabel
      script={latin}
      dir="ltr"
      labelId="example-section-label"
      service="news"
    >
      Example section
    </SectionLabel>
  </div>
);

Or, without a horizontal bar:

import SectionLabel from '@bbc/psammead-section-label';
import { latin } from '@bbc/gel-foundations/scripts';

const WrappingComponent = () => (
  <div aria-labelledby="example-section-label">
    <SectionLabel
      script={latin}
      dir="ltr"
      bar={false}
      labelId="example-section-label"
      service="news"
    >
      Example section
    </SectionLabel>
  </div>
);

On mobile, this component places a dividing line above the title. This can be disabled by setting the mobileDivider prop to false:

import SectionLabel from '@bbc/psammead-section-label';
import { latin } from '@bbc/gel-foundations/scripts';

const WrappingComponent = () => (
  <div aria-labelledby="example-section-label">
    <SectionLabel
      script={latin}
      dir="ltr"
      mobileDivider={false}
      labelId="example-section-label"
      service="news"
    >
      Example section
    </SectionLabel>
  </div>
);

You can also visually hide the SectionLabel for all breakpoints by adding the visuallyHidden prop:

import SectionLabel from '@bbc/psammead-section-label';
import { latin } from '@bbc/gel-foundations/scripts';

const WrappingComponent = () => (
  <div aria-labelledby="example-section-label">
    <SectionLabel
      script={latin}
      dir="ltr"
      visuallyHidden={true}
      labelId="example-section-label"
      service="news"
    >
      Example section
    </SectionLabel>
  </div>
);

You can even use this component as a link (typically to an index of content related to the section): NB. when doing this both the href and the linkText must be supplied. If either is missing, the link will not be rendered.

import SectionLabel from '@bbc/psammead-section-label';
import { latin } from '@bbc/gel-foundations/scripts';

const WrappingComponent = () => (
  <div aria-labelledby="example-section-label">
    <SectionLabel
      script={latin}
      dir="ltr"
      href="https://www.bbc.com/news/index"
      id="example-section-label"
      linkText="See More"
      service="news"
    >
      Example section
    </SectionLabel>
  </div>
);

You can override the header(h2) to any custom HTML element that fits your accesibility requirement depending on what use case or semantic meaning you want to portray in your pages with the overrideHeadingAs prop.

import SectionLabel from '@bbc/psammead-section-label';
import { latin } from '@bbc/gel-foundations/scripts';

const WrappingComponent = () => (
  <div aria-labelledby="example-section-label">
    <SectionLabel
      script={latin}
      dir="ltr"
      labelId="example-section-label"
      service="news"
      overrideHeadingAs="strong"
    >
      Example section
    </SectionLabel>
  </div>
);

When to use this component

This component should be used to signal the beginning of a grouping of story promos. It should not wrap the story promos or contain any content other than that section's title (aka 'strapline').

Accessibility notes

Although this component has the appearance of a horizontal rule, it does not use an <hr> tag, and therefore does not have the associated semantic meaning.

This component wraps the title string in an <h2> element. The labelId prop will be applied to the <h2> as an id attribute, allowing the content of the element to be referenced by an aria-labelledby attribute. See the examples above.

Setting the visuallyHidden prop to true visually hides this component for all breakpoints, however it will still be available to screen-readers and other assistive technology.

When supplied with an href and the linkText, the section label contains an <a> link, which is aria-labelledby the labelId described above. The linkText is only expected to be useful to visual users, so is marked as aria-hidden="true" to prevent announcement to screen readers. This aria-hidden="true" isn't strictly required - setting the aria-labelledby attribute should prevent screen readers from reading out the linkText. However, it adding it makes clear to screen readers and other developers that the linkText is designed to be ignored by screen readers.

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.

7.1.13

3 years ago

7.1.12

3 years ago

7.1.11

3 years ago

7.1.10

3 years ago

7.1.9

3 years ago

7.1.7

3 years ago

7.1.6

3 years ago

7.1.8

3 years ago

7.1.5

3 years ago

7.1.4

3 years ago

7.1.3

3 years ago

7.1.2

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.20

4 years ago

7.0.19

4 years ago

7.0.18

4 years ago

7.0.17

4 years ago

7.0.16

4 years ago

7.0.15

4 years ago

7.0.14

4 years ago

7.0.13

4 years ago

7.0.12

4 years ago

7.0.11

4 years ago

7.0.10

4 years ago

7.0.8

4 years ago

7.0.9

4 years ago

7.0.7

4 years ago

7.0.6

4 years ago

7.0.5

4 years ago

7.0.4

4 years ago

7.0.3

4 years ago

7.0.2

4 years ago

7.0.1

4 years ago

7.0.0

4 years ago

6.0.3

4 years ago

6.0.1

4 years ago

6.0.2

4 years ago

6.0.0-alpha.0

4 years ago

5.0.17

4 years ago

5.0.16

4 years ago

5.0.15

4 years ago

5.0.14

4 years ago

5.0.13

4 years ago

5.0.11

4 years ago

5.0.12

4 years ago

5.0.10

4 years ago

5.0.9

4 years ago

5.0.8

4 years ago

5.0.7

5 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.13

5 years ago

3.0.12

5 years ago

3.0.10

5 years ago

3.0.11

5 years ago

3.0.9

5 years ago

3.0.8

5 years ago

3.0.7

5 years ago

3.0.6

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.18

5 years ago

2.3.17

5 years ago

2.3.16

5 years ago

2.3.15

5 years ago

2.3.14

5 years ago

2.3.13

5 years ago

2.3.12

5 years ago

2.3.11

5 years ago

2.3.10

5 years ago

2.3.9

5 years ago

2.3.8

5 years ago

2.3.7

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.0

5 years ago

2.1.6

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.0

5 years ago

1.0.8

5 years ago

1.0.7

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

6 years ago

1.0.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.1.0-alpha.1

6 years ago

0.1.0-alpha.0

6 years ago