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-addon-deps

v2.2.0

Published

A storybook addon to display component dependencies

Downloads

4,712

Readme

storybook-addon-deps

A storybook addon to add a dependencies tree exporer tab.

Quick start

1. Install

npm i -D storybook-addon-deps

2. Add preset: .storybook/main.js

module.exports = {
  presets: ['storybook-addon-deps/preset', ...]
...
}  

3. Configure DocsPage .storybook/preview.js (was .storybook/config.js)

import { DocsPage } from 'storybook-addon-deps/blocks';

addParameters({
  docs: { page: DocsPage },
  dependencies: { withStoriesOnly: true, hideEmpty: true }
});

Advanced setup and usage

DocsPage demo

grommet-controls

Usage

In your storybook preview.js(or config.js), define some global parameters to exchange the data collected by the storybook-dep-webpack-plugin

import { addParameters } from '@storybook/{yourframework}';

addParameters({
 dependencies: {
    //display only dependencies/dependents that have a story in storybook
    //by default this is false
    withStoriesOnly: true,

    //completely hide a dependency/dependents block if it has no elements
    //by default this is false
    hideEmpty: true,

    //custom match function to find matching component in case duplicate 
    //component names. chooses first match if not configured
    match: (matchingComponents, storyFilename) => matchingComponents?.[0][0]
  }
});

A. Add a documentation block to your DocsPage (optional)

DocsPage is the zero-config default documentation that all stories get out of the box. You can add a Dependencies block to any level to your storybook

Globally (preview.js/config.js)

import { DocsPage } from 'storybook-addon-deps/blocks/DocsPage';
addParameters({ docs: { page: DocsPage } });

Component-level (Button.stories.js)

import { Button } from './Button';
import { DocsPage } from 'storybook-addon-deps/blocks/DocsPage';
export default {
  title: 'Demo/Button',
  component: Button,
  parameters: { docs: { page: DocsPage } },
};

Story-level (Button.stories.js)

import { Button } from './Button';
import { DocsPage } from 'storybook-addon-deps/blocks/DocsPage';
// export default { ... }
export const basic => () => <Button>Basic</Button>
basic.story = {
  parameters: { docs: { page: DocsPage } }
}

B. Add dependencies and dependents doc blocks to mdx stories (optional)

Button.stories.mdx

import {
  Story,
  Canvas,
  ArgsTable,
  Description,
  Meta,
} from '@storybook/addon-docs/blocks';
import { Button } from '@storybook/design-system/dist/components/Button';
import { DependenciesTable, Dependencies, Dependents } from 'storybook-addon-deps/blocks';

<Meta
  title="Design System|Button"
  component={Button}
/>

# Two ways to display blocks - combined into a single table, or separated into two tables

## 1. DependenciesTable - combined dependencies and dependents into one
<DependenciesTable titleDependencies='Dependencies' titleDependents='Dependents' of={Button} />

## 2. Dependencies and Dependents tables

<Dependencies of={Button} />

<Dependents of={Button} />

excludeFn

You can exclude specific modules from the dependencies tables by setting

excludeFn: (module: IDependency) => boolean;;

  <Dependencies of={Button} excludeFn={module => module.name === 'babel'} />

C. Add a dependencies explorer tab to storybookjs (optional)

Use the preset-explorer preset

module.exports = {
  presets: ['storybook-addon-deps/preset-explorer', ...]
...
}  

Project analysis

The charts used are Google Charts and all their properties are applicable. Detailed information on configuration options is available from Google documentation, for example Pie Chart options.

import { Meta } from '@storybook/addon-docs/blocks';
import { ChartComponentUsage, ChartStoriesPerComponent } from 'storybook-addon-deps/blocks';
  
<Meta title="About|Dashboard" />
<ChartStoriesPerComponent />
<ChartComponentUsage />

Stories per component

import { Heading } from '@storybook/addon-docs/blocks';
import { ChartStoriesPerComponent } from 'storybook-addon-deps/blocks';
<Heading>Stories per component</Heading>
<ChartStoriesPerComponent
  height='500px'
  options={{
    sliceVisibilityThreshold: 0.04,
    pieSliceText: 'value',
    s3D: true,
    pieHole: 0.7,
  }}
/>

Components by usage

Displays how many times each component is used by other components.

import { Heading } from '@storybook/addon-docs/blocks';
import { ChartStoriesPerComponent } from 'storybook-addon-deps/blocks';
<Heading>Components usage</Heading>
<ChartComponentUsage
  height='500px'
  options={{
    minColor: '#009688',
    midColor: '#f7f7f7',
    maxColor: '#ee8100',
  }}
/>

Other frameworks

web-components

web components

angular

angular

vue

vue

Options

a set of options can be passed down to the storybook-dep-webpack-plugin

filter - a RegExp or function to select the stories. example:

module.exports = {
  presets: [
    { 
      name: 'storybook-addon-deps/preset-explorer', 
      options: {
        filter: (resource) => {
          return /\.(stories|story)\.[tj]sx?$/.test(resource) && resource.indexOf("Avatar") > -1;
        }
      }
    }
  ]

exclude - a RegExp for the modules to exclude. example:

module.exports = {
  presets: [
    { 
      name: 'storybook-addon-deps/preset-explorer', 
      options: {
        //by default @storybook modules are also excluded
        exclude: /^@babel/,
      }
    }
  ]

maxLevels - How many levels deep to follow the dependencies. example:

module.exports = {
  presets: [
    { 
      name: 'storybook-addon-deps/preset-explorer', 
      options: {
        maxLevels: 10,
      }
    }
  ]

pickProperties - An array of the props to pick from the module webpack data. example:

module.exports = {
  presets: [
    { 
      name: 'storybook-addon-deps/preset-explorer', 
      options: {
        pickProperties: ['id', 'name', 'request'],
      }
    }
  ]

pickModuleProperties - An array of the props to pick from the module.module webpack data. example:

module.exports = {
  presets: [
    { 
      name: 'storybook-addon-deps/preset-explorer', 
      options: {
        pickModuleProperties: [],
      }
    }
  ]