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 🙏

© 2026 – Pkg Stats / Ryan Hefner

clazzx

v1.0.0

Published

ClazzX is a small typesafe utility library for composing CSS classes.

Readme

clazzx

Introduction

ClazzX is a small typesafe utility library for composing HTML classes. Unlike Vanilla Extract, Stitches, or CVA (all fantastic options) ClazzX takes a different approach, using state rather than variants to compose styles.

The classic approach is to create a series of variants that can be selected:

className={myButton({size: "small", intent="primary"})}
// AND
<Button size="small" intent="primary" />

In comparison, ClazzX models combinations of styles based on state.

className={MyButton.c({small: true, primary: true})}
// AND
<Button small primary />

This simplifies the logic of tying the styling of a component to complex state. Instead of a series of nested ternary operators, simple logical operators can be used to clearly define the appropriate styles.

className={MyButton.c({ 
	primary: true,
	loading: isLoading,
	error: isError 
})}
//AND
<Button primary loading={isLoading} error={isError}>

// Versus the traditional variant approach

className={myButton({
intent: isLoading ? "loading" 
: isError ? "error" 
: "primary"
})}
// AND
<Button intent={isLoading ? "loading" : isError ? "error" : "primary"}>

Installation

// Deno
import { ClazzX, clx } from "https://deno.land/x/clazzx/mod.ts"

// NPM
npm i clazzx

// Yarn
yarn add clazzx

Getting Started

A basic component

import { ClazzX } from 'clazzx'

class Input extends ClazzX {
	// the base class will always be applied
	base = "border rounded-md font-sans"

	small = "px-2 py-1 text-sm"
	md = "px-3 py-2 text-base"
	lg = "px-4 py-3 text-lg"

	// you can use both strings and string arrays freely
	primary = [
		"bg-primary",
		"border-primary-dark",
		"text-primary-content"
	]
	secondary = [
		"bg-secondary",
		"border-secondary-dark",
		"text-secondary-content"
	]
}

function MyCustomComponent(){
	return <input className={Input.c({ md: true, secondary: true })}/>
}

Default Classes

You can set default classes that are applied if nothing is passed to the classes method.

default = [this.md, this.secondary, "hover:scale-105"]

Compounds

If you want to conditionally apply styles when two or more states are true, you can create compound states.

compounds = [{
	state: ["primary", "large"],
	classes: "shadow-md"
}]

Ordering

Classes are applied in the order of the states.

className={btn.classes({rounded: true, square: true})}
// className="border-md border-none"
<Button primary secondary small medium>
// className="bg-primary bg-secondary text-sm text-md"

The order of classes works like this:

  1. base
  2. ...order based on state || default classes
  3. Compounds

StyleProps

StyleProps is an exported type that gives you access to the parameters of the style class. You can use this to strongly type components.

function MyButton({...props}: StyleProps<MyStyleClass>){}

Clx

clx is a variadic utility function that composes a string based on it's truthy inputs.

const a = clx(["bg-green-300", "text-md"])
// "bg-green-300 text-md"

const b = clx("bg-red-300", false && "text-red-700")
// "bg-red-300"

const c = clx(["p-4", false && "mt4"], "text-black", true && "font-bold")
// "p-4 text-black font-bold"

It can be imported or used as a static method on ClazzX.

Accessing fields

Each ClazzX instance exposes a static get() method to access the fields and methods of the class.

Examples

React Link

import { Style, StyleProps } from "clazzx"

class LinkStyles extends ClazzX {
	base: "font-link no-underline transition duration-200"

	primary: "text-link hover:text-link-hover"
	secondary: "text-secondary hover:text-secondary-hover"
	active: "text-active hover:text-active-hover underline"

	default = this.primary
}

interface Link {
	children: ReactNode 
	props: StyleProps<LinkStyles> & HTMLAttributes<HTMLAnchorElement>
}

function Link({children, ...props}: Link){
	return <a {...props} className={LinkStyles.c({...props})}>{children}</a>
}

function App(){
	const router = useRouter()
	// ...
	return (
		// ...
		<Link href="/about" secondary active={router.isCurrentPage}>
			My Link
		</Link>
		// ...
	)
}

With Globals

class GlobalStyles extends ClazzX {
	padding = {
		sm: "p-2",
		md: "p-4",
		lg: "p-6",
		dynamic: (i: number) => {
			`p-[${i*2}px]`
		}
	}
}

class Input extends GlobalStyles {
	sm = clx(this.padding.sm, "rounded-sm")
	md = clx(this.padding.md, "rounded-md")
	lg = clx(this.padding.lg, "rounded-lg")

	warning = "outline-red"

	compounds = [{
		state: ["sm", "warning"],
		classes: this.padding.dynamic(8)
	}]
}