@bbc/psammead-styles

中文文档
8.1.1发布于 2022/03/30Apache-2.0零依赖近 30 天下载 3.4万

A collection of string constants for use in CSS, containing non-GEL styling details that are bespoke to specific BBC services and products.

原始使用文档
文档目录9 节
  1. Exports
  2. Installation
  3. Usage
  4. font-styles
  5. detection
  6. global-styles
  7. Contributing
  8. Code of Conduct
  9. License

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

This package provides a collection of string constants for use in CSS, containing non-GEL styling details that are bespoke to specific BBC services and products

Exports

/colours - Project-defined colours that will be required by multiple Psammead components or themes. These colours are not defined by GEL. /detection - Project-defined CSS feature detection statements. /fonts - Project-defined browser behaviours for the Reith font. The primary reason these are not considered GEL-defined (and not part of @bbc/gel-foundations) is due to the custom weighting and loading definitions. More details on the font-faces defined in this package are available here.. Also includes declarations for all World Service fonts.

/font-styles provides functions that can be used to get font-styles for different services. If a font-style is not available all the functions will fallback to regular sans font-style of the service.

/global-styles Provides project-defined global styles defined using styled-normalize and box sizing.

Installation

npm install @bbc/psammead-styles --save

Usage

import { C_POSTBOX } from '@bbc/psammead-styles/colours';

import { F_REITH_SANS_REGULAR, F_REITH_SANS_ITALIC } from '@bbc/psammead-styles/fonts';

By importing a subset of the font-face definitions defined in this package, you can prioritise only the most commonly needed fonts for your project, with browser styling stepping in for less common scenarios. For example, in these examples, which import custom fonts for only Reith Sans Regular and Italic, any bold styling would be "faked" by the browser.

You will likely want to use these font-face definitions in tandem with the GEL-defined font stack definitions, which are available in @bbc/gel-foundations:

import { GEL_FF_REITH_SANS } from '@bbc/gel-foundations/typography';

These values can then be used directly within CSS declarations in code. Note that font-faces should only be declared once on a page:

import { css } from 'styled-components';

// These should only be included on your page once.
const someGlobalCSS = css`
  ${F_REITH_SANS_REGULAR};
  ${F_REITH_SANS_ITALIC};
`;

const SomeStyledComponent = css`
  background-color: ${C_POSTBOX};
  font-family: ${GEL_FF_REITH_SANS};
`;

font-styles

In case you are using embedded fonts, you need to make sure you have loaded your fonts first before using the functions. If the embedded font is not loaded, the fallback font will be applied

import { getSansRegular } from '@bbc/psammead-styles/font-styles';

const fontStyle = getSansRegular('news');

const SomeStyledComponent = css`
  ${fontStyle};
  /* more css styles */
`;

detection

We have defined custom feature detection statements (using CSS @supports syntax) to provide workarounds for browser-specific bugs.

  • grid: We experienced issues using @supports (display:grid) from browsers with buggy CSS Grid implementations, and found that detecting on @supports (grid-template-columns: fit-content(200px)) gave more consistent detection.
import { grid } from '@bbc/psammead-styles/detection';

const someGridUsingComponent = css`
  @supports (${grid}) {
    display: grid;
    /* grid CSS */
  }

  /* fallback CSS */
`;

global-styles

We export a global styles component which uses styled-normalize and defines css rules for box-sizing. This component accepts an optional fonts prop which is an array of font styles to be applied in the global styles.

import GlobalStyles from '@bbc/psammead-styles/global-styles';
import {
  F_REITH_SANS_REGULAR,
  F_REITH_SERIF_MEDIUM,
} from '@bbc/psammead-styles/fonts';

<GlobalStyles fonts={[
      F_REITH_SANS_REGULAR,
      F_REITH_SERIF_MEDIUM,
    ]}
/>

Contributing

When adding a new export to this utility package the export tests also need to be updated. When removing an exisiting export from this utility package the export tests need to be updated and the package version requires a major change (EG: 1.2.1 -> 2.0.0) as this would be considered a breaking change due to functionality being removed.

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

版本发布日期距今
8.1.1latest2022/03/304 年前
8.1.02022/03/294 年前
8.0.22022/01/064 年前
8.0.12021/10/065 年前
8.0.02021/09/305 年前
7.6.32021/09/225 年前

其他发布通道:alpha → 0.1.5-alpha-1。

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

@bbc/psammead-styles 是什么?

A collection of string constants for use in CSS, containing non-GEL styling details that are bespoke to specific BBC services and products.

如何安装 @bbc/psammead-styles?

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

@bbc/psammead-styles 支持 TypeScript 吗?

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

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

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

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

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

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

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