# classnames-plus

> A simple utility for conditionally joining classnames-plus together

Latest version **1.0.2** (published 2018-12-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install classnames-plus
pnpm add classnames-plus
yarn add classnames-plus
bun add classnames-plus
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-12-06 |
| First published | 2018-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Xu Tongbao |
| Maintainers | xutongbao |
| Keywords | react, css, classes, classname, classnames, classnames-plus, util, utility |

## Links

- npm: https://www.npmjs.com/package/classnames-plus
- Repository: https://github.com/xutongbao/classnames-plus
- Homepage: https://github.com/xutongbao/classnames-plus#readme
- Issues: https://github.com/xutongbao/classnames-plus/issues
- npm.io page: https://npm.io/package/classnames-plus

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-12-06
- 1.0.1 — 2018-12-06
- 1.0.0 — 2018-12-06

## README

classnames-plus
===========


A simple JavaScript utility for conditionally joining classNames together.

Install with [npm](https://www.npmjs.com/), [Bower](https://bower.io/), or [Yarn](https://yarnpkg.com/):

npm:
```sh
npm install classnames-plus --save
```

Bower:
```sh
bower install classnames-plus --save
```

Yarn (note that `yarn add` automatically saves the package to the `dependencies` in `package.json`):
```sh
yarn add classnames-plus
```

Use with [Node.js](https://nodejs.org/en/), [Browserify](http://browserify.org/), or [webpack](https://webpack.github.io/):

Old functions are still available:
```js
var classNamesPlus = require('classnames-plus');
classNamesPlus('foo', 'bar'); // => 'foo bar'
```


add functions:
```js
var classNamesPlus = require('classnames-plus');
var tabActiveIndex = 0;
var result = classNamesPlus({
  btn: true,
  'btn-pressed': false,
  'btn-over': true
}, 
{
  'fun': function() {
    return 'fun-plus';
  }
},
function () {
    if (0 === tabActiveIndex) {
      return 'active';
    } else {
      return '';
    }    
});
console.log(result);  // => 'btn btn-over fun-plus active'
```

in React:
```js
import React, { Component } from 'react'
import classNamesPlus from 'classnames-plus'
import './App.css'

class App extends Component {
  constructor(props) {
    super(props)
    this.state = {
      tabActiveIndex: 0
    }
  } 
  handleClick(tabActiveIndex) {
    this.setState({tabActiveIndex})
  } 
  render() {
    return (
      <ul>
        <li className={
            classNamesPlus('m-tab', () => {
              return this.state.tabActiveIndex === 0 ? 'active': ''
            })
          } 
          onClick={this.handleClick.bind(this, 0)}>css
        </li>
        <li className={
            classNamesPlus('m-tab', () => {
              return this.state.tabActiveIndex === 1 ? 'active': ''
            })
          } 
          onClick={this.handleClick.bind(this, 1)}>javascript
        </li> 
        <li className={
            classNamesPlus('m-tab', () => {
              return this.state.tabActiveIndex === 2 ? 'active': ''
            })
          } 
          onClick={this.handleClick.bind(this, 2)}>html
        </li>                
      </ul>
    );
  }
}

export default App;
```


## License

[MIT](LICENSE). Copyright (c) 2018 Xu Tongbao.

---
_Source: https://npm.io/package/classnames-plus · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
