A library of React components which follows HOC pattern, aiming at open for extension. For education, exploration and prototype purposes based on React v18.
Run the following command:
npm install otter-component-library
Yes, this module supports both mode. Under the dist folder there are 2 different outputs.
Visit npmjs.com/package/otter-component-library
It is just a choice of how to orgainse things. If you have a preferred way of structuring React components within a project you are of course welcome to do it however you like :)
The folder structure of this app is explained below:
.
├── src
│ ├── components
| │ ├── Button
| | │ ├── Button.tsx | The definition of component
| | │ ├── Button.test.tsx | Unit tests for this component
| | │ ├── Button.stories | The storybook presentation of this component
| | │ └── index.ts | The export to external for this component
| │ └── index.ts
│ └── index.ts
├── package.json
└── package-lock.json
- Install macOS nvm
- Install Windows nvm option 1:
- Install Windows nvm option 2:
- Version on
nvm
. - Commands supported by
nvm
- Display versions of
node
available fo install - Install the version of node to be used.
- The file
.nvmrc
at the root of the project directory should have the version of node you are using - node.js version
16.14.0
-
Install project defined
node
version- Assuming nvm (Node Version Manager) is installed.
- Assuming version of node defined in the
.nvmrc
file is installed (nvm install `cat .nvmrc`
)
-
Install
node modules
as defined in thepackage.json
file.
Refer to CONTRIBUTE.md
Instead of webpack, rollup is used. Typically webpack is used for bundling applications while rollup is particularly suited for bundling libraries (like ours). That's why I've chosen rollup. See the details in its config:
rollup.config.js
A plugin called terser is used to minify bundle and reduce the overall file size.
To test components I use React Testing Library, and to run those tests: Jest
jest.config.js
The bundle tool rollup has its plugin @rollup/plugin-typescript so all good. For instructing Jest, a Jest plugin called babel-jest that tells Jest to use Babel to handle JSX transformations. See config at:
babel.config.js
I override the default script inserted by Storybook init: build-storybook
This will tell Storybook to put the statically generated files into a docs-build
folder. We don't actually need to create a docs-build
folder in our repo as it will only be used temporarily for the deployment.
I am triggering the workflow only when files change inside the stories
and src/components
folders. You can customize the script accordingly if your stories and/or source files reside in another folder. Alternatively, you can trigger the workflow on every push by setting the on
section
For more details, see inside .github\workflows\storybook.yml
. For consistency, yarn
is used instead of npm
in the workflow.
The actual deployment is in github settings, which automatically takes /docs
to deploy to Github Page.
- Storybook
- Figma UX Component Dictionary
- More advanced components
- SCSS
- Automatically publish to NPM / Git module
- Host Storybook on Github Page
- Use Github's CICD (Github action)