@contentful/f36-components

中文文档
6.30.0发布于 2026/11/04MITTypeScriptESM + CJS近 30 天下载 153.9万

Contentful UI Component Library

原始使用文档
文档目录15 节
  1. Table of contents
  2. Installing package
  3. Usage
  4. Import desired component into your project
  5. Development
  6. Storybook
  7. Example component directory structure
  8. Code Style Guide
  9. Component principles
  10. Adding documentation for component
  11. Testing
  12. Run tests
  13. Building
  14. Create a build of the library
  15. Commits

Forma 36 React Components

A React component library for the Forma 36 design system created by Contentful.

Table of contents

Installing package

yarn add @contentful/f36-components

Or

npm install @contentful/f36-components

Usage

Import desired component into your project

import { Button } from '@contentful/f36-components';

Development

For local development, in the root of the repo run pnpm install to install all dependencies and then pnpm build to build all packages. This package depends on several other Forma 36 packages so you will need to build all of them.

Storybook

We use Storybook to create a development environment for our component library. To start it locally run:

pnpm storybook

When creating new component, before you start, please have a look at our contribution model for Forma 36.

Example component directory structure

A component's directory should resemble the following:

/my-component
  /examples
  /src
    index.ts // A file for exporting your component
    MyComponent.tsx  // Your React component
    MyComponent.test.tsx // Component tests
    MyComponent.styles.ts // Component styles
  /stories
    # stories for storybook of each component inside the package
  README.mdx
  package.json

For more detailes you can have a look in document that describes folder structure in details.

If you use pnpm generate in the root of the repo, this structure will be created automatically for you

Code Style Guide

Our code style guide

Component principles

We follow a number of principles when creating our components:

  1. A component is responsible for only its internal spacing

Component should only be responsible for its own internal spacing - never external spacing. This means that we're flexible in where our components can be used without having to override margins. The only outlier from this rule are typography components - they can manage their own margins. To handle margins and layout you can use our core components, like:

Adding documentation for component

We would like to make sure that every component contains a README file with recommendations and guidelines. Make sure that your documentation for the component contains following parts:

  1. A short summary of the component.
  2. Import - provide example how to import component.
  3. Examples - try to add couple of examples, both basic and more advanced, where component is used in the context with other components.
  4. Props (API reference) - Overview of properties
  5. Content guideliness - try to describe in best practices around content for your component
  6. Accessibility - If possible, we strongly recommend providing accessibility guidelines.

Testing

We are using Vitest and Testing Library to test our components.

Tests are kept next to their components and use the .test.js file extension.

Run tests

pnpm test

It is recommended to run tests in development with the optional --watch flag.

pnpm test:watch

Building

We are using tsdown and esbuild together with Microbundle to build our component library.

Each component builds to its own dist directory with:

  • index.d.ts – TypeScript type declaration file
  • index.js – CJS (CommonJS)
  • index.modern.mjs – Modern output (work in all modern browsers)
  • index.module.js – legacy ESM (ES Modules) output (for bundlers)
  • index.umd.js – legacy UMD (Universal Module Definition) output (for Node & CDN use)

Create a build of the library

pnpm build

Commits

This project uses the Angular JS Commit Message Conventions, via semantic-release. See the semantic-release Default Commit Message Format section for more details.

You can commit the changes by running

pnpm commit

版本与发布记录

@contentful/f36-components 共发布 566 个版本,首次发布于 2021/03/05;过去 12 个月发布了 68 个版本。

版本发布日期距今
6.30.0latest2026/11/046 天前
6.29.02026/10/2912 天前
6.28.12026/10/2912 天前
6.28.02026/10/2219 天前
6.27.12026/10/1625 天前
6.27.02026/10/1427 天前

其他发布通道:next-v4 → 4.0.1-next-v4-10931.2481,canary → 4.0.1-beta.2483,beta → 4.11.0-beta.0,alpha → 6.0.0-alpha.20。

关于 @contentful/f36-components 的常见问题

@contentful/f36-components 是什么?

Contentful UI Component Library

如何安装 @contentful/f36-components?

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

@contentful/f36-components 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@contentful/f36-components 支持 ESM 还是 CommonJS?

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

@contentful/f36-components 可以商用吗?

@contentful/f36-components 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@contentful/f36-components 的下载量有多少?

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

@contentful/f36-components 还在维护吗?

最新版本 6.30.0 发布于 2026/11/04(6 天前);至今共发布 566 个版本,其中过去 12 个月发布了 68 个;首次发布于 2021/03/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。