@@ -40,16 +40,9 @@ export type FlexBasisAlias = 'grow' | 'initial' | 'auto' | 'none' | 'nogrow' | '
40
40
* @see https://css-tricks.com/snippets/css/a-guide-to-flexbox/
41
41
*/
42
42
@Directive ( { selector : `
43
- [fxFlex],
44
- [fxFlex.xs],
45
- [fxFlex.gt-xs],
46
- [fxFlex.sm],
47
- [fxFlex.gt-sm],
48
- [fxFlex.md],
49
- [fxFlex.gt-md],
50
- [fxFlex.lg],
51
- [fxFlex.gt-lg],
52
- [fxFlex.xl]
43
+ [fxFlex],
44
+ [fxFlex.xs], [fxFlex.sm], [fxFlex.md], [fxFlex.lg], [fxFlex.xl],
45
+ [fxFlex.gt-xs], [fxFlex.gt-sm], [fxFlex.gt-md], [fxFlex.gt-lg]
53
46
`
54
47
} )
55
48
export class FlexDirective extends BaseFxDirective implements OnInit , OnChanges , OnDestroy {
@@ -63,55 +56,23 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
63
56
*/
64
57
protected _layoutWatcher : Subscription ;
65
58
66
- @Input ( 'fxFlex' ) set flex ( val ) {
67
- this . _cacheInput ( "flex" , val ) ;
68
- }
69
-
70
- @Input ( 'fxShrink' ) set shrink ( val ) {
71
- this . _cacheInput ( "shrink" , val ) ;
72
- }
73
-
74
- @Input ( 'fxGrow' ) set grow ( val ) {
75
- this . _cacheInput ( "grow" , val ) ;
76
- }
77
-
78
- @Input ( 'fxFlex.xs' ) set flexXs ( val ) {
79
- this . _cacheInput ( 'flexXs' , val ) ;
80
- }
81
-
82
- @Input ( 'fxFlex.gt-xs' ) set flexGtXs ( val ) {
83
- this . _cacheInput ( 'flexGtXs' , val ) ;
84
- } ;
85
-
86
- @Input ( 'fxFlex.sm' ) set flexSm ( val ) {
87
- this . _cacheInput ( 'flexSm' , val ) ;
88
- } ;
89
-
90
- @Input ( 'fxFlex.gt-sm' ) set flexGtSm ( val ) {
91
- this . _cacheInput ( 'flexGtSm' , val ) ;
92
- } ;
59
+ /* tslint:disable */
60
+ @Input ( 'fxShrink' ) set shrink ( val ) { this . _cacheInput ( "shrink" , val ) ; } ;
61
+ @Input ( 'fxGrow' ) set grow ( val ) { this . _cacheInput ( "grow" , val ) ; } ;
93
62
94
- @Input ( 'fxFlex.md' ) set flexMd ( val ) {
95
- this . _cacheInput ( 'flexMd' , val ) ;
96
- } ;
97
-
98
- @Input ( 'fxFlex.gt-md' ) set flexGtMd ( val ) {
99
- this . _cacheInput ( 'flexGtMd' , val ) ;
100
- } ;
101
-
102
- @Input ( 'fxFlex.lg' ) set flexLg ( val ) {
103
- this . _cacheInput ( 'flexLg' , val ) ;
104
- } ;
105
-
106
- @Input ( 'fxFlex.gt-lg' ) set flexGtLg ( val ) {
107
- this . _cacheInput ( 'flexGtLg' , val ) ;
108
- } ;
109
-
110
- @Input ( 'fxFlex.xl' ) set flexXl ( val ) {
111
- this . _cacheInput ( 'flexXl' , val ) ;
112
- } ;
63
+ @Input ( 'fxFlex' ) set flex ( val ) { this . _cacheInput ( "flex" , val ) ; } ;
64
+ @Input ( 'fxFlex.xs' ) set flexXs ( val ) { this . _cacheInput ( 'flexXs' , val ) ; } ;
65
+ @Input ( 'fxFlex.sm' ) set flexSm ( val ) { this . _cacheInput ( 'flexSm' , val ) ; } ;
66
+ @Input ( 'fxFlex.md' ) set flexMd ( val ) { this . _cacheInput ( 'flexMd' , val ) ; } ;
67
+ @Input ( 'fxFlex.lg' ) set flexLg ( val ) { this . _cacheInput ( 'flexLg' , val ) ; } ;
68
+ @Input ( 'fxFlex.xl' ) set flexXl ( val ) { this . _cacheInput ( 'flexXl' , val ) ; } ;
113
69
70
+ @Input ( 'fxFlex.gt-xs' ) set flexGtXs ( val ) { this . _cacheInput ( 'flexGtXs' , val ) ; } ;
71
+ @Input ( 'fxFlex.gt-sm' ) set flexGtSm ( val ) { this . _cacheInput ( 'flexGtSm' , val ) ; } ;
72
+ @Input ( 'fxFlex.gt-md' ) set flexGtMd ( val ) { this . _cacheInput ( 'flexGtMd' , val ) ; } ;
73
+ @Input ( 'fxFlex.gt-lg' ) set flexGtLg ( val ) { this . _cacheInput ( 'flexGtLg' , val ) ; } ;
114
74
75
+ /* tslint:enable */
115
76
// Explicitly @SkipSelf on LayoutDirective and LayoutWrapDirective because we want the
116
77
// parent flex container for this flex item.
117
78
constructor ( monitor : MediaMonitor ,
@@ -215,13 +176,14 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
215
176
// ≥2 (integer n): Stretch. Will be n times the size of other elements
216
177
// with 'flex-grow: 1' on the same row.
217
178
218
- // Use `null` to clear existing styles.
219
- let clearStyles = {
179
+ let hasCalc = String ( basis ) . indexOf ( 'calc' ) > - 1 ;
180
+ let clearStyles = { // Use `null` to clear existing styles.
220
181
'max-width' : null ,
221
182
'max-height' : null ,
222
183
'min-width' : null ,
223
184
'min-height' : null
224
185
} ;
186
+
225
187
switch ( basis || '' ) {
226
188
case '' :
227
189
css = extendObject ( clearStyles , { 'flex' : '1 1 0.000000001px' } ) ;
@@ -247,7 +209,6 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
247
209
css = extendObject ( clearStyles , { 'flex' : '0 0 auto' } ) ;
248
210
break ;
249
211
default :
250
- let hasCalc = String ( basis ) . indexOf ( 'calc' ) > - 1 ;
251
212
let isPercent = String ( basis ) . indexOf ( '%' ) > - 1 && ! hasCalc ;
252
213
253
214
isValue = hasCalc ||
@@ -267,27 +228,26 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
267
228
268
229
// Set max-width = basis if using layout-wrap
269
230
// tslint:disable-next-line:max-line-length
270
- // @see https ://github.com/philipwalton/flexbugs#11-min-and-max-size-declarations-are-ignored-when-wrappifl-flex-items
231
+ // @see http ://bit.ly/2m5pZVI
271
232
272
233
css = extendObject ( clearStyles , { // fix issue #5345
273
234
'flex' : `${ grow } ${ shrink } ${ ( isValue || this . _wrap ) ? basis : '100%' } ` ,
274
235
} ) ;
275
236
break ;
276
237
}
277
238
278
- let max = ( direction === 'row' ) ? 'max-width' : 'max-height' ;
279
- let min = ( direction === 'row' ) ? 'min-width' : 'min-height' ;
280
-
281
- let usingCalc = ( String ( basis ) . indexOf ( 'calc' ) > - 1 ) || ( basis == 'auto' ) ;
282
- let isPx = String ( basis ) . indexOf ( 'px' ) > - 1 || usingCalc ;
283
-
284
-
285
- // make box inflexible when shrink and grow are both zero
286
- // should not set a min when the grow is zero
287
- // should not set a max when the shrink is zero
288
- let isFixed = ! grow && ! shrink ;
289
- css [ min ] = ( basis == '0%' ) ? 0 : isFixed || ( isPx && grow ) ? basis : null ;
290
- css [ max ] = ( basis == '0%' ) ? 0 : isFixed || ( ! usingCalc && shrink ) ? basis : null ;
239
+ if ( basis !== 'auto' ) {
240
+ let max = ( direction === 'row' ) ? 'max-width' : 'max-height' ;
241
+ let min = ( direction === 'row' ) ? 'min-width' : 'min-height' ;
242
+ let isPx = String ( basis ) . indexOf ( 'px' ) > - 1 || hasCalc ;
243
+
244
+ // make box inflexible when shrink and grow are both zero
245
+ // * do not set a min when the grow is zero
246
+ // * do not set a max when the shrink is zero
247
+ let isFixed = ! grow && ! shrink ;
248
+ css [ min ] = ( basis == '0%' ) ? 0 : isFixed || ( isPx && grow ) ? basis : null ;
249
+ css [ max ] = ( basis == '0%' ) ? 0 : isFixed || ( ! hasCalc && shrink ) ? basis : null ;
250
+ }
291
251
292
252
return extendObject ( css , { 'box-sizing' : 'border-box' } ) ;
293
253
}
0 commit comments