# react-statics-styles

> React Statics Styles ====================

Latest version **3.1.0** (published 2015-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-statics-styles
pnpm add react-statics-styles
yarn add react-statics-styles
bun add react-statics-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 | 3.1.0 |
| Published | 2015-08-31 |
| First published | 2015-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Elie Rotenberg |
| Maintainers | elie.rotenberg |

## Links

- npm: https://www.npmjs.com/package/react-statics-styles
- Repository: https://github.com/elierotenberg/react-statics-styles
- Issues: https://github.com/elierotenberg/react-statics-styles/issues
- npm.io page: https://npm.io/package/react-statics-styles

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^3.9.3
- [should](https://npm.io/package/should.md) ^6.0.3
- [bluebird](https://npm.io/package/bluebird.md) ^2.9.30
- [change-case](https://npm.io/package/change-case.md) ^2.3.0

## Recent versions

- 3.1.0 (latest) — 2015-08-31
- 3.0.2 — 2015-06-17
- 3.0.1 — 2015-06-17
- 3.0.0 — 2015-06-16
- 2.0.0 — 2015-06-05
- 1.3.0 — 2015-05-25
- 1.2.0 — 2015-04-29
- 1.1.5 — 2015-02-19
- 1.1.4 — 2015-01-24
- 1.1.3 — 2015-01-22
- 1.1.2 — 2015-01-22

## README

React Statics Styles
====================

Ultra-light utility to help writing CSS inside your JS React components declarations.

Statically extracts CSS styles declared at the component class level and outputs a nicely formatted CSS string. It is then easing to pipe it to your CSS postprocessor of choice (eg. `postcss`).

Best friends with [`gulp-react-statics-styles`](https://github.com/elierotenberg/gulp-react-statics-styles) to make it work with your building pipeline.

Usage (without gulp)
====================

Declare `styles` as a `static` property of your component class (or using `statics` if you use vanilla `React.createClass`):
```js
class MyComponent extends React.Component {
  static styles = {
    '.MyComponent .MyComponent-item': {
      // you can put build-time calculations here
      fontSize: 0.8 * readFontSizeFromConfig() + 'px',
    }
  };

  render: function() {
    return <div className='MyComponent'>
      <div className='MyComponent-item'>This is smaller that usual.</div>
    </div>;
  },
};

// alternate syntax using the decorator
import { styles } from 'react-statics-styles';

@styles({
  '.MyComponent .MyComponent-item': {
    fontSize: 0.8 * readFontSizeFromConfig() + 'px',
  }
})
class MyComponent extends React.Component { ... }
```

Then pass one or more class definition(s) to `extractStyles(class)` or `extractAllStyles(array of class)`:
```js
import { extractStyles, extractAllStyles } from 'react-statics-styles';
extractStyles(MyComponent); // returns a CSS string
extractAllStyles([MyComponent1, MyComponent2, ...]);
```

Assuming that `readFontSizeFromConfig()` returns `10`, then the first line returns the string:

```css
/* @react-nexus-style MyComponent */
.MyComponent .MyComponent-item {
  font-size: 8px;
}
```

The decorator form supports passing additional options.

The only currently supported option is `prefix`, a static string which will be preprended to all the generated selectors.

```js
@styles({
  '.ES6ClassDecoratorWithPrefix': {
    minWidth: '334px',
  },
}, { prefix: '.MyApp '})
class ES6ClassDecoratorWithPrefix extends React.Component {
  static displayName = 'ES6ClassDecoratorWithPrefix';

  render() {
    return <div className='MyComponent' />;
  }
}
```

will yield

```css
/* @react-statics-styles ES6ClassDecoratorWithPrefix */
.MyApp .ES6ClassDecoratorWithPrefix {
  min-width: 334px;
}
```

Usage (with gulp)
=================

See [`gulp-react-statics-styles`](https://github.com/elierotenberg/gulp-react-statics-styles).


### Installation

This module is written in ES6/7. You will need `babel` to run it.

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