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

css-zero

v0.2.2

Published

Zero-runtime CSS-in-JS

Downloads

15

Readme

CSS-Zero

Features

  • All of the benefits of writing CSS-in-JS, but with zero runtime code
  • Write your styles with familiar CSS Syntax
  • Generates optimized, atomic CSS with no duplicated style rules
  • Style resolution based on order of application, rather than the cascade
  • Zero config server-side rendering for applications that support CSS Modules
  • Easy composition of styles, with property name collisions eliminated via static analysis
  • Theme support via CSS variables, allowing the cost of theming to be proportional to the size of the color palette
  • Fast parsing of styles, with CSS downloaded and parsed separately from JS.
  • Works without JavaScript, as styles are extracted at build-time.

These benefits are in addition to the more general benefits of using CSS-in-JS:

  • Scoped selectors to avoid accidental collision of styles
  • Styles co-located with your component reduces context switching
  • Refactor with confidence when changing/removing styles
  • Detect unused styles with EsLint, just like normal JS variables
  • Declarative dynamic styling with React

Installation

Since CSS-Zero has no runtime, it can be installed purely as a devDependency:

npm install css-zero --save-dev

Setup

The simplest way to run CSS-Zero in a React application is using our Babel Macro:

import {css, styled} from 'css-zero/macro';

For applications created using Create React App (which supports both Babel Macros and CSS Modules out-of-the-box), no further setup or configuration is needed.

For usage with other front-end frameworks, CSS-Zero can be set up with our babel-plugin.

Syntax

The basic usage of CSS-Zero looks like this:

import {css, styles} from 'css-zero';

// Write your styles using the `css` tag
const blue = css`
  color: blue;
`;

const base = css`
  color: red;
  font-size: 16px;
`;

// then use the `styles` helper to compose your styles and generate class names
export default props => <div className={styles(base, props.isBlue && blue)} />;

      ↓ ↓ ↓ ↓ ↓ ↓ Compiles to  ↓ ↓ ↓ ↓ ↓ ↓

export default props => <div className={(props.isBlue ? "x1vong5g" : "x1dqz7z3") + " " + "x1e4w2a9"} />

// along with a the following .zero.css file:
.x1vong5g {color:blue}
.x1dqz7z3 {color:red}
.x1e4w2a9 {font-size:16px}

Demo

Edit CSS-Zero Create React App Example

Inspiration