How to use the @storybook/api.useChannel function in @storybook/api

To help you get started, we’ve selected a few @storybook/api 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 microsoftgraph / microsoft-graph-toolkit / .storybook / manager.js View on Github external
const SignInPanel = () => {
  const value = useParameter(PARAM_KEY, null);

  const [state, setState] = useState(Providers.globalProvider.state);

  const emit = useChannel({
    STORY_RENDERED: id => {
      console.log('storyRendered', id);
    },
    [GETPROVIDER_EVENT]: params => {
      emitProvider(state);
    }
  });

  const emitProvider = loginState => {
    emit(SETPROVIDER_EVENT, { state: loginState });
  };

  Providers.onProviderUpdated(() => {
    setState(Providers.globalProvider.state);
    emitProvider(Providers.globalProvider.state);
  });
github bcgov / range-web / .storybook / roles-addon / Tool.js View on Github external
const ViewportTool = () => {
  const [role, setRole] = useAddonState(ADDON_ID, 'myra_range_officer')

  const emit = useChannel({
    [STORY_RENDERED]: () => {
      setTimeout(() => {
        emit('role/change', role)
      }, 100)
    }
  })

  const handleChange = e => {
    setRole(e.target.value)
    emit('role/change', e.target.value)
  }

  return (
github storybookjs / storybook / addons / live-edit / src / Editor.tsx View on Github external
const Editor = ({ api }: { api: API }) => {
  const emit = useChannel({});
  const story = useCurrentStory();
  const storyId = story && story.id ? story.id : '';
  const [initialCode, setInitialCode] = useEditor();
  const [metaData, setMetadata] = React.useState(null);

  let previousSource = '';

  const loadStoryCode = (sourceLoader: SourceLoaderInfo) => {
    const sourceCode = sourceLoader.edition.source;
    setMetadata(sourceLoader);
    if (previousSource === sourceCode || initialCode[storyId]) {
      return null;
    }
    previousSource = sourceCode;
    const sourceSplitted = sourceCode.split('\n');
github storybookjs / storybook / dev-kits / addon-roundtrip / src / panel.tsx View on Github external
export const Panel = () => {
  const [results, setState] = useAddonState(ADDON_ID, []);
  const emit = useChannel({
    [EVENTS.RESULT]: (newResults: Results) => setState(newResults),
  });

  return (
    
      <content>
       emit(EVENTS.REQUEST) },
          { title: 'setState', onClick: () =&gt; setState(['foo']) },
          {
            title: 'setState with options',
            onClick: () =&gt; setState(['bar'], { persistence: 'session' }),
          },
          { title: 'setState with function', onClick: () =&gt; setState(s =&gt; [...s, 'baz']) },</content>
github storybookjs / storybook / addons / coverage / src / CoverageTool.tsx View on Github external
export const CoverageTool: React.FunctionComponent&lt;{}&gt; = () =&gt; {
  const [active, setActive] = useState(true);
  const icon = active ? 'eye' : 'eyeclose';

  window.getStoryColor = (storyId: string) =&gt; getColor(storyId, active);
  const emit = useChannel({
    [EVENTS.COVERAGE_SUMMARY]: (summary: CoverageSummary) =&gt; {
      setCoverageSummary(summary);
    },
  });
  return (
     {
        setActive(!active);
        emit(SELECT_STORY, { kind: 'Coverage|Welcome', story: 'normal' });
      }}
    &gt;

@storybook/api

Storybook Manager API (facade)

MIT
Latest version published 9 months ago

Package Health Score

91 / 100
Full package analysis