@apolitical/styleguide2
v7.6.11
Published
Reusable React components for Apolitical UIs
Downloads
515
Maintainers
Readme
Apolitical Styleguide
This project was bootstrapped with Create React Library.
All library files are located inside src/lib folder.
Inside src/demo folder, you can test your library while developing.
Available Scripts
In the project directory, you can run:
yarn figmagic
Reads the styles defined in design system on figma and re-creates the Token folder in the src folder.
Before running this file, you would need to make sure you have correct values in your .env. This can be found on lastpass under "styleguide .env"
There are some files within the Tokens folder that are not auto-generated so when you run the command you have to recreate them. They are:
- breakpoints.js file.
- index.js file to export all the files within that folder.
- mobileFontSizes.js export all mobile fonts
Tip: copy and paste these files somewhere before running the command
In the changelog, make a note of whats been added to the folder or removed so we can keep track. This is not created by default.
After the script is run, change the module.exports in the tokens directory to export default and fix any formatting changes.
yarn start
Runs the library in development mode. Open http://localhost:3000 to view it in the browser.
yarn run test
Runs the test watcher in an interactive mode.
yarn build
Builds the library for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
yarn start:storybook
Starts the storybook components explorer on port 6006. Storybook is hosted at https://apolitical.gitlab.io/node-modules/apolitical-styleguide/
yarn publish
Publishes the library to NPM.
Troubleshooting
Developing locally
You will probably run into an error while developing saying you cannot have two Reacts in one app. This resource explains the issue in detail and how to solve it by linking react.
When you make changes in the Styleguide, you need to run yarn build
in order for the changes to be reflected in the
UI using Styleguide
Adding a dependency
- Install the dependency with
yarn add
- Make sure it was added to the
dependencies
and it uses a strict version (without^
) inpackage.json
file - Copy it to the
peerDependencies
section inpackage.json
file - Add the dependency to the externals list in the
/config/webpack.config.js
file
Note: By default, only react
, react-dom
styled-components
are defined as devDependencies
and peerDependencies
, and also listed in the externals. That means these are not part of the bundle but they are required for Styleguide to work. Also, if you are adding a dependency used only for development (not used for your components), make sure you install it as a devDependencies
(with -D
).
Configurations
Jest
"identity-obj-proxy"
helps Jest understand and handle styling when running tests. It allows Jest to treat CSS Modules as objects with identity properties, making it easier to test components that import and use them.
".+\\.module\\.(css|sass|scss)$": "identity-obj-proxy",
".+/style.(css|sass|scss)$": "identity-obj-proxy"
These configurations are needed when we're testing components that use CSS Modules or stylesheets, as they ensure that the styles are correctly mocked and don't interfere with your unit tests.
Component library
The styleguide is being moved to frontend/modules/v2/packages/component-library
.