|
| 1 | +# fela-plugin-responsive-value |
| 2 | + |
| 3 | +<img alt="npm version" src="https://badge.fury.io/js/fela-plugin-responsive-value.svg"> <img alt="npm downloads" src="https://img.shields.io/npm/dm/fela-plugin-responsive-value.svg"> <a href="https://bundlephobia.com/result?p=fela-plugin-responsive-value@latest"><img alt="Bundlephobia" src="https://img.shields.io/bundlephobia/minzip/fela-plugin-responsive-value.svg"></a> |
| 4 | + |
| 5 | +This plugin adds support for responsive values as pioneered by [styled-system](https://styled-system.com) where one passes an array of values that later resolved to respective media queries. |
| 6 | + |
| 7 | +## Installation |
| 8 | +```sh |
| 9 | +yarn add fela-plugin-responsive-value |
| 10 | +``` |
| 11 | +You may alternatively use `npm i --save fela-plugin-responsive-value`. |
| 12 | + |
| 13 | + |
| 14 | +## Usage |
| 15 | +Make sure to read the documentation on [how to use plugins](http://fela.js.org/docs/advanced/Plugins.html). |
| 16 | + |
| 17 | +```javascript |
| 18 | +import { createRenderer } from 'fela' |
| 19 | +import responsiveValue from 'fela-plugin-responsive-value' |
| 20 | + |
| 21 | +const renderer = createRenderer({ |
| 22 | + plugins: [ responsiveValue() ] |
| 23 | +}) |
| 24 | +``` |
| 25 | + |
| 26 | +### Configuration |
| 27 | +##### Parameters |
| 28 | +| Parameter | Value | Default | Description | |
| 29 | +| --- | --- | --- | --- | |
| 30 | +| getMediaQueries | *(Function)* | | Resolve the list of media queries used based on the values and props | |
| 31 | +| properties | *(Object)* | | A map of property-boolean pairs of which properties are resolved | |
| 32 | + |
| 33 | +##### Example |
| 34 | +```javascript |
| 35 | +import { createRenderer } from 'fela' |
| 36 | +import responsiveValue from 'fela-plugin-responsive-value' |
| 37 | + |
| 38 | +// if we have 2 values, use default and large media query |
| 39 | +// if we get 3, also use a tablet media query in between |
| 40 | +const getMediaQueries = (values, props) => { |
| 41 | + if (values.length === 2) { |
| 42 | + return ["@media (min-width: 1024px)"] |
| 43 | + } |
| 44 | + |
| 45 | + return ["@media (min-width: 800px)", "@media (min-width: 1024px)"] |
| 46 | +} |
| 47 | + |
| 48 | +const renderer = createRenderer({ |
| 49 | + plugins: [ |
| 50 | + responsiveValue(getMediaQueries, { |
| 51 | + padding: true, |
| 52 | + margin: true |
| 53 | + }) |
| 54 | + ] |
| 55 | +}) |
| 56 | +``` |
| 57 | + |
| 58 | +## Example |
| 59 | +Using the above example code: |
| 60 | + |
| 61 | +#### Input |
| 62 | +```javascript |
| 63 | +{ |
| 64 | + margin: [0, 10] |
| 65 | + padding: [5, 10, 15] |
| 66 | +} |
| 67 | +``` |
| 68 | +#### Output |
| 69 | +```javascript |
| 70 | +{ |
| 71 | + margin: 0, |
| 72 | + padding: 5, |
| 73 | + "@media (min-width: 800px)": { |
| 74 | + padding: 10 |
| 75 | + }, |
| 76 | + "@media (min-width: 1024px)": { |
| 77 | + margin: 10, |
| 78 | + padding: 15 |
| 79 | + } |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +## License |
| 84 | +Fela is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br> |
| 85 | +Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br> |
| 86 | +Created with ♥ by [@rofrischmann](http://rofrischmann.de) and all the great contributors. |
0 commit comments