-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Grid): expose grid-template-rows and grid-template-columns (#17)
- Loading branch information
Showing
10 changed files
with
249 additions
and
146 deletions.
There are no files selected for viewing
This file contains 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,70 +1,74 @@ | ||
# `styled-css-grid 🍱` | ||
|
||
[![Travis](https://img.shields.io/travis/azz/styled-css-grid.svg?style=flat-square)](https://travis-ci.org/azz/styled-css-grid) | ||
[![Prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
[![npm](https://img.shields.io/npm/v/styled-css-grid.svg?style=flat-square)](https://npmjs.org/styled-css-grid) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE) | ||
[![JS.ORG](https://img.shields.io/badge/js.org-dns-ffb400.svg?style=flat-square)](http://js.org) | ||
|
||
> A tiny (~2kb) [CSS grid] layout for React, built with [styled-components] 💅. | ||
## examples | ||
|
||
See the **[website]**. | ||
|
||
## installation | ||
|
||
Install React and [styled-components], then: | ||
|
||
```bash | ||
$ yarn add styled-css-grid | ||
``` | ||
|
||
## usage | ||
|
||
```jsx | ||
import React from "react"; | ||
import { Grid, Cell } from "styled-css-grid"; | ||
|
||
const MyGrid = () => ( | ||
<Grid columns={2} gap="2px"> | ||
<Cell>foo</Cell> | ||
<Cell height={2}>bar</Cell> | ||
<Cell width={2}>baz</Cell> | ||
</Grid> | ||
); | ||
``` | ||
|
||
## api | ||
|
||
### `Cell` | ||
|
||
A cell. Not too much to say... | ||
|
||
Props: | ||
|
||
* `width`: Cell width in units, default is `1`. | ||
* `height`: Cell height in units, default is `1`. | ||
* `left`: The [grid-column-start] CSS property. Not provided by default. | ||
* `top`: The [grid-row-start] CSS property. Not provided by default. | ||
* `middle`: Vertically align the contents of the cell. Default is `false`. | ||
* `center`: Horizontally align the text contents of the cell. Default is `false`. | ||
|
||
### `Grid` | ||
|
||
Wrap your cells in `Grid`. Pretty simple. | ||
|
||
Props: | ||
|
||
* `columns`: Number of columns to draw, default is `12`. | ||
* `gap`: Gap between cells. Default is `"8px"`. | ||
* `minRowHeight`: Minimum height of each row. Default is `"20px"`. | ||
* `flow`: The [grid-auto-flow] CSS property. Default is `"row"`. | ||
|
||
[website]: https://styled-css-grid.js.org/ | ||
[CSS grid]: https://mdn.io/CSS_Grid_Layout | ||
[styled-components]: https://github.com/styled-components/styled-components | ||
[grid-auto-flow]: https://mdn.io/grid-auto-flow | ||
[grid-row-start]: https://mdn.io/grid-row-start | ||
[grid-column-start]: https://mdn.io/grid-column-start | ||
# `styled-css-grid 🍱` | ||
|
||
[![Travis](https://img.shields.io/travis/azz/styled-css-grid.svg?style=flat-square)](https://travis-ci.org/azz/styled-css-grid) | ||
[![Prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
[![npm](https://img.shields.io/npm/v/styled-css-grid.svg?style=flat-square)](https://npmjs.org/styled-css-grid) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE) | ||
[![JS.ORG](https://img.shields.io/badge/js.org-dns-ffb400.svg?style=flat-square)](http://js.org) | ||
|
||
> A tiny (~2kb) [CSS grid] layout for React, built with [styled-components] 💅. | ||
## examples | ||
|
||
See the **[website]**. | ||
|
||
## installation | ||
|
||
Install React and [styled-components], then: | ||
|
||
```bash | ||
$ yarn add styled-css-grid | ||
``` | ||
|
||
## usage | ||
|
||
```jsx | ||
import React from "react"; | ||
import { Grid, Cell } from "styled-css-grid"; | ||
|
||
const MyGrid = () => ( | ||
<Grid columns={2} gap="2px"> | ||
<Cell>foo</Cell> | ||
<Cell height={2}>bar</Cell> | ||
<Cell width={2}>baz</Cell> | ||
</Grid> | ||
); | ||
``` | ||
|
||
## api | ||
|
||
### `Cell` | ||
|
||
A cell. Not too much to say... | ||
|
||
Props: | ||
|
||
* `width`: Cell width in units, default is `1`. | ||
* `height`: Cell height in units, default is `1`. | ||
* `left`: The [grid-column-start] CSS property. Not provided by default. | ||
* `top`: The [grid-row-start] CSS property. Not provided by default. | ||
* `middle`: Vertically align the contents of the cell. Default is `false`. | ||
* `center`: Horizontally align the text contents of the cell. Default is `false`. | ||
|
||
### `Grid` | ||
|
||
Wrap your cells in `Grid`. Pretty simple. | ||
|
||
Props: | ||
|
||
* `columns`: The [grid-template-columns] CSS property. When a number is passed | ||
it is a shorthand to specify the number of columns. Default is `12`. | ||
* `gap`: Gap between cells. Default is `"8px"`. | ||
* `minRowHeight`: Minimum height of each row. Default is `"20px"`. | ||
* `flow`: The [grid-auto-flow] CSS property. Default is `"row"`. | ||
* `rows`: The [grid-template-rows] CSS property. Not provided by default. | ||
|
||
[website]: https://styled-css-grid.js.org/ | ||
[CSS grid]: https://mdn.io/CSS_Grid_Layout | ||
[styled-components]: https://github.com/styled-components/styled-components | ||
[grid-auto-flow]: https://mdn.io/grid-auto-flow | ||
[grid-row-start]: https://mdn.io/grid-row-start | ||
[grid-column-start]: https://mdn.io/grid-column-start | ||
[grid-template-columns]: https://mdn.io/grid-template-columns | ||
[grid-template-rows]: https://mdn.io/grid-template-rows |
This file contains 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,25 +1,25 @@ | ||
import styled from "styled-components"; | ||
|
||
const Cell = styled.section` | ||
height: 100%; | ||
min-width: 0; | ||
overflow: hidden; | ||
align-content: space-around; | ||
grid-column-end: ${({ width = 1 }) => `span ${width}`}; | ||
grid-row-end: ${({ height = 1 }) => `span ${height}`}; | ||
${({ left }) => left && `grid-column-start: ${left}`}; | ||
${({ top }) => top && `grid-row-start: ${top}`}; | ||
${({ center = false }) => center && `text-align: center;`}; | ||
${/* prettier-ignore */ | ||
({ middle = false }) => middle && ` | ||
display: inline-flex; | ||
flex-flow: column wrap; | ||
justify-content: center; | ||
justify-self: stretch; | ||
`}; | ||
`; | ||
|
||
export default Cell; | ||
import styled from "styled-components"; | ||
|
||
const Cell = styled.section` | ||
height: 100%; | ||
min-width: 0; | ||
overflow: hidden; | ||
align-content: space-around; | ||
grid-column-end: ${({ width = 1 }) => `span ${width}`}; | ||
grid-row-end: ${({ height = 1 }) => `span ${height}`}; | ||
${({ left }) => left && `grid-column-start: ${left}`}; | ||
${({ top }) => top && `grid-row-start: ${top}`}; | ||
${({ center = false }) => center && `text-align: center;`}; | ||
${/* prettier-ignore */ | ||
({ middle = false }) => middle && ` | ||
display: inline-flex; | ||
flex-flow: column wrap; | ||
justify-content: center; | ||
justify-self: stretch; | ||
`}; | ||
`; | ||
|
||
export default Cell; |
This file contains 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,21 +1,22 @@ | ||
import styled from "styled-components"; | ||
|
||
const minmax = ({ minRowHeight = "20px" }) => `minmax(${minRowHeight}, auto)`; | ||
|
||
const columnRepeat = ({ columns = 12 }) => `repeat(${columns}, 1fr)`; | ||
|
||
const gap = ({ gap = "8px" }) => `${gap} ${gap}`; | ||
|
||
const flow = ({ flow = "row" }) => flow; | ||
|
||
const Grid = styled.div` | ||
min-height: 100%; | ||
display: grid; | ||
grid-auto-flow: ${flow}; | ||
grid-auto-rows: ${minmax}; | ||
grid-template-rows: ${minmax}; | ||
grid-template-columns: ${columnRepeat}; | ||
grid-gap: ${gap}; | ||
`; | ||
|
||
export default Grid; | ||
import styled from "styled-components"; | ||
|
||
const autoRows = ({ minRowHeight = "20px" }) => `minmax(${minRowHeight}, auto)`; | ||
|
||
const columns = ({ columns = 12 }) => | ||
typeof columns === "number" ? `repeat(${columns}, 1fr)` : columns; | ||
|
||
const gap = ({ gap = "8px" }) => `${gap} ${gap}`; | ||
|
||
const flow = ({ flow = "row" }) => flow; | ||
|
||
const Grid = styled.div` | ||
min-height: 100%; | ||
display: grid; | ||
grid-auto-flow: ${flow}; | ||
grid-auto-rows: ${autoRows}; | ||
${({ rows }) => rows && `grid-template-rows: ${rows}`}; | ||
grid-template-columns: ${columns}; | ||
grid-gap: ${gap}; | ||
`; | ||
|
||
export default Grid; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.