How to use @storybook/addons - 10 common examples

To help you get started, we’ve selected a few @storybook/addons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github truffls / storybook-addon-intl / src / manager / __tests__ / index.js View on Github external
test('register panel correctly', () => {
        //=== Before ===
        addons.loaders = {};
        addons.panels = {};
        addons.channel = {
            emit: () => {},
            on: () => {},
            removeListener: () => {}
        };


        //=== Test ===

        // Register addon
        register();
        // Register panel
        addons.loaders[ADDON_ID]();

        // The panel should be registered
        expect(typeof addons.panels[PANEL_ID]).toBe('object');
github truffls / storybook-addon-intl / src / preview / __tests__ / index.js View on Github external
intlConfig: omit(config, ['locales', 'getMessages', 'getFormats']),
            locales: config.locales,
            getMessages: config.getMessages,
            getFormats: config.getFormats,
        };

        // Set the configuraton
        setIntlConfig(config);

        // Get instance of component
        const element = withIntl(story);

        // Check if props match
        expect(element.props).toEqual({
            ...expectedProps,
            channel: addons.channel,
            children: story()
        });


        //=== After ===
        addons.channel = null;
    });
});
github truffls / storybook-addon-intl / src / manager / __tests__ / index.js View on Github external
// Check if the panel has correct values
        const panel = addons.panels[PANEL_ID];
        expect(panel.title).toBe('Locales');
        expect(typeof panel.render).toBe('function');

        // Check if render function returns correct element
        const element = panel.render({
            key: 'intl/panel',
            active: true
        });
        expect(element.type).toBe(LocalePanel);

        // Check if component receive correct props
        expect(element.props).toEqual({
            active: true,
            channel: addons.channel
        });
        expect(element.key).toEqual('intl/panel');


        //=== After ===
        addons.loaders = {};
        addons.panels = {};
        addons.channel = null;
    });
});
github truffls / storybook-addon-intl / src / manager / __tests__ / index.js View on Github external
const element = panel.render({
            active: true
        });
        expect(element.type).toBe(LocalePanel);

        // Check if component receive correct props
        expect(element.props).toEqual({
            active: true,
            channel: addons.channel
        });


        //=== After ===
        addons.loaders = {};
        addons.panels = {};
        addons.channel = null;
    });
github Skyscanner / backpack / native / storybook / rtl-addon / register.js View on Github external
channel.emit(RTL_EVENT, this.state.rtlEnabled);
  };

  render() {
    return (
      <div>
        <button type="button">
          {this.state.rtlEnabled ? 'Disable' : 'Enable'} RTL
        </button>
      </div>
    );
  }
}

// Register the addon with a unique name.
addons.register('rtl-toggle', api =&gt; {
  // Also need to set a unique name to the panel.
  addons.addPanel('rtl-toggle/panel', {
    title: 'RTL',
    render: () =&gt; ,
  });
});
github airbnb / lunar / .storybook / addons / props / index.js View on Github external
import addons, { makeDecorator } from '@storybook/addons';
import kebabCase from 'lodash/kebabCase';
import stripHOCs from '../../helpers/stripHOCs';

export const withProps = makeDecorator({
  name: 'withProps',
  parameterName: 'props',
  wrapper: (getStory, context) => {
    const components = {};

    context.parameters.inspectComponents.forEach(component => {
      components[stripHOCs(component.displayName || component.name)] = component;
    });

    // We need to cast globals to JSON, otherwise the data is lost
    addons.getChannel().emit('SET_PROPS_DATA', {
      components,
      componentChangelogs: JSON.stringify(COMPONENT_CHANGELOGS),
      componentMetadata: JSON.stringify(STORYBOOK_REACT_CLASSES),
      section: kebabCase(context.kind.split('/')[0]),
      storyPath: context.parameters.fileName,
github storybookjs / storybook / app / react-native / src / preview / index.tsx View on Github external
const { secured } = params;
        const websocketType = secured ? 'wss' : 'ws';
        const httpType = secured ? 'https' : 'http';

        const url = `${websocketType}://${host}${port}/${query}`;
        webUrl = `${httpType}://${host}${port}`;
        channel = createChannel({
          url,
          async: onDeviceUI,
          onError: () => {
            this._setInitialStory(initialSelection, shouldPersistSelection);
          },
        });
      }

      addons.setChannel(channel);
      this._stories.setChannel(channel);

      channel.emit(Events.CHANNEL_CREATED);
    }

    channel.on(Events.GET_STORIES, () => this._sendSetStories());
    channel.on(Events.SET_CURRENT_STORY, d => this._selectStoryEvent(d));

    this._sendSetStories();

    // eslint-disable-next-line @typescript-eslint/no-this-alias
    const preview = this;

    addons.loadAddons(this._clientApi);

    const appliedTheme = { ...theme, ...params.theme };
github wix / wix-react-native-storybook-template / storybook-react-native / preview / index.js View on Github external
channel = this._events;
        } else {
          const host = params.host || parse(NativeModules.SourceCode.scriptURL).hostname;
          const port = params.port !== false ? `:${params.port || 7007}` : '';

          const query = params.query || '';
          const { secured } = params;
          const websocketType = secured ? 'wss' : 'ws';
          const httpType = secured ? 'https' : 'http';

          const url = `${websocketType}://${host}${port}/${query}`;
          webUrl = `${httpType}://${host}${port}`;
          channel = createChannel({ url });
        }

        addons.setChannel(channel);

        channel.emit('channelCreated');
      }

      channel.on('getStories', () =&gt; this._sendSetStories());
      channel.on('setCurrentStory', d =&gt; this._selectStory(d));
      this._events.on('setCurrentStory', d =&gt; this._selectStory(d));
      this._sendSetStories();
      this._sendGetCurrentStory();

      // finally return the preview component
      return params.onDeviceUI ? (
        
      ) : (
        
      );
github influxdata / clockface / src / Components / Inputs / Documentation / Inputs.stories.tsx View on Github external
() =&gt; {
    const toggleRef: RefObject = createRef()
    const toggleContainerRef: RefObject = createRef()

    const [checked, setChecked] = useState(false)

    const handleToggleChange = (): void =&gt; {
      setChecked(!checked)
    }

    const handleLogRefs = (): void =&gt; {
      /* eslint-disable */
      console.log('ToggleRef', toggleRef.current)
      console.log('ToggleContainerRef', toggleContainerRef.current)
      /* eslint-enable */
    }

    return (
      <div>
        </div>
github influxdata / clockface / src / Components / Inputs / Documentation / Inputs.stories.tsx View on Github external
() =&gt; {
    const [rangeSliderValue, setRangeSliderValue] = useState(50)
    const rangeSliderRef: RefObject = createRef()

    const handleInputChange = (e: ChangeEvent): void =&gt; {
      setRangeSliderValue(parseInt(e.target.value))
    }

    const handleLogRef = (): void =&gt; {
      /* eslint-disable */
      console.log(rangeSliderRef.current)
      /* eslint-enable */
    }

    const exampleRangeSliderStyle = {width: '100%'}

    return (
      <div></div>