-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Components: Added a Storybook and some example stories for automattic/components #38496
Conversation
Test live: https://calypso.live/?branch=add/storybook |
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~21 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~208 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~37 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
packages/components/package.json
Outdated
"devDependencies": { | ||
"@storybook/addon-actions": "^5.2.8", | ||
"@storybook/preset-scss": "^1.0.2", | ||
"@storybook/react": "^5.2.8" |
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.
Packages in monorepos managed by Lerna should never have devDependencies
. They should be all hoisted to the top-level package.json
. See also the Gutenberg setup which does it the right way.
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.
Also, please pin the @storybook/*
dependencies to exact versions and define a Storybook monorepo in the project's renovate.json
. That tells Renovate to always file only one PR to do all @storybook/*
updates at once.
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.
See also the Gutenberg setup which does it the right way.
Gutenberg has setup Storybook across all of their packages. In contrast in this PR I've only setup storybook for the @automattic/components
package because I want to test the components in isolation from the rest of Calypso.
I put the dependencies in packages/components/package.json
because, following the above reasoning, the Storybook dependencies were only relevant for the @automattic/components
package.
I can think of cases where devDependencies
should be used and avoiding hoisting is necessary, but this isn't one of them and I've updated the PR as requested.
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.
Lerna docs recommend hoisting dev dependencies to the top, it's not a Calypso-only convention.
The NPM script to run Storybook (npm run components:storybook:start
) is also in the top-level package.json
and relies on the start-storybook
binary being present in node_modules/.bin
. If you added the dependencies to the package and didn't duplicate them in the root, too, as you did, the binary would be in packages/components/node_modules/.bin/start-storybook
and the top-level NPM wouldn't find it.
<Button primary onClick={ handleClick }> | ||
{ helloWorld } | ||
</Button> | ||
); |
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.
When clicking on the "Is Primary" option in the storybook, the expected styles are not applied. Can Storybook deal with styles imported as import './style.scss'
? Does the webpack config that it uses support the scss-loader
and style-loader
?
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've already added support for SCSS and you can see the black outline styles being applied in the screenshot above.
I (purposely) haven't imported the Calypso base styles where the CSS variables and other styles are being applied - the reason I haven't done this is that I want to develop and test these components as other A12s would find them - without the Calypso base styles.
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 see, the button styles are present, but the theme CSS that turns CSS variables into actual colors is not.
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.
Yep, that's intentional in order to demonstrate the isolated use of @automattic/components
.
4870f12
to
cafb069
Compare
c0ce668
to
e099f62
Compare
<Button primary onClick={ handleClick }> | ||
{ helloWorld } | ||
</Button> | ||
); |
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 see, the button styles are present, but the theme CSS that turns CSS variables into actual colors is not.
c97d833
to
61e9d20
Compare
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 good 👍 Thanks for addressing the review feedback 🤝
Changes proposed in this Pull Request
This PR adds a Storybook for
@automattic/components
./devdocs
already exists with a lot of overlap of the features provided by Storybook. The primary motivation behind adding a new thing in this PR is to make it easy to develop and test the@automattic/components
in isolation from Calypso and Calypso's global styles in order to ensure that@automattic/components
will work anywhere.I've intentionally kept this PR pretty minimal and will expand on this in future PRs e.g. build + deploy on CI, getting component styles working in isolation etc etc
Testing instructions
npm run components:storybook:start