React component library using:
- Rollup
- Sass
- TypeScript
- Storybook to help you create and show off your components
- Jest and React Testing Library enabling testing of the components
Created using this excellent resource▸
Minimal tests have been written for the components in this library.
npm run test
npm run build
To run a live-reload Storybook server on your local machine:
npm run storybook
To export your Storybook as static files:
npm run storybook:export
You can then serve the files under storybook-static
using S3, GitHub pages, Express etc.
npm run generate YourComponentName
This will generate:
/src
/components
/YourComponentName
YourComponentName.tsx
YourComponentName.stories.tsx
YourComponentName.test.tsx
YourComponentName.types.ts
YourComponentName.scss
The default templates for each file can be modified under util/templates
.
Don't forget to add the component to your index.ts
exports if you want the library to export the component!
This component library can be installed using npm link.
If you are getting errors like Invalid Hook Call Warning you may need to add the following to your webpack.config:
resolve: {
alias: {
"react/jsx-dev-runtime": "react/jsx-dev-runtime",
"react/jsx-runtime": "react/jsx-runtime",
"react": "react"
}
}
Check ../solo-viewer/config-overrides.js for how we solved this problem in an (unejected) create-react-app.
First, make sure you have an NPM account and are logged into NPM using the npm login
command.
Then update the name
field in package.json
to reflect your NPM package name in your private or public NPM registry. Then run:
npm publish
The "prepublishOnly": "npm run build"
script in package.json
will execute before publish occurs, ensuring the build/
directory and the compiled component library exist.
Usage of the component (after the library installed as a dependency into another project) will be:
import React from "react";
import { TestComponent } from "lavender-vtkjs";
const App = () => (
<div className="app-container">
<h1>Hello I'm consuming the component library</h1>
<TestComponent theme="primary" />
</div>
);
export default App;
I've found that it's helpful to export SASS variables to projects consuming the library. As such, I've added the rollup-plugin-copy
NPM package and used it to copy the src/typography.scss
and variables.scss
into the build
directory as part of the Rollup bundle process. This allows you to use these variables in your projects consuming the component library.
For example, let's say you installed lavender-vtkjs
into your project. To use the exported variables/mixins, in a SASS file you would do the following:
@import '~lavender-vtkjs/build/typography';
.example-container {
@include heading;
color: $vtkjs-white;
}