CSS Modules
We use CSS Modules for our styles as the best way to include component-level CSS.
Basic Usage
CSS Modules can be used to import styles into a component. The imported object contains the class names as properties that can be used in the component.
Dynamic Classes
We use clsx
to combine multiple classes together based on state.
Injecting styles
To "pass state" from JSX to CSS, we can use CSS variables.
Type-Safe Styles
A common issue with CSS Modules is that the class names are not type-safe. We use a tcm
watcher to continuously generate hidden TypeScript files that insure the class names are correct. It is not possible to use a class name that does not exist and still have pnpm tsc
pass.
This also provides autocompletion for class names in VSCode.