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

Commit

Permalink
Basic storybook implementation (#1636)
Browse files Browse the repository at this point in the history
* install & configure storybook (via magic npx script)

* fix indentation in storybook generated files

* eslint ignore generated storybook files (for now at least)

* unhide storybook folder, consistent with Gutenberg project

* demo story for one of our components (with no css/styles)

* hack in scss webpack config & add story for button:
- fixes scss imports breaking storybook build
- note scss / styling doesn't work yet
+ organise our component stories into folder

* git ignore storybook-static build folder

* pin dependencies for storybook

* piggy-back off main webpack config for storybook module.rules (for scss)

* use gutenberg (wp-components) styles in storybook

* use system font for storybook, consistent with wp-admin/gberg and reasonable default for components in front end

* add --ci flag to prevent storybook opening new browser tab…
- see also storybookjs/storybook#6201

* rename default stories to Default (following Gutenberg pattern)

* add story for ErrorPlaceholder

* failing ProductPreview story (committing to PR as an example for discussion)

* storybook for components/icons

* fix aliased dependencies in components for storybook:
append our webpack aliases to storybook webpack config

* basic story for PriceSlider (looks right but interaction broken)

* fix PriceSlider user interaction:
- PriceSlider expects client to handle onChange and pass in new min/max

* add comment about priceslider max/min (todoish)

* remove default stories from storybook scaffolding

* organise stories by module (aka folder in codebase)

* package-lock update after rebase

* remove unnecessary ignores (default stories are gone)

* delete experimental/risky/broken stories:
- icons components are changing in #1644
- we need to refactor/do more work to get ProductPreview working (settings globals)

* remove unnecessary import

* clarify PriceSlider component intended usage comment in story

* remove redundant wrapper divs from stories

* add common storybook addons (used by Gutenberg storybook)

* rebuild package.lock after rebase

* remove unnecessary wrapper div

* package fixes after rebase

* add configuration for storybook source loader

* add decorators for a11y and knobs plugins

* remove unnecessary react import & import useState from WP

Co-authored-by: Darren Ethier <[email protected]>
  • Loading branch information
haszari and nerrad authored Jan 30, 2020
1 parent 6af18b4 commit 1f30102
Show file tree
Hide file tree
Showing 11 changed files with 8,919 additions and 1,721 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ tests/cli/vendor
/build/
bin/languages
woocommerce-gutenberg-products-block.zip
storybook-static/
11 changes: 11 additions & 0 deletions assets/js/base/components/button/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Internal dependencies
*/
import Button from '../';

export default {
title: 'WooCommerce Blocks/@base-components/Button',
component: Button,
};

export const Default = () => <Button>Buy now</Button>;
42 changes: 42 additions & 0 deletions assets/js/base/components/price-slider/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* External dependencies
*/
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import PriceSlider from '../';

export default {
title: 'WooCommerce Blocks/@base-components/PriceSlider',
component: PriceSlider,
};

export const Default = () => {
// PriceSlider expects client to update min & max price, i.e. is a controlled component
const [ min, setMin ] = useState( 1000 );
const [ max, setMax ] = useState( 5000 );
return (
<PriceSlider
minPrice={ min }
maxPrice={ max }
onChange={ ( values ) => {
setMin( values[ 0 ] );
setMax( values[ 1 ] );
} }
minConstraint={ 1000 }
maxConstraint={ 5000 }
step={ 250 }
currency={ {
code: 'nzd',
symbol: '$',
thousandSeparator: ' ',
decimalSeparator: '.',
minorUnit: 2,
prefix: '$',
suffix: '',
} }
/>
);
};
53 changes: 53 additions & 0 deletions assets/js/base/components/read-more/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Internal dependencies
*/
import ReadMore from '../';

export default {
title: 'WooCommerce Blocks/@base-components/ReadMore',
component: ReadMore,
};

export const Default = () => (
<ReadMore maxLines={ 2 }>
<h1>
No! Alderaan is peaceful. We have no weapons. You can&apos;t
possibly…
</h1>
<p>
As you wish. But with the blast shield down, I can&apos;t even see!
How am I supposed to fight? Look, I ain&apos;t in this for your
revolution, and I&apos;m not in it for you, Princess. I expect to be
well paid. I&apos;m in it for the money.
</p>
<p>
You mean it controls your actions?
<strong>
{ ' ' }
She must have hidden the plans in the escape pod.
</strong>{ ' ' }
<em>
Send a detachment down to retrieve them, and see to it
personally, Commander.
</em>
There&apos;ll be no one to stop us this time!
</p>
<h2>Escape is not his plan. I must face him, alone.</h2>
<ol>
<li>Partially, but it also obeys your commands.</li>
<li>
Leave that to me. Send a distress signal, and inform the Senate
that all on board were killed.
</li>
<li>
A tremor in the Force. The last time I felt it was in the
presence of my old master.
</li>
</ol>
<aside>
<a href="http://fillerama.io">
Content from http://fillerama.io &quot;Star Wars&quot;
</a>
</aside>
</ReadMore>
);
19 changes: 19 additions & 0 deletions assets/js/components/error-placeholder/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Internal dependencies
*/
import ErrorPlaceholder from '../';

export default {
title: 'WooCommerce Blocks/components/ErrorPlaceholder',
component: ErrorPlaceholder,
};

export const Default = () => (
<ErrorPlaceholder
error={ {
message:
'Unfortunately, we seem to have encountered a slight problem',
type: 'general',
} }
/>
);
Loading

0 comments on commit 1f30102

Please sign in to comment.