# fela-plugin-custom-property

> Fela plugin to use custom properties

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

## Install

```sh
npm install fela-plugin-custom-property
pnpm add fela-plugin-custom-property
yarn add fela-plugin-custom-property
bun add fela-plugin-custom-property
```

## 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-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2281 |
| Author | Robin Weser |
| Maintainers | rofrischmann, txhawks |
| Keywords | fela, fela-plugin, custom property, mixin, cssinjs |

## Links

- npm: https://www.npmjs.com/package/fela-plugin-custom-property
- 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-custom-property

## Dependencies (2)

- [isobject](https://npm.io/package/isobject.md) ^3.0.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
- … 98 more at https://npm.io/package/fela-plugin-custom-property/versions

## README

# fela-plugin-custom-property

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

Sometimes it's handy to define some custom properties mostly used as shortcuts.

A custom property basically is just a plain function that takes a value as input and outputs an object of style declarations.

## Installation

```sh
yarn add fela-plugin-custom-property
```

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

## 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 customProperty from 'fela-plugin-custom-property'

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

### Configuration

In order to get custom properties resolved, you need to configure the plugin with all custom properties once.

```javascript
import { createRenderer } from 'fela'
import customProperty from 'fela-plugin-custom-property'

const sizeProperty = (size) => ({
  width: size + 'px',
  height: size + 'px',
})

const customPropertyPlugin = customProperty({
  // the key defines the used CSS property
  // the value references the resolving function
  size: sizeProperty,
})

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

## Example

Let's say we want to have a custom property `size` that accepts a single number which will then be transformed into both `width` and `height` with a `px` unit applied.

#### Input

```javascript
{
  size: 25
}
```

#### Output

```javascript
{
  width: '25px',
  height: '25px'
}
```

## 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-custom-property · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
