All Projects → marc-rutkowski → storybook-addon-props

marc-rutkowski / storybook-addon-props

Licence: other
React Storybook Addon to show component properties and stories into panels

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to storybook-addon-props

Profilinggo
A quick tour (or reminder) of Go performance tools
Stars: ✭ 219 (+895.45%)
Mutual labels:  tooling
swift-watch
Watches over your Swift project's source
Stars: ✭ 43 (+95.45%)
Mutual labels:  tooling
react-module-boilerplate
Sample React presentational components package.
Stars: ✭ 16 (-27.27%)
Mutual labels:  storybook
Bootboot
Dualboot your Ruby app made easy
Stars: ✭ 239 (+986.36%)
Mutual labels:  tooling
pattern-library
AXA CH UI component library. Please share, comment, create issues and work with us!
Stars: ✭ 103 (+368.18%)
Mutual labels:  storybook
assistant
🤖 Bring your Figma design & development pipeline to the next level - with design to code, in-design-content-management, component management, tools for faster design
Stars: ✭ 451 (+1950%)
Mutual labels:  storybook
Nix Index
Quickly locate nix packages with specific files
Stars: ✭ 197 (+795.45%)
Mutual labels:  tooling
nextjs-ts-antd-redux-storybook-starter
🏃🏼 Next.js + TypeScript + Ant Design + Redux Toolkit + Redux Saga + Styled Components + Jest + Storybook 企业级项目脚手架模板
Stars: ✭ 78 (+254.55%)
Mutual labels:  storybook
storybook-preset-craco
Craco preset for Storybook
Stars: ✭ 34 (+54.55%)
Mutual labels:  storybook
react-learning-resources
A curated list of resources to learn React and related web technologies as fast as possible.
Stars: ✭ 65 (+195.45%)
Mutual labels:  storybook
Go Tooling Workshop
A workshop covering all the tools gophers use in their day to day life
Stars: ✭ 2,683 (+12095.45%)
Mutual labels:  tooling
storybook-xstate-addon
A storybook addon to assist with writing stories that rely on xstate
Stars: ✭ 48 (+118.18%)
Mutual labels:  storybook
react-bones
💀 Dead simple content loading components for React and React-Native. 💀
Stars: ✭ 42 (+90.91%)
Mutual labels:  storybook
Orchard
A fertile ground for Clojure tooling
Stars: ✭ 219 (+895.45%)
Mutual labels:  tooling
eslint-config-galex
hopefully the last eslint config you'll ever need - customizable & modern best practices for JS, TS, Node, React, Remix, Next, Jest, testing-library & storybook
Stars: ✭ 166 (+654.55%)
Mutual labels:  storybook
Js Refactor
JS Refactoring tool for Visual Studio Code
Stars: ✭ 195 (+786.36%)
Mutual labels:  tooling
vue-cli-template-library
Template for developing open-source vue.js libraries with Rollup + Jest + Babel + Storybook + TravisCI + SemanticRelease
Stars: ✭ 61 (+177.27%)
Mutual labels:  storybook
amazin
A MERN-stack app for eCommerce platform, Webshop, Web Store. Storybook: https://www.amazin.one/ Alternative: https://ntrix.github.io/amazin-story
Stars: ✭ 27 (+22.73%)
Mutual labels:  storybook
datahub
Datahub v2
Stars: ✭ 16 (-27.27%)
Mutual labels:  storybook
storybook-chapters
React Storybook Addon for Hierarchical Substories (Chapters)
Stars: ✭ 46 (+109.09%)
Mutual labels:  react-storybook

React Storybook Props addon

Display Props and Story documentation/source into Storybook UI panels.

Status

This repo is intented to be deprecated when this PR will be finally merged. But if you want to try it...

Purpose

The addon provides two new panels for the Storybook UI.

snap1

  • Story. Shows story description and source code.

snap2

Visible information are similar to Storybook Info addon, but doesn't alter the output of the story into the preview area. This provides a better usage for the Storyshots feature because snapshots will only contains the rendered stories.

Install

npm i storybook-addon-props --save-dev

or (using Yarn) :

yarn add storybook-addon-props --dev

Usage

Add a custom .storybook/.babelrc file

{
  "presets": ["env", "react", "stage-0"],
  "plugins": [
    [
      "babel-plugin-react-docgen",
      {
        "DOC_GEN_COLLECTION_NAME": "STORYBOOK_REACT_CLASSES",
        "resolver": "findAllExportedComponentDefinitions"
      }
    ]
  ]
}

The custom balel config is used to set a different resolver for the babel-plugin-react-docgen. This is necessary to avoid warnings about files with multiple React component exports.

Register addon into the .storybook/addons.js file (view doc)

import '@storybook/addons';
import 'storybook-addon-props/register';

Set addon into the .storybook/config.js file

import { configure, setAddon } from '@storybook/react';
import addWithDoc from 'storybook-addon-props';

setAddon(addWithDoc);

function loadStories() {
  // ...
}
configure(loadStories, module);

Write stories

Create your stories using the new addWithDoc function provided by this addon.

import Button from '../Button';

storiesOf('Button', module)
.addWithDoc('with label', Button,
    'It should render a button with a label',
    () => <Button onClick={action('clicked')}>Hello Button</Button>
));

For another example, have a look at this file.

addWithDoc expects the following parameters:

addWithDoc(storyName, component, description, storyFn)

Parameter Description
storyName Name of the story (appears into the Left Panel)
component The main component of the story
description A string displayed into the Story panel (Markdown supported here!)
storyFn The story rendering function

Options

Alternatively you can configure the addWithDoc function using the configureDoc named export.

This function allows you to pass an options object.

At this time only two options are supported to enable automatic links insertion on a issues tracker when a issue ID pattern is detected into the description field of a story.

Supported options are :

Parameter Description Default
trackerUrl The tracker URL template string. Use %ID% to insert the issue ID.
pattern The issue ID regexp pattern. #([0-9]+)

Pass options into .storybook/config.js like this:

import { configureDoc } from 'storybook-addon-props'

const addWithDoc = configureDoc({
  trackerUrl: 'https://github.com/marc-rutkowski/storybook-addon-props/issues/%ID%',
});

setAddon(addWithDoc);

Then into a story you can reference an issue like this:

storiesOf('Button', module)
.addWithDoc('with label', Button,
  'It should render a button with a label (sample link to tracker #3)',
  () => <Button onClick={action('clicked')}>Hello Button</Button>
)

And a link to issue #3 will be added into the story panel:

snap4

Flow type support

This addon support flow type annotations extracted by react-docgen.

For the following code :

export type User = {
  id: number,
  name: string,
  country?: string,
};

type Props = {
  /** User info */
  user: User,
  /** Some number */
  num: number,
  /** Optional property */
  option?: string,
  /** Optional callback */
  func?: (value: string) => void,
  /** Optional array of users */
  friends?: Array<User>
};

/** Render user details */
class UserDetails extends React.Component {
  props: Props;

  static defaultProps = {
    option: 'foo',
  };
  
  render() {
  }
}

the Props panel will show something like this:

snap3

View complete example: component code and story.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].