All Projects β†’ storybookjs β†’ Addon Jsx

storybookjs / Addon Jsx

Licence: mit
This Storybook addon show you the JSX / template of the story

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Addon Jsx

storybook-addon-headless
A Storybook addon to preview content from a headless CMS in components
Stars: ✭ 23 (-89%)
Mutual labels:  addon, storybook
Storycap
A Storybook Addon, Save the screenshot image of your stories πŸ“· via puppeteer.
Stars: ✭ 451 (+115.79%)
Mutual labels:  addon, storybook
storybook-styled-components
No description or website provided.
Stars: ✭ 76 (-63.64%)
Mutual labels:  addon, storybook
storybook-addon-next
A no config Storybook addon that makes Next.js features just work in Storybook
Stars: ✭ 184 (-11.96%)
Mutual labels:  addon, storybook
Storybook Addon
Develop themable components with Emotion/Styled Components/Material-UI with help of Storybook & React Theming
Stars: ✭ 122 (-41.63%)
Mutual labels:  addon, storybook
storybook-addon-mock
This addon allows you to mock fetch or XMLHttpRequest in the storybook.
Stars: ✭ 67 (-67.94%)
Mutual labels:  addon, storybook
react-enterprise-starter-kit
Highly Scalable Awesome React Starter Kit for an enterprise application with a very easy maintainable codebase. πŸ”₯
Stars: ✭ 55 (-73.68%)
Mutual labels:  jsx, storybook
msw-storybook-addon
Mock API requests in Storybook with Mock Service Worker.
Stars: ✭ 168 (-19.62%)
Mutual labels:  addon, storybook
Storybook Addon Preview
Storybook Addon Preview can show user selected knobs in various framework code in Storybook
Stars: ✭ 43 (-79.43%)
Mutual labels:  addon, storybook
Storybook Addon A11y
REPO/PACKAGE MOVED - Storybook addon to help, improving accessibility within you're react components.
Stars: ✭ 37 (-82.3%)
Mutual labels:  addon, storybook
storybook-xstate-addon
A storybook addon to assist with writing stories that rely on xstate
Stars: ✭ 48 (-77.03%)
Mutual labels:  addon, storybook
Storybook Addon Styled Component Theme
storybook addon
Stars: ✭ 168 (-19.62%)
Mutual labels:  addon, storybook
Addon Smart Knobs
🧠 This Storybook plugin uses @storybook/addon-knobs but creates the knobs automatically based on PropTypes.
Stars: ✭ 215 (+2.87%)
Mutual labels:  addon, storybook
create-material-ui-app
create-react-app + storybook + storybook-addon-material-ui
Stars: ✭ 55 (-73.68%)
Mutual labels:  addon, storybook
Storybook Addon Material Ui
Addon for storybook wich wrap material-ui components into MuiThemeProvider. πŸ“ƒ This helps and simplifies development of material-ui based components.
Stars: ✭ 513 (+145.45%)
Mutual labels:  addon, storybook
React Storybook Addon Props Combinations
Given possible values for each prop, renders your component with all combinations of prop values.
Stars: ✭ 130 (-37.8%)
Mutual labels:  addon, storybook
Storybook Addon Jest
REPO/PACKAGE MOVED - React storybook addon that show component jest report
Stars: ✭ 177 (-15.31%)
Mutual labels:  addon, storybook
Fre
πŸ‘» Tiny Footprint Concurrent UI library for Fiber.
Stars: ✭ 3,195 (+1428.71%)
Mutual labels:  jsx
Koa Vue Notes Web
πŸ€“ This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and Vuex store modules.
Stars: ✭ 200 (-4.31%)
Mutual labels:  storybook
Treestyletab
Tree Style Tab, Show tabs like a tree.
Stars: ✭ 2,438 (+1066.51%)
Mutual labels:  addon


Storybook-addon-jsx

Build Status Total Download Current Version

This Storybook addon shows you the JSX of the story. This preview works for Vue components as well. The outputted JSX will reflect any changes made to the storybok by knobs or controls.

Storybook Addon JSX Demo

Getting started

Installation

First install the addon from npm:

npm i --save-dev storybook-addon-jsx
# or
yarn add --dev storybook-addon-jsx

Configuration

For the latest storybook all you need to do is add the addon to your .storybook/main.js:

module.exports = {
  addons: ['storybook-addon-jsx']
};

If you are using [email protected] or lower you will need to add the following to .storybook/addons.js:

import 'storybook-addon-jsx/register';

Usage

Import it into your stories file and then use it when you write stories:

import React from "react";
import { storiesOf } from "@storybook/react";
import { jsxDecorator } from "storybook-addon-jsx";

import { TestComponent } from './TestComponent':

export default {
  title: "Components/TestComponent",
  decorators: [jsxDecorator],
};

export const Paris = () => (
  <TestComponent fontSize={45} fontFamily="Roboto" align="center" color="#CAF200">
    Hello
  </TestComponent>
);

export const Orleans = () => <Test color="#236544">Hello</Test>;

Or to configure it globally add the jsxDecorator to your .storybook/preview.js:

