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

v1.0.0

Published

Storybook addon which helps you write stories faster

Downloads

6

Readme

Motivation

Storybook Addon Ghostwriter allows you to write your Storybook stories faster. Your codebase changes continuously and you don't want to update your Storybook stories every time your components change. Ghostwriter extracts your components’ PropTypes / Flow types and allows you to edit React props dynamically using the Storybook UI. Your components get documented automatically by providing a static overview of the available props. Ghostwriter generates code snippets for both your component and your Storybook stories, allowing you to ship new components faster.

Advantages

  • Write Storybook stories faster
  • Less maintenance
  • Dynamic component prop generation
  • Works with High Order Components
  • Component documentation

Installation

Please make sure you have the following peer dependencies installed:

  • babel-plugin-react-docgen
  • @storybook/addon-actions
  • @storybook/addon-info
  • @storybook/addon-knobs
  • @storybook/addons
  • lodash
  • react

Add Ghostwriter and its peer dependencies as a devDependency to your project using NPM:

npm install --save-dev storybook-addon-ghostwriter
# Install peer dependencies
npm install --save-dev babel-plugin-react-docgen @storybook/addon-actions @storybook/addon-info @storybook/addon-info @storybook/addons lodash @storybook/addon-knobs

Or, if you prefer Yarn:

yarn add --dev storybook-addon-ghostwriter
# Install peer dependencies
yarn add --dev babel-plugin-react-docgen @storybook/addon-actions @storybook/addon-info @storybook/addon-info @storybook/addons lodash @storybook/addon-knobs

Add the following line to your .babelrc file:

{
  "plugins": [
    [
      "react-docgen",
      {
        "resolver": "findAllComponentDefinitions"
      }
    ]
  ]
}

Configure Ghostwriter as an addon by adding it to addons.js file (located in the Storybook config directory):

// .storybook/addons.js
import 'storybook-addon-ghostwriter/register';

Writing stories

Now, write your stories with Ghostwriter.

import React from 'react';
import { storiesOf } from '@storybook/react';

// Story components
import ghostwriter from 'storybook-addon-ghostwriter';

// This is an example component.
import PropTypes from 'prop-types';

export default class ExampleComponent extends React.Component {
  render() {
    const { className, propName, children } = this.props;
    return (
      <div className={className}>
        <strong>{propName}</strong> {children}
      </div>
    );
  }
}

ExampleComponent.propTypes = {
  className: PropTypes.string,
  propName: PropTypes.string.isRequired,
  children: PropTypes.element,
};

/**
 * Overwrite the default props This could be a knob form the knob addon.
 * see https://github.com/storybooks/storybook/tree/master/addons/knobs
 * It has to be function otherwise overwriting knobs won't work properly
 * e.g. prop: text('knob text', 'knob'),
 */
const getDefaultProps = () => ({ className: 'overwrite' });
const markdown = `# Markdown example`;

storiesOf('components', module)
  .addDecorator(
    ghostwriter({
      // Notice that we dont use angle brackets; '<' and '>'
      component: ExampleComponent,
      // This overwrites the knobs by docs
      componentProps: getDefaultProps,
      // Extra info in markdown
      markdown: markdown,
      /**
       * Sometimes there is a need for additionalContext.
       * This could be de case whenever a component needs an action from outside the prop scope.
       * For example a Modal that waits for a ref to be called.
       * <button onClick={()=> this.modalRef.open}>Open</button>
       * Then additionalContext is the perfect place. Most of the time you won't need it though
       * because knobs will be your friend.
       */
      additionalContext: <span>This is JSX</span>,
    }),
  )
  .add('ExampleComponent', () => {
    return (
      <div>
        <p>Put your component in context. Like:</p>
        <p>this is a component in the wild!</p>
        <div
          style={{
            border: '2px solid #000',
            padding: '40px',
            borderRadius: '4px',
            textAlign: 'center',
          }}>
          <ExampleComponent className="some-class-name" propName="make some context">
            Wow context
          </ExampleComponent>
        </div>
      </div>
    );
  });

Snippet for VSCode, Atom and Sublime-text

One of the goals of Ghostwriter is that it tries to optimize your SWT™️ (story write time). Therefore a snippet in your editor could help you out a lot. We made one for you with he fantastic snippet-generator by Pawel Grzybek. So if you use Atom, Sublime-text or VSCode be sure to check out the snippet

Contributing

Want to help us make Storybook Addon Ghostwriter better? We take pull requests.

Working at Mollie

Mollie is always looking for new talent to join our teams. We’re looking for inquisitive minds with good ideas and strong opinions, and, most importantly, who know how to ship great products. Want to join the future of payments? Check out our vacancies.

License

New BSD (Berkeley Software Distribution) License. Copyright 2013-2018, Mollie B.V.