1
+ import { assert } from '@ember/debug' ;
2
+
1
3
import {
2
4
lt as _lt ,
3
5
lte as _lte ,
@@ -7,39 +9,52 @@ import {
7
9
betweenRightClosed
8
10
} from './utils' ;
9
11
10
- function buildDefinition ( comparisonFunction ) {
12
+ function buildDefinition ( comparisonFunction , dimension = 'width' ) {
13
+ dimension = typeof dimension === 'string' ? dimension . toLowerCase ( ) : dimension ;
14
+
15
+ assert (
16
+ `Breakpoint definition dimensions must be a string defined as 'width' or 'height', received ${ dimension } ` ,
17
+ dimension === 'width' || dimension === 'height'
18
+ ) ;
19
+
11
20
return {
12
- comparison : comparisonFunction
21
+ comparison : comparisonFunction ,
22
+ dimension
13
23
} ;
14
24
}
15
25
16
- export function lt ( definedValue ) {
17
- return buildDefinition ( value => _lt ( value , definedValue ) ) ;
26
+ export function lt ( definedValue , { dimension } = { } ) {
27
+ return buildDefinition ( value => _lt ( value , definedValue ) , dimension ) ;
18
28
}
19
29
20
- export function lte ( definedValue ) {
21
- return buildDefinition ( value => _lte ( value , definedValue ) ) ;
30
+ export function lte ( definedValue , { dimension } = { } ) {
31
+ return buildDefinition ( value => _lte ( value , definedValue ) , dimension ) ;
22
32
}
23
33
24
- export function gt ( definedValue ) {
25
- return buildDefinition ( value => _gt ( value , definedValue ) ) ;
34
+ export function gt ( definedValue , { dimension } = { } ) {
35
+ return buildDefinition ( value => _gt ( value , definedValue ) , dimension ) ;
26
36
}
27
37
28
- export function gte ( definedValue ) {
29
- return buildDefinition ( value => _gte ( value , definedValue ) ) ;
38
+ export function gte ( definedValue , { dimension } = { } ) {
39
+ return buildDefinition ( value => _gte ( value , definedValue ) , dimension ) ;
30
40
}
31
41
32
- export function eq ( definedValue ) {
33
- return buildDefinition ( value => _eq ( value , definedValue ) ) ;
42
+ export function eq ( definedValue , { dimension } = { } ) {
43
+ return buildDefinition ( value => _eq ( value , definedValue ) , dimension ) ;
34
44
}
35
45
36
- export function between ( firstDefined , secondDefined ) {
37
- return buildDefinition ( value => betweenRightClosed ( value , firstDefined , secondDefined ) ) ;
46
+ export function between ( firstDefined , secondDefined , { dimension } = { } ) {
47
+ return buildDefinition (
48
+ value => betweenRightClosed ( value , firstDefined , secondDefined ) ,
49
+ dimension
50
+ ) ;
38
51
}
39
52
40
- export function definitionsMap ( currentValue , definitions ) {
53
+ export function definitionsMap ( { width , height } , definitions ) {
41
54
return Object . keys ( definitions ) . reduce ( ( map , breakpointLabel ) => {
42
- const { comparison } = definitions [ breakpointLabel ] ;
55
+ const { comparison, dimension } = definitions [ breakpointLabel ] ;
56
+ const currentValue = dimension === 'width' ? width : height || 0 ;
57
+
43
58
return {
44
59
...map ,
45
60
[ breakpointLabel ] : comparison ( currentValue )
0 commit comments