fela-plugin-unit
Always writing length values as string with a value applied seems not like the JavaScript way to do it. You can also use mathematics to process number values.
It is aware of unitless properties such as lineHeight
and also adds units to multiple values inside an array.
Installation
npm i --save fela-plugin-unit
Assuming you are using npm as your package mananger you can just npm install
.
Otherwise we also provide a UMD. You can easily use it via unpkg. It registers a FelaPluginUnit
global.
<script src="https://unpkg.com/fela-plugin-unit@3.0.2/dist/fela-plugin-unit.js"></script>
<script src="https://unpkg.com/fela-plugin-unit@3.0.2/dist/fela-plugin-unit.min.js"></script>
Usage
Make sure to read the documentation on how to use plugins.
import { createRenderer } from 'fela'
import unit from 'fela-plugin-unit'
const renderer = createRenderer({
plugins: [ unit() ]
})
Configuration
Parameters
Parameter | Value | Default | Description |
---|
unit | ch , em , ex , rem , vh , vw , vmin , vmax , px , cm , mm , in , pc , pt , mozmm | px | unit which gets applied |
Example
import { createRenderer } from 'fela'
import unit from 'fela-plugin-unit'
const unitPlugin = unit('em')
const renderer = createRenderer({
plugins: [ unitPlugin ]
})
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
{
width: 25,
lineHeight: 1.4,
height: '53'
}
Output
{
width: '25px',
lineHeight: 1.4,
height: '53px'
}
License
Fela is licensed under the MIT License.
Documentation is licensed under Creative Common License.
Created with ♥ by @rofrischmann and all the great contributors.