Skip to content

Commit

Permalink
Merge pull request #3099 from mshaaban088/master
Browse files Browse the repository at this point in the history
viewport-addon: Make the addon configurable
  • Loading branch information
Hypnosphi authored Mar 20, 2018
2 parents c3d9a41 + af02d9a commit b2f0115
Show file tree
Hide file tree
Showing 24 changed files with 831 additions and 207 deletions.
97 changes: 91 additions & 6 deletions addons/viewport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@ or with yarn:

yarn add -D @storybook/addon-viewport

## Basic Usage

## Configuration

Import and use the `configure` function in your `config.js` file.

```js
import { configure } from '@storybook/addon-viewport';
```

### defaultViewport : String
----
Setting this property to, let say `iphone6`, will make `iPhone 6` the default device/viewport for all stories. Default is `'responsive'` which fills 100% of the preview area.

### viewports : Object
----
A key-value pair of viewport's key and properties for all viewports to be displayed. Default is [`INITIAL_VIEWPORTS`](src/shared/index.js)

## Examples

### Basic Usage

Simply import the Storybook Viewport Addon in the `addons.js` file in your `.storybook` directory.

Expand All @@ -26,12 +45,78 @@ import '@storybook/addon-viewport/register'

This will register the Viewport Addon to Storybook and will show up in the action area.

## FAQ

#### How do I add a new device?
### Use Custom Set of Devices

Unfortunately, this is currently not supported.
This will replace all previous devices with `Kindle Fire 2` and `Kindle Fire HD` by simply calling `configure` with the two devices as `viewports` in `config.js` file in your `.storybook` directory.

```js
import { configure } from '@storybook/addon-viewport';

const newViewports = {
kindleFire2: {
name: 'Kindle Fire 2',
styles: {
width: '600px',
height: '963px'
}
},
kindleFireHD: {
name: 'Kindle Fire HD',
styles: {
width: '533px',
height: '801px'
}
}
};

configure({
viewports: newViewports
});
```

#### How can I make a custom screen size?

Unfortunately, this is currently not supported.
### Add New Device

This will add both `Kindle Fire 2` and `Kindle Fire HD` to the list of devices. This is acheived by making use of the exported [`INITIAL_VIEWPORTS`](src/shared/index.js) property, by merging it with the new viewports and pass the result as `viewports` to `configure` function

```js
import { configure, INITIAL_VIEWPORTS } from '@storybook/addon-viewport';

const newViewports = {
kindleFire2: {
name: 'Kindle Fire 2',
styles: {
width: '600px',
height: '963px'
}
},
kindleFireHD: {
name: 'Kindle Fire HD',
styles: {
width: '533px',
height: '801px'
}
}
};

configure({
viewports: {
...INITIAL_VIEWPORTS,
...newViewports
}
});
```


### Change The Default Viewport

This will make `iPhone 6` the default viewport for all stories.

```js
import { configure } from '@storybook/addon-viewport';

configure({
defaultViewport: 'iphone6'
});
```
2 changes: 1 addition & 1 deletion addons/viewport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"storybook"
],
"license": "MIT",
"main": "register.js",
"main": "preview.js",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
Expand Down
7 changes: 7 additions & 0 deletions addons/viewport/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const preview = require('./dist/preview');

exports.configure = preview.configure;
exports.DEFAULT_VIEWPORT = preview.DEFAULT_VIEWPORT;
exports.INITIAL_VIEWPORTS = preview.INITIAL_VIEWPORTS;
exports.withViewport = preview.withViewport;
exports.Viewport = preview.Viewport;
119 changes: 0 additions & 119 deletions addons/viewport/src/components/Panel.js

This file was deleted.

19 changes: 0 additions & 19 deletions addons/viewport/src/components/tests/viewportInfo.spec.js

This file was deleted.

Loading

0 comments on commit b2f0115

Please sign in to comment.