Classix

2.2.12 · active · verified Sun Apr 19

classix is a highly optimized utility for conditionally joining CSS class names, focusing on speed and minimal bundle size. It distinguishes itself by exclusively accepting string expressions as arguments, diverging from common patterns in libraries like `clsx` and `classnames` which often support object syntax. This design choice simplifies the API, improves typing experience, and enables better performance and a smaller footprint. The current stable version is 2.2.12. The project maintains a frequent release cadence, primarily issuing patch updates for dependency upgrades and minor improvements, as seen in the recent changelog. It supports both ES Modules and CommonJS environments across all major browsers and Node.js versions, provides full TypeScript typing, and has zero runtime dependencies.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic class joining, conditional class application, and ternary operator usage for 'if/else' logic with `classix`.

import cx from "classix";

const isPrimary = true;
const isLarge = false;

// Basic usage: join multiple string arguments
console.log(cx("class1", "class2"));
// Expected output: "class1 class2"

// Conditional class application using boolean logic
console.log(cx("base-class", true && "active-class"));
// Expected output: "base-class active-class"

// Ternary operator for if-else class logic
console.log(cx(isPrimary ? "bg-primary-100" : "bg-secondary-100"));
// Expected output: "bg-primary-100"

// Combining static classes with multiple conditional expressions
const result = cx(
  "flex",
  isPrimary ? "bg-primary-100" : "bg-secondary-100",
  isLarge ? "m-4 p-4" : "m-2 p-2"
);
console.log(result);
// Assuming isPrimary is true and isLarge is false:
// Expected output: "flex bg-primary-100 m-2 p-2"

view raw JSON →