How to use the @storybook/api.useParameter 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 });
  };
github storybookjs / storybook / addons / viewport / src / Tool.tsx View on Github external
withTheme(({ theme }: { theme: Theme }) => {
    const { viewports, defaultViewport, disable } = useParameter(
      PARAM_KEY,
      {
        viewports: {},
        defaultViewport: responsiveViewport.id,
      }
    );
    const [state, setState] = useAddonState(ADDON_ID, {
      selected: defaultViewport || responsiveViewport.id,
      isRotated: false,
    });
    const list = toList(viewports);

    const { selected, isRotated } = state;
    const item =
      list.find(i => i.id === selected) ||
      list.find(i => i.id === defaultViewport) ||
github storybookjs / storybook / addons / design-assets / src / panel.tsx View on Github external
export const Panel = () => {
  const results = useParameter(PARAM_KEY, []);
  const [selected, setSelected] = useAddonState(ADDON_ID, 0);
  const { storyId } = useStorybookState();

  return useMemo(() => {
    if (results.length === 0) {
      return null;
    }

    if (results.length && !results[selected]) {
      setSelected(0);
      return null;
    }
    const url = getUrl(results[selected]).replace('{id}', storyId);
    return (
github storybookjs / storybook / dev-kits / addon-parameter / src / register.tsx View on Github external
export const Content = () => {
  const results = useParameter(PARAM_KEY, []);

  return useMemo(
    () =>
      results.length ? (
        <ol>
          {results.map((i: string) =&gt; (
            <li>{i}</li>
          ))}
        </ol>
      ) : null,
    [results]
  );
};
github storybookjs / storybook / addons / viewport / src / Tool.tsx View on Github external
withTheme(({ theme }: { theme: Theme }) =&gt; {
    const {
      viewports = MINIMAL_VIEWPORTS,
      defaultViewport = responsiveViewport.id,
      disable,
    } = useParameter(PARAM_KEY, {});
    const [state, setState] = useAddonState(ADDON_ID, {
      selected: defaultViewport,
      isRotated: false,
    });
    const list = toList(viewports);

    useEffect(() =&gt; {
      setState({
        selected:
          defaultViewport || (viewports[state.selected] ? state.selected : responsiveViewport.id),
        isRotated: state.isRotated,
      });
    }, [defaultViewport]);

    const { selected, isRotated } = state;
    const item =
github JosephusPaye / Keen-UI / .storybook / source-addon.js View on Github external
const SourcePanel = ({ active }) => {
    const source = useParameter(PARAM_KEY, null);
    return active && source
        ? React.createElement(
              SyntaxHighlighter,
              {
                  language: 'html',
                  showLineNumbers: false,
                  copyable: true,
                  padded: true,
                  format: false,
              },
              source
          )
        : null;
};
github axa-ch / patterns-library / .storybook / addons / changelog / register.js View on Github external
const MyPanel = () =&gt; {
  const value = useParameter('changelog', null);

  const replaceUnneeded = (value) =&gt; {
    if (value) {
      return value
        .replace('module.exports = "', '')
        .replace(/\\n";/g, '<br>')
        .replace(/\\n/g, '<br>');
    }
    return 'No Changelog found.';
  };

  return <div style="{{"></div>;
};

@storybook/api

Storybook Manager API (facade)

MIT
Latest version published 9 months ago

Package Health Score

91 / 100
Full package analysis