GithubHelp home page GithubHelp logo

doytsujin / storybook-filepath-chapters Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hadfieldn/storybook-filepath-chapters

0.0 1.0 0.0 1.18 MB

React Storybook loader that uses storybook-chapters to create hierarchical navigation that mirrors the filesystem

JavaScript 100.00%

storybook-filepath-chapters's Introduction

storybook-filepath-chapters

npm package Live demo

A simple loader for Storybook(source) that uses storybook-chapters to create a hierarchical navigation tree that mirrors your component filesystem.

Live Demo

Paths in the filesystem...

filesystem screenshot

...become branches in the navigational tree:

screenshot

Installation

npm install --save-dev storybook-filepath-chapters

Configuration

// stories.js

import { loadStorybook } from 'storybook-filepath-chapters';
const stories = require.context('../app/components', true, /.*stories((\.jsx?)|\/(index\.jsx?|.*?stories\.jsx?))$/i);
loadStorybook('Demo Components', stories);

IMPORTANT: In your stories, import storiesOf from storybook-filepath-chapters instead of @kadira/storybook:

// app/components/widgets/buttons/_stories.js

import React from 'react';
import { storiesOf } from 'storybook-filepath-chapters';
import Button1 from './Button1';
import Button2 from './Button2';

storiesOf('Buttons', module)
  .add('Button1', () => <Button1>Button 1</Button1>)
  .add('Button2', () => <Button2>Button 2</Button2>)
;
// app/components/widgets/labels/_stories.js

import React from 'react';
import { storiesOf } from 'storybook-filepath-chapters';
import Label1 from './Label1';
import Label2 from './Label2';

storiesOf('Labels', module)
  .add('Label1', () => <Label1>Label 1</Label1>)
  .add('Label2', () => <Label2>Label 2</Label2>)
;

The above example results in the following Storybook navigational tree:

  // File system:
  // app/components/widgets/butons/_stories.js
  // app/components/widgets/labels/_stories.js

  // Storybook
  Demo Components
    └──[widgets]
          ├──[buttons]
               ├──Button1
               └──Button2
          └──[labels]
                ├──Label1
                └──Label2

API

loadStorybook(rootName, requireContext, options);

Loads the stories matched by requireContext into a hierarchical navigation tree corresponding to their locations within the file system.

  • rootName: Story name to show at the root of the navigational tree.
  • requireContext: A webpack require context that identifies the files to be searched for stories. (See the example above.)
  • options: (optional) { wrapStories: true } will wrap each call to storiesOf in a new chapter. By default, all stories in a given folder are wrapped inside one chapter.
storiesOf(storyName, module)

Drop-in replacement for the storiesOf function provided in @kadira/storybook. Creates a link to the story in a chapter corresponding to its path in the filesystem.

storiesOf.skip(storyName, module)

Causes the story to be omitted from the navigation tree.

storiesOf.dev(storyName, module)

Renders the story into the root navigation pane. This can be handy during development in order to make a component immediately accessible, as storybook-chapters does not currently retain your navigation selection when the page is refreshed.

Special Thanks

to Oleg Proskurin for a brilliant solution for enabling hierarchical navigation in React Storybook.

storybook-filepath-chapters's People

Contributors

hadfieldn avatar ndelangen avatar

Watchers

 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.