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 #93 from bocoup/storybook
Add React Storybook to the project
- Loading branch information
Showing
11 changed files
with
114 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"presets": [ | ||
["es2015", {"modules": "commonjs"}], | ||
|
||
"react" | ||
], | ||
"plugins": [ | ||
"react-hot-loader/babel", | ||
"transform-object-rest-spread" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// In order to use Storybook's Add-Ons we have to manually reference the | ||
// add-ons we care about from this file. | ||
// | ||
// More information: | ||
// https://getstorybook.io/docs/react-storybook/addons/introduction | ||
// https://github.com/storybooks/storybook-addon-knobs | ||
|
||
// Include Storybook's built-in addons (actions and links) | ||
import '@kadira/storybook/addons'; | ||
|
||
// Include the "knobs" add-on to support dynamically editing React props | ||
import '@kadira/storybook-addon-knobs/register'; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { configure } from '@kadira/storybook'; | ||
|
||
// We write our stories as *.stories.jsx files that live alongside the | ||
// component that they exercise. The logic in this function finds all | ||
// *.stories.jsx files within our front-end source directory and executes | ||
// them; each file should call `storiesOf('ProgressBar', module)` in the | ||
// normal fashion described in the Storybook documentation. | ||
function loadStories() { | ||
// Reassure ESLint that this async require is intentional | ||
// eslint-disable-next-line global-require | ||
const req = require.context('../frontend', true, /\.stories\.jsx$/); | ||
req.keys().forEach(filename => req(filename)); | ||
} | ||
|
||
configure(loadStories, module); |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// For more information on Storybook's webpack configuration, refer the docs: | ||
// https://getstorybook.io/docs/configurations/custom-webpack-config | ||
|
||
const path = require('path'); | ||
const webpackConfig = require('../webpack.config'); | ||
|
||
const projectRoot = path.resolve(__dirname, '../'); | ||
|
||
// Storybook still uses Webpack 1 under the hood! This means we have to map | ||
// our Webpack 2 config back to use Webpack 1 syntax; and since Storybook | ||
// handles the Babel / JSX parsing for us, this means we also need to pick | ||
// out the rules relevant to our non-JS styles & files loaders. | ||
const styleAndImageRules = webpackConfig.module.rules | ||
// We filter our rules list down with a simple file-type regex test to | ||
// whitelist the loader tests we want to pull in to Storybook: | ||
.filter(rule => /png|svg|jpg|gif|styl/i.test(rule.test.toString())) | ||
// This map statement converts _the most basic_ Webpack 2 loader config | ||
// objects into something Webpack 1 can understand; it works here because | ||
// this project does not get too tricky with loaders, but could break if | ||
// the base project Webpack configuration is substantially modified. | ||
// TODO: Rip this out ASAP as soon as Storybook upgrades to Webpack 2! | ||
.map(rule => ({ | ||
test: rule.test, | ||
loaders: rule.use.map((loader) => { | ||
if (typeof loader === 'string') { | ||
// String loader values are passed through as-is | ||
return loader; | ||
} | ||
// Otherwise, make a string out of the loader options object and | ||
// add it to the loader name. Loaders can conveniently accept options | ||
// as a JSON string: https://webpack.github.io/docs/using-loaders.html | ||
return `${loader.loader}?${JSON.stringify(loader.options)}`; | ||
}), | ||
// Since this file is not the project root, augment each rule with | ||
// an include path specifying the project's root directory | ||
include: projectRoot, | ||
})); | ||
|
||
module.exports = { | ||
module: { | ||
loaders: styleAndImageRules, | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
import ProgressBar from './'; | ||
|
||
storiesOf('ProgressBar', module) | ||
.add('0%', () => ( | ||
<ProgressBar current={1} total={4} incrementName="Step" /> | ||
)) | ||
.add('25%', () => ( | ||
<ProgressBar current={2} total={4} incrementName="Step" /> | ||
)) | ||
// .add('no border', () => ( | ||
// <ProgressBar current={1} total={4} border={false} incrementName="Step" /> | ||
// )) | ||
.add('100%', () => ( | ||
<ProgressBar current={5} total={4} incrementName="Step" /> | ||
)); |
2 changes: 1 addition & 1 deletion
2
frontend/components/ProgressBar.styl → ...d/components/ProgressBar/ProgressBar.styl
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,4 +1,4 @@ | ||
@import './shared/mixins.styl'; | ||
@import '../shared/mixins.styl'; | ||
|
||
.label { | ||
visually-hidden(); | ||
|
File renamed without changes.
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