import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as qs from 'querystring'; import config from 'stories/config'; const { stories, decorator } = config; // TODO: // going to need to support story setup like initializeIcons for Fabric. // or leave it up to static init in the story? assuming it doesn't run for all stories.. const div = document.createElement('div'); document.body.appendChild(div); // TODO: use iterations from story object const defaultIterations = 1; // This is structure to follow storybook conventions to take advantage of existing storybook CSFs. // https://storybook.js.org/docs/testing/automated-visual-testing/#custom-solutions const queryParams = qs.parse(window.location.search.substring(1)); const iterations = queryParams.iterations ? parseInt(queryParams.iterations as string, 10) : defaultIterations; const selectedKind = queryParams.selectedKind ? (queryParams.selectedKind as string) : undefined; const selectedStory = queryParams.selectedStory ? (queryParams.selectedStory as string) : undefined; // TODO: eval functions here or in config? check perf differences! other considerations? // TODO: make sure decorator impl doesn't affect perf. if (selectedKind && selectedStory) { ReactDOM.render( decorator(
{Array.from({ length: iterations }, () => stories[selectedKind][selectedStory]())}
), div, ); } else { ReactDOM.render( decorator(
Required params missing.
Required params: selectedKind, selectedStory
Optional params: iterations
Displaying all kinds and stories:
{' '} {Object.keys(stories).map(kindKey => { return (

Kind: {kindKey} {Object.keys(stories[kindKey]) .filter(storyKey => typeof stories[kindKey][storyKey] === 'function') .map(storyKey => { return (

Story:{' '} {storyKey}
{stories[kindKey][storyKey]()}
); })}
); })}
, ), div, ); }