|
1 |
| -# container-query-toolkit |
| 1 | +# container-query-toolkit |
| 2 | + |
| 3 | +:wrench: Basic utilities to work with container query. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +``` |
| 8 | +npm i -S container-query-toolkit |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +```js |
| 14 | +const kit = require('container-query-toolkit'); |
| 15 | +// or |
| 16 | +import * as kit from 'container-query-toolkit'; |
| 17 | +// or |
| 18 | +import {matchQueries} from 'container-query-toolkit'; |
| 19 | +// or |
| 20 | +import matchQueries from 'container-query-toolkit/lib/matchQueries'; |
| 21 | + |
| 22 | +const query = { |
| 23 | + a: {minWidth: 400, maxWidth: 500, minHeight: 400, maxHeight: 500}, |
| 24 | + b: {minWidth: 500, maxWidth: 600, minHeight: 400, maxHeight: 500}, |
| 25 | + c: {minWidth: 400, maxWidth: 500, minHeight: 500, maxHeight: 600}, |
| 26 | + d: {minWidth: 500, maxWidth: 600, minHeight: 500, maxHeight: 600}, |
| 27 | +}; |
| 28 | + |
| 29 | +const result1 = matchQueries(query)({width: 300, height: 300}); |
| 30 | +expect(result1).toEqual({a: false, b: false, c: false, d: false}); |
| 31 | + |
| 32 | +const result2 = matchQueries(query)({width: 450, height: 450}); |
| 33 | +expect(result2).toEqual({a: true, b: false, c: false, d: false}); |
| 34 | + |
| 35 | +const result3 = matchQueries(query)({width: 450, height: 550}); |
| 36 | +expect(result3).toEqual({a: false, b: false, c: true, d: false}); |
| 37 | + |
| 38 | +const result4 = matchQueries(query)({width: 550, height: 450}); |
| 39 | +expect(result4).toEqual({a: false, b: true, c: false, d: false}); |
| 40 | + |
| 41 | +const result5 = matchQueries(query)({width: 550, height: 550}); |
| 42 | +expect(result5).toEqual({a: false, b: false, c: false, d: true}); |
| 43 | + |
| 44 | +const result6 = matchQueries(query)({width: 700, height: 700}); |
| 45 | +expect(result6).toEqual({a: false, b: false, c: false, d: false}); |
| 46 | +``` |
| 47 | + |
| 48 | +## API |
| 49 | + |
| 50 | +### `matchQueries(rules)(contentSize)` |
| 51 | + |
| 52 | +- `rules: {[key: string]: {minWidth?: number, maxWidth?: number, minHeight?: number, maxHeight?: number}}` |
| 53 | +- `contentSize: {height: number, width: number}` |
0 commit comments