FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(Grid): Update grid layout to support new 2xl breakpoint by jessiehuff · Pull Request #2305 · patternfly/patternfly-react · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (3) .md  (1) .snap  (1) .ts  (2) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
      • Grid.js
      • GridItem.d.ts
      • GridItem.js
        • Grid.md
      • sizes.d.ts
      • sizes.js
21 changes: 10 additions & 11 deletions packages/patternfly-4/react-core/src/layouts/Grid/Grid.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const propTypes = {
lg: gridItemSpanValueShape,
/** the number of columns all grid items should span on a xLarge device */
xl: gridItemSpanValueShape,
/** the number of columns all grid items should span on a 2xLarge device */
xl2: gridItemSpanValueShape,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

should we call it 2xl or is there a reason it's xl2 here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I had to name it xl2 to meet JSX attribute name requirements. It won't allow a prop to start with a number. :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe '2xl': gridItemSpanValueShape will make JSX happy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That works for defining the prop, but it doesn't work when actually creating a <GridItem 2xl={2}>

/** Additional props are spread to the container <div> */
'': PropTypes.any // eslint-disable-line react/require-default-props
};
Expand All @@ -37,22 +39,19 @@ const defaultProps = {
sm: null,
md: null,
lg: null,
xl: null
xl: null,
xl2: null
};

const Grid = ({ children, className, gutter, span, ...props }) => {
const classes = [styles.grid, span && getGridSpanModifier(span)];

Object.keys(DeviceSizes).forEach(size => {
const popProp = (propKey, getModifierFn) => {
const propValue = props[propKey];
if (propValue) {
classes.push(getModifierFn(propValue, size));
}
delete props[propKey];
};

popProp(size, getGridSpanModifier);
Object.entries(DeviceSizes).forEach(([propKey, gridSpanModifier]) => {
const propValue = props[propKey];
if (propValue) {
classes.push(getGridSpanModifier(propValue, gridSpanModifier));
}
delete props[propKey];
});

return (
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export interface GridItemProps extends HTMLProps<HTMLDivElement> {
xl?: GridItemSpanValue;
xlRowSpan?: GridItemSpanValue;
xlOffset?: GridItemSpanValue;
xl2?: GridItemSpanValue;
xl2RowSpan?: GridItemSpanValue;
xl2Offset?: GridItemSpanValue;
}

declare const GridItem: FunctionComponent<GridItemProps>;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const propTypes = {
xlRowSpan: PropTypes.oneOf(gridSpans),
/** the number of columns the grid item is offset on xLarge device. Value should be a number 1-12 */
xlOffset: PropTypes.oneOf(gridSpans),
/** the number of columns the grid item spans on 2xLarge device. Value should be a number 1-12 */
xl2: PropTypes.oneOf(gridSpans),
/** the number of rows the grid item spans on 2xLarge device. Value should be a number 1-12 */
xl2RowSpan: PropTypes.oneOf(gridSpans),
/** the number of columns the grid item is offset on 2xLarge device. Value should be a number 1-12 */
xl2Offset: PropTypes.oneOf(gridSpans),
/** Additional props are spread to the container <div> */
'': PropTypes.any // eslint-disable-line react/require-default-props
};
Expand All @@ -68,7 +74,10 @@ const defaultProps = {
lgOffset: null,
xl: null,
xlRowSpan: null,
xlOffset: null
xlOffset: null,
xl2: null,
xl2RowSpan: null,
xl2Offset: null
};

const GridItem = ({ children, className, span, rowSpan, offset, ...props }) => {
Expand All @@ -79,18 +88,22 @@ const GridItem = ({ children, className, span, rowSpan, offset, ...props }) => {
rowSpan && getRowSpanModifier(rowSpan)
];

Object.keys(DeviceSizes).forEach(size => {
const popProp = (propKey, getModifierFn) => {
const propValue = props[propKey];
if (propValue) {
classes.push(getModifierFn(propValue, size));
}
Object.entries(DeviceSizes).forEach(([propKey, classModifier]) => {
const spanValue = props[propKey];
if (spanValue) {
classes.push(getSpanModifier(spanValue, classModifier));
delete props[propKey];
};

popProp(size, getSpanModifier);
popProp(getRowSpanKey(size), getRowSpanModifier);
popProp(getOffsetKey(size), getOffsetModifier);
}
const rowSpanValue = props[getRowSpanKey(propKey)];
if (rowSpanValue) {
classes.push(getRowSpanModifier(rowSpanValue, classModifier));
delete props[getRowSpanKey(propKey)];
}
const offsetValue = props[getOffsetKey(propKey)];
if (offsetValue) {
classes.push(getOffsetModifier(offsetValue, classModifier));
delete props[getOffsetKey(propKey)];
}
});

return (
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`adds 2xl offset classes 1`] = `"pf-l-grid__item"`;

exports[`adds 2xl row classes 1`] = `"pf-l-grid__item"`;

exports[`adds 2xl span class 1`] = `"pf-l-grid__item"`;

exports[`adds lg offset classes 1`] = `"pf-l-grid__item pf-m-offset-1-col-on-lg"`;

exports[`adds lg row classes 1`] = `"pf-l-grid__item pf-m-1-row-on-lg"`;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import React from 'react';
import { Grid, GridItem, Button } from '@patternfly/react-core';
import ItemControl from './ItemControl';

<Grid sm={6} md={4} lg={3}>
<Grid sm={6} md={4} lg={3} xl2={1}>
<GridItem pan={3} rowSpan={2}>
span = 3 rowSpan= 2
</GridItem>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ export const BaseSizes: {
'4xl': '4xl';
};

export const DeviceSizes: Pick<typeof BaseSizes, 'sm' | 'md' | 'lg' | 'xl'>;
export const DeviceSizes: {
sm: 'sm';
md: 'md';
lg: 'lg';
xl: 'xl';
xl2: '2xl';
};
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export const DeviceSizes = {
[BaseSizes.sm]: BaseSizes.sm,
[BaseSizes.md]: BaseSizes.md,
[BaseSizes.lg]: BaseSizes.lg,
[BaseSizes.xl]: BaseSizes.xl
[BaseSizes.xl]: BaseSizes.xl,
xl2: BaseSizes['2xl']
};

Back | FazBrowse Home | New Git URL