ScalingFunds Styleguide
Styleguide for reusable React components across our frontends
- Production: styleguide.scalingfunds.com
- Staging: styleguide.staging.scalingfunds.com
This repo consists of three main parts:
1. 🧩 A collection of individual React components to be re-used across all our frontends
- Based on Material UI
- Themable, to allow customizing the design for each client
1. 📦 An npm package named @scalingfunds/styleguide
- The interface between our frontends and the styleguide components
- Uses rollup.js for bundling the npm package
- Frontends can import components from the styleguide like so:
``ts`
import { Button, CheckBox, TextField } from '@scalingfunds/styleguide'
1. 📕 A storybook deployed to styleguide.scalingfunds.com
- For developing React components in isolation
- To serve as our shared source of truth for UI components between Design and Engineering
- Install dependencies: yarn installyarn start
- Run storybook server: S
- Open storybook: http://localhost:8080/
- Familiarize yourself with storybook's shortcuts for a faster development experience: http://localhost:8080/?path=/settings/shortcuts
- For example, try hitting to toggle the sidebar on and off
- Run yarn link:all in your local styleguide repoyarn build:watch:dev
- Run to start rollup in watch-mode so it recompiles the ./build folder on every file changeyarn link:styleguide
- In the frontend app, run yarn start
- In the frontend app, run
- Your frontend app should now be using your local styleguide and changing code in the styleguide should also hot-reload your frontend app 😎
---
1. Create a new folder for your component
- Most components will live in the root src/ foldersrc/Forms/
- For some components there are sub-categories, for example mui-overrides.js
1. Decide what kind of component it is:
1. Material UI component with styling changes only
- Example: Chip
- Create a file in which you tweak the component styles using the providedindex.js
classes from Material UI, for example: https://material-ui.com/api/button/#css
1. Material UI component with functionality changes (e.g. extending a MUI component with new features)
- Example: Button
- Create a file that wraps the original MUI component in our own React component and add any features you needstyles.js
- Create a if your component needs any custom stylingindex.js
1. A custom component (either combining several MUI components into a new one, or a component that isn't available in MUI)
- Example: UserName
- Create a file that implements the componentstyles.js
- Create a if your component needs any custom stylingstories.js
1. Create a file that renders the componentstories.js
- How to write stories
1. Navigate to your new component in storybook (creating a new story in in the right format will add it to the sidebar automatically)
1. Develop your component, all code changes are live-reloaded into storybook
A component's story page in storybook serves as the interface between Engineering and Design.
The better we document our components and allow the Design team to interact with them, the more productive our collaboration becomes.
1. Add documentation to your component's stories.jsstories.js
1. Add controls to your component's to allow the Design team to play with the component
- Controls are very useful for our design team to understand all the different states a component can be in
- How to use controls
To use a local version of the styleguide in a local Admin Dashboard or Investor Portal
we make use of yarn link. This allows us to symlink
the node_modules/@scalingfunds/styleguide folder in the Admin Dashboard to our local styleguide project.
#### From your local styleguide repo
1. Make required dependencies available to your local package registry: yarn link:allyarn link
- This will the local styleguide package as well as the styleguide's version of react, react-dom and @material-ui/coreadmin-dashboard
- This workaround is necessary due to this React issue
- Without this, the would throw a hooks error, because it thinks it has _two_ versions of Reactadmin-dashboard/node_modules/react
(one in and the other in admin-dashboard/node_modules/@scalingfunds/styleguide/node_modules/react)yarn build:watch
1. Start the styleguide in watch-mode: rollup
- This starts in watch-mode where every change will re-compile the styleguide npm package on the fly
and live-reload the consuming application (e.g. the admin dashboard)
#### From your local frontend app repo (e.g. admin-dashboard)
1. Symlink required dependencies from local package registry: yarn link:styleguideyarn start
- This will solve the duplicate dependency issue by using the styleguide's versions of React and Material UI
1. Start your frontend app:
1. All changes to styleguide components should now trigger a live-reload in your frontend app 🥳
---
- Navigate to the component in the Storybook sidebar, for example: http://localhost:8080/?path=/story/buttons-%F0%9F%94%98--play
- Open the component in your IDE:
- ./src/Button/index.js ➡️ The actual
---
- Every merge into master will automatically release a new version of the @scalingfunds/styleguide package to npmyarn upgrade --latest @scalingfunds/styleguide
- After a successful npm release, update the package version in the consuming frontend apps (e.g. admin dashboard):
- Run to install the latest version of the styleguide package
- Every merge into master` will automatically be deployed to https://staging.styleguide.scalingfunds.com
- Every successful npm package release will automatically trigger a production deploy to https://styleguide.scalingfunds.com
- You don't need to do anything :)