Skip to content

Commit b317703

Browse files
jordanjusticeazz
authored andcommitted
feat: add columnGap and rowGap props (#49)
This PR adds the `columnGap` and `rowGap` props to enable use of the [column-gap](https://mdn.io/column-gap) and [row-gap](https://mdn.io/row-gap) properties respectively. There are no defaults for these since `gap` already included that. Closes #44.
1 parent 015458a commit b317703

File tree

4 files changed

+3082
-526
lines changed

4 files changed

+3082
-526
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Props:
4747
* `columns`: The [grid-template-columns] CSS property. When a number is passed
4848
it is a shorthand to specify the number of columns. Default is `12`.
4949
* `gap`: The [grid-gap] CSS property. Default is `"8px"`.
50+
* `columnGap`: The [column-gap] CSS property. Not provided by default.
51+
* `rowGap`: The [row-gap] CSS property. Not provided by default.
5052
* `minRowHeight`: Minimum height of each row. Default is `"20px"`.
5153
* `height`: The [height] CSS property. Default is `"auto"`.
5254
* `flow`: The [grid-auto-flow] CSS property. Default is `"row"`.
@@ -92,6 +94,8 @@ You can use CSS grid _soon_ if you have to support the latest version of modern
9294
[grid-area]: https://mdn.io/grid-area
9395
[height]: https://mdn.io/css-height
9496
[grid-gap]: https://mdn.io/grid-gap
97+
[column-gap]: https://mdn.io/column-gap
98+
[row-gap]: https://mdn.io/row-gap
9599
[justify-content]: https://mdn.io/justify-content
96100
[align-content]: https://mdn.io/align-content
97101
[caniuse]: http://caniuse.com/#feat=css-grid

lib/Grid.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const Grid = styled.div`
2020
${({ rows }) => rows && `grid-template-rows: ${frGetter(rows)}`};
2121
grid-template-columns: ${({ columns = 12 }) => frGetter(columns)};
2222
grid-gap: ${gap};
23+
${({ columnGap }) => columnGap && `column-gap: ${columnGap}`};
24+
${({ rowGap }) => rowGap && `row-gap: ${rowGap}`};
2325
${({ areas }) => areas && `grid-template-areas: ${formatAreas(areas)}`};
2426
${({ justifyContent }) =>
2527
justifyContent && `justify-content: ${justifyContent}`};
@@ -30,6 +32,8 @@ Grid.propTypes = {
3032
className: PropTypes.string,
3133
columns: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
3234
gap: PropTypes.string,
35+
columnGap: PropTypes.string,
36+
rowGap: PropTypes.string,
3337
height: PropTypes.string,
3438
minRowHeight: PropTypes.string,
3539
flow: PropTypes.string,

lib/__tests__/Grid.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ describe("<Grid />", () => {
4040
expect(tree).toHaveStyleRule("grid-gap", "7px");
4141
});
4242

43+
test("'columnGap' prop sets 'column-gap'", () => {
44+
const tree = renderer.create(<Grid columnGap="7px" />).toJSON();
45+
expect(tree).toHaveStyleRule("column-gap", "7px");
46+
});
47+
48+
test("'rowGap' prop sets 'row-gap'", () => {
49+
const tree = renderer.create(<Grid rowGap="7px" />).toJSON();
50+
expect(tree).toHaveStyleRule("row-gap", "7px");
51+
});
52+
4353
test("'minRowHeight' prop sets 'grid-auto-rows'", () => {
4454
const tree = renderer.create(<Grid minRowHeight="7px" />).toJSON();
4555
expect(tree).toHaveStyleRule("grid-auto-rows", "minmax(7px,auto)");

0 commit comments

Comments
 (0)