CSS Components for Astro
npm install astro-css-components⚠️ Very early in development, more of a proof of concept than a real thing at the moment ⚠️
Add "CSS Components" support to Astro, inspired by eleventy-assets. This allows you to for instance, add page specific CSS. In my personal blog, I use it to add the CSS needed for syntax coloring only to the page that have code in them
The API is currently.. not very good. Use at your own caution - it should works, however
_Page.astro_
``astro
---
import BaseLayout from "BaseLayout.astro"
import { CSSComponent } from "astro-css-components"
---
My super text
`
_BaseLayout.astro_
`astro
---
import { CSSComponent } from "astro-css-components"
---
Result
`html
Document
My super text
`API
The CSSComponent component takes the following props:
$3
Used to register a new component, it takes an object with the following attributes:
- name: Name of your component
- content: CSS style your component has
OR
- contentFile: File which contain your CSS, path must be relative from the root of your project
Unless used with global, the component will be tied to the current URL
Examples:
`jsx
``jsx
`#### global
By adding this props, you can make the component global, this mean you can call it from everywhere using getByName
Example:
`jsx
`#### conditional
By adding this props, you can only register the component when a certain condition is met
Example:
`jsx
`#### minify
By adding this props, the CSS will be minified through csso
Example:
`jsx
`$3
Get the components for the current URL, this get all the components registered for the current URL, to get a specific component, use getByName
Example:
`jsx
`$3
Get a specific component by name, this look in both the library for the current url and the global one
Example:
`jsx
``