Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@bbc/psammead-story-promo

bbc236Apache-2.08.0.38

A story promo for use on index pages

bbc, story, promo

readme

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

Description

The StoryPromo component is designed to be used on 'index' pages, which are pages that link to other articles/stories. This info can be any collection of nodes, however typically these would be a headline, text summary and timestamp.

Exports

/index-alsos - components for links to stories that are related to the top story.

Installation

npm install @bbc/psammead-story-promo

StoryPromo Props

Argument Type Required Default Example
image node no Null <img>
info node yes N/A <h2>Title</h2>
mediaIndicator node no null <MediaIndicator duration="2:15" datetime="PT2M15S" offscreenText="Video 2 minutes 15 seconds" />
dir string no ltr rtl
displayImage boolean no true false
promoType string no regular top

Headline Props

Argument Type Required Default Example
Script object yes latin { 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'
promoHasImage bool no true false
promoType string no regular top

Summary Props

Argument Type Required Default Example
Script object yes latin { 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'
promoHasImage bool no true false
promoType string no regular top

IndexAlsos

The Index Alsos are links to stories that are related to the top story.

Within the IndexAlsos component there is a Visually Hidden level 4 heading, which announces text passed as prop.

When there are more than one Index Alsos, they should be wrapped in a list item IndexAlsosLi within an unordered list IndexAlsosUl with the role listitem and list respectively.

On the other hand, when there is exactly one Index Also, it should use the IndexAlso component and it should not be contained within a list.

Props

IndexAlsos Props

Argument Type Required Default Example
children node yes N/A <IndexAlsosUl><IndexAlsosLi script={latin} service="news" url="https://www.bbc.co.uk/news" mediaIndicator={<MediaIndicator service="news" type="video" indexAlsos/>}>Related content 1</IndexAlsosLi><IndexAlsosLi script={latin} service="news" url="https://www.bbc.co.uk/news">Related content 2</IndexAlsosLi></IndexAlsosUl>
offScreenText string no null Related content

Data attributes, such as data-e2e can be passed in for testing as well.

IndexAlsoUl Props

Argument Type Required Default Example
children node yes N/A <IndexAlsosLi script={latin} service="news" url="https://www.bbc.co.uk/news" mediaIndicator={<MediaIndicator service="news" type="video" indexAlsos/>}>Related content 1</IndexAlsosLi><IndexAlsosLi script={latin} service="news url="https://www.bbc.co.uk/news">Related content 2</IndexAlsosLi>

IndexAlsoLi Props

Argument Type Required Default Example
children node yes N/A This is a headline
script object yes latin { 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'
url string yes N/A 'https://www.bbc.co.uk/news'
dir string no ltr rtl
mediaIndicator node no null <MediaIndicator service="news" type="video" indexAlsos/>
mediaType string no null Video

IndexAlso Props

Argument Type Required Default Example
children node yes N/A This is a headline
script object yes latin { 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'
url string yes N/A 'https://www.bbc.co.uk/news'
dir string no ltr rtl
mediaIndicator node no null <MediaIndicator service="news" type="video" indexAlsos/>
mediaType string no null Video

Usage

The typical use-case of this component is as displayed below. A Image sits on the left side of the promo with info elements on the right, except in Leading stories which are reversed. These info elements are typically a headline, text summary paragraph and timestamp. The Headline and Summary components are provided by this package and can be imported as seen below.

This component also has an option to display a media indicator, which consists of a play icon and duration of the media, if that data is provided.

The promoType prop of top can be passed to adopt a vertical card layout under 600px. At breakpoints above 600px a horizontal layout is maintained with the image and text summary each occupying 1/2 of the parent container.

On the other hand, a promoType prop of leading can be passed to place the Info on the left side and the Image or the right side of the component. The image occupies 2/3 of the parent container and the text summary occupies 1/3.

This prop must be passed to the StoryPromo, Headline and Summary components.

import React, { Fragment } from 'react';
import StoryPromo, {
  Headline,
  Summary,
  Link,
  IndexAlsos,
  IndexAlso,
  IndexAlsosUl,
  IndexAlsosLi,
} from '@bbc/psammead-story-promo';
import MediaIndicator from '@bbc/psammead-media-indicator';
import { latin } from '@bbc/gel-foundations/scripts';
import LiveLabel from '@bbc/psammead-live-label';
import VisuallyHiddenText from '@bbc/psammead-visually-hidden-text';

const Image = <img src="https://foobar.com/image.jpg" />;

const IndexAlsosComponent = ({ alsoItems, script, service }) => (
  //This example doesn't show how the alsoItems are destructured to get the respective data
  <IndexAlsos offScreenText="Related content">
    {alsoItems.length > 1 ? (
      <IndexAlsosUl>
        <IndexAlsosLi
          script={script}
          service={service}
          url="https://www.bbc.co.uk/news"
          mediaIndicator={
            <MediaIndicator service={service} type="video" indexAlsos />
          }
        >
          Related text 1
        </IndexAlsosLi>
        <IndexAlsosLi
          script={script}
          service={service}
          url="https://www.bbc.co.uk/news"
        >
          Related text 2
        </IndexAlsosLi>
      </IndexAlsosUl>
    ) : (
      <IndexAlso>Related text</IndexAlso>
    )}
  </IndexAlsos>
);

const Info = ({ isLive, alsoItems }) => (
  <Fragment>
    <Headline script={latin} service="news" promoType="top">
      <Link href="https://www.bbc.co.uk/news">
        {isLive ? (
          <LiveLabel service="news" dir={dir} ariaHidden offScreenText="Live">
            The headline of the live promo
          </LiveLabel>
        ) : (
          'The headline of the promo'
        )}
      </Link>
    </Headline>
    <Summary script={latin} service="news" promoType="top">
      The summary of the promo
    </Summary>
    <time>12 March 2019</time>
    {topStory && alsoItems && (
      <IndexAlsosComponent
        alsoItems={alsoItems}
        script={latin}
        service="news"
      />
    )}
  </Fragment>
);

<StoryPromo image={Image} info={Info({ isLive: false })} promoType="top" />;

When to use this component

The StoryPromo component is designed to be used within a link element to allow the user to navigate to the story on another page.

Accessibility notes

This component uses full semantic markup for the Headline, Summary, and Link, using h3, p and a respectively. Other accessibility factors such as image alt text and time elements are passed in as props and aren't explicitly set in this component.

The link is nested inside the h3 for better support with VoiceOver Mac and Safari. We use the faux block link pattern which makes the entire block clickable, whilst also enabling links nested within in that block to also be clickable.

The LiveLabel example above shows this component being hidden to screen readers, and has visually hidden text rendered alongside it. This is to ensure the screen reader announces the word 'Live' correctly. This does not need to be accounted for in other languages.

Roadmap

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

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.

changelog

Psammead Story Promo Changelog

Version Description
8.0.38 PR#4632 psammead-styles bump
8.0.37 PR#4609 Bump from psammead-styles
8.0.36 PR#4608 Bump dependencies
8.0.35 PR#4606 Bump dependencies
8.0.34 PR#4603 Conditionally add aria-labelledby attribute
8.0.33 PR#4602 Use 'children' value instead of 'URL' for aria-labelledby
8.0.32 PR#4588 Fix TalkBack reading nested spans incorrectly
8.0.31 PR#4578 Fix Firefox underline rendering bug
8.0.30 PR#4574 Bumps psammead-styles
8.0.29 PR#4568 Bump dependencies
8.0.28 PR#4565 Bump from psammead-styles
8.0.27 PR#4562 Bump psammead-styles
8.0.26 PR#4561 Bump dependencies for @bbc/psammead-styles
8.0.25 PR#4548 Bumps dependencies
8.0.24 PR#4547 Bumps packages
8.0.23 PR#4545 Bump dependencies for @bbc/psammead-styles
8.0.22 PR#4552 Bump psammead-styles
8.0.21 PR#4497 Bump psammead-styles
8.0.20 PR#4486 upgrade minor/patch dependencies
8.0.18 PR#4420 bumps 3rd-party dependencies
8.0.17 PR#4368 use Yarn Workspaces
8.0.16 PR#4335 switch to yarn for package management
8.0.15 PR#4304 Talos - Bump Dependencies - @bbc/gel-foundations, @bbc/psammead-styles
8.0.14 PR#4303 Trigger rebuild following babel config update for emotion 11
8.0.13 PR#4271 change react peer dep to >=16.9.0
8.0.12 PR#4260 Talos - Bump Dependencies - @bbc/gel-foundations
8.0.11 PR#4256 Talos - Bump Dependencies - @bbc/psammead-styles
8.0.10 PR#4193 Upgrade Emotion to v11
8.0.9 PR#4226 Talos - Bump Dependencies - @bbc/psammead-styles
8.0.8 PR#4189 Talos - Bump Dependencies - @bbc/psammead-styles
8.0.7 PR#4072 Talos - Bump Dependencies - @bbc/psammead-styles
8.0.6 PR#4052 Talos - Bump Dependencies - @bbc/gel-foundations
8.0.5 PR#4030 Update snapshots.
8.0.4 PR#4029 Talos - Bump Dependencies - @bbc/psammead-styles
8.0.3 PR#3944 Talos - Bump Dependencies - @bbc/psammead-styles
8.0.2 PR#3928 Update snapshots
8.0.1 PR#3925 Talos - Bump Dependencies - @bbc/psammead-styles
8.0.0 PR#3891 Talos - Bump Dependencies - @bbc/psammead-styles
7.0.4 PR#3885 Talos - Bump Dependencies - @bbc/psammead-styles
7.0.3 PR#3883 Talos - Bump Dependencies - @bbc/psammead-styles
7.0.2 PR#3855 Talos - Bump Dependencies - @bbc/gel-foundations
7.0.1 PR#3854 Talos - Bump Dependencies - @bbc/psammead-styles
7.0.0-alpha.0 PR#3843 Bump Dependencies - @bbc/psammead-styles alpha version
6.0.15 PR#3836 Talos - Bump Dependencies - @bbc/psammead-styles
6.0.14 PR#3816 Talos - Bump Dependencies
6.0.13 PR#3728 Tweaks following Storybook v5.3.19 to v6.0.22 update
6.0.12 PR#3811 Talos - Bump Dependencies - @bbc/psammead-styles
6.0.11 PR#3785 Talos - Bump Dependencies - @bbc/gel-foundations
6.0.10 PR#3772 Bump prettier to 2.1.2
6.0.9 PR#3709 Bump prettier from 2.0.5 to 2.1.1
6.0.8 PR#3710 Talos - Bump Dependencies - @bbc/psammead-styles
6.0.7 PR#3707 Talos - Bump Dependencies - @bbc/psammead-styles
6.0.6 PR#3623 Talos - Bump Dependencies - @bbc/gel-foundations
6.0.5 PR#3604 Talos - Bump Dependencies - @bbc/gel-foundations
6.0.4 PR#3541 Remove padding-top in TextGridItem when no image displayed
6.0.3 PR#3467 Talos - Bump Dependencies - @bbc/psammead-styles
6.0.2 PR#3410 Add overflow-wrap property to Link
6.0.1 PR#3397 Talos - Bump Dependencies - @bbc/psammead-styles
6.0.0 PR#3264 Use LiveLabel component
5.1.0 PR#3206 Add prop to toggle if live label is hidden, as styled components strips aria tag
5.0.0 PR#3202 Live Label is no longer aria hidden
4.0.0 PR#3154 Remove alpha tag
4.0.0-alpha.13 PR#3150 Fix fallback width for Leading promo
4.0.0-alpha.12 PR#3135 Talos - Bump Dependencies - @bbc/gel-foundations
4.0.0-alpha.11 PR#3136 Fix visually hidden text so it isn't split across multiple strings.
4.0.0-alpha.10 PR#3129 Talos - Bump Dependencies - @bbc/gel-foundations
4.0.0-alpha.9 PR#3107 Pass in dir prop to MediaIndicator in IndexAlsosContainer.
4.0.0-alpha.8 PR#3073 Use new major version of MediaIndicator. StoryPromo has updated styling around the MediaIndicator. Index Alsos test helper now using prop isInline for the MediaIndicator.
4.0.0-alpha.7 PR#3027 Use mobile and tablet stylings
4.0.0-alpha.6 PR#3030 Talos - Bump Dependencies - @bbc/psammead-styles
4.0.0-alpha.5 PR#3026 Apply Pica to the regular story promo headline across all breakpoints
4.0.0-alpha.4 PR#3023 Refactor no image headline stylings
4.0.0-alpha.3 PR#2990 Use GEL_SPACING constant in the LiveLabel component
4.0.0-alpha.2 PR#2989 Update snapshot
4.0.0-alpha.1 PR#2937 Add promoType prop, remove topStory prop, integrate Leading promo and move Image and Text styles into a separate file
3.0.0-alpha.13 PR#2978 Talos - Bump Dependencies - @bbc/gel-foundations
3.0.0-alpha.12 PR#2973 Talos - Bump Dependencies - @bbc/psammead-styles
3.0.0-alpha.11 PR#2920 Talos - Bump Dependencies - @bbc/gel-foundations
3.0.0-alpha.10 PR#2701 Talos - Bump Dependencies - @bbc/psammead-styles
3.0.0-alpha.9 PR#2697 Talos - Bump Dependencies - @bbc/psammead-styles
3.0.0-alpha.8 PR#2648 Rename displayImage prop to promoHasImage to better indicate its use
3.0.0-alpha.7 PR#2626 Increase image and summary width of top story at 1008px+ for grid fallbacks
3.0.0-alpha.6 PR#2397 Add a displayImage prop to render story promo without an image
3.0.0-alpha.5 PR#2519 Talos - Bump Dependencies - @bbc/psammead-styles
3.0.0-alpha.4 PR#2488 Talos - Bump Dependencies - @bbc/gel-foundations
3.0.0-alpha.3 PR#2477 Talos - Bump Dependencies - @bbc/psammead-styles
3.0.0-alpha.2 PR#2440 Talos - Bump Dependencies - @bbc/psammead-styles
3.0.0-alpha.1 PR#2404 replace inputProvider and dirDecorator with withServicesInput
3.0.0-alpha.0 PR#2377 Spread extra props to the component
2.8.0-alpha.1 PR#2354 Add sectionName prop to set data-story-promo for event tracking
2.8.0-alpha.0 PR#2296 Change Story Promo design 1080+px
2.7.18 PR#2289 Talos - Bump Dependencies - @bbc/psammead-styles
2.7.17 PR#2273 Talos - Bump Dependencies - @bbc/psammead-styles
2.7.16 PR#2251 Talos - Bump Dependencies - @bbc/psammead-styles
2.7.15 PR#2181 Remove Timestamp in StoryPromo story
2.7.14 PR#2191 Talos - Bump Dependencies - @bbc/gel-foundations
2.7.13 PR#2119 Add visuallyHiddenText for media types in storybook
2.7.12 PR#2145 Talos - Bump Dependencies - @bbc/psammead-styles
2.7.11 PR#2040 Pass props to IndexAlsos without destructuring to allow passing in of attributes onto the top-level to use data attributes, IDs, etc.
2.7.10 PR#2040 Fix summary visibility for breakpoints below 1008px
2.7.9 PR#2081 Talos - Bump Dependencies - @bbc/psammead-styles
2.7.8 PR#1926 Update component storybook to use latest inputProvider changes
2.7.7 PR#1987 Fix font-size and line-height not being applied in IE11
2.7.6 PR#1993 Talos - Bump Dependencies
2.7.5 PR#1960 Change <React.Fragment> to <>
2.7.4 PR#1942 Talos - Bump React to 16.9.0
2.7.3 PR#1930 Fix headline font-size in standard story promo
2.7.2 PR#1938 Consistent use of destructuring props
2.7.1 PR#1931 Talos - Bump Dependencies
2.7.0 PR#1835 Add desktop width top story and show indexAlsos
2.6.2 PR#1923 Add support for RTL to Index Alsos
2.6.1 PR#1845 Remove padding-bottom from Index Alsos Wrapper
2.6.0 PR#1832 Export IndexAlsos from src/index.jsx
2.5.3 PR#1826 Talos - Bump Dependencies
2.5.2 PR#1804 Talos - Bump Dependencies
2.5.1 PR#1803 Patches broken links on badges in documentation
2.5.0 PR#1794 Add david dependency badges
2.4.0 PR#1567 Add Index Alsos
2.3.4 PR#1734 Talos - Bump Dependencies
2.3.5 PR#1685 Bump dependencies
2.3.2 PR#1682 Move all dev dependencies to top level package.json
2.3.1 PR#1641 Bump dependencies
2.3.0 PR#1359 Add LiveLabel to story promo exports
2.2.1 PR#1502 Add media type knob to story
2.2.0 PR#1408 Use @bbc/psammead-styles/detection to detect grid support
2.1.2 PR#1409 Bump media-indicator to v2.3.0
2.1.1 PR#1365 Bump psammead-styles to 1.2.0
2.1.0 PR#1233 Add ESM modules entry
2.0.4 PR#1089 Remove extra margin from 1st story promo
2.0.3 PR#1182 Bump dependencies and update test/story to have service prop
2.0.2 PR#1082 Bump lodash security vulnerability
2.0.1 PR#892 Bump dependencies
2.0.0 PR#1022 Apply font based on service prop
1.0.1 PR#892 Bump dependencies
1.0.0 PR#937 Remove alpha tag, swarm done
1.0.0-alpha.6 PR#893 Fix knobs for story promo stories
1.0.0-alpha.5 PR#769 Fix stories not appearing in storybook when using install:packages:link
1.0.0-alpha.4 PR#706 Fix amp images not showing in IE11
1.0.0-alpha.3 PR#713 Update styled-components to 4.3.2
1.0.0-alpha.2 PR#694 Fix floating media indicator and promo link bugs
1.0.0-alpha.1 PR#677 Use @bbc/gel-foundations@3.0.0
1.0.0-alpha.0 PR#679 Bump version number
0.2.0-alpha.9 PR#663 Add assertion tests
0.2.0-alpha.8 PR#578 Add Top Story promo design
0.2.0-alpha.7 PR#628 Update Story Promo Changelog title
0.2.0-alpha.6 PR#588 Update Story promo headline to use Pica under 600px.
0.2.0-alpha.5 PR#522 AddMediaIndicator.
0.2.0-alpha.4 PR#546 Replace colours and hide summary under 600px width screen.
0.2.0-alpha.3 PR#534 Remove Timestamp padding.
0.2.0-alpha.2 PR#535 Fix issues with knobs on storybook.
0.2.0-alpha.1 PR#513 Add Link with hover, focus and visited states.
0.1.4 PR#489 Add grid fallback.
0.1.3 PR#498 Update stories to use new input provider.
0.1.2 PR#488 Hide story summary on device width lower than 600px.
0.1.1 PR#474 Update Story promo headline to use Great Primer.
0.1.0 PR#453 Create initial package.