Skip to content

Commit

Permalink
Merge branch 'master' into typography-variants
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jun 10, 2018
2 parents f72917b + cd4847c commit 143fc49
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
59 changes: 32 additions & 27 deletions packages/material-ui/src/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,30 @@ import { keys as breakpointKeys } from '../styles/createBreakpoints';
import requirePropFactory from '../utils/requirePropFactory';

const GUTTERS = [0, 8, 16, 24, 32, 40];
const GRID_SIZES = [true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const GRID_SIZES = ['auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

function generateGrid(globalStyles, theme, breakpoint) {
// For the auto layouting
const styles = {
[`grid-${breakpoint}`]: {
flexBasis: 0,
flexGrow: 1,
maxWidth: '100%',
},
};
const styles = {};

GRID_SIZES.forEach(size => {
if (typeof size === 'boolean') {
// Skip the first one as handle above.
const key = `grid-${breakpoint}-${size}`;

if (size === true) {
// For the auto layouting
styles[key] = {
flexBasis: 0,
flexGrow: 1,
maxWidth: '100%',
};
return;
}

if (size === 'auto') {
styles[key] = {
flexBasis: 'auto',
flexGrow: 0,
maxWidth: 'none',
};
return;
}

Expand All @@ -40,8 +49,9 @@ function generateGrid(globalStyles, theme, breakpoint) {

// Close to the bootstrap implementation:
// https://github.com/twbs/bootstrap/blob/8fccaa2439e97ec72a4b7dc42ccc1f649790adb0/scss/mixins/_grid.scss#L41
styles[`grid-${breakpoint}-${size}`] = {
styles[key] = {
flexBasis: width,
flexGrow: 0,
maxWidth: width,
};
});
Expand Down Expand Up @@ -192,16 +202,11 @@ function Grid(props) {
[classes[`align-content-xs-${String(alignContent)}`]]:
alignContent !== Grid.defaultProps.alignContent,
[classes[`justify-xs-${String(justify)}`]]: justify !== Grid.defaultProps.justify,
[classes['grid-xs']]: xs === true,
[classes[`grid-xs-${String(xs)}`]]: xs && xs !== true,
[classes['grid-sm']]: sm === true,
[classes[`grid-sm-${String(sm)}`]]: sm && sm !== true,
[classes['grid-md']]: md === true,
[classes[`grid-md-${String(md)}`]]: md && md !== true,
[classes['grid-lg']]: lg === true,
[classes[`grid-lg-${String(lg)}`]]: lg && lg !== true,
[classes['grid-xl']]: xl === true,
[classes[`grid-xl-${String(xl)}`]]: xl && xl !== true,
[classes[`grid-xs-${String(xs)}`]]: xs !== false,
[classes[`grid-sm-${String(sm)}`]]: sm !== false,
[classes[`grid-md-${String(md)}`]]: md !== false,
[classes[`grid-lg-${String(lg)}`]]: lg !== false,
[classes[`grid-xl-${String(xl)}`]]: xl !== false,
},
classNameProp,
);
Expand Down Expand Up @@ -269,17 +274,17 @@ Grid.propTypes = {
* Defines the number of grids the component is going to use.
* It's applied for the `lg` breakpoint and wider screens if not overridden.
*/
lg: PropTypes.oneOf([false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
lg: PropTypes.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
/**
* Defines the number of grids the component is going to use.
* It's applied for the `md` breakpoint and wider screens if not overridden.
*/
md: PropTypes.oneOf([false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
md: PropTypes.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
/**
* Defines the number of grids the component is going to use.
* It's applied for the `sm` breakpoint and wider screens if not overridden.
*/
sm: PropTypes.oneOf([false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
sm: PropTypes.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
/**
* Defines the space between the type `item` component.
* It can only be used on a type `container` component.
Expand All @@ -294,12 +299,12 @@ Grid.propTypes = {
* Defines the number of grids the component is going to use.
* It's applied for the `xl` breakpoint and wider screens.
*/
xl: PropTypes.oneOf([false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
xl: PropTypes.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
/**
* Defines the number of grids the component is going to use.
* It's applied for all the screen sizes with the lowest priority.
*/
xs: PropTypes.oneOf([false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
xs: PropTypes.oneOf([false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
/**
* If `true`, it sets `min-width: 0` on the item.
* Refer to the limitations section of the documentation to better understand the use case.
Expand Down
7 changes: 6 additions & 1 deletion packages/material-ui/src/Grid/Grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ describe('<Grid />', () => {
describe('prop: xs', () => {
it('should apply the flex-grow class', () => {
const wrapper = shallow(<Grid item xs />);
assert.strictEqual(wrapper.hasClass(classes['grid-xs']), true);
assert.strictEqual(wrapper.hasClass(classes['grid-xs-true']), true);
});

it('should apply the flex size class', () => {
const wrapper = shallow(<Grid item xs={3} />);
assert.strictEqual(wrapper.hasClass(classes['grid-xs-3']), true);
});

it('should apply the flex auto class', () => {
const wrapper = shallow(<Grid item xs="auto" />);
assert.strictEqual(wrapper.hasClass(classes['grid-xs-auto']), true);
});
});

describe('prop: spacing', () => {
Expand Down
13 changes: 7 additions & 6 deletions pages/api/grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ filename: /packages/material-ui/src/Grid/Grid.js
| <span class="prop-name">direction</span> | <span class="prop-type">enum:&nbsp;'row'&nbsp;&#124;<br>&nbsp;'row-reverse'&nbsp;&#124;<br>&nbsp;'column'&nbsp;&#124;<br>&nbsp;'column-reverse'<br> | <span class="prop-default">'row'</span> | Defines the `flex-direction` style property. It is applied for all screen sizes. |
| <span class="prop-name">item</span> | <span class="prop-type">bool | <span class="prop-default">false</span> | If `true`, the component will have the flex *item* behavior. You should be wrapping *items* with a *container*. |
| <span class="prop-name">justify</span> | <span class="prop-type">enum:&nbsp;'flex-start', 'center', 'flex-end', 'space-between', 'space-around'<br> | <span class="prop-default">'flex-start'</span> | Defines the `justify-content` style property. It is applied for all screen sizes. |
| <span class="prop-name">lg</span> | <span class="prop-type">enum:&nbsp;false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `lg` breakpoint and wider screens if not overridden. |
| <span class="prop-name">md</span> | <span class="prop-type">enum:&nbsp;false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `md` breakpoint and wider screens if not overridden. |
| <span class="prop-name">sm</span> | <span class="prop-type">enum:&nbsp;false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `sm` breakpoint and wider screens if not overridden. |
| <span class="prop-name">lg</span> | <span class="prop-type">enum:&nbsp;false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `lg` breakpoint and wider screens if not overridden. |
| <span class="prop-name">md</span> | <span class="prop-type">enum:&nbsp;false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `md` breakpoint and wider screens if not overridden. |
| <span class="prop-name">sm</span> | <span class="prop-type">enum:&nbsp;false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `sm` breakpoint and wider screens if not overridden. |
| <span class="prop-name">spacing</span> | <span class="prop-type">enum:&nbsp;0, 8, 16, 24, 32, 40<br> | <span class="prop-default">0</span> | Defines the space between the type `item` component. It can only be used on a type `container` component. |
| <span class="prop-name">wrap</span> | <span class="prop-type">enum:&nbsp;'nowrap'&nbsp;&#124;<br>&nbsp;'wrap'&nbsp;&#124;<br>&nbsp;'wrap-reverse'<br> | <span class="prop-default">'wrap'</span> | Defines the `flex-wrap` style property. It's applied for all screen sizes. |
| <span class="prop-name">xl</span> | <span class="prop-type">enum:&nbsp;false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `xl` breakpoint and wider screens. |
| <span class="prop-name">xs</span> | <span class="prop-type">enum:&nbsp;false, true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for all the screen sizes with the lowest priority. |
| <span class="prop-name">xl</span> | <span class="prop-type">enum:&nbsp;false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for the `xl` breakpoint and wider screens. |
| <span class="prop-name">xs</span> | <span class="prop-type">enum:&nbsp;false, 'auto', true, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12<br> | <span class="prop-default">false</span> | Defines the number of grids the component is going to use. It's applied for all the screen sizes with the lowest priority. |
| <span class="prop-name">zeroMinWidth</span> | <span class="prop-type">bool | <span class="prop-default">false</span> | If `true`, it sets `min-width: 0` on the item. Refer to the limitations section of the documentation to better understand the use case. |

Any other properties supplied will be spread to the root element (native element).
Expand Down Expand Up @@ -62,7 +62,8 @@ This property accepts the following keys:
- `spacing-xs-24`
- `spacing-xs-32`
- `spacing-xs-40`
- `grid-xs`
- `grid-xs-auto`
- `grid-xs-true`
- `grid-xs-1`
- `grid-xs-2`
- `grid-xs-3`
Expand Down

0 comments on commit 143fc49

Please sign in to comment.