Skip to content

Commit 018fef4

Browse files
authored
Merge pull request #7 from suitcss/flex-shrink
Add flex-shrink, flex-basis and flex shorthand utilities
2 parents 637f3b3 + 8fc6eae commit 018fef4

File tree

11 files changed

+3819
-103
lines changed

11 files changed

+3819
-103
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- "4"
5-
- "5"
4+
- "stable"

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
### HEAD
22

3-
* Enable BEM linter reporting in tests
4-
* Update stylelint-config-suitcss to `4.0.0`
3+
* Add utils for `flex-basis` and `flex` shorthand (initial, auto, none)
4+
* Add `flex-shrink` utility
5+
* Remove IE10 hack for applying `flex-shrink` to all children
6+
* Update suitcss-preprocessor to `3.0.1`
57
* Move custom media below imports to fix warning
68

79
### 1.1.1 (February 08, 2016)

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ SUIT CSS flexbox utilities
7777

7878
`X` can be any of the following numbers: `1`, `2`, `3`, `4`, `5`.
7979

80+
**`flex-shrink`**
81+
82+
* `u-flexShrinkX` - Specify how much the flex item will shrink relatively
83+
84+
`X` can be any of the following numbers: `0`, `1`, `2`, `3`, `4`, `5`.
85+
86+
**`flex-basis`**
87+
88+
Used to override other utilities and tweak [how space is
89+
distributed](https://www.w3.org/TR/css-flexbox-1/images/rel-vs-abs-flex.svg).
90+
91+
* `u-flexBasisAuto`
92+
* `u-flexBasis0`
93+
94+
**`flex` shorthand**
95+
96+
* `u-flexInitial` - Sizes the item based on the width/height properties
97+
* `u-flexAuto` - Sizes the item based on the width/height properties, but makes
98+
them fully flexible, so that they absorb any free space along the main axis.
99+
* `u-flexNone` - Sizes the item according to the width/height properties, but
100+
makes the flex item fully inflexible. Similar to initial, except that flex
101+
items are not allowed to shrink, even in overflow situations.
102+
80103
**Aligning with `auto` margins**
81104

82105
* `u-flexExpand` - Expand all margins to fill remaining space
@@ -160,6 +183,25 @@ Note: The `Grid` component already sets `display: flex` on the root element.
160183

161184
Please refer to the README for [SUIT CSS utils](https://github.com/suitcss/utils/)
162185

186+
## Setting `flex-shrink` in IE10
187+
188+
In IE10 it is required to [explicitly set `flex-shrink` on flex
189+
items](https://github.com/philipwalton/flexbugs#6-the-default-flex-value-has-changed),
190+
or use the longhand `flex` declaration.
191+
192+
In prior versions of `utils-flex` this was set automatically on all flex items.
193+
Due to issues with specificity this has been removed.
194+
195+
Should you need to apply the fix for IE10 then add a `u-flexShrink` class
196+
manually:
197+
198+
```html
199+
<div class="u-flex u-flexNoWrap">
200+
<div class="FlexItem u-flexShrink1">Content</div>
201+
<div class="FlexItem u-flexShrink1">Content</div>
202+
</div>
203+
```
204+
163205
## Testing
164206

165207
Install [Node](http://nodejs.org) (comes with npm).

lib/flex-lg.css

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,6 @@
140140
align-content: space-around !important;
141141
}
142142

143-
/**
144-
* 1. Set the flex-shrink default explicitly to fix IE10 - http://git.io/vllC7
145-
*/
146-
147-
/* postcss-bem-linter: ignore */
148-
149-
.u-lg-flex > *,
150-
.u-lg-flexInline > * {
151-
flex-shrink: 1; /* 1 */
152-
}
153-
154143
/* Applies to flex items
155144
======================================================================== */
156145

@@ -231,6 +220,35 @@
231220
flex: 5 1 0% !important;
232221
}
233222

223+
/**
224+
* Specify the flex shrink factor, which determines how much the flex item
225+
* will shrink relative to the rest of the flex items in the flex container.
226+
*/
227+
228+
.u-lg-flexShrink0 {
229+
flex-shrink: 0 !important;
230+
}
231+
232+
.u-lg-flexShrink1 {
233+
flex-shrink: 1 !important;
234+
}
235+
236+
.u-lg-flexShrink2 {
237+
flex-shrink: 2 !important;
238+
}
239+
240+
.u-lg-flexShrink3 {
241+
flex-shrink: 3 !important;
242+
}
243+
244+
.u-lg-flexShrink4 {
245+
flex-shrink: 4 !important;
246+
}
247+
248+
.u-lg-flexShrink5 {
249+
flex-shrink: 5 !important;
250+
}
251+
234252
/**
235253
* Aligning with `auto` margins
236254
* http://www.w3.org/TR/css-flexbox-1/#auto-margins
@@ -256,5 +274,56 @@
256274
margin-bottom: auto !important;
257275
}
258276

259-
}
277+
/**
278+
* Basis
279+
*/
280+
281+
.u-lg-flexBasisAuto {
282+
flex-basis: auto !important;
283+
}
284+
285+
.u-lg-flexBasis0 {
286+
flex-basis: 0 !important;
287+
}
288+
289+
/*
290+
* Shorthand
291+
*
292+
* Declares all values instead of keywords like 'initial' to work around IE10
293+
* https://www.w3.org/TR/css-flexbox-1/#flex-common
294+
*
295+
* 1. Fixes issue in IE 10 where flex-basis is ignored - https://git.io/vllMt
296+
* This ensures it overrides flex-basis set in other utilities.
297+
*/
298+
299+
/*
300+
* Sizes the item based on the width/height properties
301+
*/
260302

303+
.u-lg-flexInitial {
304+
flex: 0 1 auto !important;
305+
flex-basis: auto !important; /* 1 */
306+
}
307+
308+
/*
309+
* Sizes the item based on the width/height properties, but makes them fully
310+
* flexible, so that they absorb any free space along the main axis.
311+
*/
312+
313+
.u-lg-flexAuto {
314+
flex: 1 1 auto !important;
315+
flex-basis: auto !important; /* 1 */
316+
}
317+
318+
/*
319+
* Sizes the item according to the width/height properties, but makes the flex
320+
* item fully inflexible. Similar to initial, except that flex items are
321+
* not allowed to shrink, even in overflow situations.
322+
*/
323+
324+
.u-lg-flexNone {
325+
flex: 0 0 auto !important;
326+
flex-basis: auto !important; /* 1 */
327+
}
328+
329+
}

lib/flex-md.css

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,6 @@
140140
align-content: space-around !important;
141141
}
142142

