-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from Financial-Times/matth/decouple-storybook…
…-from-docs Decouple Storybook from docs
- Loading branch information
Showing
7 changed files
with
30 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,22 @@ | ||
import React from 'react'; | ||
import { withPrefix } from 'gatsby'; | ||
|
||
class StoryViewer extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
const StoryViewer = ({ name }) => { | ||
const queryString = `?path=/story/${name}--*`; | ||
const iframeUrl = withPrefix(`/storybook/iframe.html${queryString}`); | ||
const linkUrl = withPrefix(`/storybook/index.html${queryString}`); | ||
|
||
this.state = { | ||
selected: 0 | ||
}; | ||
} | ||
|
||
onClick(index) { | ||
if (this.state.selected !== index) { | ||
this.setState({ selected: index }); | ||
} | ||
} | ||
|
||
render() { | ||
const story = this.props.stories[this.state.selected]; | ||
const queryString = `?selectedKind=${this.props.name}&selectedStory=${story}`; | ||
const iframeUrl = withPrefix(`/storybook/iframe.html${queryString}`); | ||
const linkUrl = withPrefix(`/storybook/index.html${queryString}`); | ||
|
||
return ( | ||
<div id="component-demos" className="story-viewer"> | ||
<h2 className="story-viewer__heading">Component demos</h2> | ||
<ul className="story-viewer__list" role="tablist"> | ||
{this.props.stories.map((story, i) => ( | ||
<li key={`story-${i}`} className="story-viewer__item"> | ||
<button | ||
role="tab" | ||
className="story-viewer__button" | ||
aria-selected={this.state.selected === i} | ||
onClick={this.onClick.bind(this, i)}> | ||
{story} | ||
</button> | ||
</li> | ||
))} | ||
</ul> | ||
<div className="story-viewer__panel" role="tabpanel"> | ||
<iframe title={`${story} demo`} src={iframeUrl}></iframe> | ||
</div> | ||
<p className="story-viewer__footer"> | ||
<a href={linkUrl}>View in Storybook</a> | ||
</p> | ||
return ( | ||
<div id="component-demos" className="story-viewer"> | ||
<h2 className="story-viewer__heading">Component demos</h2> | ||
<div className="story-viewer__panel"> | ||
<iframe title={`${name} demo`} src={iframeUrl}></iframe> | ||
</div> | ||
); | ||
} | ||
<p className="story-viewer__footer"> | ||
<a href={linkUrl}>View in Storybook</a> | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default StoryViewer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters