Skip to content

Commit

Permalink
Replace playground with Storybook
Browse files Browse the repository at this point in the history
Ran with the same command (`yarn dev`) this contains all the
functionality you know and love - hot reloading, a playground, percy
snapshots just with a different veneer
  • Loading branch information
BPScott committed Jan 8, 2019
1 parent 4be4e51 commit c7831a1
Show file tree
Hide file tree
Showing 40 changed files with 3,398 additions and 1,057 deletions.
6 changes: 2 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ jobs:
key: v3-npm-deps-{{ arch }}-{{ checksum "yarn.lock" }}-{{ checksum ".yarnclean" }}
paths:
- node_modules
- run: yarn run heroku-postbuild
- run: yarn start & sleep 20; yarn run test:percy
- run: yarn run test:percy
a11y:
docker:
- image: circleci/node:10.13.0-browsers
Expand All @@ -47,8 +46,7 @@ jobs:
key: v3-npm-deps-{{ arch }}-{{ checksum "yarn.lock" }}-{{ checksum ".yarnclean" }}
paths:
- node_modules
- run: yarn run heroku-postbuild
- run: yarn start & sleep 20; yarn run test:a11y
- run: yarn run test:a11y

workflows:
version: 2
Expand Down
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ node_modules
/styles.scss
/styles
/src/styles/polaris-tokens
/playground/build
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Take a look at [our best practices](https://github.com/Shopify/web-foundation/tr

After cloning Polaris React, run `yarn` to fetch its dependencies. Then you can run several commands:

- `yarn dev` runs a local development server and mounts `playground/Playground.tsx`
- `yarn dev` runs a Storybook server which includes a playground editable at `playground/Playground.tsx`
- `yarn test` runs the complete test suite
- `yarn test:coverage` runs tests and generates a test coverage report
- `yarn test <pattern>` runs tests with matching filenames
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ node_modules
/sandbox
.DS_Store
*.scss.d.ts
/playground/build
/src/styles/polaris-tokens
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ node_modules
/styles.scss
/styles
/src/styles/polaris-tokens
/playground/build

/package.json
/.github
6 changes: 6 additions & 0 deletions .storybook/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["shopify/web", {"modules": false}],
["shopify/react", {"hot": true}]
]
}
5 changes: 5 additions & 0 deletions .storybook/addons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// The order of these imports defines the order of the tabs in the addons panel
import '@storybook/addon-actions/register';
import '@storybook/addon-notes/register';
import '@storybook/addon-a11y/register';
import '@storybook/addon-options/register';
82 changes: 82 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
configure,
addDecorator,
getStorybook,
setAddon,
} from '@storybook/react';
import {setConsoleOptions} from '@storybook/addon-console';
import {withNotes} from '@storybook/addon-notes';
import {withOptions} from '@storybook/addon-options';
import {themes} from '@storybook/components';
import createPercyAddon from '@percy-io/percy-storybook';
import tokens from '@shopify/polaris-tokens';

import {
addPlaygroundStory,
generateStories,
hydrateExecutableExamples,
} from './stories-from-readme';

// addon-options
addDecorator(
withOptions({
name: 'Shopify Polaris Storybook',
url: '/',
hierarchySeparator: /\//,
hierarchyRootSeparator: /\|/,
theme: {
...themes.normal,
mainTextSize: '16',
mainBorderRadius: 0,
mainBackground: tokens.colorSkyLight,
mainTextColor: tokens.colorInk,
highlightColor: tokens.colorIndigoDark,
dimmedTextColor: tokens.colorInkLighter,
successColor: tokens.colorGreenDark,
failColor: tokens.colorRedDark,
warnColor: tokens.colorOrange,
// TODO more pretty brand colors?
// SEE https://github.com/storybooks/storybook/blob/next/lib/components/src/theme.js
},
}),
);

// addon-notes
addDecorator(withNotes);

// addon-console
setConsoleOptions((opts: any) => {
// When transpiling TS using isolatedModules, the compiler doesn't strip
// out exported types as it doesn't know if an item is a type or not.
// Ignore those warnings as we don't care about them.
// ignore color because the addon doesn't handle colored logs properly
opts.panelExclude = [
...opts.panelExclude,
/export .* was not found in/,
/color: #999933;/,
];
return opts;
});

// percy-storybook
const {percyAddon, serializeStories} = createPercyAddon();
setAddon(percyAddon);

// import all README.md files within component folders
const readmeReq = require.context(
'../src/components',
true,
/\/.+\/README.md$/,
);
function loadStories() {
addPlaygroundStory();

readmeReq.keys().forEach((filename) => {
const readme = readmeReq(filename).component;
generateStories(hydrateExecutableExamples(readme));
});
}

configure(loadStories, module);

serializeStories(getStorybook);
Loading

0 comments on commit c7831a1

Please sign in to comment.