@@ -31,7 +31,8 @@ export type FlexBasisAlias = 'grow' | 'initial' | 'auto' | 'none' | 'nogrow' | '
31
31
*
32
32
* @see https://css-tricks.com/snippets/css/a-guide-to-flexbox/
33
33
*/
34
- @Directive ( { selector : `
34
+ @Directive ( {
35
+ selector : `
35
36
[fxFlex],
36
37
[fxFlex.xs]
37
38
[fxFlex.gt-xs],
@@ -43,7 +44,7 @@ export type FlexBasisAlias = 'grow' | 'initial' | 'auto' | 'none' | 'nogrow' | '
43
44
[fxFlex.gt-lg],
44
45
[fxFlex.xl]
45
46
`
46
- } )
47
+ } )
47
48
export class FlexDirective extends BaseFxDirective implements OnInit , OnChanges , OnDestroy {
48
49
49
50
/** The flex-direction of this element's flex container. Defaults to 'row'. */
@@ -55,29 +56,62 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
55
56
*/
56
57
private _layoutWatcher : Subscription ;
57
58
58
- @Input ( 'fxFlex' ) set flex ( val ) { this . _cacheInput ( "flex" , val ) ; }
59
- @Input ( 'fxShrink' ) set shrink ( val ) { this . _cacheInput ( "shrink" , val ) ; }
60
- @Input ( 'fxGrow' ) set grow ( val ) { this . _cacheInput ( "grow" , val ) ; }
59
+ @Input ( 'fxFlex' ) set flex ( val ) {
60
+ this . _cacheInput ( "flex" , val ) ;
61
+ }
62
+
63
+ @Input ( 'fxShrink' ) set shrink ( val ) {
64
+ this . _cacheInput ( "shrink" , val ) ;
65
+ }
66
+
67
+ @Input ( 'fxGrow' ) set grow ( val ) {
68
+ this . _cacheInput ( "grow" , val ) ;
69
+ }
70
+
71
+ @Input ( 'fxFlex.xs' ) set flexXs ( val ) {
72
+ this . _cacheInput ( 'flexXs' , val ) ;
73
+ }
74
+
75
+ @Input ( 'fxFlex.gt-xs' ) set flexGtXs ( val ) {
76
+ this . _cacheInput ( 'flexGtXs' , val ) ;
77
+ } ;
78
+
79
+ @Input ( 'fxFlex.sm' ) set flexSm ( val ) {
80
+ this . _cacheInput ( 'flexSm' , val ) ;
81
+ } ;
82
+
83
+ @Input ( 'fxFlex.gt-sm' ) set flexGtSm ( val ) {
84
+ this . _cacheInput ( 'flexGtSm' , val ) ;
85
+ } ;
86
+
87
+ @Input ( 'fxFlex.md' ) set flexMd ( val ) {
88
+ this . _cacheInput ( 'flexMd' , val ) ;
89
+ } ;
90
+
91
+ @Input ( 'fxFlex.gt-md' ) set flexGtMd ( val ) {
92
+ this . _cacheInput ( 'flexGtMd' , val ) ;
93
+ } ;
94
+
95
+ @Input ( 'fxFlex.lg' ) set flexLg ( val ) {
96
+ this . _cacheInput ( 'flexLg' , val ) ;
97
+ } ;
98
+
99
+ @Input ( 'fxFlex.gt-lg' ) set flexGtLg ( val ) {
100
+ this . _cacheInput ( 'flexGtLg' , val ) ;
101
+ } ;
61
102
62
- @Input ( 'fxFlex.xs' ) set flexXs ( val ) { this . _cacheInput ( 'flexXs' , val ) ; }
63
- @Input ( 'fxFlex.gt-xs' ) set flexGtXs ( val ) { this . _cacheInput ( 'flexGtXs' , val ) ; } ;
64
- @Input ( 'fxFlex.sm' ) set flexSm ( val ) { this . _cacheInput ( 'flexSm' , val ) ; } ;
65
- @Input ( 'fxFlex.gt-sm' ) set flexGtSm ( val ) { this . _cacheInput ( 'flexGtSm' , val ) ; } ;
66
- @Input ( 'fxFlex.md' ) set flexMd ( val ) { this . _cacheInput ( 'flexMd' , val ) ; } ;
67
- @Input ( 'fxFlex.gt-md' ) set flexGtMd ( val ) { this . _cacheInput ( 'flexGtMd' , val ) ; } ;
68
- @Input ( 'fxFlex.lg' ) set flexLg ( val ) { this . _cacheInput ( 'flexLg' , val ) ; } ;
69
- @Input ( 'fxFlex.gt-lg' ) set flexGtLg ( val ) { this . _cacheInput ( 'flexGtLg' , val ) ; } ;
70
- @Input ( 'fxFlex.xl' ) set flexXl ( val ) { this . _cacheInput ( 'flexXl' , val ) ; } ;
103
+ @Input ( 'fxFlex.xl' ) set flexXl ( val ) {
104
+ this . _cacheInput ( 'flexXl' , val ) ;
105
+ } ;
71
106
72
107
73
108
// Explicitly @SkipSelf on LayoutDirective and LayoutWrapDirective because we want the
74
109
// parent flex container for this flex item.
75
- constructor (
76
- monitor : MediaMonitor ,
77
- elRef : ElementRef ,
78
- renderer : Renderer ,
79
- @Optional ( ) @SkipSelf ( ) private _container : LayoutDirective ,
80
- @Optional ( ) @SkipSelf ( ) private _wrap : LayoutWrapDirective ) {
110
+ constructor ( monitor : MediaMonitor ,
111
+ elRef : ElementRef ,
112
+ renderer : Renderer ,
113
+ @Optional ( ) @SkipSelf ( ) private _container : LayoutDirective ,
114
+ @Optional ( ) @SkipSelf ( ) private _wrap : LayoutWrapDirective ) {
81
115
82
116
super ( monitor , elRef , renderer ) ;
83
117
@@ -139,34 +173,34 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
139
173
}
140
174
141
175
this . _applyStyleToElement ( this . _validateValue . apply ( this ,
142
- this . _parseFlexParts ( String ( flexBasis ) ) ) ) ;
176
+ this . _parseFlexParts ( String ( flexBasis ) ) ) ) ;
143
177
}
144
178
145
179
/**
146
180
* If the used the short-form `fxFlex="1 0 37%"`, then parse the parts
147
181
*/
148
- private _parseFlexParts ( basis :string ) {
149
- basis = basis . replace ( ";" , "" ) ;
182
+ private _parseFlexParts ( basis : string ) {
183
+ basis = basis . replace ( ";" , "" ) ;
150
184
151
185
let hasCalc = basis && basis . indexOf ( "calc" ) > - 1 ;
152
186
let matches = ! hasCalc ? basis . split ( " " ) : this . _getPartsWithCalc ( basis . trim ( ) ) ;
153
- return ( matches . length === 3 ) ? matches : [ this . _queryInput ( "grow" ) ,
154
- this . _queryInput ( "shrink" ) , basis ] ;
187
+ return ( matches . length === 3 ) ? matches : [ this . _queryInput ( "grow" ) ,
188
+ this . _queryInput ( "shrink" ) , basis ] ;
155
189
}
156
190
157
191
/**
158
192
* Extract more complicated short-hand versions.
159
193
* e.g.
160
194
* fxFlex="3 3 calc(15em + 20px)"
161
195
*/
162
- private _getPartsWithCalc ( value :string ) {
163
- let parts = [ this . _queryInput ( "grow" ) , this . _queryInput ( "shrink" ) , value ] ;
196
+ private _getPartsWithCalc ( value : string ) {
197
+ let parts = [ this . _queryInput ( "grow" ) , this . _queryInput ( "shrink" ) , value ] ;
164
198
let j = value . indexOf ( 'calc' ) ;
165
199
166
- if ( j > 0 ) {
200
+ if ( j > 0 ) {
167
201
parts [ 2 ] = value . substring ( j ) ;
168
202
let matches = value . substr ( 0 , j ) . trim ( ) . split ( " " ) ;
169
- if ( matches . length == 2 ) {
203
+ if ( matches . length == 2 ) {
170
204
parts [ 0 ] = matches [ 0 ] ;
171
205
parts [ 1 ] = matches [ 1 ] ;
172
206
}
@@ -236,10 +270,10 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
236
270
let isPercent = String ( basis ) . indexOf ( '%' ) > - 1 ;
237
271
238
272
isValue = String ( basis ) . indexOf ( 'px' ) > - 1 ||
239
- String ( basis ) . indexOf ( 'calc' ) > - 1 ||
240
- String ( basis ) . indexOf ( 'em' ) > - 1 ||
241
- String ( basis ) . indexOf ( 'vw' ) > - 1 ||
242
- String ( basis ) . indexOf ( 'vh' ) > - 1 ;
273
+ String ( basis ) . indexOf ( 'calc' ) > - 1 ||
274
+ String ( basis ) . indexOf ( 'em' ) > - 1 ||
275
+ String ( basis ) . indexOf ( 'vw' ) > - 1 ||
276
+ String ( basis ) . indexOf ( 'vh' ) > - 1 ;
243
277
244
278
// Defaults to percentage sizing unless `px` is explicitly set
245
279
if ( ! isValue && ! isPercent && ! isNaN ( basis as any ) ) {
@@ -266,7 +300,7 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
266
300
let usingCalc = String ( basis ) . indexOf ( 'calc' ) > - 1 ;
267
301
let isPx = String ( basis ) . indexOf ( 'px' ) > - 1 || usingCalc ;
268
302
269
- css [ min ] = ( basis == '0%' ) ? 0 : isPx ? basis : null ;
303
+ css [ min ] = ( basis == '0%' ) ? 0 : isPx ? basis : null ;
270
304
css [ max ] = ( basis == '0%' ) ? 0 : usingCalc ? null : basis ;
271
305
272
306
return extendObject ( css , { 'box-sizing' : 'border-box' } ) ;
0 commit comments