To reduce development overhead and synchronization issues between libraries, all new View Components include their corresponding CSS directly within the primer/view_components repository rather than in primer/css.
This approach ensures that component logic (Ruby) and component styling (CSS) are developed together. The CSS is built using PostCSS with the preset-env plugin, enabling modern CSS features like nested selectors, match functions, and container queries.
Integration Options
When consuming these styles in a production bundle, there are two primary patterns:
- Main Bundle Import: Including the compiled CSS file directly in your main stylesheet via:
@import "@primer/view-components/app/assets/styles/primer_view_components.css"; - Dynamic Loading (CSS Modules): Loading specific bundles for each component dynamically when the component is rendered on a page (planned/advanced usage).
/* Example of including the component styles in your main bundle */
@import "@primer/view-components/app/assets/styles/primer_view_components.css";