Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/morajabi/rc-classnames

🍭 Manage classNames conditionally in React and JSX easily
https://github.com/morajabi/rc-classnames

classname jsx react

Last synced: 2 months ago
JSON representation

🍭 Manage classNames conditionally in React and JSX easily

Awesome Lists containing this project

README

        

# rc-classnames
[![Version](http://img.shields.io/npm/v/rc-classnames.svg)](https://www.npmjs.org/package/rc-classnames)
[![Build Status](https://travis-ci.org/morajabi/rc-classnames.svg?branch=master)](https://travis-ci.org/morajabi/rc-classnames)
[![David](https://img.shields.io/david/morajabi/rc-classnames.svg?maxAge=2592000)]()
[![GitHub issues](https://img.shields.io/github/issues/morajabi/rc-classnames.svg?maxAge=2592000?style=flat)]()
[![Maintenance](https://img.shields.io/maintenance/yes/2017.svg?maxAge=2592000)]()

[![JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

Manage classNames conditionally in React and JSX easily in **any format**

**There's also another classnames library which I didn't find when I was building this. It's more popular so take a look at it: [JedWatson / classnames](https://github.com/JedWatson/classnames)**

Install with npm:
```
npm install rc-classnames --save
```
Or with bower:
```
bower install rc-classnames
```
You can use CDN with minified version as well:
```

```
You can use with UMD as well.

We use [SemVer](http://semver.org) for versioning.

## Why react-classnames
Do you remember when you wanted a button in JSX to have diffrent states conditionally? You might end up with something like this:
```js

```
Or in ES6 syntax:
```js

```
Oh, It's very hard to read. But with rc-classnames those days are gone! It's intelligent! You can give it classNames in **Any Format** you want and it will generate a neat classname for you. Let's see how can we implement our button with rc-classnames:
```js
// ES6
import c from 'rc-classnames';

// CommonJS
var c = require('rc-classnames');

```
Even with Arrays and Nested Arrays:
```js

```
Or Arrays containing objects:
```js

```
See? Give your classNames in **Any Format** you wish!

## Usage Without react
While main purpose of this library is using with React, you **can** use it without react, just call the exported function.

First import `index.js` file with script tag:
```

```
`ReactClassNames` is available globally with Pure JS:
```
window.getElementById('someId').classList = ReactClassNames('hey', { 'foo': true, 'bar': false });
```
We support UMD as well.

## TODO
- Add HoC for custom `classNames` prop in React
- ...
If you want a feature or have an idea, fill an issue and tell me what you want.

## Have problems?
I hope you don't have any problem with the library, but if library have problems, fill an issue containing the case with a seperate Repo and me or other friends will answer ASAP. Please double check your code before sumbiting issues.

## License
Copyright (c) 2016 Mohammad Rajabifard

The MIT License (MIT)
```
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```