File tree Expand file tree Collapse file tree 2 files changed +50
-3
lines changed
Expand file tree Collapse file tree 2 files changed +50
-3
lines changed Original file line number Diff line number Diff line change 1+ import postcss from 'postcss'
2+ import plugin from '../src/lib/substituteScreenAtRules'
3+ import config from '../stubs/defaultConfig.stub.js'
4+
5+ function run ( input , opts = config ) {
6+ return postcss ( [ plugin ( opts ) ] ) . process ( input , { from : undefined } )
7+ }
8+
9+ test ( 'it can generate media queries from configured screen sizes' , ( ) => {
10+ const input = `
11+ @screen sm {
12+ .banana { color: yellow; }
13+ }
14+ @screen md {
15+ .banana { color: red; }
16+ }
17+ @screen lg {
18+ .banana { color: green; }
19+ }
20+ `
21+
22+ const output = `
23+ @media (min-width: 500px) {
24+ .banana { color: yellow; }
25+ }
26+ @media (min-width: 750px) {
27+ .banana { color: red; }
28+ }
29+ @media (min-width: 1000px) {
30+ .banana { color: green; }
31+ }
32+ `
33+
34+ return run ( input , {
35+ theme : {
36+ screens : {
37+ sm : '500px' ,
38+ md : '750px' ,
39+ lg : '1000px' ,
40+ } ,
41+ } ,
42+ separator : ':' ,
43+ } ) . then ( result => {
44+ expect ( result . css ) . toMatchCss ( output )
45+ expect ( result . warnings ( ) . length ) . toBe ( 0 )
46+ } )
47+ } )
Original file line number Diff line number Diff line change 11import _ from 'lodash'
22import buildMediaQuery from '../util/buildMediaQuery'
33
4- export default function ( config ) {
4+ export default function ( { theme } ) {
55 return function ( css ) {
66 css . walkAtRules ( 'screen' , atRule => {
77 const screen = atRule . params
88
9- if ( ! _ . has ( config . screens , screen ) ) {
9+ if ( ! _ . has ( theme . screens , screen ) ) {
1010 throw atRule . error ( `No \`${ screen } \` screen found.` )
1111 }
1212
1313 atRule . name = 'media'
14- atRule . params = buildMediaQuery ( config . screens [ screen ] )
14+ atRule . params = buildMediaQuery ( theme . screens [ screen ] )
1515 } )
1616 }
1717}
You can’t perform that action at this time.
0 commit comments