-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Viewport Addon #1753
Viewport Addon #1753
Conversation
…ngle button to switch.. unclear if that's good or not though.
Viewport Addon
Codecov Report
@@ Coverage Diff @@
## release/3.3 #1753 +/- ##
===============================================
+ Coverage 22.8% 23.31% +0.51%
===============================================
Files 269 277 +8
Lines 5934 6031 +97
Branches 696 709 +13
===============================================
+ Hits 1353 1406 +53
- Misses 4080 4107 +27
- Partials 501 518 +17
Continue to review full report at Codecov.
|
… into 1624-viewport-addon
@shilman, i was able to fix-up the lint errors, add a readme, and wrote a bunch of unit tests (it's not 100% coverage - didn't think we needed tests for simple exports yet). i also noticed the code coverage reports also include the |
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.
If you need any help with making these changes, I'm very much willing to jump in and help! Just let me know. This feature is fantastic, a lot of people are going to be super happy with this!
addons/viewport/.gitignore
Outdated
@@ -0,0 +1,5 @@ | |||
*.sw* |
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.
Please move any necessary gitignore to the root
addons/viewport/.storybook/addons.js
Outdated
@@ -0,0 +1 @@ | |||
import '@storybook/addon-viewport/register'; |
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.
Please remove the dev setup for this addon, and use the cra-kitchen-sink to develop on.
|
||
Storybook Viewport Addon allows your stories to be displayed in different sizes and layouts in [Storybook](https://storybookjs.org). This helps build responsive components inside of Storybook. | ||
|
||
This addon works with Storybook for: [React](https://github.com/storybooks/storybook/tree/master/app/react) and [Vue](https://github.com/storybooks/storybook/tree/master/app/vue). |
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.
Awesome, great work!
addons/viewport/README.md
Outdated
|
||
This addon works with Storybook for: [React](https://github.com/storybooks/storybook/tree/master/app/react) and [Vue](https://github.com/storybooks/storybook/tree/master/app/vue). | ||
|
||
![Screenshot](docs/viewport.png) |
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.
Can we make this is full URL? so it shows up in places like npm?
addons/viewport/README.md
Outdated
|
||
Install the following npm module: | ||
|
||
npm i -D @storybook/addon-viewport |
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.
Use fenced code-blocks please like so:
npm i --save-dev @storybook/addon-viewport
@@ -0,0 +1,249 @@ | |||
/* global document */ |
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.
Please import any global from the global package.
@@ -0,0 +1,249 @@ | |||
/* global document */ | |||
import React from 'react'; | |||
import { shallow } from 'enzyme'; // eslint-disable-line import/no-extraneous-dependencies |
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.
We use a <name>.test.js
naming convention for tests.
describe('componentDidMount', () => { | ||
let previousGet; | ||
|
||
beforeEach(() => { |
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.
low priority:
I prefer to use beforeEach
and afterEach
functions as last resort only.
The reason being it becomes harder and hard to know/understand all the steps executed to setup a test.
Not directly necessary to get this PR merged, but I'd like to see a setup
function being used to get a shallow render in a specific state.
@@ -0,0 +1,91 @@ | |||
import React from 'react'; | |||
import { shallow } from 'enzyme'; // eslint-disable-line import/no-extraneous-dependencies |
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.
Please use the .test.js naming convention here too
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.
No use of .jsx file extention
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.
Should I change all .jsx
files to be .js
?
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.
Yes please!
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.
If you can rename all .spec.
to .test.
and all .jsx
to .js
I think this is good to go!
Let me know if you need any help! 👍
addons/viewport/src/manager.jsx
Outdated
const ADDON_ID = 'storybook-addon-viewport'; | ||
const PANEL_ID = `${ADDON_ID}/addon-panel`; | ||
|
||
function addChannel(api) { |
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.
Looks like these could be arrow functions? any reason to make them function declarations?
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.
not a huge thing - but from what i understand chrome specifically will do a better job at optimizing named functions like this over arrow functions. happy to update to be an arrow function instead :D
…the component in the vue example
Looking good @saponifi3d, looks like we could merge this soon. What do you think @usulpro @Hypnosphi ? |
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.
LGTM
@ndelangen just updated all the file names, let me know if there's anything else you wanted done (a lot of the comments just go smushed from the filename change). thanks so much for the review / feedback!!! |
@@ -0,0 +1,3 @@ | |||
// NOTE: loading addons using this file is deprecated! | |||
// please use manager.js and preview.js files instead | |||
require('./manager'); |
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.
@ndelangen @mnmtanish tangential to this PR but do you know when register
was deprecated? This is the first time I've seen it. And isn't it strange that all of our existing addons use a deprecated format (AFAIK)? Seems like something we should figure out?
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.
It's also weird that we actually recommend importing this file in addon's documentation
this.props.channel.removeListener('addon:viewport:update', this.changeViewport); | ||
} | ||
|
||
iframe = undefined; |
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.
@saponifi3d define in constructor?
@saponifi3d made a minor suggestion but I think it looks great to release for alpha. I'd like to generalize it in a way that also supports something like #1394 but I think we can do that in a later revision and it's better for us to get this out as part of the alpha. Looking forward to merging and putting out our first 3.3 alpha this week! |
What's the differences between this new addon and |
@@ -0,0 +1 @@ | |||
export { register } from './manager'; |
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.
manager.js
don't have this export
@@ -0,0 +1,3 @@ | |||
// NOTE: loading addons using this file is deprecated! | |||
// please use manager.js and preview.js files instead | |||
require('./manager'); |
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.
It's also weird that we actually recommend importing this file in addon's documentation
"name": "@storybook/addon-viewport", | ||
"version": "3.2.0", | ||
"description": "Storybook addon to change the viewport size to mobile", | ||
"main": "dist/index.js", |
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.
This file is broken (see #1753 (comment))
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.
#2589 fixes that by removing the index.js
file and using register.js
(or should it be manager.js
?) as main
Issue: #1624
What @saponifi3d did 😉
This is a fairly early PR of a viewport plugin which allows you to resize the iframe of storybook.
Remaining Tasks
Possible Features
iframe
rather than just grabbing the iframe from the DOM add listeners to the iframe to allow us to interact with itScreen Cap
How to test
FIXME
Is this testable with jest or storyshots?
Does this need a new example in the kitchen sink apps?
Does this need an update to the documentation?
If your answer is yes to any of these, please make sure to include it in your PR.