@bbc/psammead-most-read

中文文档
6.1.0发布于 2021/06/03Apache-2.0ESM + CJS近 30 天下载 2761

A component for the most read item

原始使用文档
文档目录20 节
  1. Description
  2. Installation
  3. Components
  4. MostReadList
  5. Props
  6. Usage
  7. MostReadItemWrapper
  8. Props
  9. Usage
  10. MostReadRank
  11. Props
  12. Usage
  13. MostReadLink
  14. Props
  15. Usage
  16. When to use these components
  17. Accessibility notes
  18. Contributing
  19. Code of Conduct
  20. License

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

ArgumentTypeRequiredDefaultExample
numberOfItemsnumberyesN/A10
childrennodeyesN/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>,
dirstringyes'ltr''ltr'
columnLayoutstringno'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

ArgumentTypeRequiredDefaultExample
dirstringyes'ltr''ltr'
childrennodeyesN/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" />
columnLayoutstringno'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

ArgumentTypeRequiredDefaultExample
servicestringyesN/A'news'
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' } } }
listIndexnumberyesN/A1
numberOfItemsnumberyesN/A10
dirstringno"ltr""ltr"
columnLayoutstringno'multiColumn'twoColumn
sizestringno'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"
/>;

Props

ArgumentTypeRequiredDefaultExample
dirstringyes'ltr''ltr'
servicestringyesN/A'news'
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' } } }
titlestringyesN/A"This is a article headline"
hrefstringyesN/A"/bbc.co.uk/news/00000027051997"
childrennodenonull<Timestamp datetime="2019-03-01T14:00+00:00" script={script} padding={false} service={service}>Last updated: 5th November 2016</Timestamp>
sizestringno'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.

版本与发布记录

@bbc/psammead-most-read 共发布 109 个版本,首次发布于 2019/10/31;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.1.0latest2021/06/035 年前
6.0.312021/05/275 年前
6.0.302021/05/265 年前
6.0.292021/05/105 年前
6.0.282021/03/165 年前
6.0.272021/03/105 年前

其他发布通道:alpha → 5.0.0-alpha.0。

关于 @bbc/psammead-most-read 的常见问题

@bbc/psammead-most-read 是什么?

A component for the most read item

如何安装 @bbc/psammead-most-read?

在项目目录运行 npm install @bbc/psammead-most-read,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@emotion/styled(^11.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bbc/psammead-most-read 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bbc__psammead-most-read 是否存在。

@bbc/psammead-most-read 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bbc/psammead-most-read 可以商用吗?

@bbc/psammead-most-read 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bbc/psammead-most-read 的下载量有多少?

根据 npm 官方下载统计,@bbc/psammead-most-read 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,761 次,日均约 92 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bbc/psammead-most-read 还在维护吗?

最新版本 6.1.0 发布于 2021/06/03(5 年前);至今共发布 109 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/10/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。