@bbc/psammead-brand

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

Provides the BBC News logo (as SVG), nested a hardcoded link to https://www.bbc.co.uk/news

原始使用文档
文档目录11 节
  1. Description
  2. Exports
  3. Installation
  4. Props
  5. Usage
  6. When to use this component
  7. Accessibility notes
  8. Additional notes
  9. Contributing
  10. Code of Conduct
  11. License

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

Description

The Brand component provides the BBC service logo (as SVG), nested inside a styled link and div. The link is currently hardcoded to "https://www.bbc.co.uk/news".

Brand takes a product, svgHeight, minWidth, maxWidth, url, serviceLocalisedName, backgroundColour, logoColour and svg as props.

The product is passed to a VisuallyHiddenText component, nested inside Brand.

The serviceLocalisedName is an optional prop referring to the local name of a service eg Yoruba. It is also passed to VisuallyHiddenText inside the Brand component.

The svg prop must contain a group, viewbox values and a ratio, which is used within an svg element. Examples of the svg object can be found in @bbc/psammead-assets.

The minWidth and maxWidth values are required to allow the ability for the svg element to dynamically scale as the viewport becomes a very small size EG: feature phones.

The svgHeight value acts as a placeholder for the svg element meaning the overall banner height does not change with the dynamic scaling, also the height allows the contents of the svg element to remain vertically centred within the banner at all times.

The backgroundColour is the background colour and logoColour is the colour of the SVG and the underline when hovering/focusing on the brand.

The url value is the link that points to the frontpage of the service associated with the svg.

The scriptLink can be used to render ScriptLink component which is a link to the service variant.

Exports

/skip-link - Use the skip link component to help keyboard-only users skip to the main content on the page.

Installation

npm install @bbc/psammead-brand

Props

ArgumentTypeRequiredDefaultExample
productStringyesN/A'BBC News'
svgHeightNumberyesN/A24
minWidthNumberyesN/A240
maxWidthNumberyesN/A380
svgObjectyesN/A{ group: (<g fillrule="evenodd"><path d="M84.32" /></g>), viewbox: { height: 24, width: 167.95 }, ratio: 6.9979 }
backgroundColourStringyesN/A${C_POSTBOX} or relevant string hex code
logoColourStringyesN/A${C_WHITE} or relevant string hex code
urlStringnoN/Ahttps://www.bbc.co.uk/news
serviceLocalisedNameStringnoN/A'Yoruba'
borderTopBooleannofalsetrue
borderBottomBooleannofalsetrue
scriptLinkNodenonull<ScriptLink service='news' script={latin} href='https://www.bbc.com/serbian/lat'> Lat </ScriptLink>
skipLinkNodenonull<SkipLink service='news' script={latin} href='#content'> Skip to content </SkipLink>
linkIdStringnonull'brandLink'

Usage

The typical use-case of this component is at the top of pages in a header element. When this is done it is recommend that the component is wrapped in a banner role. However, a header with a banner role should only appear once on a page.

When using Brand in the header, you should ensure that borderBottom prop is set to true. Similarly, when using brand on the footer you should set borderTop to true. This ensures when in High Contrast Mode on PC and when the user changes colour preferences in FireFox that the top/bottom of the Brand component is visible.

ScriptLink component should be passed to scriptLink only when linking to a service variant.

import Brand from '@bbc/psammead-brand';
import SkipLink from '@bbc/psammead-brand/skip-link';
import { igbo } from '@bbc/psammead-assets/svgs';
import ScriptLink from '@bbc/psammead-script-link';
import { C_POSTBOX, C_WHITE } from '@bbc/psammead-styles/colours';
import { latin } from '@bbc/gel-foundations/scripts';

const scriptLink = (
  <ScriptLink
    service="news"
    script={latin}
    href="https://www.bbc.com/serbian/lat"
  >
    Lat
  </ScriptLink>
);

const skipLink = (
  <SkipLink service="news" script={latin} href="#content">
    Skip to content
  </SkipLink>
);

const Header = (product, serviceName) => (
  <header role="banner">
    <Brand
      product={product}
      serviceLocalisedName={serviceName}
      svgHeight={24}
      maxWidth={280}
      minWidth={180}
      svg={igbo}
      url="https://www.bbc.co.uk/news"
      backgroundColour={backgroundColour}
      logoColour={logoColour}
      borderBottom
      scriptLink={scriptLink}
      skipLink={skipLink}
    />
  </header>
);

When to use this component

The Brand component is designed to be used where a BBC logo is required as SVG. Brand is used in the BrandContainer, which consumes a service context it passes to the Brand.

Accessibility notes

  • Visually hidden text is provided (e.g. for screen reader users)
  • Brand is keyboard-accessible and provides hover and focus styles
  • The brand SVG has support for users with css disabled or high contrast mode enabled.

Additional notes

  • width: 100% is needed on both <a> and the <svg> to allow the brand to dynamically scale on the Firefox browser

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-brand 共发布 170 个版本,首次发布于 2018/12/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
7.3.18latest2022/03/304 年前
7.3.172022/03/294 年前
7.3.162022/01/064 年前
7.3.152021/11/174 年前
7.3.142021/11/164 年前
7.3.132021/11/025 年前

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

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

@bbc/psammead-brand 是什么?

Provides the BBC News logo (as SVG), nested a hardcoded link to https://www.bbc.co.uk/news

如何安装 @bbc/psammead-brand?

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

@bbc/psammead-brand 支持 TypeScript 吗?

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

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

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

@bbc/psammead-brand 可以商用吗?

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

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

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

@bbc/psammead-brand 还在维护吗?

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