Fela plugin to resolve responsive array values
npm install fela-plugin-responsive-valueThis plugin adds support for responsive values as pioneered by styled-system where one passes an array of values that later resolved to respective media queries.
> Warning: This package might clash with fela-plugin-fallback-value and thus requires a list of whitelisted properties. We recommend using it before the fallback value.
``sh`
yarn add fela-plugin-responsive-value
You may alternatively use npm i --save fela-plugin-responsive-value.
Make sure to read the documentation on how to use plugins.
`javascript
import { createRenderer } from 'fela'
import responsiveValue from 'fela-plugin-responsive-value'
const renderer = createRenderer({
plugins: [responsiveValue()],
})
`
##### Parameters
| Parameter | Value | Default | Description |
| --------------- | ------------ | ------- | -------------------------------------------------------------------- |
| getMediaQueries | _(Function)_ | | Resolve the list of media queries used based on the values and props |
| properties | _(Object)_ | | A map of property-boolean pairs of which properties are resolved |
##### Example
`javascript
import { createRenderer } from 'fela'
import responsiveValue from 'fela-plugin-responsive-value'
// if we have 2 values, use default and large media query
// if we get 3, also use a tablet media query in between
const getMediaQueries = (values, props) => {
if (values.length === 2) {
return ['@media (min-width: 1024px)']
}
return ['@media (min-width: 800px)', '@media (min-width: 1024px)']
}
const renderer = createRenderer({
plugins: [
responsiveValue(getMediaQueries, {
padding: true,
margin: true,
}),
],
})
`
Using the above example code:
#### Input
`javascript`
{
margin: [0, 10]
padding: [5, 10, 15]
}
#### Output
`javascript``
{
margin: 0,
padding: 5,
"@media (min-width: 800px)": {
padding: 10
},
"@media (min-width: 1024px)": {
margin: 10,
padding: 15
}
}
Fela is licensed under the MIT License.
Documentation is licensed under Creative Commons License.
Created with ♥ by @robinweser and all the great contributors.