Coder Social home page Coder Social logo

jedhomenick / csf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from componentdriven/csf

0.0 0.0 0.0 923 KB

Component Story Format is an open standard for UI component examples based on JavaScript ES6 modules.

Home Page: https://www.componentdriven.org/

License: MIT License

TypeScript 100.00%

csf's Introduction

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 @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

csf's People

Contributors

shilman avatar tmeasday avatar kasperpeulen avatar ghengeveld avatar atanasster avatar ndelangen avatar dependabot[bot] avatar wkich avatar winkervsbecks avatar domyen avatar georges-gomes avatar unematiii avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.