Skip to content

Commit 14d66db

Browse files
committed
introduce Storybook Viewport
1 parent 55d40eb commit 14d66db

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

.storybook/addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import '@storybook/addon-knobs/register';
22
import '@storybook/addon-actions/register';
3+
import '@storybook/addon-viewport/register';

.storybook/config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
11
import { configure, addDecorator } from '@storybook/react';
22
import { withKnobs } from '@storybook/addon-knobs';
3+
import { configureViewport } from '@storybook/addon-viewport';
34

45
// pick all stories.js files within the src/ folder
56
const req = require.context('../src', true, /stories\.js$/);
67

78
addDecorator(withKnobs);
89

10+
const viewports = {
11+
small: {
12+
name: 'small',
13+
styles: {
14+
width: '320px',
15+
height: '240px',
16+
},
17+
},
18+
medium: {
19+
name: 'medium',
20+
styles: {
21+
width: '800px',
22+
height: '600px',
23+
},
24+
},
25+
large: {
26+
name: 'large',
27+
styles: {
28+
width: '1280px',
29+
height: '1024px',
30+
},
31+
},
32+
};
33+
34+
configureViewport({
35+
viewports,
36+
});
37+
938
function loadStories() {
1039
req.keys().forEach(filename => req(filename));
1140
}

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@storybook/addon-actions": "^4.0.0-alpha.6",
2222
"@storybook/addon-knobs": "^4.0.0-alpha.6",
2323
"@storybook/addon-storyshots": "^4.0.0-alpha.6",
24+
"@storybook/addon-viewport": "^4.0.0-alpha.6",
2425
"@storybook/react": "^4.0.0-alpha.6",
2526
"babel-core": "^6.26.0",
2627
"babel-loader": "^7.1.4",

src/Checkbox/stories.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { storiesOf } from '@storybook/react';
33
import { text } from '@storybook/addon-knobs';
44
import { action } from '@storybook/addon-actions';
5+
import { Viewport } from '@storybook/addon-viewport';
56
import Checkbox from './';
67

78
class CheckboxStateful extends React.Component {
@@ -28,6 +29,32 @@ class CheckboxStateful extends React.Component {
2829
}
2930

3031
storiesOf('Checkbox', module)
32+
.add('with medium', () => {
33+
const value = true;
34+
const children = text('label', 'My Checkbox Label');
35+
const onCheckboxChange = action('toggle');
36+
37+
return (
38+
<Viewport name="medium">
39+
<CheckboxStateful value={value} onCheckboxChange={onCheckboxChange}>
40+
{children}
41+
</CheckboxStateful>
42+
</Viewport>
43+
);
44+
})
45+
.add('with iphone6 Plus', () => {
46+
const value = true;
47+
const children = text('label', 'My Checkbox Label');
48+
const onCheckboxChange = action('toggle');
49+
50+
return (
51+
<Viewport name="iphone6p">
52+
<CheckboxStateful value={value} onCheckboxChange={onCheckboxChange}>
53+
{children}
54+
</CheckboxStateful>
55+
</Viewport>
56+
);
57+
})
3158
.add('with checked', () => {
3259
const value = true;
3360
const children = text('label', 'My Checkbox Label');

0 commit comments

Comments
 (0)