How to use the @storybook/csf.toId function in @storybook/csf

To help you get started, we’ve selected a few @storybook/csf 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 / lib / api / src / modules / url.ts View on Github external
if (addons === '0') {
    addition.showPanel = false;
  }
  if (panelRight === '1') {
    addition.panelPosition = 'right';
  }
  if (stories === '0') {
    addition.showNav = false;
  }

  if (addonPanel) {
    selectedPanel = addonPanel;
  }

  if (selectedKind && selectedStory) {
    const id = toId(selectedKind, selectedStory);
    setTimeout(() => navigate(`/${viewMode}/${id}`, { replace: true }), 1);
  } else if (selectedKind) {
    // Create a "storyId" of the form `kind-sanitized--*`
    const standInId = toId(selectedKind, 'star').replace(/star$/, '*');
    setTimeout(() => navigate(`/${viewMode}/${standInId}`, { replace: true }), 1);
  } else if (!queryPath || queryPath === '/') {
    setTimeout(() => navigate(`/${viewMode}/*`, { replace: true }), 1);
  } else if (Object.keys(query).length > 1) {
    // remove other queries
    setTimeout(() => navigate(`${queryPath}`, { replace: true }), 1);
  }

  return { viewMode, layout: addition, selectedPanel, location, path, customQueryParams, storyId };
};
github storybookjs / storybook / lib / source-loader / src / server / abstract-syntax-tree / parse-helpers.js View on Github external
}

  const framework = tmp.callee && tmp.callee.name && storiesOfIdentifiers[tmp.callee.name];

  const storyName = addArgs[0];
  const body = addArgs[1];
  const lastArg = addArgs[addArgs.length - 1];

  if (storyName.type !== 'Literal' && storyName.type !== 'StringLiteral') {
    // if story name is not literal, it's much harder to extract it
    return {};
  }

  const kind = findRelatedKind(node.object) || '';
  if (kind && storyName.value) {
    const key = toId(kind, storyName.value);
    let idToFramework;
    if (key && framework) {
      idToFramework = { [key]: framework };
    }

    return {
      toAdd: {
        [key]: {
          // Debug: code: source.slice(storyName.start, lastArg.end),
          startLoc: {
            col: storyName.loc.start.column,
            line: storyName.loc.start.line,
          },
          endLoc: {
            col: lastArg.loc.end.column,
            line: lastArg.loc.end.line,
github storybookjs / storybook / lib / api / src / modules / url.ts View on Github external
addition.panelPosition = 'right';
  }
  if (stories === '0') {
    addition.showNav = false;
  }

  if (addonPanel) {
    selectedPanel = addonPanel;
  }

  if (selectedKind && selectedStory) {
    const id = toId(selectedKind, selectedStory);
    setTimeout(() => navigate(`/${viewMode}/${id}`, { replace: true }), 1);
  } else if (selectedKind) {
    // Create a "storyId" of the form `kind-sanitized--*`
    const standInId = toId(selectedKind, 'star').replace(/star$/, '*');
    setTimeout(() => navigate(`/${viewMode}/${standInId}`, { replace: true }), 1);
  } else if (!queryPath || queryPath === '/') {
    setTimeout(() => navigate(`/${viewMode}/*`, { replace: true }), 1);
  } else if (Object.keys(query).length > 1) {
    // remove other queries
    setTimeout(() => navigate(`${queryPath}`, { replace: true }), 1);
  }

  return { viewMode, layout: addition, selectedPanel, location, path, customQueryParams, storyId };
};
github storybookjs / storybook / lib / core / src / client / preview / url.js View on Github external
export const getIdFromLegacyQuery = ({ path, selectedKind, selectedStory }) =>
  (path && pathToId(path)) || (selectedKind && selectedStory && toId(selectedKind, selectedStory));
github storybookjs / storybook / addons / links / src / preview.ts View on Github external
return new Promise(resolve => {
    const { storyId } = storyStore.getSelection();
    const current = storyStore.fromId(storyId);
    resolve(generateUrl(toId(kind || current.kind, name)));
  });
};
github storybookjs / storybook / lib / source-loader / src / server / abstract-syntax-tree / parse-helpers.js View on Github external
export function handleExportedName(kind, storyName, node) {
  const startLoc = {
    col: node.loc.start.column,
    line: node.loc.start.line,
  };
  const endLoc = {
    col: node.loc.end.column,
    line: node.loc.end.line,
  };
  return {
    [toId(kind, storyName)]: {
      startLoc,
      endLoc,
      startBody: startLoc,
      endBody: endLoc,
    },
  };
}

@storybook/csf

Component Story Format (CSF) utilities

MIT
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis

Popular @storybook/csf functions