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

Viewport Addon #1753

Merged
merged 33 commits into from
Sep 6, 2017
Merged

Viewport Addon #1753

merged 33 commits into from
Sep 6, 2017

Conversation

shilman
Copy link
Member

@shilman shilman commented Aug 28, 2017

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

  • Fix lint issues
  • Add unit tests
  • Add documentation and screenshots to readme.

Possible Features

  • Responsive hooks, basically add the ability to drag the ends of the iframe to change the size
  • Improve interaction with the iframe rather than just grabbing the iframe from the DOM add listeners to the iframe to allow us to interact with it

Screen Cap

viewport

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.

@codecov
Copy link

codecov bot commented Aug 28, 2017

Codecov Report

Merging #1753 into release/3.3 will increase coverage by 0.51%.
The diff coverage is 63.09%.

Impacted file tree graph

@@               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
Impacted Files Coverage Δ
addons/viewport/register.js 0% <0%> (ø)
addons/viewport/src/index.js 0% <0%> (ø)
addons/viewport/manager.js 0% <0%> (ø)
addons/viewport/src/components/Panel.js 100% <100%> (ø)
addons/viewport/src/components/styles.js 100% <100%> (ø)
addons/viewport/src/components/SelectViewport.js 15% <23.07%> (ø)
addons/viewport/src/components/RotateViewport.js 22.72% <35.71%> (ø)
addons/viewport/src/components/viewportInfo.js 36.36% <36.36%> (ø)
addons/viewport/src/manager.js 87.5% <87.5%> (ø)
lib/ui/src/modules/ui/configs/handle_routing.js 26.74% <0%> (ø) ⬆️
... and 47 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1ff05a...d51d0c7. Read the comment docs.

@saponifi3d
Copy link

saponifi3d commented Aug 29, 2017

@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 dist directories from addons, want me to fix that in this PR, a separate one, or is someone already fixing that?

Copy link
Member

@ndelangen ndelangen left a 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!

@@ -0,0 +1,5 @@
*.sw*
Copy link
Member

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

@@ -0,0 +1 @@
import '@storybook/addon-viewport/register';
Copy link
Member

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).
Copy link
Member

Choose a reason for hiding this comment

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

Awesome, great work!


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)
Copy link
Member

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?


Install the following npm module:

npm i -D @storybook/addon-viewport
Copy link
Member

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 */
Copy link
Member

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
Copy link
Member

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(() => {
Copy link
Member

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
Copy link
Member

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

Copy link
Member

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

Yes please!

Copy link
Member

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! 👍

const ADDON_ID = 'storybook-addon-viewport';
const PANEL_ID = `${ADDON_ID}/addon-panel`;

function addChannel(api) {
Copy link
Member

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?

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

@ndelangen
Copy link
Member

Looking good @saponifi3d, looks like we could merge this soon.

What do you think @usulpro @Hypnosphi ?

Copy link
Member

@Hypnosphi Hypnosphi left a comment

Choose a reason for hiding this comment

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

LGTM

@saponifi3d
Copy link

@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!!!

@danielduan danielduan added this to the v3.3.0 milestone Sep 6, 2017
@@ -0,0 +1,3 @@
// NOTE: loading addons using this file is deprecated!
// please use manager.js and preview.js files instead
require('./manager');
Copy link
Member Author

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?

Copy link
Member

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;
Copy link
Member Author

Choose a reason for hiding this comment

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

@saponifi3d define in constructor?

@shilman
Copy link
Member Author

shilman commented Sep 6, 2017

@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!

@ndelangen ndelangen merged commit 3fda202 into release/3.3 Sep 6, 2017
@ndelangen ndelangen deleted the 1624-viewport-addon branch September 6, 2017 18:43
@avaly
Copy link
Contributor

avaly commented Oct 19, 2017

What's the differences between this new addon and storybook-addon-scissors?

@@ -0,0 +1 @@
export { register } from './manager';
Copy link
Member

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');
Copy link
Member

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",
Copy link
Member

@Hypnosphi Hypnosphi Dec 27, 2017

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))

Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants