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 ; const div = document . createElement ( 'div' ) ; document . body . appendChild ( div ) ; const defaultIterations = 1 ; 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 ; if ( selectedKind && selectedStory ) { ReactDOM . render ( decorator ( < div > { Array . from ( { length : iterations } , ( ) => stories [ selectedKind ] [ selectedStory ] ( ) ) } < /div>), div); } else { ReactDOM . render ( decorator ( < div > < div > Required params missing . < /div> < div > Required params : selectedKind , selectedStory < /div> < div > Optional params : iterations < /div> < div > Displaying all kinds and stories : < /div>{' '} { Object . keys ( stories ) . map ( kindKey => { return ( < div > < br /> < b > Kind : { kindKey } < /b> { Object . keys ( stories [ kindKey ] ) . filter ( storyKey => typeof stories [ kindKey ] [ storyKey ] === 'function' ) . map ( storyKey => { return ( < div > < br /> < div > Story : { ' ' } < a href = { `?selectedKind=${ kindKey }&selectedStory=${ storyKey }&iterations=50` } > { storyKey } < /a> < /div> < div > { stories [ kindKey ] [ storyKey ] ( ) } < /div> < /div>); } ) } < /div>); } ) } < /div>), div); }