Get started with your Styleguide with great tools at your hand, utilizing create-react-app, react-styleguidist, react-styleguidist-visual, Jest and react-testing-library!
Maintained with ❤ by Eric Zieger and Sven Bischoff.
- clone the repo
- run
npm install
- run
npm start
to spin up the local dev server
- run
npm run create
(atm. only Linux/Mac) - follow the instructions shown in the terminal
- this repo ships with Jest and react-testing-library
- when running
npm run create
you will always get a super basic snaphsot test - add your own tests to the Component.test.js file
- run your tests via
npm run test-code
- you can also run a watcher via
npm run test-watch
- this repo ships with react-styleguidist-visual
- every iteration of the your pattern library will be checked visually against the former version, failing if there are changes
- run your visual tests via
npm run test-visual
- if the test returns a false positive (e.g. the changes marked are intended), just approve them via
npm run approve
- run
npm run build
- run
npm run build-styleguide
- copy the contents of the folder
/styleguide
to thehtdocs
-Directory of your server
- create bundler index file, where you're importing all components you want your bundle to include and export them as one object - e.g.
src/build-files/somefancyproject.js
:import { renderSomeFancyComponent } from '../SomeFancyComponent/SomeFancyComponent.js'; import { renderAnotherFancyComponent } from '../AnotherFancyComponent/AnotherFancyComponent.js'; export { renderSomeFancyComponent, renderAnotherFancyComponent };
- run the bundler for your project:
npm run bundleLegacy somefancyproject
- the .css and .js file created by the bundle command to your legacy app build pipeline or simply insert it inside your HTML
- after the code is loaded mount your components, via
_preactComponents.render<YOURCOMPONENTNAME>(props, container, callback)
e.g._preactComponents.renderSomeFancyComponent( {"foo": "bar"}, document.getElementById("foo"), function(){ console.log("Rendered foo!"); });
- the variable name can be changed by editing
library
insideconfig.output
in the file./scripts/bundle.js
- run
npm run build
See: https://react-styleguidist.js.org/
Command | Description |
---|---|
npm run start |
Starts the development server |
npm run build-styleguide |
Builds the documentation and puts it inside /styleguide |
npm run test |
Runs all tests (npm run test-code and npm run test-visual ) |
npm run test-code |
Runs all component tests with Jest |
npm run test-watch |
Starts the component test watcher |
npm run test-visual |
Runs all visual tests with react-styleguidist-visual |
npm run approve |
Approves all visual changes for react-styleguidist-visuals test |
npm run create |
Creates a new component with predefined skeleton files |
npm run transpile |
Transpiles the JavaScript to /dist for consuming in other projects |
npm run scss |
Copies the Sass to /dist for consuming in other projects |
npm run build |
Builds all components for consuming in other projects to /dist |
npm run bundleLegacy |
Build the bundles for consuming in other projects |