How to use the @storybook/components.SourceError.SOURCE_UNAVAILABLE function in @storybook/components

To help you get started, we’ve selected a few @storybook/components 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 / addons / docs / src / blocks / Source.tsx View on Github external
export const getSourceProps = (
  { language, code, id }: SourceProps,
  { id: currentId, storyStore }: DocsContextProps
): PureSourceProps => {
  let source = code; // prefer user-specified code
  if (!source) {
    const targetId = id || currentId; // prefer user-specified story id
    const { parameters } = storyStore.fromId(targetId);
    if (parameters) {
      const { mdxSource, storySource } = parameters;
      source = mdxSource || (storySource && extract(targetId, storySource));
    }
  }
  return source
    ? { code: source, language: language || 'jsx' }
    : { error: SourceError.SOURCE_UNAVAILABLE };
};