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 🙏

© 2025 – Pkg Stats / Ryan Hefner

storybook-addon-export-to-codesandbox

v0.8.4

Published

Allows to export Story code to CodeSandbox

Downloads

4,255

Readme

Export to CodeSandbox

This Storybook plugin adds "Open in CodeSandbox" button to each story displayed in Docs mode.

Installation

  1. Install the plugin npm i storybook-addon-export-to-codesandbox.
  2. Register the plugin in .storybook/main.js - Add 'storybook-addon-export-to-codesandbox' to the list of addons.
// .storybook/main.js

module.exports = {
  // ...
  addons: ['storybook-addon-export-to-codesandbox' /* ... */],
};
  1. Use .storybook/babel.plugin.js in your Storybook.
  2. Define required parameters in your .storybook/preview.js:

⚠️ Make sure all necessary dependencies are included in the requiredDependencies config.

export const parameters = {
  exportToCodeSandbox: {
    // Dependencies that should be included with every story
    requiredDependencies: {
      react: 'latest',
      'react-dom': 'latest', // for React
      'react-scripts': 'latest', // necessary when using typescript in CodeSandbox
    },
    // Dependencies that should be included in the story if it exists in the code
    optionalDependencies: {
      '@fluentui/react-icons': '^9.0.0-beta',
    },
    // Content of index.tsx in CodeSandbox
    indexTsx: dedent`
            import * as ReactDOM from 'react-dom';
            import { FluentProvider, webLightTheme } from '@fluentui/react-components';
            import { STORY_NAME as Example } from './example';
            //
            // You can edit this example in "example.tsx".
            //
            ReactDOM.render(
                <FluentProvider theme={webLightTheme}>
                    <Example />
                </FluentProvider>,
                document.getElementById('root'),
            );`,
  },
};

Recommended story setup

Each story should be put into its own file with a .stories.tsx extension. This file should not contain a default export, only a single named export, which is the story. All story files should then be re-exported from a file .stories.tsx with a default export. See RFC: Authoring storybook stories for more details and examples.

This practice is recommended so that the "Open in CodeSandbox" button would export a single story.

Dependency replacement with Babel plugin

Configure dependency replacement

It's possible to further configure dependency replacement using babel plugin options. By default only dependencies that are declared in the babel plugin options will be replaced, any other dependencies will remain as is.

By default all dependencies will be replaced with @fluentui/react-components

// main.js
module.exports = {
  stories: [],
  addons: [],
  webpackFinal: config => {
    if (config.module && config.module.rules) {
      config.module.rules.unshift({
        test: /\.stories\.tsx$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            plugins: [
              [
                require('storybook-addon-export-to-codesandbox').babelPlugin,
                {
                  '@fluentui/react-button': { replace: '@fluentui/react-components' },
                  // imports of @fluentui/react-unstable-component will be replaced with @fluentui/react-components/unstable
                  '@fluentui/react-unstable-component': { replace: '@fluentui/react-components/unstable'}
                }
              ]
            ],
          },
        },
      });
    }
};

Relative imports

This step runs before any other dependency replacement

When the addon encounters relative imports in a story, the package name of the closest package.json in the file tree will be used.

{
  "name": "@fluentui/react-button",
  "version": "9.0.0-rc.11"
}
// Before
import { Button } from '../index';

// After
import { Button } from '@fluentui/react-button';