Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ahmadawais/mxcn

172-byte utility library to use bothclsx and tailwind-merge in one go. Where class merging becomes a seamless dance, leaving style conflicts in the dust!
https://github.com/ahmadawais/mxcn

clsx tailwind tailwind-merge

Last synced: 1 day ago
JSON representation

172-byte utility library to use bothclsx and tailwind-merge in one go. Where class merging becomes a seamless dance, leaving style conflicts in the dust!

Awesome Lists containing this project

README

        

[![mxcn](./.github/logo.jpg)](https://github.com/AhmadAwais/mxcn)

# mxcn

[![DOWNLOADS](https://img.shields.io/npm/dt/mxcn?label=DOWNLOADS%20%20āÆ&colorA=21262D&colorB=30363D&style=flat)](https://www.npmjs.com/package/mxcn) [![Node.js CLI](https://img.shields.io/badge/-NodeCLI.com-gray.svg?colorA=21262D&colorB=30363D&style=flat)](https://NodeCLI.com/?utm_source=FOSS) [![Learn VSCode](https://img.shields.io/badge/-VSCODE.pro-gray.svg?colorA=21262D&colorB=30363D&style=flat)](https://VSCode.pro/?utm_source=FOSS) [![Sponsor](https://img.shields.io/badge/-Sponsor-gray.svg?colorA=21262D&colorB=30363D&style=flat)](https://github.com/ahmadawais/sponsor?utm_source=FOSS)
[![Follow @MrAhmadAwais on Twitter](https://img.shields.io/badge/[email protected]?colorA=21262D&colorB=30363D&style=flat)](https://twitter.com/mrahmadawais/)

> 172-byte utility library to use both[`clsx`](https://github.com/lukeed/clsx) and [`tailwind-merge`](https://github.com/dcastil/tailwind-merge) in one go. Where class merging becomes a seamless dance, leaving style conflicts in the dust!


- šŸ“¦ Use [`clsx`](https://github.com/lukeed/clsx) and [`tailwind-merge`](https://github.com/dcastil/tailwind-merge) in one go
- šŸ§æ Fully typed, built-in TypeScript declarations
- šŸŽ›ļø Works in modern browsers & Node >=12
- šŸŽ–ļø This module is available in three formats:
- šŸ“Ÿ ES Module: `dist/index.js`
- šŸ“¼ CommonJS: `dist/index.cjs`
- šŸŒ UMD: `dist/index.global.js`


[![šŸ“Ÿ](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/install.png)](./../../)

## Install

```sh
npm i mxcn
```


[![āš™ļø](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/usage.png)](./../../)

## Usage

```js
// Note: I called it `cn` as in className.
// Use ESM `import` statement syntax for ESM lib.
import cn from 'mxcn';
import { cn } from 'mxcn'; // Or named import.

// OR use CommonJS `require` syntax for CommonJS lib.
const cn = require('mxcn');

// Basic usage in React.

// Example: Combined, any example of tailwind-merge or clsx works.
cn('px-2 py-1 bg-red hover:bg-dark-red', null, true && 'p-3 bg-[#B91C1C]')
//=> 'hover:bg-dark-red p-3 bg-[#B91C1C]'

// Example: tailwind-merge
cn('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]')
//=> 'hover:bg-dark-red p-3 bg-[#B91C1C]'
// Why? px-2 and py-1 are removed because of p-3 that came afterwards.

// Example: clsx
// Strings (variadic)
cn('foo', true && 'bar', 'baz')
//=> 'foo bar baz'

// Objects
cn({ foo:true, bar:false, baz:isTrue() })
//=> 'foo baz'

// Objects (variadic)
cn({ foo:true }, { bar:false }, null, { '--foobar':'hello' })
//=> 'foo --foobar'

// Arrays
cn(['foo', 0, false, 'bar'])
//=> 'foo bar'

// Arrays (variadic)
cn(['foo'], ['', 0, false, 'bar'], [['baz', [['hello'], 'there']]])
//=> 'foo bar baz hello there'

// The famous Kitchen sink (with nesting)
cn('foo', [1 && 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya')
//=> 'foo bar hello world cya'
```

> For more please check the docs of [`clsx`](https://github.com/lukeed/clsx) and [`tailwind-merge`](https://github.com/dcastil/tailwind-merge). Cheers!


[![šŸ“](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/log.png)](changelog.md)

## Changelog

[āÆ Read the changelog here ā†’](changelog.md)


**KEY**: `šŸ“¦ NEW`, `šŸ‘Œ IMPROVE`, `šŸ› FIX`, `šŸ“– DOC`, `šŸš€ RELEASE`, and `šŸ¤– TEST`

> _I use [Emoji-log](https://github.com/ahmadawais/Emoji-Log), you should try it and simplify your git commits._


[![šŸ“ƒ](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/license.png)](./../../)

## License & Conduct

- MIT Ā© [Ahmad Awais](https://twitter.com/MrAhmadAwais/)
- [Code of Conduct](code-of-conduct.md)


[![šŸ™Œ](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/connect.png)](./../../)

## Connect


Twitter @MrAhmadAwaisĀ  (follow) To get #OneDevMinute development tips


LinkedIn @MrAhmadAwaisĀ (connect) On LinkedIn, you know what to do here


YouTube AhmadAwaisĀ (subscribe) Tech talks & #OneDevMinute videos


Blog: AhmadAwais.comĀ (read) In-depth & long-form technical articles



GitHub @AhmadAwaisĀ (follow) my free and open-source work


[![āš™ļø](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/usage.png)](./../../)

## Course Recommendation

### [NodeCLI.com][n] ā€” Learn to build Node.js CLI Automation

> Node CLI Automation development ā€” without wasting a thousand hours

After building hundreds of developer automation tools used by millions of developers, I am teaching exactly how you can do it yourself with minimum effective effort. Learn to build Node.js & JavaScript-based CLI (Command Line Interface) apps & npm packages. Automate the grunt work, do more in less time, impress your manager, make more salary, and help the community. I'm sharing it all in [this step-by-step 100-videos][n] course.

[![Node CLI Course](https://raw.githubusercontent.com/ahmadawais/stuff/master/nodecli/featured.jpg)][n]


[![šŸ‘Œ](https://raw.githubusercontent.com/ahmadawais/stuff/master/images/git/sponsor.png)](./../../)

## Sponsor

I ([Ahmad Awais](https://twitter.com/mrahmadawais/)) and my incredible wife ([Maedah Batool](https://twitter.com/MaedahBatool/)) are two engineers who fell in love with open source and then with each other. You can read more [about me here](https://ahmadawais.com/about). If you or your company use any of my projects or like what Iā€™m doing then consider backing me. I'm in this for the long run. An open-source developer advocate.

[![Sponsor Awais](https://raw.githubusercontent.com/ahmadawais/stuff/master/sponsor/sponsor.jpg)][s]

āÆāÆ Professional Development Courses ā†“

[![Node CLI Course](https://img.shields.io/badge/LEARN-Node%20CLI%20Automation-gray.svg?colorA=215732&colorB=44883e&style=for-the-badge)][n] [![VSCode Course](https://img.shields.io/badge/LEARN-VSCode%20Power%20User-gray.svg?colorA=655BE1&colorB=4F44D6&style=for-the-badge)][v] [![Node.js Course](https://img.shields.io/badge/LEARN-Node.js%20(free)-gray.svg?colorA=21262D&colorB=30363D&style=for-the-badge)][nj]

[s]: https://github.com/AhmadAwais/sponsor
[n]: https://NodeCLI.com?utm_source=github.com/ahmadawais/mxcn&utm_medium=referral&utm_campaign=profile
[v]: https://VSCode.pro?utm_source=github.com/ahmadawais/mxcn&utm_medium=referral&utm_campaign=profile
[nj]: https://NodejsBeginner.com?utm_source=github.com/ahmadawais/mxcn&utm_medium=referral&utm_campaign=profile
[g]: https://github.com/AhmadAwais