@bbc/psammead-image-placeholder

中文文档
3.4.15发布于 2022/04/13Apache-2.0ESM + CJS近 30 天下载 6587

Provides a 'BBC' image placeholder

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

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

Description

The psammead-image-placeholder component has two placeholders available. The default is a div with a base-64 encoded SVG background image that depicts the BBC logo. The component accepts a ratio as a prop. In the Psammead component library, Image Placeholder is used within the psammead-figure component.

The alternative is an AMP supported placeholder which uses the same base-64 encoded SVG but as multiple amp-img components, which are loaded based on the current screen size. The component adheres to the parent amp-img size and functions as both a fallback and placeholder. See the AMP documentation on fallbacks and placeholders.

When to use this component

Psammead Image Placeholder is designed to appear as a temporary stand-in to be replaced by an actual image, for example in the case of lazy loading.

Installation

npm install @bbc/psammead-image-placeholder

Usage

ImagePlaceholder

The ImagePlaceholder component is expected to contain an image as a child element.

import ImagePlaceholder from '@bbc/psammead-image-placeholder';

const WrapperComponent = ({
  ratio,
}) => (
  <ImagePlaceholder ratio={ratio}>
    <img src="http://some-image.url">
  </ImagePlaceholder>
);

ImagePlaceholderAmp

The ImagePlaceholderAmp component is expected to be used as a child element of an amp-img component. Information about amp-img can be found on the AMP documentation website

import ImagePlaceholderAmp from '@bbc/psammead-image-placeholder';

const WrapperComponent = () => (
  <amp-img
    src="http://some-image.url"
    width="645px"
    height="128px"
  >
    <ImagePlaceholderAmp />
  </amp-img>
);

Props

ImagePlaceholder

ArgumentTypeRequiredDefaultExample
RatioNumber, ratio between height and widthYesN/A65.625
darkModeBool, true (dark) or false (normal)Nofalsefalse
forwardStyleStyling object that applies additional stylingNonull{ background: 'none' }

ImagePlaceholderAmp

ArgumentTypeRequiredDefaultExample
darkModeBool, true (dark) or false (normal)Nofalsefalse

Accessibility notes

As a div with a background image or as an amp-img for it's AMP counterpart, Psammead Image Placeholder is a presentational element without semantic meaning. As such it does not need to meet colour contrast requirements.

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

版本发布日期距今
3.4.15latest2022/04/134 年前
3.4.142022/04/084 年前
3.4.132022/03/304 年前
3.4.122022/02/104 年前
3.4.112022/01/064 年前
3.4.102021/11/304 年前

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

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

@bbc/psammead-image-placeholder 是什么?

Provides a 'BBC' image placeholder

如何安装 @bbc/psammead-image-placeholder?

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

@bbc/psammead-image-placeholder 支持 TypeScript 吗?

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

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

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

@bbc/psammead-image-placeholder 可以商用吗?

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

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

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

@bbc/psammead-image-placeholder 还在维护吗?

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