@bbc/psammead-consent-banner

中文文档
5.5.15发布于 2022/03/30Apache-2.0ESM + CJS近 30 天下载 4275

React styled components for the Consent Banner

原始使用文档
文档目录7 节
  1. Description
  2. Installation
  3. Props
  4. Usage
  5. Contributing
  6. Code of Conduct
  7. License

psammead-consent-banner - Known Vulnerabilities Dependency Status peerDependencies Status Storybook GitHub license npm version PRs Welcome

Description

The psammead-consent-banner component is a styled div that encapsulates information regarding privacy and cookie policy. The component also has two options, for users to accept the policy or be directed to a page with additional information regarding the data policy.

Installation

npm install @bbc/psammead-consent-banner

Props

ArgumentTypeRequiredDefaultExample
titlestringYesN/AWe've updated our Privacy and Cookies Policy
textelementYesN/A<ConsentBannerText script={script}> This is some text</ConsentBannerText>
acceptelementYesN/A<button type="button">Accept</button>
rejectelementYesN/A<a href="https://www.bbc.co.uk/usingthebbc/your-data-matters">Find out what's changed</a>
idstringNoNullConsentBanner
hiddenboolNoNullfalse
dirstringNo'ltr'One of 'rtl' 'ltr'
scriptscriptYesN/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'
headingRefReferencenonulluseRef(null)

Usage

The typical use-case of this component is on top of the webpage of all page types. It is visible for new users.

The headingRef prop is used so that the title of the consent banner can be programmatically focussed for accessibility reasons. This ref will be assigned to an HTML heading element which can be focussed using the DOM APIs: headingRef.current.focus().

import { ConsentBanner, ConsentBannerText } from '@bbc/psammead-consent-banner';
import { latin } from '@bbc/gel-foundations/scripts';

const Accept = (
  <button onClick={() => {}} type="button">
    OK
  </button>
);

const Reject = (
  <a href="https://www.bbc.co.uk/usingthebbc/your-data-matters">
    Find out what&apos;s changed
  </a>
);

const Text = (
  <ConsentBannerText dir="ltr" script={latin} service="news">
    This is some text with <a href="https://www.bbc.com/news">a link</a> inside
    the consent banner. We have made some important changes to our Privacy and
    Cookie Policy.
  </ConsentBannerText>
);

const props = {
  dir: 'ltr',
  title: 'We have updated our Privacy and Cookies Policy',
  text: Text,
  accept: Accept,
  reject: Reject,
  id: null,
  hidden: false,
  script: latin,
  service: 'news',
};

<ConsentBanner {...props} />;

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-consent-banner 共发布 99 个版本,首次发布于 2019/06/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.5.15latest2022/03/304 年前
5.5.142022/03/294 年前
5.5.132022/01/064 年前
5.5.122021/10/065 年前
5.5.112021/09/305 年前
5.5.102021/09/225 年前

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

关于 @bbc/psammead-consent-banner 的常见问题

@bbc/psammead-consent-banner 是什么?

React styled components for the Consent Banner

如何安装 @bbc/psammead-consent-banner?

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

@bbc/psammead-consent-banner 支持 TypeScript 吗?

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

@bbc/psammead-consent-banner 支持 ESM 还是 CommonJS?

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

@bbc/psammead-consent-banner 可以商用吗?

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

@bbc/psammead-consent-banner 的下载量有多少?

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

@bbc/psammead-consent-banner 还在维护吗?

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