Skip to content
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 #11

Merged
merged 11 commits into from Jan 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc.json
Expand Up @@ -7,10 +7,11 @@
"import"
],
"rules": {
"arrow-body-style": 0
"arrow-body-style": 0,
"react/jsx-closing-bracket-location": 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なぜかVSCodeのESLint autosaveと相性が悪く、かつ体裁のルールなので、オフで問題ないと思い一旦オフにしてます 😓

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おや。これがあるとどうなります?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

↓これはESLint pluginのautosaveをONにした状態で「保存」を試している例なのですが、なぜかインデント戻ってしまうのです。autosaveをdisableにするか、ここのルールだけignoreするかで考えて、後者を選びました。

screencast 2017-01-11 11-34-03-dq051

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど。一旦disableしてしかるべきところに報告できるといいすな。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

はい。たぶんPlugin側かな... issues ないか見てみます。

},
"env": {
"es6": true,
"mocha": true
}
}
}
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -21,4 +21,4 @@ npm-debug.log

# app
lib

build
7 changes: 7 additions & 0 deletions .storybook/config.js
@@ -0,0 +1,7 @@
import { configure, addDecorator } from '@kadira/storybook';

function loadStories() {
require('../stories/image.jsx');
}

configure(loadStories, module);
2 changes: 0 additions & 2 deletions .vscode/settings.json
Expand Up @@ -2,9 +2,7 @@
"editor.renderWhitespace": "all",
"editor.tabSize": 2,
"editor.insertSpaces": true,

"files.trimTrailingWhitespace": true,
"files.autoSave": "onFocusChange",

"eslint.autoFixOnSave": true
}
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -8,6 +8,8 @@
"build": "babel src --out-dir lib --source-maps",
"test": "nyc mocha --opts spec/mocha.opts spec/**/*.spec.jsx",
"coveralls": "nyc report --reporter=text-lcov | $(npm bin)/coveralls",
"story:start": "start-storybook -p 9001 -c .storybook",
"story:build": "build-storybook -c .storybook -o build",
"prepublish": "yarnpkg build"
},
"files": [
Expand All @@ -28,6 +30,7 @@
},
"homepage": "https://github.com/bitjourney/react-simple-image#readme",
"devDependencies": {
"@kadira/storybook": "^2.35.2",
"babel-cli": "^6.14.0",
"babel-plugin-istanbul": "^3.0.0",
"babel-preset-es2015": "^6.18.0",
Expand Down
2 changes: 1 addition & 1 deletion src/image.jsx
Expand Up @@ -56,7 +56,7 @@ export default class Image extends React.Component {
src={this.props.src}
srcSet={this.buildSrcSet()}
sizes={this.buildSizes()}
/>
/>
);
}
}
49 changes: 49 additions & 0 deletions stories/image.jsx
@@ -0,0 +1,49 @@
import React from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { storiesOf } from '@kadira/storybook';
import Image from '../src/image';
import photo1x from './images/astronaut.jpg';
import photo2x from './images/astronaut@2x.jpg';
import photo300 from './images/react-300.png';
import photo900 from './images/react-900.png';

storiesOf('<Image />', module)
.addDecorator(story => (
<div style={{ textAlign: 'center' }}>
{story()}
</div>
))
.add('with pixel descriptor', () => (
<div>
<Image
alt="react-simple-image storybook component"
src={photo1x}
className="additional-className"
srcSet={{
'1x': photo1x,
'2x': photo2x,
}}
/>
<p>License: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication</p>
<p><a href="https://visualhunt.com/photo/15033/close-up-of-astronaut-in-space/">Visual Hunt</a></p>
</div>
))
.add('with width descriptor', () => (
<div>
<Image
alt="react-simple-image storybook component"
src={photo300}
className="additional-className"
srcSet={{
'300w': photo300,
'900w': photo900,
}}
sizes={[
{ size: '100vw', mediaCondition: '(max-width: 480px)' },
{ size: '50vw', mediaCondition: '(max-width: 1200px)' },
{ size: 'calc(33vw - 100px)' },
]}
/>
<p>License: <a href="https://facebook.github.io/react/">React</a></p>
</div>
));
Binary file added stories/images/astronaut.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added stories/images/astronaut@2x.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added stories/images/react-300.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added stories/images/react-900.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.