2.3.3 β€’ Published 2 years ago

classnames-clone v2.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ClassNames Clone

Created for fun, using the latest technologies that make it tiny and pretty fast

Not Another Clone πŸ₯±

  • Blazing Fast⚑
  • Teensy Small (204B) 🀏
  • Really Easy To Use πŸ‘Ά
  • Completely Type Safe πŸ‘·β€β™€οΈ

Installation

To install classnames-clone, use:

npm i classnames-clone

Well What Does It Do?

Ever wanted to conditionally render your classnames? Well before your code used to look like this:

<div
  className={
    `text-2xl italic ${isActive ? "bg-gray-400" : ""}`
  }
>
  Hmm not the best
</div>

Now it looks like this:

<div
  className={
    classNames('text-2xl italic', {"bg-gray-400" : isActive})
  }
>
  Yummy! πŸ₯ž
</div>

Usage:

import { classNames } from "classnames-clone";

// Joins strings
classNames("bg-white", "text-red-300") // ==> returns "bg-white text-red-300"

// Joins object keys with truthy values
classNames("bg-white", {"text-red-300": true}) // ==> returns "bg-white text-red-300"

// Even flattens out arrays
classNames("bg-white", ["text-red-300"]) // ==> returns "bg-white text-red-300"

// Ignores falsy values
classNames("bg-white", {"text-red-300": false}) // ==> returns "bg-white"

Opinions:

The official package for classnames allows numbers in it's type definition, however that doesn't make sense when it comes to writing classes so for this package's purpose that has been left out.

Perfect for conditional state class formatting like isActive etc.

This package was created using TSDX

2.3.3

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

1.1.0

2 years ago

1.6.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago