# fela-plugin-extend

> Fela plugin to extend style objects

Latest version **12.2.1** (published 2022-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install fela-plugin-extend
pnpm add fela-plugin-extend
yarn add fela-plugin-extend
bun add fela-plugin-extend
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 12.2.1 |
| Published | 2022-11-16 |
| First published | 2016-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2282 |
| Author | Robin Weser |
| Maintainers | rofrischmann, txhawks |
| Keywords | fela, fela-plugin, extend |

## Links

- npm: https://www.npmjs.com/package/fela-plugin-extend
- Repository: https://github.com/robinweser/fela
- Homepage: https://github.com/robinweser/fela#readme
- Issues: https://github.com/robinweser/fela/issues
- npm.io page: https://npm.io/package/fela-plugin-extend

## Dependencies (4)

- [isobject](https://npm.io/package/isobject.md) ^3.0.1
- [fast-loops](https://npm.io/package/fast-loops.md) ^1.0.0
- [fela-utils](https://npm.io/package/fela-utils.md) ^12.2.1
- [css-in-js-utils](https://npm.io/package/css-in-js-utils.md) ^3.0.0

## Recent versions

- 12.2.1 (latest) — 2022-11-16
- 12.0.0-rc.3.0 (next) — 2022-02-22
- 12.2.0 — 2022-07-06
- 12.1.2 — 2022-05-04
- 12.1.1 — 2022-04-07
- 12.1.0 — 2022-04-06
- 12.0.2 — 2022-02-23
- 12.0.1 — 2022-02-23
- 12.0.0 — 2022-02-23
- 12.0.0-y.0 — 2022-02-22
- 12.0.0-rc.2 — 2022-02-21
- 12.0.0-rc.1 — 2022-02-18
- 12.0.0-rc.0 — 2022-02-16
- 11.7.0 — 2021-09-24
- 11.6.1 — 2021-03-25
- … 93 more at https://npm.io/package/fela-plugin-extend/versions

## README

# fela-plugin-extend

<img alt="npm version" src="https://badge.fury.io/js/fela-plugin-extend.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/fela-plugin-extend.svg"> <a href="https://bundlephobia.com/result?p=fela-plugin-extend@latest"><img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/fela-plugin-extend.svg"></a>

Allows styles to be extended with other style objects. Supports a condition-based API.<br>
It automatically removes `null` and `undefined` values **before** merging styles.

## Installation

```sh
yarn add fela-plugin-extend
```

You may alternatively use `npm i --save fela-plugin-extend`.

## Usage

Make sure to read the documentation on [how to use plugins](https://fela.js.org/docs/latest/advanced/plugins#using-plugins).

```javascript
import { createRenderer } from 'fela'
import extend from 'fela-plugin-extend'

const renderer = createRenderer({
  plugins: [extend()],
})
```

## Example

### `extend: styleObject`

#### Input

```javascript
{
  color: 'red',
  extend: { backgroundColor: 'blue' }
}
```

#### Output

```javascript
{
  color: 'red',
  backgroundColor: 'blue'
}
```

### `extend: { condition, styleObject }`

#### Input

```javascript
{
  color: 'red',
  extend: {
    condition: props.bg === true,
    style: { backgroundColor: 'blue' }
  }
}
```

#### Output

Rendered using `{ bg: true }` as `props`:

```javascript
{
  color: 'red',
  backgroundColor: 'blue'
}
```

Rendered using `{ bg: false }` as `props`

```javascript
{
  color: 'red'
}
```

### `extend: [...]`

You can also mix basic and conditional extending.
It will extend the styles from left to right.

```javascript
{
  color: 'red',
  extend: [{
    fontSize: '12px',
    lineHeight: 1.5
  }, {
    condition: props.bg === true,
    style: { backgroundColor: 'blue' }
  }, {
    lineHeight: 1.2
  }]
}
```

#### Output

Using `{ bg: true }` as `props`:

```javascript
{
  color: 'red',
  fontSize: '12px',
  lineHeight: 1.2,
  backgroundColor: 'blue'
}
```

## License

Fela is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br>
Documentation is licensed under [Creative Commons License](http://creativecommons.org/licenses/by/4.0/).<br>
Created with ♥ by [@robinweser](http://weser.io) and all the great contributors.

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