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

classno

v0.0.0-alpha.10

Published

> Use CSS in JS without messing with Babel or esbuild.

Downloads

3

Readme

classno

Use CSS in JS without messing with Babel or esbuild.

Introduction

classno is a CSS-in-JS library that doesn’t require you to have a custom Babel config or to install an esbuild plugin, nor to hack your JSX runtime. In some ways, it works like Tailwind.

  1. Parses your TypeScript source files.
  2. Collects the CSS.
  3. Merges all of the CSS into one file.

Known Limitations

  • Only works with source files with ESM import syntax.

Installation

npm

npm install -D classno

yarn

yarn add -D classno

pnpm

pnpm add -D classno

Setup

The .classno File

Create a .classno file in the root directory of your project with a content similar to this:

{
  "paths": ["src/**/*.ts", "src/**/*.tsx"],
  "out": "src/styles/main.css"
}

The paths option could be modified to include your target source files. Same for the out option if you want to change where the CSS goes.

Importing the Output File

Import the path you included in the out option to your app. It can be loaded both as a module or from the head using a <link /> tag.

Extending Scripts

Extend the scripts option of your package.json in a way like the following.

    "scripts": {
+       "dev": "concurrently \"classno --watch\" \"your dev command\"" 
-       "dev": "your dev command"
+       "build": "classno && your build command" 
-       "build": "your build command"
    }

If you’re going to use concurrently, don’t forget to install it to your devDependencies.

Usage

To use classno, import the default function exported from classno. There are two ways of using it:

  1. With a template literal that has an interpolation of a string literal at its beginning (e.g. `${"my-component"} ...`): The passed string literal must be a valid class name, and it will also be the returned value. The rest must be a valid CSS (or Stylus) block.
  2. With a template literal that has no interpolations (e.g. `...`): This must be valid CSS (or Sylus). No value will be returned.

Declaring a Class

import classno from "classno";

const myComponent = classno`${"my-component"}
  width: 100px;
  height: 100px;
  background-color: green;
`;

export default function MyComponent() {
  return <div className={myComponent}></div>;
}

Using Stylus Syntax

Like mentioned above, you can also use Stylus:

const myComponent = classno`${"my-component"}
  width: 100px;
  height: 100px;
  background-color: green;

  &:hover {
      opacity: 0.5;

      @media (prefers-color-scheme: dark) {
          & > p {
              text: blue;
          }
      }
  }
`;

This also works:

const myComponent = classno`${"my-component"}
  width 100px
  height 100px
  background-color green

  :hover
      opacity 0.5

      @media (prefers-color-scheme: dark)
          > p
              text blue
`;

Conditional Styles

Conditional styles can be applied like this:

const dropdown = classno`${"dropdown"}
  /* Your main styles here, perhaps some transition-duration? */
`;

const dropdownOpen = classno`${"dropdown-open"}
   /* Conditional styles */
`;

const dropdownClosed = classno`${"dropdown-closed"}
  /* Conditional styles */
`;

export default function Dropdown() {
  return (
    <div className={`${dropdown} ${open ? dropdownOpen : dropdownClosed}`}>
    </div>
  );
}

Global Styles

You can also declare global styles. Just don’t pass the class name:

classno`
  my_black = rgba(10, 10, 10, 0.8)

  apply-common-max-width()
    max-width 980px
    margin 0 auto
    width 100%

  html
    scroll-behavior smooth
`;

PS

The project is in its early stages, expect everything or nothing to change, and know that I am currently not sure if it is worth investing more time in.