-
-
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: Make the addon configurable #3099
Conversation
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.
Congrats on your first PR! Great work.
|
||
// deprecated usage of infoAddon | ||
import infoAddon from '@storybook/addon-info'; | ||
|
||
import viewports from './viewports.json'; |
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.
I think that you need to move the example to the official-storybook
. @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.
Yes, that would be right
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.
@igor-dv @Hypnosphi I moved it to official-storybook
addons/viewport/src/preview/index.js
Outdated
import addons from '@storybook/addons'; | ||
import { ADD_VIEWPORTS_EVENT_ID, SET_VIEWPORTS_EVENT_ID } from '../shared'; | ||
|
||
export function init() {} |
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.
What is this for?
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.
I couldn't find a clear API documentation describing the preview API's, so I decided to follow the same approach as 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.
Got it, but this method is a bit misleading, so let's remove it.
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.
I removed it
Codecov Report
@@ Coverage Diff @@
## master #3099 +/- ##
==========================================
- Coverage 35.9% 35.89% -0.02%
==========================================
Files 437 440 +3
Lines 9485 9620 +135
Branches 912 906 -6
==========================================
+ Hits 3406 3453 +47
- Misses 5500 5572 +72
- Partials 579 595 +16
Continue to review full report at Codecov.
|
@igor-dv @Hypnosphi thanks for reviewing it |
|
||
this.setState({ | ||
viewports: { | ||
...initialViewports, |
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 it be current viewports instead?
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.
My intention was to make add
works by adding new viewports to the initial ones, but indeed your point makes more sense
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.
done
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 update addon documentation
@Hypnosphi I updated the documentation and addressed your comment regarding using previous |
@shilman, are we still merging the features? You wanted to lock in favor of the release. |
@shilman if we're feature-frozen, we probably should edit those lines on master and add 'feature request' there: https://github.com/storybooks/storybook/blob/master/dangerfile.js#L13-L15 |
I'm going to rebase with master again to not have those |
We're actually OK with those |
915aca0
to
e2ed8ca
Compare
@igor-dv @Hypnosphi @danielduan @ndelangen Could you please re-review it, apart from the conflicts, do you think this way of implementing it is better? |
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
Please fix eslint warnings and unit tests |
7e8b611
to
63d11ce
Compare
@Hypnosphi Are you aware of any historical reason behind making |
No I'm not. I think we're free to change it in this PR as it wasn't exposed to user before. On the other side, it may be convenient as it is now, if user wants to pick only particular viewports from defaults or override some values in a particular viewport:
|
@Hypnosphi This is absolutely a valid use-case. The reason why this question is popped up, is that the order of |
@mshaaban088 can you please resolve the conflict? |
@Hypnosphi sure |
- By default, viewport addon is reading both initial viewports' set and default viewport from `INITIAL_VIEWPORTS` and `DEFAULT_VIEWPORT` respectively which are exported by the addon - `configure` function is exported which accepts an object with `defaultViewport` and `viewports` - Change the default viewport by setting `defaultViewport` property to the key of the viewport (e.g. `configure({ defaultViewport: 'iphone5' })`) - Replace the entire viewports by setting brand new viewports to `viewports` property (e.g. `configure({ viewports: { brandNewDevice: { ... } } })`) - Add custom viewports by first merging both the `INITIAL_VIEWPORTS` and your custom viewports, and then pass the result as `viewports` to configure function
Fix linting issues
@Hypnosphi done |
Note: This is my first open-source PR.
Edit
I addressed #2395 and the respective comment
Issue: Currently you cannot customize or add new viewports/devices as described in the README file
What I did
configure
function to easily customize the addondefault
option with a new viewport calledresponsive
to treat the default as 1st-class citizenviewport
addon to theofficial-storybook
exampleAdd new device
Use new list of devices
Change the default viewport
Change the default viewport per story
How to test
cd examples/official-storybook
yarn storybook
viewport
panelextra-viewports.json
fileIs this testable with jest or storyshots?
Yes
Does this need a new example in the kitchen sink apps?
No, I added it to the
official-storybook
alreadyDoes this need an update to the documentation?
Yes
If your answer is yes to any of these, please make sure to include it in your PR.