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

Start Storybook and react components additions #334

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
aa397ab
revert postcss and postcss plugins to version 7
dalecreativ Feb 19, 2021
ec93827
feat: add storybook react starter with examples and test spinning wit…
dalecreativ Feb 19, 2021
0786a2c
add foundations vars, global and typogrpahy as dependencies to use i…
dalecreativ Feb 19, 2021
15b2988
feat: add test blockquote component with styles
dalecreativ Feb 19, 2021
b9fc499
remove test stories from storybook install
dalecreativ Feb 19, 2021
1d9d1c4
add storybook addon packages
dalecreativ Feb 19, 2021
9467ed4
feat: start coopTheme and storybook config updates
dalecreativ Feb 19, 2021
4c3006f
Merge branch 'master' into pcss7-storybook-test
dalecreativ Feb 22, 2021
41a2b98
add eslint react plugin to deps
dalecreativ Feb 22, 2021
564100f
update eslint.base
dalecreativ Feb 22, 2021
746e3d7
add rules to eslint ignore
dalecreativ Feb 22, 2021
a890f6f
add jsx extension to lint:js script
dalecreativ Feb 22, 2021
f51f0b6
add react version latest to eslint settings
dalecreativ Feb 22, 2021
78d1189
add react peer and dev deps to blockquote package
dalecreativ Feb 22, 2021
2461205
rename extension from js to jsx for blockquote component
dalecreativ Feb 22, 2021
d1db497
add file extensions to imports in blockquote react component files
dalecreativ Feb 22, 2021
bf5aee4
remove setting import/resolve extensions
dalecreativ Feb 22, 2021
bf1dcff
add enzyme and react-test-renderer to blockquote dev deps
dalecreativ Feb 22, 2021
0f680ce
update eslintrc.base config
dalecreativ Feb 22, 2021
cb7cb3f
add react@16 react-dom@16 and enzym
dalecreativ Feb 23, 2021
f7a5dc8
update babel.config to include support for react
dalecreativ Feb 23, 2021
bd7e385
add setupTest script for enzyme support add mocks for css imports int…
dalecreativ Feb 23, 2021
afbb018
move test directory to root of package, causing errors when in src di…
dalecreativ Feb 23, 2021
12aad30
update import css to pcss in BlockQuote component
dalecreativ Feb 23, 2021
56a9176
rename and comment blockquote.css to .pcss
dalecreativ Feb 23, 2021
1807a89
fix update blockquote version
dalecreativ Feb 23, 2021
f545f78
add storybook webpack config, css-loader, style-loader to handle pcss…
dalecreativ Feb 23, 2021
31ad323
fix: revert and update package-lock to stop comments in dist
dalecreativ Feb 23, 2021
9064714
add component-block dist from build
dalecreativ Feb 23, 2021
3196b8c
update package-lock
dalecreativ Feb 23, 2021
24f9efe
add conditional for babel plugins, stop storybook converting pcss to …
dalecreativ Feb 24, 2021
4b0c49a
update package-lock after npm version global update
dalecreativ Feb 24, 2021
23fd539
fix: remove console.log from babel config
dalecreativ Feb 24, 2021
4c51046
update blockquote component dist after babel config update
dalecreativ Feb 24, 2021
494404e
blockquote component, update react and react-dom to v16.14.0 and remo…
dalecreativ Feb 24, 2021
d002b5c
test import and use blockquote compoennt from dist in a story
dalecreativ Feb 24, 2021
30c720b
update children prop to quote and update quote to string proptype, bu…
dalecreativ Mar 1, 2021
384380a
update order naming for components
dalecreativ Mar 1, 2021
c6ebf84
start update of readme for storybook and component creation
dalecreativ Mar 1, 2021
6c6f65e
update: start component-template package updates with react and story…
dalecreativ Mar 2, 2021
152c430
update README start storybook docs
dalecreativ Mar 2, 2021
d67feee
update component-template docs in storybook
dalecreativ Mar 2, 2021
9dc6a99
update README
dalecreativ Mar 2, 2021
b0a379f
add storybook-static directory to gitignore
dalecreativ Mar 3, 2021
aec0773
update babel versin with --legacy-peer-deps flag to stop postcssversi…
dalecreativ Mar 3, 2021
e1ada05
merge master
dalecreativ Mar 3, 2021
27e0906
run packages build for component-template after merge with master
dalecreativ Mar 3, 2021
cb0078b
update babel versions in design-system, stops lerna hoist warnings
dalecreativ Mar 3, 2021
59f9858
fix: temporary revert postcss to version 7 to stop lerna warning and …
dalecreativ Mar 4, 2021
5238be2
fix: rever gulp-postcss to version 8 for postcss 7 compatability
dalecreativ Mar 4, 2021
3b90c10
refactor: update props in blockquote stories
dalecreativ Mar 4, 2021
27fcdf1
Merge branch 'master' into pcss7-storybook-test
dalecreativ Mar 4, 2021
b662713
add static html examples for blockquote
dalecreativ Mar 8, 2021
512beff
update blockquote to use BEM classes, remove uneeded Camel casing of …
dalecreativ Mar 11, 2021
0cfcf5d
build blockquote dist with renamed files
dalecreativ Mar 11, 2021
4a22b44
fix: remove dist, file names not updating afte rchange in src
dalecreativ Mar 11, 2021
a5bca8b
rename files
dalecreativ Mar 11, 2021
83ca528
rename blockquote test files
dalecreativ Mar 11, 2021
08a7a74
update tests to reflect required props
dalecreativ Mar 11, 2021
9b54bf4
fix: add dist again after file renaming fail
dalecreativ Mar 11, 2021
2d85c29
chore: add readme and start documentation of react blockquote component
dalecreativ Mar 11, 2021
88a39bc
refactor: change order of args in blockquote stories
dalecreativ Mar 11, 2021
89ab4f7
chore: temp update circleci config for snapshot test updates
dalecreativ Mar 11, 2021
d551376
fix: typo in circleci.yml
dalecreativ Mar 11, 2021
1d07eac
update dist on blockquote component
dalecreativ Mar 12, 2021
372f71e
chore: remove design-system from babel ignore handled in cli command
dalecreativ Mar 12, 2021
a43cb2b
fix: add missing comma to story args object
dalecreativ Mar 12, 2021
af74a03
refactor: start migration to react-testing-library from enzyme and te…
dalecreativ Mar 12, 2021
0e7bd1d
update tests to use react-testing-library
dalecreativ Mar 15, 2021
4d6df04
refactor: remove deps for enzyme and react-test-renderer from root an…
dalecreativ Mar 15, 2021
0a8b907
ci: remove update snapshot step from circleci config
dalecreativ Mar 15, 2021
242a9ca
docs: update blockquote story docs and content for stories
dalecreativ Mar 17, 2021
d2aadf5
Merge branch 'master' into pcss7-storybook-test
dalecreativ Mar 23, 2021
228a8d4
merge master
dalecreativ Mar 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
storybook-static/**/*.js

