An open API service indexing awesome lists of open source software.

https://github.com/moishinetzer/classnames-clone


https://github.com/moishinetzer/classnames-clone

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

          

# 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:

```bash
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:
```js


Hmm not the best

```

Now it looks like this:
```js


Yummy! πŸ₯ž

```

### Usage:
```js
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](https://tsdx.io/)