New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add React Storybook to the project #93
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yet,
Totally stumped here, passing this to
glob
manually finds the right file, I don't know why ESLint isn't whitelisting this pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gnarf identified that we had a duplicative
.eslintrc.js
file inside frontend that was defining an override for this rule specifically, preventing the parent config from taking effect insidefrontend/
. Since the intent of the nested file was already accomplished by the existing config in the parent, I've removed the nested.eslintrc.js
.