Fela plugin to extend style objects
npm install fela-plugin-extendAllows styles to be extended with other style objects. Supports a condition-based API.
It automatically removes null and undefined values before merging styles.
``sh`
yarn add fela-plugin-extend
You may alternatively use npm i --save fela-plugin-extend.
Make sure to read the documentation on how to use plugins.
`javascript
import { createRenderer } from 'fela'
import extend from 'fela-plugin-extend'
const renderer = createRenderer({
plugins: [extend()],
})
`
#### Input
`javascript`
{
color: 'red',
extend: { backgroundColor: 'blue' }
}
#### Output
`javascript`
{
color: 'red',
backgroundColor: 'blue'
}
#### 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'
}
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'
}
Fela is licensed under the MIT License.
Documentation is licensed under Creative Commons License.
Created with ♥ by @robinweser and all the great contributors.