npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

storybook-filepath-chapters

v1.4.0

Published

React Storybook navigation using storybook-chapters and the filesystem

Downloads

12

Readme

storybook-filepath-chapters

npm package Live demo

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

Live Demo

Paths in the filesystem...

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