Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@bbc/psammead-most-read

4.1.8 • Public • Published

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

Description

The MostRead component is designed to display the most read articles given a designated period of time which is dependent on service. The component comprises of a MostReadList containing an ordered list of MostReadItemWrapper. A MostReadItemWrapper is a list item comprised of and a MostReadLink, a link to the article, and a MostReadRank which is a numerical counter representing the article's ranking.

The MostReadLink and MostReadRank components also support a size prop. This prop currently only accepts a default and small size. Internally these values change the CSS used for sizing parts of the components. This will allow more sizes to be added in the future.

Installation

npm install @bbc/psammead-most-read

Components

MostReadList

Props

Argument Type Required Default Example
numberOfItems number yes N/A 10
children node yes N/A <MostReadItemWrapper dir="ltr"><MostReadRank service="news" script={latin} listIndex={1} numberOfItems={10} dir="ltr" /> <MostReadLink dir="ltr" href="/bbc.co.uk/news/articles/27051997" service="news" script={latin} title="This is a news article headline" /></MostReadItemWrapper>,
dir string yes 'ltr' 'ltr'
columnLayout string no 'multiColumn' twoColumn

Usage

This component is to be used in conjunction with the other MostRead components, example can be seen below.

import React from 'react';
import {
  MostReadList,
  MostReadLink,
  MostReadRank,
  MostReadItemWrapper,
} from '@bbc/psammead-most-read';
import { latin } from '@bbc/gel-foundations/scripts';
 
<MostReadList
  items={items}
  service="news"
  script={latin}
  dir="ltr"
  columnLayout="twoColumn"
>
  <MostReadItemWrapper dir="ltr" children columnLayout="twoColumn">
    <MostReadRank
      service="news"
      script={latin}
      listIndex={1}
      numberOfItems={10}
      dir="ltr"
      columnLayout="twoColumn"
    />
    <MostReadLink
      dir="ltr"
      href="/bbc.co.uk/news/articles/27051997"
      service="news"
      script={latin}
      title="This is a news article headline"
    />
  </MostReadItemWrapper>
</MostReadList>;

MostReadItemWrapper

Props

Argument Type Required Default Example
dir string yes 'ltr' 'ltr'
children node yes N/A <MostReadRank service="news" script={latin} listIndex={1} numberOfItems={10} dir="ltr" /> <MostReadLink dir="ltr" href="/bbc.co.uk/news/articles/27051997" service="news" script={latin} title="This is a news article headline" />
columnLayout string no 'multiColumn' twoColumn

Usage

This component is used to wrap MostReadLink and MostReadRank together, as seen below.

import React from 'react';
import { latin } from '@bbc/gel-foundations/scripts';
import {
  MostReadLink,
  MostReadRank,
  MostReadItemWrapper,
} from '@bbc/psammead-most-read';
<MostReadItemWrapper dir="ltr" children columnLayout="twoColumn">
  <MostReadRank
    service="news"
    script={latin}
    listIndex={1}
    numberOfItems={10}
    dir="ltr"
    columnLayout="twoColumn"
  />
  <MostReadLink
    dir="ltr"
    script={latin}
    service="news"
    title="This is a article headline"
    href="/bbc.co.uk/news/00000027051997"
  />
</MostReadItemWrapper>;

MostReadRank

Props

Argument Type Required Default Example
service string yes N/A 'news'
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' } } }
listIndex number yes N/A 1
numberOfItems number yes N/A 10
dir string no "ltr" "ltr"
columnLayout string no 'multiColumn' twoColumn
size string no 'default' 'small'

Usage

import React from 'react';
import { latin } from '@bbc/gel-foundations/scripts';
import { MostReadRank } from '@bbc/psammead-most-read';
 
<MostReadRank
  service="news"
  script={latin}
  listIndex={1}
  numberOfItems={5}
  dir="ltr"
  columnLayout="twoColumn"
  size="small"
/>;

MostReadLink

Props

Argument Type Required Default Example
dir string yes 'ltr' 'ltr'
service string yes N/A 'news'
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' } } }
title string yes N/A "This is a article headline"
href string yes N/A "/bbc.co.uk/news/00000027051997"
children node no null <Timestamp datetime="2019-03-01T14:00+00:00" script={script} padding={false} service={service}>Last updated: 5th November 2016</Timestamp>
size string no 'default' 'small'

Usage

A typical use-case of this component is as displayed below. It contains an info element. The info element is a link which points to the corresponding article.

import React from 'react';
import { latin } from '@bbc/gel-foundations/scripts';
import { MostReadLink } from '@bbc/psammead-most-read';
import Timestamp from '@bbc/psammead-timestamp';
 
<MostReadLink
  dir="ltr"
  script={latin}
  service="news"
  title="This is a article headline"
  href="/bbc.co.uk/news/00000027051997"
  size="small"
>
  <Timestamp
    datetime="2019-03-01T14:00+00:00"
    script={script}
    padding={false}
    service={service}
  >
    Last updated: 5th November 2016
  </Timestamp>
</MostReadLink>;

When to use these components

These components are intended to be used on article, front, story and mostRead pages.

Accessibility notes

  • These components are expected to provide information about the Most Read articles in an ordered list when using a screenreader by announcing the region landmark, reading out the title 'Most Read', and read out each headline link in the correct order.
  • Due to the faux block link code, it is not expected to read out the rank as well.

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.

Keywords

Install

npm i @bbc/psammead-most-read

DownloadsWeekly Downloads

1,610

Version

4.1.8

License

Apache-2.0

Unpacked Size

202 kB

Total Files

31

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar