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 1
1
import _ from 'lodash'
2
2
import buildMediaQuery from '../util/buildMediaQuery'
3
3
4
- export default function ( config ) {
4
+ export default function ( { theme } ) {
5
5
return function ( css ) {
6
6
css . walkAtRules ( 'screen' , atRule => {
7
7
const screen = atRule . params
8
8
9
- if ( ! _ . has ( config . screens , screen ) ) {
9
+ if ( ! _ . has ( theme . screens , screen ) ) {
10
10
throw atRule . error ( `No \`${ screen } \` screen found.` )
11
11
}
12
12
13
13
atRule . name = 'media'
14
- atRule . params = buildMediaQuery ( config . screens [ screen ] )
14
+ atRule . params = buildMediaQuery ( theme . screens [ screen ] )
15
15
} )
16
16
}
17
17
}
You can’t perform that action at this time.
0 commit comments