Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Basic storybook implementation #1636

Merged
merged 35 commits into from
Jan 30, 2020
Merged

Basic storybook implementation #1636

merged 35 commits into from
Jan 30, 2020

Conversation

haszari
Copy link
Member

@haszari haszari commented Jan 23, 2020

Fixes #1601

This PR is an experiment. Goals:

  • Install and configure storybook for our repo.
  • Add a meaningful story for at least one component.

What is Storybook? It's developer tooling to document and develop components in isolation, outside of the context of your app. For us this means we can develop and test things like PriceSlider or QuantitySelector outside of WordPress + Woo (+ Woo Blocks Plugin) environment.

Why? Documenting our components allows us as developers to be explicit about the intended use and interface (props) of a component. Designers and product people can easily test and experience components in isolation, so that as a broader product team we can build up a library of consistent components for building new features or iterating on the UI. It also provides a nice way to review our components alongside those from other projects (e.g. Gutenberg, wc-admin).

Check out storybook docs here: https://storybook.js.org

Check out Gutenberg project storybook here: https://wordpress.github.io/gutenberg/

Screenshot

Screen Shot 2020-01-27 at 4 11 01 PM

What's working

  • Some stories to get us started:
    • Button, ReadMore and PriceSlider from js/base/components
    • ErrorPlaceholder and Icons from js/components
  • Component styles are used in storybook, with some base styles applied from @wordpress/components; we may need more base styles / resets to simulate a "typical" theme front end or wp-admin environment
  • We're using chunks of our webpack config directly, mixed-in with Storybook defaults; hopefully this is reasonably stable
  • npm run storybook to launch storybook server - open browser to http://localhost:6006/
  • npm run build-storybook to build a static storybook site to storybook-static folder (we could publish this somewhere, e.g. GitHub Pages)

What's not working

  • Woo runtime dependencies (i.e. globals) aren't available, and some components depend on them, in particular wcSettings (see ProductPreview for an example broken story). I'm thinking we handle this as a follow-up; we can still write useful stories for many components.

How to test the changes in this Pull Request:

  1. Clone this branch, npm install (a few new things).
  2. npm run storybook to run storybook dev server.
  3. Browse to http://localhost:6006 and browse component stories. Stories are alongside each component in a stories folder (similar to Gutenberg project).
  4. Write a story for a component :)

Changelog

Dev: Added Storybook for documenting internal components.

@haszari haszari requested a review from a team January 23, 2020 01:29
@haszari haszari self-assigned this Jan 23, 2020
@nerrad nerrad added tools Used for work on build or release tools. and removed status: in progress labels Jan 24, 2020
@haszari haszari requested review from senadir, nerrad and mikejolley and removed request for a team January 27, 2020 02:59
@haszari haszari changed the title Try/storybook Basic storybook implementation Jan 27, 2020
@haszari
Copy link
Member Author

haszari commented Jan 27, 2020

This PR has been rebased (package.json conflicts)

@nerrad nerrad added this to the 2.6.0 milestone Jan 27, 2020
Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

Great work @haszari ! This was working for me. I've left some feedback inline that can be addressed. Also, I'd like if we could add the same storybook addons as what gutenberg is using. All of them have great utility and it should be trivial to setup in this pull. That way going forward as we build and expand on stories we can utilize these add-ons. Having it configured from the get-go saves having to figure things out later.

  • @storybook/addon-docs: allows us to add extra docs for stories to help explain things further if needed.
  • @storybook/addon-knobs: allows for configuring variations of props fed to components in a story by the user (which can be useful for demonstrating and seeing various behaviour controlled via props).
  • @storybook/addon-storysource: displays the source of the story in the storybook which I think is super useful for seeing the code used for the story (which is another way for developers to learn how things are implemented).
  • @storybook/addon-viewport: This allows us to display stories in different sizes and layouts. Super useful for seeing responsive behaviour (does it behave as expected with breakpoints etc).
  • @storybook/addon-a11y: This adds some accessibility checks to stories. I think this can help us keep on top of any potential accessibility issues in our components.

Along with the potential followups already identified, I also think it'd be neat if (in a followup at some point) we could wire things up so that pulls trigger the creation of an accessible storybook that can be viewed along with the pull. This could potentially help with visual reviews of components as well (Gutenberg is doing something similar). But that's definitely not needed right away.

assets/js/base/components/button/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/stories/index.js Outdated Show resolved Hide resolved
assets/js/base/components/price-slider/stories/index.js Outdated Show resolved Hide resolved
assets/js/components/error-placeholder/stories/index.js Outdated Show resolved Hide resolved
assets/js/components/icons/stories/index.js Outdated Show resolved Hide resolved
assets/js/components/product-preview/sad-stories/index.js Outdated Show resolved Hide resolved
storybook/webpack.config.js Outdated Show resolved Hide resolved
@haszari haszari requested a review from a team as a code owner January 30, 2020 00:54
@haszari
Copy link
Member Author

haszari commented Jan 30, 2020

@nerrad Thanks for the feedback – now ready for a final review.

Note regarding addons – these are installed and configured (based on Gutenberg config) now. I've confirmed that they don't break the build and show up in the Storybook UI. I figure we'll need to revisit these in subsequent pulls as we add more stories - I haven't tested and configured all addons.

I did some brief testing and some aren't fully working out of the box:

  • a11y - the audit seems to never finish
  • storysource - never seems to find the story source

Rather than hold up merging this initial PR on investigating these addons, I suggest we merge and handle as follow up on the first few stories.

viewport works great out of the box. knobs and and docs need opt-in per story to do useful stuff, we should use when writing the next few stories :)

@haszari
Copy link
Member Author

haszari commented Jan 30, 2020

Looks like I need to rebase again. Keen to merge this ASAP!

append our webpack aliases to storybook webpack config
- PriceSlider expects client to handle onChange and pass in new min/max
- icons components are changing in #1644
- we need to refactor/do more work to get ProductPreview working (settings globals)
Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

I pushed a couple of commits that fixed the inoperative addons. I've added some comments for things that should be addressed. Once that's done, go ahead and merge (so pre-approving).

.eslintignore Outdated Show resolved Hide resolved
Comment on lines 1 to 5
/**
* External dependencies
*/
import React from 'react';

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not needed.

Comment on lines 1 to 4
/**
* External dependencies
*/
import { React, useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

React is a default export (so usage is wrong) and is not needed. useState should be imported from @wordpress/element.

Comment on lines 1 to 4
/**
* External dependencies
*/
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to import React. To save repeating this everywhere, this comment applies to everywhere. Importing is not needed because the JSX is handled via babel pragma.

@haszari haszari merged commit 1f30102 into master Jan 30, 2020
@haszari haszari deleted the try/storybook branch January 30, 2020 20:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tools Used for work on build or release tools.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add storybook for internal components.
3 participants