How to use the @storybook/core-events.SET_CURRENT_STORY function in @storybook/core-events

To help you get started, we’ve selected a few @storybook/core-events 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 storybookjs / storybook / app / react-native / src / preview / index.tsx View on Github external
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 };

    // react-native hot module loader must take in a Class - https://github.com/facebook/react-native/issues/10991
    return class StorybookRoot extends PureComponent {
      render() {
        if (onDeviceUI) {
          return (
github storybookjs / storybook / lib / core / src / client / preview / start.js View on Github external
showException(ex);
      }
    }
  };

  const forceReRender = () => renderUI(true);

  // channel can be null in NodeJS
  if (isBrowser) {
    const deprecatedToId = deprecate(
      toId,
      `Passing name+kind to the SET_CURRENT_STORY event is deprecated, use a storyId instead`
    );

    channel.on(Events.FORCE_RE_RENDER, forceReRender);
    channel.on(Events.SET_CURRENT_STORY, ({ storyId: inputStoryId, name, kind, viewMode }) => {
      let storyId = inputStoryId;
      // For backwards compatibility
      if (!storyId) {
        if (!name || !kind) {
          throw new Error('You should pass `storyId` into SET_CURRENT_STORY');
        }
        storyId = deprecatedToId(kind, name);
      }

      storyStore.setSelection({ storyId, viewMode });
      setPath({ storyId, viewMode });
    });

    // Handle keyboard shortcuts
    window.onkeydown = event => {
      if (!focusInInput(event)) {
github storybookjs / storybook / app / react-native / src / client / preview / components / StoryListView / index.js View on Github external
changeStory(kind, story) {
    const { events } = this.props;

    events.emit(Events.SET_CURRENT_STORY, { kind, story });
  }
github Workday / canvas-kit / .storybook / config.js View on Github external
function setCurrentStory(categorization, story) {
  clearCurrentStory();
  addons.getChannel().emit(Events.SET_CURRENT_STORY, {
    storyId: toId(categorization, story),
  });
  forceReRender();
}
github storybookjs / storybook / app / react-native-server / src / client / manager / provider.js View on Github external
{({ storiesHash, storyId, api, viewMode }) => {
          if (storiesHash[storyId]) {
            api.emit(Events.SET_CURRENT_STORY, { storyId });
          }
          return viewMode === 'story' ?  : null;
        }}
github storybookjs / storybook / app / react-native / src / preview / components / StoryListView / index.tsx View on Github external
changeStory(kind: string, story: string) {
    const channel = addons.getChannel();
    channel.emit(Events.SET_CURRENT_STORY, { kind, story });
  }
github storybookjs / storybook / app / react-native / src / preview / components / StoryListView / index.tsx View on Github external
changeStory(storyId: string) {
    const channel = addons.getChannel();
    channel.emit(Events.SET_CURRENT_STORY, { storyId });
  }