Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@storybook/csf

ComponentDriven50mMIT0.1.13TypeScript support: included

Component Story Format (CSF) utilities

storybook, component story format, csf, stories

readme

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, WebComponents.dev, Components.studio, RedwoodJS, UXPin

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

CSF utilities

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

Install

yarn add @storybook/csf

API

See package source for function definitions and types:

  • storyNameFromExport(key) - Enhance export name (key) of the story. Implemented to have parity 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

changelog

v0.1.13 (Tue Dec 24 2024)

🐛 Bug Fix

  • fix: story ComponentAnnotations['subcomponents'] to correctly use its own type for subcomponents rather than attempt to inherit from the component #103 (@lburgess)

Authors: 2


v0.1.12 (Fri Nov 29 2024)

🐛 Bug Fix

Authors: 4


v0.1.11 (Tue Jul 02 2024)

🐛 Bug Fix

Authors: 1


v0.1.10 (Tue Jul 02 2024)

🐛 Bug Fix

  • Consolidate loader, play and render context and add a self referencing context property #98 (@kasperpeulen)
  • Add canvas prop to the context #99 (@kasperpeulen)

Authors: 1


v0.1.9 (Mon Jun 24 2024)

🐛 Bug Fix

Authors: 2


v0.1.8 (Mon Jun 03 2024)

🐛 Bug Fix

  • Add project initialGlobals & component/story globals, deprecate project globals #92 (@shilman)

Authors: 1


v0.1.7 (Mon May 06 2024)

🐛 Bug Fix

  • Fix the package name in the readme #81 (@stof)
  • Add utility for tag combination & negation #80 (@shilman)

Authors: 2


v0.1.6 (Tue Apr 30 2024)

🐛 Bug Fix

Authors: 1


v0.1.5 (Thu Apr 25 2024)

🐛 Bug Fix

  • chore: resolve eslint issues #87 (@Cherry)
  • fix: better handle readonly InputType options #85 (@Cherry)

Authors: 2


v0.1.4 (Fri Apr 12 2024)

🐛 Bug Fix

Authors: 1


v0.1.3 (Mon Mar 18 2024)

🐛 Bug Fix

Authors: 4


v0.1.2 (Wed Nov 22 2023)

🐛 Bug Fix

Authors: 2


v0.1.1 (Fri Jun 02 2023)

🐛 Bug Fix

Authors: 1


v0.1.0 (Mon Apr 03 2023)

🚀 Enhancement

🐛 Bug Fix

⚠️ Pushed to master

📝 Documentation

🔩 Dependency Updates

Authors: 12