const { addDecorator } = require('@storybook/react');
const { jsxDecorator } = require('storybook-addon-jsx');

addDecorator(jsxDecorator);

Vue

You can also use this addon with @storybook/vue.

.storybook/preview.js

import { configure, addDecorator } from '@storybook/vue';
import { jsxDecorator } from 'storybook-addon-jsx';

addDecorator(jsxDecorator);

If a Vue story defines its view with a template string then it will be displayed.

import { storiesOf } from '@storybook/vue';

storiesOf('Vue', module).add('template property', () => ({
  template: `<div></div>`
}));

Options

JSX

This addon support all options from react-element-to-jsx-string as well as the following options.

  • skip (default: 0) : Skip element in your component to display
export default {
  title: 'Components/TestComponent',
  parameters: {
    jsx: { skip: 1 }
  }
};
  • onBeforeRender(domString: string) => string (default: undefined) : function that receives the dom as a string before render.
export default {
  title: 'Components/TestComponent',
  parameters: {
    jsx: {
      onBeforeRender: domString => {
        if (domString.search('dangerouslySetInnerHTML') < 0) {
          return '';
        }

        try {
          domString = /(dangerouslySetInnerHTML={{)([^}}]*)/.exec(domString)[2];
          domString = /(')([^']*)/.exec(domString)[2];
        } catch (err) {}

        return domString;
      }
    }
  }
};
  • displayName (default: 0) : You can manually name the components that use useMemo or useRef.
export default {
  title: 'Components/TestComponent',
  parameters: {
    jsx: {
      displayName: () => 'CustomName'
    }
  }
};

Disable JSX Addon

If enabled globally, the JSX addon can be disabled on individual stories:

export const Simple = () => <div>Hello</div>;

Simple.story = {
  parameters: {
    jsx: {
      disable: true
    }
  }
};

Vue Options

  • enableBeautify (default: true) : Beautify the template string
  • All HTML options from js-beautify

Global Options

To configure global options for this plugin, add the following to your config.js.

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

addParameters({
  jsx: {
    // your options
  }
});

Function Props

If you provide a funtion to one of your props storybook-addon-jsx will display that functions toString result. This is usaully very ugly. To override this include the following util function that will print an easiy to read string.

/**
 * Overrides the toString on a function so that it addon-jsx prints
 * the callbacks in a copy-paste-able way.
 */
export const callback = <T extends Function>(fn: T): T => {
  /** A toString to render the function in storybook */
  // eslint-disable-next-line no-param-reassign
  fn.toString = () => '() => {}';
  return fn;
};

This works well with the @storybook/addon-actions too.

export ExampleStory = () => (
  <TestComponent onClick={callback(action('onClick'))} />
)

Including DocGen Information

This addon will display prop type information while hovering over a component or prop. This is accomplished through a babel plugin in the default storybook configuration. To use the docgen information for TypeScript components you must include be using a typescript docgen loader

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

addParameters({
  jsx: {
    // your options
  }
});

TypeScript Monorepo DocGen

In a TypeScript monorepo you will probably be importing components through package names. In this situation storybook will load your compiled typescript and lose information about the props.

One solution to get around this is to add a unique property to your component's package.json that points directly at the TypeScript source. We can then set storybook's webpack configuration to look for this property first, which will allow the TypeScript loader to insert docgen information.

In your component's package.json:

{
  // Can be any string you want, here we choose "source"
  "source": "src/index.tsx"
}

Then in your webpack config for storybook:

config.resolve.mainFields = ['source', 'module', 'main'];

Testing with storyshots

If you are using the addWithJSX method you will need to include storybook-addon-jsx in your test file.

import initStoryshots from '@storybook/addon-storyshots';
import { setAddon } from '@storybook/react';
import JSXAddon from 'storybook-addon-jsx';

setAddon(JSXAddon);

initStoryshots({
  /* configuration options */
});

Usage with IE11

Some of the dependencies that this package has use APIs not available in IE11. To get around this you can add the following to your webpack.config.js file (your paths might be slightly different):

config.module.rules.push({
  test: /\.js/,
  include: path.resolve(__dirname, '../node_modules/stringify-object'),
  use: [
    {
      loader: 'babel-loader',
      options: {
        presets: ['env']
      }
    }
  ]
});

Contributors ✨

Thanks goes to these wonderful people (emoji key):


William

πŸ’» 🎨 πŸ€” πŸ“–

Andrew Lisowski

πŸ’» πŸ“– πŸš‡ 🚧

Norbert de Langen

πŸ’» πŸ“–

Samuel Vaillant

πŸ’» πŸ“–

Alexandre BODIN

πŸ’»

Christophe Coevoet

πŸ’»

Leonel GalΓ‘n

πŸ’»

Lincoln Anderson

πŸ’»

Simon Mollweide

πŸ’»

lflpowell

πŸ’»

lionelbenychou

πŸ’»

Brad Adams

πŸ“–

Andrew Hansen

πŸ’»

Peter Mikitsh

πŸ“– πŸ’»

lisamartin00

πŸ’»

Semih Raif GΓΌrel

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

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