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

Components: Added a Storybook and some example stories for automattic/components #38496

Merged
merged 4 commits into from
Dec 19, 2019

Conversation

jameslnewell
Copy link
Contributor

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

image

Testing instructions

  • Run npm run components:storybook:start

@jameslnewell jameslnewell requested a review from a team as a code owner December 18, 2019 00:45
@matticbot
Copy link
Contributor

@jameslnewell jameslnewell added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 18, 2019
@matticbot
Copy link
Contributor

matticbot commented Dec 18, 2019

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~21 bytes added 📈 [gzipped])

name                 parsed_size           gzip_size
entry-login                +30 B  (+0.0%)       +4 B  (+0.0%)
entry-main                 +27 B  (+0.0%)       +0 B
entry-gutenboarding        +22 B  (+0.0%)      +17 B  (+0.0%)

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

name                   parsed_size           gzip_size
woocommerce                 +171 B  (+0.0%)      +81 B  (+0.0%)
domains                      +64 B  (+0.0%)      +18 B  (+0.0%)
email                        +56 B  (+0.0%)      +19 B  (+0.0%)
checkout                     +32 B  (+0.0%)      +15 B  (+0.0%)
wp-super-cache               +24 B  (+0.0%)       +8 B  (+0.0%)
hosting                      +24 B  (+0.0%)      +11 B  (+0.0%)
purchases                    +20 B  (+0.0%)       +7 B  (+0.0%)
site-blocks                  +16 B  (+0.0%)       +5 B  (+0.0%)
security                     +16 B  (+0.0%)       +3 B  (+0.0%)
privacy                      +16 B  (+0.0%)       +5 B  (+0.0%)
plans                        +16 B  (+0.0%)       +6 B  (+0.0%)
notification-settings        +16 B  (+0.0%)       +5 B  (+0.0%)
me                           +16 B  (+0.0%)       +5 B  (+0.0%)
help                         +16 B  (+0.0%)       +5 B  (+0.0%)
checklist                    +16 B  (+0.0%)       +5 B  (+0.0%)
account-close                +16 B  (+0.0%)       +5 B  (+0.0%)
account                      +16 B  (+0.0%)       +5 B  (+0.0%)

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

name                                                         parsed_size           gzip_size
async-load-my-sites-current-site-domain-warnings                   +16 B  (+0.0%)       +5 B  (+0.0%)
async-load-my-sites-checklist-wpcom-checklist-component-jsx        +16 B  (+0.0%)       +5 B  (+0.0%)
async-load-design-blocks                                           +16 B  (+0.0%)      +14 B  (+0.0%)
async-load-design                                                  +16 B  (+0.0%)       +8 B  (+0.0%)
async-load-reader-sidebar                                          +12 B  (+0.0%)       +5 B  (+0.0%)

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.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

"devDependencies": {
"@storybook/addon-actions": "^5.2.8",
"@storybook/preset-scss": "^1.0.2",
"@storybook/react": "^5.2.8"
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@jameslnewell jameslnewell Dec 18, 2019

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.

Copy link
Member

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

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?

Copy link
Contributor Author

@jameslnewell jameslnewell Dec 18, 2019

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

package.json Outdated Show resolved Hide resolved
<Button primary onClick={ handleClick }>
{ helloWorld }
</Button>
);
Copy link
Member

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.

Copy link
Member

@jsnajdr jsnajdr left a 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 🤝

@jameslnewell jameslnewell merged commit cf46a34 into master Dec 19, 2019
@jameslnewell jameslnewell deleted the add/storybook branch December 19, 2019 21:23
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants