JSPM

@toptal/davinci-storybook-live-edit-addon

0.2.4-alpha-fix-incorrect-package-publishing-b1e63a0c.5+b1e63a0c
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q136309F
  • License ISC

Live edit addon for Storybook

Package Exports

  • @toptal/davinci-storybook-live-edit-addon
  • @toptal/davinci-storybook-live-edit-addon/dist/preset.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@toptal/davinci-storybook-live-edit-addon) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Storybook Addon Live Edit

Storybook Addon Live Edit allows user editing code in realtime

Features

  • Typescript support
  • Compatible with Storybook decorators
  • Ability to enable/disable addon for specified story/component or for the whole project

Installation

1. Install addon

yarn add -D @toptal/davinci-storybook-live-edit-addon

2. Register this addon to Storybook

module.exports = {
  addons: ['@toptal/davinci-storybook-live-edit-addon']
}

This live-edit addon also brings @toptal/davinci-storybook-theme.

Usage

NOTE: You must specify a scope for each story, beforehand. It means, all variables that are used inside story must be specified inside the scope

ReferenceError: Component is not defined

After loading stories, there is a big chance you will get the error above. It happens due to a lack of defined scope.

To define a scope, you may use parameters from story, component or project levels:

// extra variables that are used inside stories
const extraVariable = 1;
const MyCustomComponent = () => null

export default {
  title: 'Example/Button',
  component: Button,
  parameters: {
    scope: {
      // all variables that are used inside stories must be defined inside the scope
      Button,
      extraVariable,
      MyCustomComponent
    },
  },
} as ComponentMeta<typeof Button>;

export const Primary = (args) => {
  return (
    <MyCustomComponent> // <-- MyCustomComponent must be defined
      <Button {...args}> // <-- Button must be defined
        {extraVariable} // <-- extraVariable must be defined
      </Button>
    </MyCustomComponent>
  )
};

Primary.args = {
  primary: true,
  label: 'Button',
};

Info

Instead of overriding the whole Canvas, this addon extends the default DocStory component and keeps default Canvas. Basically, it adds a new button Live Edit next to Show Code button.

Parameters:

disableLiveEdit — disable live edit. It might be used for a single story, component, or whole project.

Example of disabling the addon globally:

// .storybook/preview.js
export const parameters = {
  disableLiveEdit: true // Disable Live Edit globally
}

Example of disabling the addon:

  1. on a component level
  2. only for a particular story
// MyComponent.stories.tsx
export default {
  title: 'MyComponent',
  component: MyComponent,
  parameters: {
    disableLiveEdit: true, // Disable Live Edit in all stories in the file
  }
}

const Template = (args) => ({
  // 👈 Your template goes here
});

export const Primary = Template.bind({});

Primary.parameters = {
  disableLiveEdit: true, // Disable Live Edit only for `Primary` story
};

Implementation

This addon uses react-live under the hood.