Skip to content

Commit 2f56d8c

Browse files
committed
Added "range" simple minMax and maxMin support
1 parent e884625 commit 2f56d8c

File tree

2 files changed

+94
-4
lines changed

2 files changed

+94
-4
lines changed

lib/create-sort.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// Private
33
// ----------------------------------------
44

5-
const minMaxWidth = /(!?\(\s*min(-device-)?-width)(.|\n)+\(\s*max(-device)?-width/i;
5+
const minMaxWidth =
6+
/(!?\(\s*min(-device)?-width)(.|\n)+\(\s*max(-device)?-width|\(\s*width\s*>(=)?(.|\n)+\(\s*width\s*<(=)?/i;
67
const minWidth = /\(\s*min(-device)?-width|\(\s*width\s*>(=)?/i;
7-
const maxMinWidth = /(!?\(\s*max(-device)?-width)(.|\n)+\(\s*min(-device)?-width/i;
8+
const maxMinWidth =
9+
/(!?\(\s*max(-device)?-width)(.|\n)+\(\s*min(-device)?-width|\(\s*width\s*<(=)?(.|\n)+\(\s*width\s*>(=)?/i;
810
const maxWidth = /\(\s*max(-device)?-width|\(\s*width\s*<(=)?/i;
911

1012
const isMinWidth = _testQuery(minMaxWidth, maxMinWidth, minWidth);

tests/index.spec.js

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,24 +328,52 @@ test(`multiline #1. mobile-first`, () => {
328328
`@media (min-width: 3em)
329329
and (max-width: 48.999em)`,
330330
`@media (min-width: 31em)
331-
and (max-width: 48.999em)`
331+
and (max-width: 48.999em)`,
332+
`@media (width > 48em)
333+
and (width < 59.999em)`,
334+
`@media (width > 40em)
335+
and (width < 47.999em)`,
336+
`@media (width > 15em)
337+
and (width < 47.999em)`,
338+
`@media (width > 2em)
339+
and (width < 47.999em)`,
340+
`@media (width > 20em)
341+
and (width < 47.999em)`,
342+
`@media (width > 3em)
343+
and (width < 48.999em)`,
344+
`@media (width > 31em)
345+
and (width < 48.999em)`
332346
];
333347

334348
const expectedOrder = [
335349
`@media (min-width: 2em)
336350
and (max-width: 47.999em)`,
351+
`@media (width > 2em)
352+
and (width < 47.999em)`,
337353
`@media (min-width: 3em)
338354
and (max-width: 48.999em)`,
355+
`@media (width > 3em)
356+
and (width < 48.999em)`,
339357
`@media (min-width: 15em)
340358
and (max-width: 47.999em)`,
359+
`@media (width > 15em)
360+
and (width < 47.999em)`,
341361
`@media (min-width: 20em)
342362
and (max-width: 47.999em)`,
363+
`@media (width > 20em)
364+
and (width < 47.999em)`,
343365
`@media (min-width: 31em)
344366
and (max-width: 48.999em)`,
367+
`@media (width > 31em)
368+
and (width < 48.999em)`,
345369
`@media (min-width: 40em)
346370
and (max-width: 47.999em)`,
371+
`@media (width > 40em)
372+
and (width < 47.999em)`,
347373
`@media (min-width: 48em)
348-
and (max-width: 59.999em)`
374+
and (max-width: 59.999em)`,
375+
`@media (width > 48em)
376+
and (width < 59.999em)`
349377
];
350378

351379
const expected = expectedOrder.join('\n');
@@ -386,6 +414,36 @@ test(`multiline #2. mobile-first`, () => {
386414
387415
388416
417+
`,
418+
`
419+
420+
@media (width > 48em)
421+
422+
423+
and (width < 59.999em)
424+
425+
`,
426+
`
427+
428+
429+
@media (width > 40em)
430+
431+
and (width < 47.999em)
432+
433+
434+
`,
435+
`
436+
437+
438+
439+
@media (width > 15em)
440+
441+
442+
443+
and (width < 47.999em)
444+
445+
446+
389447
`
390448
];
391449

@@ -402,6 +460,19 @@ test(`multiline #2. mobile-first`, () => {
402460
403461
404462
463+
`,
464+
`
465+
466+
467+
468+
@media (width > 15em)
469+
470+
471+
472+
and (width < 47.999em)
473+
474+
475+
405476
`,
406477
`
407478
@@ -411,6 +482,15 @@ test(`multiline #2. mobile-first`, () => {
411482
and (max-width: 47.999em)
412483
413484
485+
`,
486+
`
487+
488+
489+
@media (width > 40em)
490+
491+
and (width < 47.999em)
492+
493+
414494
`,
415495
`
416496
@@ -419,6 +499,14 @@ test(`multiline #2. mobile-first`, () => {
419499
420500
and (max-width: 59.999em)
421501
502+
`,
503+
`
504+
505+
@media (width > 48em)
506+
507+
508+
and (width < 59.999em)
509+
422510
`
423511
];
424512

0 commit comments

Comments
 (0)