# class-styles

> A simple utility for folding style objects like css classes

Latest version **1.0.0** (published 2017-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install class-styles
pnpm add class-styles
yarn add class-styles
bun add class-styles
```

## 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.0 |
| Published | 2017-02-10 |
| First published | 2016-08-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jed Watson, Tom McKenzie |
| Maintainers | grrowl |
| Keywords | react, css, classes, classname, classnames, class-styles, util, utility |

## Links

- npm: https://www.npmjs.com/package/class-styles
- Repository: https://github.com/grrowl/class-styles
- Homepage: https://github.com/grrowl/class-styles#readme
- Issues: https://github.com/grrowl/class-styles/issues
- npm.io page: https://npm.io/package/class-styles

## Dependencies (1)

- [object-assign](https://npm.io/package/object-assign.md) ^4.1.0

## 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.0 (latest) — 2017-02-10
- 1.0.0-rc.5 — 2016-08-23
- 1.0.0-rc.4 — 2016-08-11
- 1.0.0-rc.3 — 2016-08-10
- 1.0.0-rc.2 — 2016-08-09
- 1.0.0-rc.1 — 2016-08-09

## README

`classStyles`
===========

[![Version](http://img.shields.io/npm/v/class-styles.svg)](https://www.npmjs.org/package/class-styles)

Forked version of [classnames](https://github.com/JedWatson/classnames) to
support inline styles generated from a group of objects and "class" names
(really just root-level keys on the objects)

## Rules

* classStyles can be bound to an object or an array of objects. These objects
  should have a `{ key: styleObject, otherKey: otherStyle }` structure.
* Arguments are applied from left to right, overwriting defined styles as they
  are applied.
* String arguments are split by space (`" "`) and are applied in turn.
* Object arguments are applied as raw style objects.
* Arrays are recursed into, applying these rules to Strings, Objects and Arrays
  as they're encountered.
* Property values of `undefined`, `null`, `""`, `true` or `false` are not
  applied and will skip overwriting previously encountered properties.
  * `{ heading: { fontSize: "12pt" } }` followed by
  * `{ heading: { fontSize: null, color: "black" } }` will result in
  * `{ heading: { fontSize: "12pt", color: "black" } }`

## Usage

```js
import classStyles from 'class-styles'

// Define style objects
const markupStyles = { container: { backgroundColor: 'white', margin: '0px auto' } },
  otherStyles = { container: { color: 'red' }, outer: { margin: '10px' } }

// Bind style objects to classStyles. Can be either an object, or an array of objects.
const cx = classStyles.bind([ markupStyles, otherStyles ])

cx('container outer')
// => { margin: '10px', backgroundColor: 'white', color: 'red' }

cx('container', { paddingBottom: '5px' })
// => { backgroundColor: 'white', margin: '0px auto', paddingBottom: '5px' }

cx({ padding: '10px' }, 'not-exist')
// => { padding: '10px' }

// or, without using .bind
classStyles.call([ markupStyles, otherStyles ], 'outer')
// => { margin: '10px' }

```

## Installation

```sh
npm install class-styles --save
```

Alternatively, you can simply include `index.js` on your page with a standalone
`<script>` tag and it will export a global `classStyles` method, or define the
module if you are using RequireJS.

---

`class-styles` follows the [SemVer](http://semver.org/) standard for versioning.

There is also a [Changelog](https://github.com/grrowl/class-styles/blob/master/HISTORY.md).


## Polyfills needed to support older browsers

#### `classNames >=2.0.0`

`Array.isArray`: see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray) for details about unsupported older browsers (e.g. <= IE8) and a simple polyfill.

## License

[MIT](LICENSE). Copyright (c) 2016 Jed Watson, Tom McKenzie.

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