npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

astro-css-components

v0.4.0

Published

CSS Components for Astro

Downloads

12

Readme

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

Usage

Page.astro

---
import BaseLayout from "BaseLayout.astro"
import { CSSComponent } from "astro-css-components"
---

<CSSComponent register={{ name: "should-be-red", content: ".should-be-red {color: red;}" }} />

<BaseLayout>
  <article>
    <div class="should-be-red">My super text</div>
  </article>
</BaseLayout>

BaseLayout.astro

---
import { CSSComponent } from "astro-css-components"
---

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>

    <CSSComponent getForURL />
</head>
<body>
    <slot />q
</body>
</html>

Result

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>

    <style>.should-be-red {color: red;}</style>
</head>
<body>
  <article>
    <div class="should-be-red">My super text</div>
  </article>
</body>
</html>

API

The CSSComponent component takes the following props:

register

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:

<CSSComponent register={{ name: "should-be-red", content: ".should-be-red {color: red;}" }} />
<CSSComponent register={{ name: "code", contentFile: "src/theme/css/modules/code.css" }} />

global

By adding this props, you can make the component global, this mean you can call it from everywhere using getByName

Example:

<CSSComponent global register={{ name: "should-be-blue", content: ".should-be-blue {color: blue;}" }} />

conditional

By adding this props, you can only register the component when a certain condition is met

Example:

<CSSComponent register={{ name: "should-be-orange", content: ".should-be-orange {color: orange;}" }} conditional={page.loadCSSModules.includes("orange")} />

minify

By adding this props, the CSS will be minified through csso

Example:

<CSSComponent minify register={{ name: "should-be-purple", content: ".should-be-purple {color: purple;}" }} />

getForURL

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:

<CSSComponent getForURL />

getByName

Get a specific component by name, this look in both the library for the current url and the global one

Example:

<CSSComponent getByName="should-be-yellow" />