6 changes: 6 additions & 0 deletions .eslintrc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ module.exports = {
extends: [
'airbnb-base',
'plugin:jest/recommended',
'plugin:react/recommended',
],
parserOptions: {
ecmaVersion: 12,
},
settings: {
react: {
version: 'detect',
},
},
plugins: ['jest'],
rules: {
'import/extensions': [
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
.sass-cache
.DS_STORE
*.log
storybook-static

# local env files
.env.local
Expand Down
4 changes: 4 additions & 0 deletions .storybook/coop-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions .storybook/coopTheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { create } from '@storybook/theming/create';
import Logo from './coop-logo.svg';

export default create({
base: 'light',
brandTitle: 'Coop UI',
brandImage: Logo,
});
26 changes: 26 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
"stories": [
"../packages/**/**/*.stories.mdx",
],
"addons": [
{
name: '@storybook/addon-docs',
options: {
configureJSX: true,
},
},
"@storybook/addon-links",
"@storybook/addon-essentials",
'@storybook/addon-storysource',
'@storybook/addon-a11y',
'@whitespace/storybook-addon-html',
'storybook-addon-designs/register',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.pcss$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
});
return config;
},
}
6 changes: 6 additions & 0 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { addons } from '@storybook/addons';
import coopTheme from './coopTheme';