143-
/**
144-
* 1. Set the flex-shrink default explicitly to fix IE10 - http://git.io/vllC7
145-
*/
146-
147-
/* postcss-bem-linter: ignore */
148-
149-
.u-md-flex > *,
150-
.u-md-flexInline > * {
151-
flex-shrink: 1; /* 1 */
152-
}
153-
154143
/* Applies to flex items
155144
======================================================================== */
156145

@@ -231,6 +220,35 @@
231220
flex: 5 1 0% !important;
232221
}
233222

223+
/**
224+
* Specify the flex shrink factor, which determines how much the flex item
225+
* will shrink relative to the rest of the flex items in the flex container.
226+
*/
227+
228+
.u-md-flexShrink0 {
229+
flex-shrink: 0 !important;
230+
}
231+
232+
.u-md-flexShrink1 {
233+
flex-shrink: 1 !important;
234+
}
235+
236+
.u-md-flexShrink2 {
237+
flex-shrink: 2 !important;
238+
}
239+
240+
.u-md-flexShrink3 {
241+
flex-shrink: 3 !important;
242+
}
243+
244+
.u-md-flexShrink4 {
245+
flex-shrink: 4 !important;
246+
}
247+
248+
.u-md-flexShrink5 {
249+
flex-shrink: 5 !important;
250+
}
251+
234252
/**
235253
* Aligning with `auto` margins
236254
* http://www.w3.org/TR/css-flexbox-1/#auto-margins
@@ -256,4 +274,56 @@
256274
margin-bottom: auto !important;
257275
}
258276

277+
/**
278+
* Basis
279+
*/
280+
281+
.u-md-flexBasisAuto {
282+
flex-basis: auto !important;
283+
}
284+
285+
.u-md-flexBasis0 {
286+
flex-basis: 0 !important;
287+
}
288+
289+
/*
290+
* Shorthand
291+
*
292+
* Declares all values instead of keywords like 'initial' to work around IE10
293+
* https://www.w3.org/TR/css-flexbox-1/#flex-common
294+
*
295+
* 1. Fixes issue in IE 10 where flex-basis is ignored - https://git.io/vllMt
296+
* This ensures it overrides flex-basis set in other utilities.
297+
*/
298+
299+
/*
300+
* Sizes the item based on the width/height properties
301+
*/
302+
303+
.u-md-flexInitial {
304+
flex: 0 1 auto !important;
305+
flex-basis: auto !important; /* 1 */
306+
}
307+
308+
/*
309+
* Sizes the item based on the width/height properties, but makes them fully
310+
* flexible, so that they absorb any free space along the main axis.
311+
*/
312+
313+
.u-md-flexAuto {
314+
flex: 1 1 auto !important;
315+
flex-basis: auto !important; /* 1 */
316+
}
317+
318+
/*
319+
* Sizes the item according to the width/height properties, but makes the flex
320+
* item fully inflexible. Similar to initial, except that flex items are
321+
* not allowed to shrink, even in overflow situations.
322+
*/
323+
324+
.u-md-flexNone {
325+
flex: 0 0 auto !important;
326+
flex-basis: auto !important; /* 1 */
327+
}
328+
259329
}

0 commit comments

Comments
 (0)