@componentdriven/csf

中文文档
0.0.2-alpha.0发布于 2020/08/07MITTypeScriptCommonJS近 30 天下载 1.7万

Component Story Format (CSF) utilities

原始使用文档
文档目录9 节
  1. Why a standard format?
  2. The "Story" is the source of truth for a component.
  3. Component Story Format
  4. Who uses CSF?
  5. CSF utilities
  6. Install
  7. API
  8. Contributing
  9. run tests:

Component Story Format (CSF)

Why a standard format?

Components have risen to dominate the UI landscape. There are new component-oriented tools for development, testing, design, and prototyping. These tools engage in the creation and consumption of components and component examples (a.k.a. stories). But each tool has its own proprietary format because a simple, platform-agnostic way to express component examples doesn't yet exist.

The "Story" is the source of truth for a component.

A story is a code snippet that renders an example of a component in a specific state. Think about it like a "user story".

It uses the production code shipped to users, making it the most accurate representation of a component example. What's more, stories are expressed in the view layer you use to build your app.

Component Story Format

The Component Story Format is an open standard for component examples based on JavaScript ES6 modules. This enables interoperation between development, testing, and design tools.

export default { title: 'atoms/Button' };
export const text = () => <Button>Hello</Button>;
export const emoji = () => <Button>😀😎👍💯</Button>;

💎 Simple. Writing component "stories" is as easy as exporting ES6 functions using a clean, widely-used format.

🚚 Non-proprietary. CSF doesn't require any vendor-specific libraries. Component stories are easily consumed anywhere ES6 modules live, including your favourite testing tools like Jest and Cypress.

☝️ Declarative. The declarative syntax is isomorphic to higher-level formats like MDX, enabling clean, verifiable transformations.

🔥 Optimized. Component stories don't need any libraries other than your components. And because they're ES6 modules, they're even tree-shakeable!

Who uses CSF?

Tools: Storybook, UXPin & WebComponents.dev

Compatible with: Jest, Enzyme, Testing Library, Cypress, Mocha, etc.

CSF utilities

A minimal set of utility functions for dealing with Component Story Format (CSF).

Install

yarn add @componentdriven/csf

API

See package source for function definitions and types:

  • storyNameFromExport(key) - Enhance export name (key) of the story. Currently implemented with startCase.

  • isExportStory(key, { includeStories, excludeStories }) - Does a named export match CSF inclusion/exclusion options?

  • parseKind(kind, { rootSeparator, groupSeparator }) - Parse out the component/kind name from a path, using the given separator config.

  • sanitize(string) - Remove punctuation and illegal characters from a story ID.

  • toId(kind, name) - Generate a storybook ID from a component/kind and story name.

Contributing

If you have any suggestions, please open an issue or a PR.

All contributions are welcome!

run tests:

yarn test

版本与发布记录

@componentdriven/csf 共发布 1 个版本,首次发布于 2020/08/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.2-alpha.0latest2020/08/076 年前

关于 @componentdriven/csf 的常见问题

@componentdriven/csf 是什么?

Component Story Format (CSF) utilities

如何安装 @componentdriven/csf?

在项目目录运行 npm install @componentdriven/csf,或使用 pnpm add / yarn add / bun add。

@componentdriven/csf 支持 TypeScript 吗?

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

@componentdriven/csf 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@componentdriven/csf 可以商用吗?

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

@componentdriven/csf 的下载量有多少?

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

@componentdriven/csf 还在维护吗?

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