addons.setConfig({
theme: coopTheme,
});
7 changes: 7 additions & 0 deletions .storybook/preview-body.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- .storybook/preview-body.html -->

<style>
body {
font-size: 1.2499999rem;
}
</style>
28 changes: 28 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import "@coopdigital/foundations-vars";
import "@coopdigital/foundations-typography";
import "@coopdigital/foundations-global";

export const parameters = {
options: {
showRoots: true,
storySort: {
order: ['Docs', ['Intro'], 'Foundations', 'Elements', 'Components', 'Patterns', 'Layout'],
},
},
actions: { argTypesRegex: "^on[A-Z].*" },
dependencies: {
// display only dependencies/dependents that have a story in storybook
// by default this is false
withStoriesOnly: true,

// completely hide a dependency/dependents block if it has no elements
// by default this is false
hideEmpty: true,
},
html: {
prettier: {
tabWidth: 4,
useTabs: false,
},
},
}
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
A mono-repository containing the design system website and foundations and component packages needed for designing and building digital services for the Co‑op. All packages can be found in the [packages](./packages) directory.

## Co-op Design system
The [design system](http://coop.co.uk/designsystem) is a sub folder of this repo and can be run locally and deployed to Heroku independently of the foundations and component packages.
The [design system](http://coop.co.uk/designsystem) is a sub folder of this repo and can be run locally and deployed to Heroku independently of the foundations and component packages.

[How to install, run and deploy the design system](https://github.com/coopdigital/coop-frontend/blob/master/design-system/README.md)


## Developing foundation and component packages for the design system
This repository uses [lerna](https://github.com/lerna/lerna) to automatically manage versioning of all the different packages. These are published as separate packages to [Co-op digital's NPM organisation](https://www.npmjs.com/org/coopdigital). These packages can be installed by digital teams as required as dependencies of their project.

Expand All @@ -16,3 +15,43 @@ This repository uses [lerna](https://github.com/lerna/lerna) to automatically ma
If you publish a new or amended component - create a release for the coop-frontend repo adding release notes to let everyone know what changes you have made and why.

The Slack github integration will let everyone on the #frontend and #designsystem channels know that there has been an update.

## Storybook react UI library
Storybook allows you to create and update react components within the `./packages` directory, using existing css and utility packages.
### **How to install, run and deploy the Co-op react storybook**
To run storybook locally, run the following commands:
- `npm ci`
- `npm run storybook`

Storybook should now be available at `http://localhost:6006`

### **Add components and stories to Storybook**
The two most common ways you will create components for react are, adding a react component to an existing package, or creating a brand new package.
#### **If you are creating a react compoennt for an existing package:**
- From the `./packages/component-template` directory, copy the `index.mjs`, `Component.jsx` and `Component.stories.mdx` files, and the `__test__` directory from the package
- Paste these into component directory you are working on and rename the component accordingly.
- Add your tests to `__test__/<Yourcomponent>.test.jsx`;
- Stories are added to `<Yourcomponent>.stories.mdx` files. Review the `Component.stories.mdx` example file and its comments for help with creating stories,
#### **If you are creating a new react component, follow these steps:**
- Make a copy of the `./component-template` directory in the `./packages` directory
- Rename the copied directory and its contained files, to your component name.
- Start adding tests and creating the component

### Info and useful links for Storybook and react
In storybook there are addons allowing you to view your component stories as raw html, have basic accessibility checks, link to the relevant designs within Figma, and more.

<!-- Co-op Storybook stories are broken into the following groups:
- Foundations - for foundation packages
- Elements - for element react/html packages
- Components - for component packages, (can be made from one or more element packages) -->
<!-- - (tbc) Patterns -->

#### Useful links
- [Storybook react docs](https://storybook.js.org/docs/react/get-started/introduction)
- [Component Story Format](https://storybook.js.org/docs/react/api/csf)
- [Storybook react mdx docs](https://storybook.js.org/docs/react/writing-docs/mdx)
- [Storybook react mdx api docs](https://storybook.js.org/docs/react/api/mdx)
- [MDX - Official site and docs](https://mdxjs.com/)
- [React - Getting Started](https://reactjs.org/docs/getting-started.html)
- [Jest docs](https://jestjs.io/docs/en/getting-started)
<!-- - [React testing library](https://testing-library.com/docs/react-testing-library/intro/) -->
2 changes: 2 additions & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

module.exports = {};
46 changes: 38 additions & 8 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
function isBabelCli(caller) {
return !!(caller && caller.name === "@babel/cli");
}

/** remove pcss to stop storybook build breaking */
const moduleExtensions = ['module-extension', {
cjs: '',
mjs: '',
jsx: '',
}];

/** when using the transform on pcss,
* it breaks our storybook build due to src component
* not being able to find .css extensions.
* Only add this extension transform on cli build */
const moduleExtensionsWithPcss = ['module-extension', {
cjs: '',
mjs: '',
jsx: '',
pcss: 'css',
}];

module.exports = (api) => {
const plugins = [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-object-rest-spread',
];

if (api.caller(isBabelCli) === true) {
plugins.push(moduleExtensionsWithPcss);
} else {
plugins.push(moduleExtensions);
}

api.cache(true);

const presets = [
Expand All @@ -9,19 +43,15 @@ module.exports = (api) => {
shippedProposals: true,
useBuiltIns: 'usage',
}],
'@babel/preset-react',
'@babel/preset-typescript',
];

const plugins = [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-optional-chaining',
['module-extension', {
cjs: '',
mjs: '',
}],
];
const ignore = ['**/*.stories.(js|mdx)'];

return {
presets,
plugins,
ignore,
};
};
22 changes: 11 additions & 11 deletions design-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,30 @@
"prismjs": "^1.23.0"
},
"devDependencies": {
"@babel/core": "^7.13.1",
"@babel/plugin-transform-runtime": "^7.13.7",
"@babel/preset-env": "^7.13.5",
"@babel/core": "^7.13.8",
"@babel/plugin-transform-runtime": "^7.13.9",
"@babel/preset-env": "^7.13.9",
"@babel/runtime": "^7.13.7",
"autoprefixer": "^10.2.4",
"autoprefixer": "^9.8.6",
"babel-plugin-module-extension": "^0.1.3",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"core-js": "^3.9.0",
"core-js": "^3.8.3",
"cssnano": "^4.1.10",
"gulp": "^4.0.2",
"gulp-buffer": "0.0.2",
"gulp-changed": "^4.0.2",
"gulp-connect": "^5.7.0",
"gulp-postcss": "^9.0.0",
"gulp-postcss": "^8.0.0",
"gulp-rename": "^2.0.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-tap": "^2.0.0",
"gulp-terser": "^2.0.1",
"postcss": "^8.2.6",
"postcss-calc": "^8.0.0",
"postcss-custom-media": "^8.0.0",
"postcss-custom-properties": "^11.0.0",
"postcss-import": "^14.0.0",
"postcss": "^7.0.35",
"postcss-calc": "^7.0.4",
"postcss-custom-media": "^7.0.8",
"postcss-custom-properties": "^9.2.0",
"postcss-import": "^12.0.1",
"postcss-nesting": "^7.0.1"
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default {
modulePathIgnorePatterns: [
'./node_modules/',
],
moduleNameMapper: {
'\\.(css|pcss)$': '<rootDir>/__mocks__/styleMock.js',
},
roots: [
'./packages',
],
Expand Down
Loading