From 0ef9e057f6d3739a3843975660e5c7514475e621 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Mon, 28 Aug 2017 12:43:27 -0400
Subject: [PATCH 01/14] Rewrite with CSS grid layout
---
.babelrc | 3 +-
.gitignore | 5 +--
.npmignore | 6 ++++
README.md | 55 ++++++++--------------------
demo/App.js | 33 -----------------
demo/entry.js | 9 -----
demo/index.html | 18 ----------
index.js | 5 ---
package.json | 50 ++++++++++++++------------
src/Grid.js | 7 ----
src/create-styles.js | 70 ------------------------------------
src/createGrid.js | 56 -----------------------------
src/index.js | 36 +++++++++++++++++++
storybook/Grid.js | 27 ++++++++++++++
storybook/config.js | 29 +++++++++++++++
test.js | 29 +++++++++++++++
test.js.md | 50 ++++++++++++++++++++++++++
test.js.snap | Bin 0 -> 358 bytes
test/Grid.js | 83 -------------------------------------------
test/index.js | 16 ---------
webpack.config.js | 28 ---------------
21 files changed, 223 insertions(+), 392 deletions(-)
delete mode 100644 demo/App.js
delete mode 100644 demo/entry.js
delete mode 100644 demo/index.html
delete mode 100644 index.js
delete mode 100644 src/Grid.js
delete mode 100644 src/create-styles.js
delete mode 100644 src/createGrid.js
create mode 100644 src/index.js
create mode 100644 storybook/Grid.js
create mode 100644 storybook/config.js
create mode 100644 test.js
create mode 100644 test.js.md
create mode 100644 test.js.snap
delete mode 100644 test/Grid.js
delete mode 100644 test/index.js
delete mode 100644 webpack.config.js
diff --git a/.babelrc b/.babelrc
index 974a1ca..add9366 100644
--- a/.babelrc
+++ b/.babelrc
@@ -1,7 +1,6 @@
{
"presets": [
- "es2015",
- "stage-0",
+ "env",
"react"
]
}
diff --git a/.gitignore b/.gitignore
index ee09a8a..75f69c3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
-
dist
-demo/bundle.js
+.site
+.nyc_output
+coverage
diff --git a/.npmignore b/.npmignore
index e69de29..9b05c0c 100644
--- a/.npmignore
+++ b/.npmignore
@@ -0,0 +1,6 @@
+src
+storybook
+.site
+.nyc_output
+coverage
+test.js*
diff --git a/README.md b/README.md
index 23a1796..79c0914 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,12 @@
# React CSS Grid
-**Experimental**
-Responsive CSS-based React grid component
+React layout component based on [CSS Grid Layout][spec]
-[](https://travis-ci.org/jxnblk/react-css-grid)
-[](http://standardjs.com/)
+[![Build Status][travis-badge]][travis]
+
+[travis-badge]: https://travis-ci.org/jxnblk/react-css-grid.svg?branch=master
+[travis]: https://travis-ci.org/jxnblk/react-css-grid
```sh
npm i react-css-grid
@@ -19,49 +20,23 @@ import Grid from 'react-css-grid'
class App extends React.Component {
render () {
return (
-
- Column
- Column
- Column
- Column
-
+
+ Column
+ Column
+ Column
+ Column
+
)
}
}
```
-```jsx
-// Higher order component
-import React from 'react'
-import { createGrid } from 'react-css-grid'
-
-const CustomGrid = (props) =>
-
-export default createGrid(CustomGrid)
-```
-
## Features
-- Simple, encapsulated grid layout API
-- Uses CSS for native @media-rule-based responsive styles
-- Works with server-side rendering
-
-## Grid component props
-- `col` (number 0–12) sets width across all breakpoints based on a 12 column grid.
-- `sm` (number 0–12) sets width from the `sm` breakpoint up
-- `md` (number 0–12) sets width from the `md` breakpoint up
-- `lg` (number 0–12) sets width from the `lg` breakpoint up
-- `align` (string, `top`, `middle`, `bottom`, or `baseline`) - sets vertical align
-## How it works
-
-The Grid component uses `display: inline-block` to create grid layouts.
-It creates CSS rules based on props and inserts that string into an inline style tag.
-The component only creates the rules it needs for itself,
-however other Grid components may generate duplicative styles of their own.
+- Simple, encapsulated grid layout API
-## Caveats
-- Produces an inline style **tag** within the body (e.g. not inline styles)
-- Similar component instances create duplicative CSS rules – this may or may not affect performance
-- Atomic class selectors are global
+[spec]: https://www.w3.org/TR/css-grid-1/
MIT License
diff --git a/demo/App.js b/demo/App.js
deleted file mode 100644
index d87b66d..0000000
--- a/demo/App.js
+++ /dev/null
@@ -1,33 +0,0 @@
-
-import React from 'react'
-import Grid from '../src/Grid'
-
-class App extends React.Component {
- render () {
- return (
-
-
- React CSS Grid Demo
- GitHub
-
-
-
- sm6 md3
-
-
- sm6 md3
-
-
- sm6 md3
-
-
- sm6 md3
-
-
-
- )
- }
-}
-
-export default App
-
diff --git a/demo/entry.js b/demo/entry.js
deleted file mode 100644
index 7b734fa..0000000
--- a/demo/entry.js
+++ /dev/null
@@ -1,9 +0,0 @@
-
-import React from 'react'
-import ReactDOM from 'react-dom'
-import App from './App'
-
-const div = document.getElementById('app')
-
-ReactDOM.render( , div)
-
diff --git a/demo/index.html b/demo/index.html
deleted file mode 100644
index 0c2729c..0000000
--- a/demo/index.html
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
diff --git a/index.js b/index.js
deleted file mode 100644
index b52ef3e..0000000
--- a/index.js
+++ /dev/null
@@ -1,5 +0,0 @@
-
-module.exports = require('./dist/Grid').default
-module.exports.createGrid = require('./dist/createGrid').default
-module.exports.createStyles = require('./dist/create-styles').default
-
diff --git a/package.json b/package.json
index f7e797f..f5c0a62 100644
--- a/package.json
+++ b/package.json
@@ -1,39 +1,43 @@
{
"name": "react-css-grid",
- "version": "1.0.0-beta.1",
- "description": "Responsive CSS-based React grid component",
- "main": "index.js",
+ "version": "1.0.0",
+ "description": "React layout component based on CSS Grid Layout",
+ "main": "dist/index.js",
"scripts": {
- "build": "webpack -p",
- "start": "webpack-dev-server",
- "gh-pages": "gh-pages -d demo",
- "prepublish": "mkdir -p dist && babel src --out-dir dist",
- "test": "standard && ava -v"
+ "prepublish": "babel src -d dist",
+ "start": "start-storybook -c storybook -p 8000",
+ "build": "build-storybook -c storybook -o .site",
+ "deploy": "storybook-to-ghpages",
+ "test": "nyc ava"
},
"keywords": [
"react",
"react-component",
+ "styled-components",
+ "layout",
+ "css-grid",
"grid",
"css"
],
"author": "Brent Jackson",
"license": "MIT",
+ "dependencies": {
+ "prop-types": "^15.5.10",
+ "styled-components": "^2.1.2"
+ },
"devDependencies": {
- "ava": "^0.15.2",
- "babel-cli": "^6.11.4",
- "babel-loader": "^6.2.4",
- "babel-preset-es2015": "^6.9.0",
- "babel-preset-react": "^6.11.1",
- "babel-preset-stage-0": "^6.5.0",
- "babel-register": "^6.11.6",
- "enzyme": "^2.4.1",
- "gh-pages": "^0.11.0",
- "react": "^15.3.0",
- "react-addons-test-utils": "^15.3.0",
- "react-dom": "^15.3.0",
- "standard": "^7.1.2",
- "webpack": "^1.13.1",
- "webpack-dev-server": "^1.14.1"
+ "@storybook/react": "^3.2.8",
+ "@storybook/storybook-deployer": "^2.0.0",
+ "ava": "^0.22.0",
+ "babel-cli": "^6.26.0",
+ "babel-core": "^6.26.0",
+ "babel-preset-env": "^1.6.0",
+ "babel-preset-react": "^6.24.1",
+ "babel-register": "^6.26.0",
+ "nyc": "^11.1.0",
+ "react": "^15.6.1",
+ "react-dom": "^15.6.1",
+ "react-test-renderer": "^15.6.1"
},
"ava": {
"require": [
diff --git a/src/Grid.js b/src/Grid.js
deleted file mode 100644
index 15a07c0..0000000
--- a/src/Grid.js
+++ /dev/null
@@ -1,7 +0,0 @@
-
-import createGrid from './createGrid'
-
-const Grid = createGrid('div')
-
-export default Grid
-
diff --git a/src/create-styles.js b/src/create-styles.js
deleted file mode 100644
index f300d20..0000000
--- a/src/create-styles.js
+++ /dev/null
@@ -1,70 +0,0 @@
-
-export const width = col => `${col / 12 * 100}%`
-
-export const createClassName = prefix => base => `__${prefix}${base}`
-
-export const createWidthRule = breakpoints => breakpoint => className => col => {
- if (typeof col !== 'number') {
- return ''
- }
- const media = breakpoints[breakpoint]
- const rule = `.${className}{width:${width(col)}}`
-
- return media ? `@media ${media}{${rule}}` : rule
-}
-
-export const createRule = className => prop => val => {
- return `.${className}{${prop}:${val}}`
-}
-
-const createStyles = breakpoints => ({
- align = 'top',
- ...rest
-}) => {
- const createBreakpointRule = createWidthRule(breakpoints)
-
- const styles = Object.keys(rest).map(key => {
- const val = rest[key]
- if (!val) {
- return false
- }
- const className = createClassName(key)(val)
- const rule = createBreakpointRule(key)(className)(val)
-
- return {
- className,
- rule
- }
- }).filter(s => s !== false)
-
- const boxSizingClassName = createClassName('b')('b')
- styles.push({
- className: boxSizingClassName,
- rule: createRule(boxSizingClassName)('box-sizing')('border-box')
- })
-
- const displayClassName = createClassName('d')('ib')
- styles.push({
- className: displayClassName,
- rule: createRule(displayClassName)('display')('inline-block')
- })
-
- const alignClassName = createClassName('a')(align)
- styles.push({
- className: alignClassName,
- rule: createRule(alignClassName)('vertical-align')(align)
- })
-
- const css = styles.reduce((a, b) => {
- return a + b.rule
- }, '')
-
- const className = styles.reduce((a, b) => {
- return a + b.className + ' '
- }, '').trim()
-
- return { css, className }
-}
-
-export default createStyles
-
diff --git a/src/createGrid.js b/src/createGrid.js
deleted file mode 100644
index b380912..0000000
--- a/src/createGrid.js
+++ /dev/null
@@ -1,56 +0,0 @@
-
-import React from 'react'
-import createStyles from './create-styles'
-
-const breakpoints = {
- sm: 'screen and (min-width:40em)',
- md: 'screen and (min-width:52em)',
- lg: 'screen and (min-width:64em)'
-}
-
-const cols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
-
-export const createGrid = (Comp) => {
- class GridWrap extends React.Component {
- render () {
- const {
- col = 12,
- sm,
- md,
- lg,
- align,
- children,
- ...props
- } = this.props
-
- const { css, className } = createStyles(breakpoints)({ align, col, sm, md, lg })
-
- const cx = className + ' ' + (props.className || '')
-
- return (
-
-
- {children}
-
- )
- }
- }
-
- GridWrap.propTypes = {
- col: React.PropTypes.oneOf(cols),
- sm: React.PropTypes.oneOf(cols),
- md: React.PropTypes.oneOf(cols),
- lg: React.PropTypes.oneOf(cols),
- align: React.PropTypes.oneOf([
- 'top',
- 'middle',
- 'bottom',
- 'baseline'
- ])
- }
-
- return GridWrap
-}
-
-export default createGrid
-
diff --git a/src/index.js b/src/index.js
new file mode 100644
index 0000000..ffd6d0f
--- /dev/null
+++ b/src/index.js
@@ -0,0 +1,36 @@
+import styled from 'styled-components'
+import PropTypes from 'prop-types'
+
+const px = n => typeof n === 'number' ? n + 'px' : n
+
+const width = props => ({
+ gridTemplateColumns: `repeat(auto-fit, minmax(${px(props.width)}, 1fr))`
+})
+
+const gutter = props => ({
+ gridGap: px(props.gutter)
+})
+
+const Grid = styled.div`
+ display: grid;
+ ${width}
+ ${gutter}
+`
+
+Grid.propTypes = {
+ width: PropTypes.oneOfType([
+ PropTypes.number,
+ PropTypes.string
+ ]).isRequired,
+ gutter: PropTypes.oneOfType([
+ PropTypes.number,
+ PropTypes.string
+ ]).isRequired
+}
+
+Grid.defaultProps = {
+ width: 256,
+ gutter: 32
+}
+
+export default Grid
diff --git a/storybook/Grid.js b/storybook/Grid.js
new file mode 100644
index 0000000..5294b9e
--- /dev/null
+++ b/storybook/Grid.js
@@ -0,0 +1,27 @@
+import React from 'react'
+import styled from 'styled-components'
+import { storiesOf } from '@storybook/react'
+import Grid from '../src'
+
+const Col = styled.div`
+ box-shadow: inset 0 0 0 1px cyan;
+`
+
+storiesOf('Grid', module)
+ .add('Demo', () => (
+
+
+ React CSS Grid
+
+
+ With varying height columns
+ React layout component for simple grids using CSS Grid
+
+
+ React layout component for simple grids using CSS Grid
+
+
+ React layout component for simple grids using CSS Grid
+
+
+ ))
diff --git a/storybook/config.js b/storybook/config.js
new file mode 100644
index 0000000..3f88d0d
--- /dev/null
+++ b/storybook/config.js
@@ -0,0 +1,29 @@
+import React from 'react'
+import { configure, addDecorator } from '@storybook/react'
+import { injectGlobal } from 'styled-components'
+import Grid from '../src'
+
+injectGlobal([], {
+ '*': {
+ boxSizing: 'border-box'
+ },
+ body: {
+ fontFamily: '-apple-system, BlinkMacSystemFont, sans-serif',
+ lineHeight: 1.5,
+ margin: 0
+ }
+})
+
+addDecorator(story => (
+
+ {story()}
+
+))
+
+const req = require.context('.', true, /\.js$/)
+
+const load = () => {
+ req.keys().forEach(req)
+}
+
+configure(load, module)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..8d18614
--- /dev/null
+++ b/test.js
@@ -0,0 +1,29 @@
+import test from 'ava'
+import React from 'react'
+import { create as render } from 'react-test-renderer'
+import Grid from './src'
+
+test('renders', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
+
+test('renders with width prop', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
+
+test('renders with string width prop', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
+
+test('renders with gutter prop', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
+
+test('renders with string gutter prop', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
diff --git a/test.js.md b/test.js.md
new file mode 100644
index 0000000..f36cfbd
--- /dev/null
+++ b/test.js.md
@@ -0,0 +1,50 @@
+# Snapshot report for `test.js`
+
+The actual snapshot is saved in `test.js.snap`.
+
+Generated by [AVA](https://ava.li).
+
+## renders
+
+> Snapshot 1
+
+
+
+## renders with gutter prop
+
+> Snapshot 1
+
+
+
+## renders with string gutter prop
+
+> Snapshot 1
+
+
+
+## renders with string width prop
+
+> Snapshot 1
+
+
+
+## renders with width prop
+
+> Snapshot 1
+
+
diff --git a/test.js.snap b/test.js.snap
new file mode 100644
index 0000000000000000000000000000000000000000..8f731c424eca621a50b0dac449be3a8a9ee4b096
GIT binary patch
literal 358
zcmV-s0h#_mRzV?+B8)6TjLa#SWdedCjO;>;Z2n1EsUW3rrl6o8)Bkz~Mji%6CI&`6pbjQcMrH<(
zKF;Kv#NuMV#N1Svh(K|&Zc<8EqF16qdXi(lS2~&w*7D4hk_<49nF(azAaQJ}Z&0{v
z2tLO;3?9d3M0t2Qx#4y!kjG+TkeWMq9PAq! {
- t.notThrows(() => {
- wrapper = shallow( )
- })
-})
-
-test('includes a style tag', t => {
- const style = wrapper.find('style')
- t.is(style.type(), 'style')
-})
-
-test('includes default rules', t => {
- const html = wrapper.find('style').html()
- t.regex(html, /display:inline-block/)
- t.regex(html, /vertical-align:top/)
- t.regex(html, /box-sizing:border-box/)
-})
-
-test('applies default classNames', t => {
- t.regex(wrapper.props().className, /__col12 __bb __dib __atop/)
-})
-
-test('sm prop creates @media rules', t => {
- t.plan(3)
- wrapper = shallow( )
- const style = wrapper.find('style').html()
- t.regex(style, /@media/)
- t.regex(style, /(min-width:40em)/)
- t.regex(style, /width:50%/)
-})
-
-test('sm prop applies sm className', t => {
- wrapper = shallow( )
- t.regex(wrapper.props().className, /__sm6/)
-})
-
-test('md prop creates @media rules', t => {
- t.plan(3)
- wrapper = shallow( )
- const style = wrapper.find('style').html()
- t.regex(style, /@media/)
- t.regex(style, /(min-width:52em)/)
- t.regex(style, /width:50%/)
-})
-
-test('md prop applies md className', t => {
- wrapper = shallow( )
- t.regex(wrapper.props().className, /__md6/)
-})
-
-test('lg prop creates @media rules', t => {
- t.plan(3)
- wrapper = shallow( )
- const style = wrapper.find('style').html()
- t.regex(style, /@media/)
- t.regex(style, /(min-width:64em)/)
- t.regex(style, /width:50%/)
-})
-
-test('lg prop applies lg className', t => {
- wrapper = shallow( )
- t.regex(wrapper.props().className, /__lg6/)
-})
-
-test('align prop creates vertical align rules', t => {
- t.plan(4)
- wrapper = shallow( )
- const style = wrapper.find('style').html()
- const { className } = wrapper.props()
- t.regex(style, /vertical-align:middle/)
- t.false(/vertical-align:top/.test(style))
- t.regex(className, /__amiddle/)
- t.false(/__atop/.test(className))
-})
-
diff --git a/test/index.js b/test/index.js
deleted file mode 100644
index 34d9c8b..0000000
--- a/test/index.js
+++ /dev/null
@@ -1,16 +0,0 @@
-
-import test from 'ava'
-import Grid, { createGrid, createStyles } from '../index'
-
-test('exports Grid', t => {
- t.is(typeof Grid, 'function')
-})
-
-test('exports createGrid', t => {
- t.is(typeof createGrid, 'function')
-})
-
-test('exports createStyles', t => {
- t.is(typeof createStyles, 'function')
-})
-
diff --git a/webpack.config.js b/webpack.config.js
deleted file mode 100644
index 23af3cf..0000000
--- a/webpack.config.js
+++ /dev/null
@@ -1,28 +0,0 @@
-
-var path = require('path')
-
-module.exports = {
- entry: './demo/entry.js',
-
- output: {
- path: path.join(__dirname, 'demo'),
- filename: 'bundle.js'
- },
-
- module: {
- loaders: [
- {
- test: /\.js$/,
- exclude: /node_modules/,
- loaders: [
- 'babel'
- ]
- }
- ]
- },
-
- devServer: {
- contentBase: 'demo/'
- }
-}
-
From ecf4d986d9cdc67b76b5fce26d9c4d007be97af5 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Mon, 28 Aug 2017 12:58:36 -0400
Subject: [PATCH 02/14] Edit readme
---
.travis.yml | 2 +-
LICENSE.md | 10 ++++++++++
README.md | 31 ++++++++++++++++++++++++++++---
src/index.js | 10 +++++-----
test.js | 8 ++++----
test.js.md | 18 ++++++++++++++++++
test.js.snap | Bin 358 -> 408 bytes
7 files changed, 66 insertions(+), 13 deletions(-)
create mode 100644 LICENSE.md
diff --git a/.travis.yml b/.travis.yml
index 3a0a434..245900f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,3 @@
language: node_js
node_js:
- - 6.2
+ - 8
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..80a44d3
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,10 @@
+
+# The MIT License (MIT)
+Copyright (c) 2017 Brent Jackson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/README.md b/README.md
index 79c0914..0b3c26d 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# React CSS Grid
-React layout component based on [CSS Grid Layout][spec]
+React layout component based on [CSS Grid Layout][spec] ([Demo][demo])
[![Build Status][travis-badge]][travis]
@@ -33,10 +33,35 @@ class App extends React.Component {
}
```
+
## Features
-- Simple, encapsulated grid layout API
+- Responsive grid layout with zero media queries
+- Simple API for handling tiled layouts
+- Customizable column width and gutters
+
+
+## Props
+
+- `width` (number or string) width at which child elements will break into columns - either a number pixel value or any valid CSS width value as a string
+- `gap` (number or string) gutter (`grid-gap`) between columns - either a number pixel value or any valid CSS width value as a string
+
+
+## Browser Support
+
+See http://caniuse.com/#feat=css-grid
+
+## Related
+
+- [Grid Styled](https://github.com/jxnblk/grid-styled)
+- [styled-components](https://github.com/styled-components/styled-components)
+- [CSS Grid Layout Module][spec]
+- [CSS Grid Layout on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout)
+- [Grid by Example](https://gridbyexample.com/video/series-auto-fill-auto-fit/)
+- [Spring Into CSS Grid](http://jonibologna.com/spring-into-css-grid/)
+
[spec]: https://www.w3.org/TR/css-grid-1/
+[demo]: http://jxnblk.com/react-css-grid/
-MIT License
+[MIT License](LICENSE.md)
diff --git a/src/index.js b/src/index.js
index ffd6d0f..d86c8e8 100644
--- a/src/index.js
+++ b/src/index.js
@@ -7,14 +7,14 @@ const width = props => ({
gridTemplateColumns: `repeat(auto-fit, minmax(${px(props.width)}, 1fr))`
})
-const gutter = props => ({
- gridGap: px(props.gutter)
+const gap = props => ({
+ gridGap: px(props.gap)
})
const Grid = styled.div`
display: grid;
${width}
- ${gutter}
+ ${gap}
`
Grid.propTypes = {
@@ -22,7 +22,7 @@ Grid.propTypes = {
PropTypes.number,
PropTypes.string
]).isRequired,
- gutter: PropTypes.oneOfType([
+ gap: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
]).isRequired
@@ -30,7 +30,7 @@ Grid.propTypes = {
Grid.defaultProps = {
width: 256,
- gutter: 32
+ gap: 32
}
export default Grid
diff --git a/test.js b/test.js
index 8d18614..5c48233 100644
--- a/test.js
+++ b/test.js
@@ -18,12 +18,12 @@ test('renders with string width prop', t => {
t.snapshot(a)
})
-test('renders with gutter prop', t => {
- const a = render( ).toJSON()
+test('renders with gap prop', t => {
+ const a = render( ).toJSON()
t.snapshot(a)
})
-test('renders with string gutter prop', t => {
- const a = render( ).toJSON()
+test('renders with string gap prop', t => {
+ const a = render( ).toJSON()
t.snapshot(a)
})
diff --git a/test.js.md b/test.js.md
index f36cfbd..fcecb07 100644
--- a/test.js.md
+++ b/test.js.md
@@ -47,4 +47,22 @@ Generated by [AVA](https://ava.li).
Snapshot 1
+
+
+
+## renders with string gap prop
+
+> Snapshot 1
+
+
\ No newline at end of file
diff --git a/test.js.snap b/test.js.snap
index 8f731c424eca621a50b0dac449be3a8a9ee4b096..21ae2974fed6ce9e47489e60dbddf86a34a096b5 100644
GIT binary patch
literal 408
zcmV;J0cZX}RzV
y1Rn1T&CYpN;Q6Gy400000000x)
z!@$76&JfAaF)9xHtN0H_Bfn##<;U=_FG@`tmB5AODvS`g{+rIisZD#XITkoP9{rqh*n)jy9W
zED^PgmSF^o?gwHf23eq67#W2a1ro~=bqjJz(=+pQi&7JlOBg|biIF)Rs2~=I`+-=5
zkwu7+IVH19Kv0B{U5Js*KPf8}q!i8+6cl9oU(dkE!@$VIz{m&G!6eGa%mC8InVgeY
zToTsa?JNiN7KPto|#gT0p>9?feaiZj!pFq3U>{`=U9iq
zQnESWFC3a|e%ueM5u%@P_UnN(vcHQI0;2L&dSfEo1>iXt(Nn1pol}
C&$W*L
literal 358
zcmV-s0h#_mRzV?+B8)6TjLa#SWdedCjO;>;Z2n1EsUW3rrl6o8)Bkz~Mji%6CI&`6pbjQcMrH<(
zKF;Kv#NuMV#N1Svh(K|&Zc<8EqF16qdXi(lS2~&w*7D4hk_<49nF(azAaQJ}Z&0{v
z2tLO;3?9d3M0t2Qx#4y!kjG+TkeWMq9PAq!
Date: Mon, 28 Aug 2017 13:46:59 -0400
Subject: [PATCH 03/14] Edit readme
---
README.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 0b3c26d..1b1f198 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# React CSS Grid
-React layout component based on [CSS Grid Layout][spec] ([Demo][demo])
+React layout component based on [CSS Grid Layout][spec] and built with [styled-components][sc] ([Demo][demo])
[![Build Status][travis-badge]][travis]
@@ -54,7 +54,7 @@ See http://caniuse.com/#feat=css-grid
## Related
- [Grid Styled](https://github.com/jxnblk/grid-styled)
-- [styled-components](https://github.com/styled-components/styled-components)
+- [styled-components][sc]
- [CSS Grid Layout Module][spec]
- [CSS Grid Layout on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout)
- [Grid by Example](https://gridbyexample.com/video/series-auto-fill-auto-fit/)
@@ -63,5 +63,6 @@ See http://caniuse.com/#feat=css-grid
[spec]: https://www.w3.org/TR/css-grid-1/
[demo]: http://jxnblk.com/react-css-grid/
+[sc]: https://styled-components.com
[MIT License](LICENSE.md)
From 267a45a4d3d4094cb9caea005da098c48591b790 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 07:54:35 -0400
Subject: [PATCH 04/14] Add docs setup
---
.gitignore | 1 -
.npmignore | 3 ++-
docs/App.js | 21 +++++++++++++++++++++
docs/Col.js | 5 +++++
docs/entry.js | 5 +++++
docs/index.html | 6 ++++++
package.json | 16 ++++++++++------
webpack.config.js | 37 +++++++++++++++++++++++++++++++++++++
8 files changed, 86 insertions(+), 8 deletions(-)
create mode 100644 docs/App.js
create mode 100644 docs/Col.js
create mode 100644 docs/entry.js
create mode 100644 docs/index.html
create mode 100644 webpack.config.js
diff --git a/.gitignore b/.gitignore
index 75f69c3..f3389d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
dist
-.site
.nyc_output
coverage
diff --git a/.npmignore b/.npmignore
index 9b05c0c..60a7634 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,6 +1,7 @@
src
+docs
storybook
-.site
+webpack.config.js
.nyc_output
coverage
test.js*
diff --git a/docs/App.js b/docs/App.js
new file mode 100644
index 0000000..6b3295f
--- /dev/null
+++ b/docs/App.js
@@ -0,0 +1,21 @@
+import React from 'react'
+import Grid from 'react-css-grid'
+import { Box } from 'grid-styled'
+import Col from './Col'
+
+const App = props => (
+
+
+
+ React CSS Grid
+
+
+
+ React layout component based on CSS Grid Layout and built with styled-components
+
+
+
+
+)
+
+export default App
diff --git a/docs/Col.js b/docs/Col.js
new file mode 100644
index 0000000..bab8153
--- /dev/null
+++ b/docs/Col.js
@@ -0,0 +1,5 @@
+import styled from 'styled-components'
+
+export default styled.div`
+ box-shadow: 0 0 0 1px rgba(0, 127, 255, .5);
+`
diff --git a/docs/entry.js b/docs/entry.js
new file mode 100644
index 0000000..763a33b
--- /dev/null
+++ b/docs/entry.js
@@ -0,0 +1,5 @@
+import React from 'react'
+import { render } from 'react-dom'
+import App from './App'
+
+render( , app)
diff --git a/docs/index.html b/docs/index.html
new file mode 100644
index 0000000..ddcc4ac
--- /dev/null
+++ b/docs/index.html
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/package.json b/package.json
index f5c0a62..fa51098 100644
--- a/package.json
+++ b/package.json
@@ -1,13 +1,12 @@
{
"name": "react-css-grid",
"version": "1.0.0",
- "description": "React layout component based on CSS Grid Layout",
+ "description": "React layout component based on CSS Grid Layout and built with styled-components",
"main": "dist/index.js",
"scripts": {
"prepublish": "babel src -d dist",
- "start": "start-storybook -c storybook -p 8000",
- "build": "build-storybook -c storybook -o .site",
- "deploy": "storybook-to-ghpages",
+ "start": "webpack-dev-server",
+ "build": "webpack -p",
"test": "nyc ava"
},
"keywords": [
@@ -27,17 +26,22 @@
},
"devDependencies": {
"@storybook/react": "^3.2.8",
- "@storybook/storybook-deployer": "^2.0.0",
"ava": "^0.22.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
+ "grid-styled": "^2.0.0-10",
"nyc": "^11.1.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
- "react-test-renderer": "^15.6.1"
+ "react-live": "^1.7.0",
+ "react-test-renderer": "^15.6.1",
+ "react-x-ray": "^1.0.0-2",
+ "refunk": "^1.0.0-2",
+ "webpack": "^3.5.5",
+ "webpack-dev-server": "^2.7.1"
},
"ava": {
"require": [
diff --git a/webpack.config.js b/webpack.config.js
new file mode 100644
index 0000000..38a12ff
--- /dev/null
+++ b/webpack.config.js
@@ -0,0 +1,37 @@
+const path = require('path')
+const webpack = require('webpack')
+
+module.exports = {
+ entry: './docs/entry.js',
+
+ output: {
+ path: path.join(__dirname, 'docs'),
+ filename: 'bundle.js'
+ },
+
+ resolve: {
+ alias: {
+ 'react-css-grid': path.join(__dirname, 'src')
+ }
+ },
+
+ module: {
+ rules: [
+ {
+ test: /\.js$/,
+ exclude: /node_modules/,
+ loader: 'babel-loader'
+ }
+ ]
+ },
+
+ plugins: [
+ new webpack.DefinePlugin({
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
+ })
+ ],
+
+ devServer: {
+ contentBase: 'docs/'
+ }
+}
From ca7148574cf330b186d53473287dea0fb277c030 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 21:01:24 -0400
Subject: [PATCH 05/14] Add docs
---
README.md | 25 +++++-
docs/App.js | 211 +++++++++++++++++++++++++++++++++++++++++++---
docs/BlockLink.js | 12 +++
docs/Code.js | 8 ++
docs/Flex.js | 8 ++
docs/Heading.js | 16 ++++
docs/Image.js | 10 +++
docs/Link.js | 7 ++
docs/List.js | 8 ++
docs/Live.js | 55 ++++++++++++
docs/Pre.js | 14 +++
docs/Text.js | 12 +++
docs/Tweet.js | 26 ++++++
docs/index.html | 16 ++++
src/index.js | 24 ++++--
15 files changed, 431 insertions(+), 21 deletions(-)
create mode 100644 docs/BlockLink.js
create mode 100644 docs/Code.js
create mode 100644 docs/Flex.js
create mode 100644 docs/Heading.js
create mode 100644 docs/Image.js
create mode 100644 docs/Link.js
create mode 100644 docs/List.js
create mode 100644 docs/Live.js
create mode 100644 docs/Pre.js
create mode 100644 docs/Text.js
create mode 100644 docs/Tweet.js
diff --git a/README.md b/README.md
index 1b1f198..acd8e11 100644
--- a/README.md
+++ b/README.md
@@ -43,17 +43,38 @@ class App extends React.Component {
## Props
-- `width` (number or string) width at which child elements will break into columns - either a number pixel value or any valid CSS width value as a string
-- `gap` (number or string) gutter (`grid-gap`) between columns - either a number pixel value or any valid CSS width value as a string
+### `width` (number or string)
+
+Sets the width at which child elements will break into columns.
+Pass a number for pixel values or a string for any other valid CSS length.
+
+```jsx
+
+```
+
+### `gap` (number or string)
+
+Sets the gutter (`grid-gap`) between columns.
+Pass a number for pixel values or a string for any other valid CSS length.
+
+```jsx
+
+```
+
+### `align` (string)
+
+Sets `align-items` to control child element alignment.
## Browser Support
See http://caniuse.com/#feat=css-grid
+
## Related
- [Grid Styled](https://github.com/jxnblk/grid-styled)
+- [Styled System](https://github.com/jxnblk/styled-system)
- [styled-components][sc]
- [CSS Grid Layout Module][spec]
- [CSS Grid Layout on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout)
diff --git a/docs/App.js b/docs/App.js
index 6b3295f..9f221ac 100644
--- a/docs/App.js
+++ b/docs/App.js
@@ -1,21 +1,206 @@
import React from 'react'
+import { createProvider } from 'refunk'
+import XRay from 'react-x-ray'
import Grid from 'react-css-grid'
import { Box } from 'grid-styled'
import Col from './Col'
+import Heading from './Heading'
+import Pre from './Pre'
+import Text from './Text'
+import Link from './Link'
+import Flex from './Flex'
+import BlockLink from './BlockLink'
+import Image from './Image'
+import Tweet from './Tweet'
+import Code from './Code'
+import List from './List'
+import Live from './Live'
const App = props => (
-
-
-
- React CSS Grid
-
-
-
- React layout component based on CSS Grid Layout and built with styled-components
-
-
-
-
+
+ {
+ props.update(toggleXRay)
+ }}
+ children='xray'
+ />
+
+ width {props.width}
+ props.update(handleWidthChange(e.target.value))}
+ />
+
+
+ gap {props.gap}
+ props.update(handleGapChange(e.target.value))}
+ />
+
+
+
+ React CSS Grid
+
+
+ React layout component based on CSS Grid Layout and built with
+ {' '}
+
+ styled-components
+
+
+
+ npm i react-css-grid
+
+
+
+
+
+
+
+
+
+
+
+ Features
+
+ Responsive grid layout with zero media queries
+ Simple API for handling tiled layouts
+ Customizable column width and gutters
+
+
+
+ Props
+
+
+ width
+
+ Sets the width at which child elements will break into columns.
+ Pass a number for pixel values or a string for any other valid CSS length.
+
+
+
+ gap
+
+ Sets the gutter (grid-gap) between columns.
+ Pass a number for pixel values or a string for any other valid CSS length.
+
+
+
+ align
+
+ Sets align-items to control child element alignment.
+
+
+
+
+
+ Width
+
+
+
+ Gap
+
+
+
+
+ GitHub
+
+ Made by Jxnblk
+
+
+
+
+
)
-export default App
+const usage = `import React from 'react'
+import Grid from 'react-css-grid'
+
+class App extends React.Component {
+ render () {
+ return (
+
+ Column
+ Column
+ Column
+ Column
+
+ )
+ }
+}`
+
+const widthExample = `
+ Hello
+ Hi
+ `
+
+const gapExample = `
+ Hello
+ Hi
+ `
+
+const state = {
+ width: 320,
+ gap: 32,
+ xray: false
+}
+
+const toggleXRay = state => ({ xray: !state.xray })
+
+const widths = [
+ 128,
+ 192,
+ 256,
+ 320,
+ 384,
+ 512,
+ 768,
+ 1024
+]
+
+const handleWidthChange = val => state => ({
+ width: widths[parseInt(val)]
+})
+
+const gaps = [
+ 0,
+ 8,
+ 16,
+ 32,
+ 64,
+ 128
+]
+
+const handleGapChange = val => state => ({
+ gap: gaps[parseInt(val)]
+})
+
+export default createProvider(state)(App)
diff --git a/docs/BlockLink.js b/docs/BlockLink.js
new file mode 100644
index 0000000..e9ae6f1
--- /dev/null
+++ b/docs/BlockLink.js
@@ -0,0 +1,12 @@
+import styled from 'styled-components'
+import { space } from 'styled-system'
+
+const BlockLink = styled.a`
+ margin: 0;
+ display: block;
+ text-decoration: none;
+ color: inherit;
+ ${space}
+`
+
+export default BlockLink
diff --git a/docs/Code.js b/docs/Code.js
new file mode 100644
index 0000000..eba7bde
--- /dev/null
+++ b/docs/Code.js
@@ -0,0 +1,8 @@
+import styled from 'styled-components'
+
+const Code = styled.code`
+ font-family: Menlo, monospace;
+ font-size: 14px;
+`
+
+export default Code
diff --git a/docs/Flex.js b/docs/Flex.js
new file mode 100644
index 0000000..18ac9d6
--- /dev/null
+++ b/docs/Flex.js
@@ -0,0 +1,8 @@
+import styled from 'styled-components'
+
+const Flex = styled.div`
+ display: flex;
+ align-items: center;
+`
+
+export default Flex
diff --git a/docs/Heading.js b/docs/Heading.js
new file mode 100644
index 0000000..b497e5a
--- /dev/null
+++ b/docs/Heading.js
@@ -0,0 +1,16 @@
+import styled from 'styled-components'
+import { space, fontSize } from 'styled-system'
+
+const Heading = styled.h2`
+ ${space}
+ ${fontSize}
+`
+
+Heading.defaultProps = {
+ f: 5,
+ m: 0
+}
+
+Heading.h1 = Heading.withComponent('h1')
+
+export default Heading
diff --git a/docs/Image.js b/docs/Image.js
new file mode 100644
index 0000000..76338cb
--- /dev/null
+++ b/docs/Image.js
@@ -0,0 +1,10 @@
+import styled from 'styled-components'
+
+const Image = styled.img`
+ display: block;
+ margin: 0;
+ max-width: 100%;
+ height: auto;
+`
+
+export default Image
diff --git a/docs/Link.js b/docs/Link.js
new file mode 100644
index 0000000..6577110
--- /dev/null
+++ b/docs/Link.js
@@ -0,0 +1,7 @@
+import styled from 'styled-components'
+
+const Link = styled.a`
+ color: #07c;
+`
+
+export default Link
diff --git a/docs/List.js b/docs/List.js
new file mode 100644
index 0000000..e9ad8da
--- /dev/null
+++ b/docs/List.js
@@ -0,0 +1,8 @@
+import styled from 'styled-components'
+
+const List = styled.ul`
+ padding-left: 0;
+ margin: 0;
+`
+
+export default List
diff --git a/docs/Live.js b/docs/Live.js
new file mode 100644
index 0000000..e35d6b9
--- /dev/null
+++ b/docs/Live.js
@@ -0,0 +1,55 @@
+import React from 'react'
+import Grid from 'react-css-grid'
+import XRay from 'react-x-ray'
+import styled from 'styled-components'
+import {
+ LiveProvider,
+ LivePreview,
+ LiveEditor,
+ LiveError,
+} from 'react-live'
+
+const Preview = styled(LivePreview)`
+ padding: 16px;
+ border: 1px solid #999;
+ border-radius: 3px 3px 0 0;
+`
+
+const Editor = styled(LiveEditor)`
+ font-family: Menlo, monospace;
+ font-size: 12px;
+ tab-size: 2;
+ padding: 16px;
+ margin: 0;
+ color: white;
+ background-color: black;
+ border-radius: 0 0 3px 3px;
+ outline: none;
+`
+
+const Err = styled(LiveError)`
+ font-family: Menlo, monospace;
+ font-size: 12px;
+ padding: 16px;
+ color: white;
+ background-color: red;
+`
+
+const scope = {
+ Grid
+}
+
+const Live = props => (
+
+
+
+
+
+
+
+)
+
+export default Live
diff --git a/docs/Pre.js b/docs/Pre.js
new file mode 100644
index 0000000..d8575b5
--- /dev/null
+++ b/docs/Pre.js
@@ -0,0 +1,14 @@
+import styled from 'styled-components'
+import { space } from 'styled-system'
+
+const Pre = styled.pre`
+ font-family: Menlo, monospace;
+ font-size: 14px;
+ ${space}
+`
+
+Pre.defaultProps = {
+ m: 0
+}
+
+export default Pre
diff --git a/docs/Text.js b/docs/Text.js
new file mode 100644
index 0000000..ad4d620
--- /dev/null
+++ b/docs/Text.js
@@ -0,0 +1,12 @@
+import styled from 'styled-components'
+import {
+ space,
+ fontSize
+} from 'styled-system'
+
+const Text = styled.div`
+ ${space}
+ ${fontSize}
+`
+
+export default Text
diff --git a/docs/Tweet.js b/docs/Tweet.js
new file mode 100644
index 0000000..527e52f
--- /dev/null
+++ b/docs/Tweet.js
@@ -0,0 +1,26 @@
+import React from 'react'
+
+const text = ``
+
+class Tweet extends React.Component {
+ componentDidMount () {
+ if (typeof twttr !== 'undefined') {
+ twttr.widgets.load(
+ this.root
+ )
+ }
+ }
+
+ render () {
+ return (
+ this.root = ref}
+ className='twitter-share-button'
+ href={`https://twitter.com/intent/tweet?via=jxnblk`}
+ children='Tweet'
+ />
+ )
+ }
+}
+
+export default Tweet
diff --git a/docs/index.html b/docs/index.html
index ddcc4ac..4338590 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -1,6 +1,22 @@
+React CSS Grid
+
+
+
+
+
+
diff --git a/src/index.js b/src/index.js
index d86c8e8..61ff39f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -11,11 +11,21 @@ const gap = props => ({
gridGap: px(props.gap)
})
-const Grid = styled.div`
- display: grid;
- ${width}
- ${gap}
-`
+const align = props => props.align ? ({
+ alignItems: props.align
+}) : null
+
+const span = props => props.span ? ({
+ gridColumn: `span ${props.span}`
+}) : null
+
+const Grid = styled.div([], {
+ display: 'grid'
+},
+ width,
+ gap,
+ align
+)
Grid.propTypes = {
width: PropTypes.oneOfType([
@@ -29,8 +39,10 @@ Grid.propTypes = {
}
Grid.defaultProps = {
- width: 256,
+ width: 320,
gap: 32
}
+Grid.Item = styled.div([], span)
+
export default Grid
From 6c4c7701d5e78aad6c7b108a0906c74d945a0f4b Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 21:38:37 -0400
Subject: [PATCH 06/14] Add slider
---
docs/App.js | 135 +++++++++++++++++++++++++++++--------------------
docs/Bar.js | 9 ++++
docs/Pre.js | 2 +
docs/Slider.js | 33 ++++++++++++
src/index.js | 11 ++--
5 files changed, 131 insertions(+), 59 deletions(-)
create mode 100644 docs/Bar.js
create mode 100644 docs/Slider.js
diff --git a/docs/App.js b/docs/App.js
index 9f221ac..216b39e 100644
--- a/docs/App.js
+++ b/docs/App.js
@@ -3,6 +3,8 @@ import { createProvider } from 'refunk'
import XRay from 'react-x-ray'
import Grid from 'react-css-grid'
import { Box } from 'grid-styled'
+import Bar from './Bar'
+import Slider from './Slider'
import Col from './Col'
import Heading from './Heading'
import Pre from './Pre'
@@ -18,72 +20,78 @@ import Live from './Live'
const App = props => (
- {
- props.update(toggleXRay)
- }}
- children='xray'
- />
-
- width {props.width}
- props.update(handleWidthChange(e.target.value))}
- />
-
-
- gap {props.gap}
- props.update(handleGapChange(e.target.value))}
- />
-
-
+
+
+ {
+ props.update(toggleXRay)
+ }}
+ children='xray'
+ />
+
+ width {props.width}
+ props.update(handleWidthChange(e.target.value))}
+ />
+
+
+ gap {props.gap}
+ props.update(handleGapChange(e.target.value))}
+ />
+
+
+
+
- React CSS Grid
-
+ React CSS Grid
+
React layout component based on CSS Grid Layout and built with
{' '}
styled-components
+
+
+
+
+
+
+
+
+
- npm i react-css-grid
-
-
-
-
-
-
-
-
-
+
Install
+
npm i react-css-grid
+
+
Usage
-
+
Features
@@ -125,12 +133,20 @@ const App = props => (
Gap
+
+ Align
+
+
-
- GitHub
-
- Made by Jxnblk
-
+ Footer
+
+
+ GitHub
+
+
+ Made by Jxnblk
+
+
@@ -167,6 +183,13 @@ const gapExample = `Hi
`
+const alignExample = `
+ Hello
+ Hi
+ `
+
const state = {
width: 320,
gap: 32,
diff --git a/docs/Bar.js b/docs/Bar.js
new file mode 100644
index 0000000..45f3ae3
--- /dev/null
+++ b/docs/Bar.js
@@ -0,0 +1,9 @@
+import styled from 'styled-components'
+import { Box } from 'grid-styled'
+
+const Bar = styled(Box)`
+ color: white;
+ background-color: black;
+`
+
+export default Bar
diff --git a/docs/Pre.js b/docs/Pre.js
index d8575b5..148f8ab 100644
--- a/docs/Pre.js
+++ b/docs/Pre.js
@@ -4,6 +4,8 @@ import { space } from 'styled-system'
const Pre = styled.pre`
font-family: Menlo, monospace;
font-size: 14px;
+ max-width: 100%;
+ overflow: auto;
${space}
`
diff --git a/docs/Slider.js b/docs/Slider.js
new file mode 100644
index 0000000..52879b8
--- /dev/null
+++ b/docs/Slider.js
@@ -0,0 +1,33 @@
+import styled from 'styled-components'
+
+const Slider = styled.input`
+ display: block;
+ width: 100%;
+ margin: 0;
+ height: 2px;
+ cursor: pointer;
+ color: inherit;
+ background-color: rgba(255, 255, 255, .25);
+ border-radius: 0;
+ appearance: none;
+
+ &::-webkit-slider-thumb {
+ width: 12px;
+ height: 12px;
+ background-color: currentcolor;
+ border: 0;
+ border-radius: 9999px;
+ appearance: none;
+ }
+
+ &:focus {
+ outline: none;
+ background-color: rgba(255, 255, 255, .5);
+ }
+`
+
+Slider.defaultProps = {
+ type: 'range'
+}
+
+export default Slider
diff --git a/src/index.js b/src/index.js
index 61ff39f..3c8d5ef 100644
--- a/src/index.js
+++ b/src/index.js
@@ -4,7 +4,9 @@ import PropTypes from 'prop-types'
const px = n => typeof n === 'number' ? n + 'px' : n
const width = props => ({
- gridTemplateColumns: `repeat(auto-fit, minmax(${px(props.width)}, 1fr))`
+ // ['@media screen and (min-width:320px)']: {
+ gridTemplateColumns: `repeat(auto-fit, minmax(${px(props.width)}, 1fr))`
+ // }
})
const gap = props => ({
@@ -20,7 +22,8 @@ const span = props => props.span ? ({
}) : null
const Grid = styled.div([], {
- display: 'grid'
+ display: 'grid',
+ maxWidth: '100%'
},
width,
gap,
@@ -43,6 +46,8 @@ Grid.defaultProps = {
gap: 32
}
-Grid.Item = styled.div([], span)
+Grid.Item = styled.div([], {
+ maxWidth: '100%'
+}, span)
export default Grid
From d7d9e284edf57805fcbef5b7cca87e2a51f21eb4 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 22:23:58 -0400
Subject: [PATCH 07/14] Adjust docs styles
---
docs/App.js | 32 ++++++++++++++++++--------------
docs/Button.js | 18 ++++++++++++++++++
docs/Label.js | 9 +++++++++
docs/Slider.js | 5 ++++-
4 files changed, 49 insertions(+), 15 deletions(-)
create mode 100644 docs/Button.js
create mode 100644 docs/Label.js
diff --git a/docs/App.js b/docs/App.js
index 216b39e..5525cce 100644
--- a/docs/App.js
+++ b/docs/App.js
@@ -4,6 +4,8 @@ import XRay from 'react-x-ray'
import Grid from 'react-css-grid'
import { Box } from 'grid-styled'
import Bar from './Bar'
+import Button from './Button'
+import Label from './Label'
import Slider from './Slider'
import Col from './Col'
import Heading from './Heading'
@@ -20,16 +22,13 @@ import Live from './Live'
const App = props => (
-
-
- {
- props.update(toggleXRay)
- }}
- children='xray'
- />
+
+
- width {props.width}
+ width {props.width}
(
/>
- gap {props.gap}
+ gap {props.gap}
(
onChange={e => props.update(handleGapChange(e.target.value))}
/>
+ {
+ props.update(toggleXRay)
+ }}
+ children='x-ray'
+ />
+ gap={props.gap}>
- React CSS Grid
+ React CSS Grid
React layout component based on CSS Grid Layout and built with
{' '}
@@ -85,7 +89,7 @@ const App = props => (
-
Install
+
Install
npm i react-css-grid
diff --git a/docs/Button.js b/docs/Button.js
new file mode 100644
index 0000000..17f7da7
--- /dev/null
+++ b/docs/Button.js
@@ -0,0 +1,18 @@
+import styled from 'styled-components'
+
+const Button = styled.button`
+ display: inline-block;
+ text-align: center;
+ font-family: inherit;
+ font-size: 10px;
+ text-transform: uppercase;
+ letter-spacing: 0.2em;
+ height: 32px;
+ border: 0;
+ color: white;
+ background-color: #333;
+ border-radius: 3px;
+ appearance: none;
+`
+
+export default Button
diff --git a/docs/Label.js b/docs/Label.js
new file mode 100644
index 0000000..13f9cd4
--- /dev/null
+++ b/docs/Label.js
@@ -0,0 +1,9 @@
+import styled from 'styled-components'
+
+const Label = styled.label`
+ display: block;
+ width: 100%;
+ font-size: 12px;
+`
+
+export default Label
diff --git a/docs/Slider.js b/docs/Slider.js
index 52879b8..2997abe 100644
--- a/docs/Slider.js
+++ b/docs/Slider.js
@@ -3,7 +3,10 @@ import styled from 'styled-components'
const Slider = styled.input`
display: block;
width: 100%;
- margin: 0;
+ margin-top: 8px;
+ margin-bottom: 8px;
+ margin-left: 0;
+ margin-right: 0;
height: 2px;
cursor: pointer;
color: inherit;
From 4464be0f89c52e5a5eb43ae8e14d27f634ba11b8 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 22:25:53 -0400
Subject: [PATCH 08/14] Add tests
---
test.js | 15 +++++++++++++++
test.js.md | 50 +++++++++++++++++++++++++++++---------------------
test.js.snap | Bin 408 -> 473 bytes
3 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/test.js b/test.js
index 5c48233..289dbe4 100644
--- a/test.js
+++ b/test.js
@@ -27,3 +27,18 @@ test('renders with string gap prop', t => {
const a = render( ).toJSON()
t.snapshot(a)
})
+
+test('renders with align prop', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
+
+test('Grid.Item renders', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
+
+test('Grid.Item renders with span prop', t => {
+ const a = render( ).toJSON()
+ t.snapshot(a)
+})
diff --git a/test.js.md b/test.js.md
index fcecb07..a3b3c27 100644
--- a/test.js.md
+++ b/test.js.md
@@ -4,65 +4,73 @@ The actual snapshot is saved in `test.js.snap`.
Generated by [AVA](https://ava.li).
-## renders
+## Grid.Item renders
> Snapshot 1
-## renders with gutter prop
+## renders
> Snapshot 1
-## renders with string gutter prop
+## renders with align prop
> Snapshot 1
-## renders with string width prop
+## renders with gap prop
> Snapshot 1
-## renders with width prop
+## renders with string gap prop
> Snapshot 1
-## renders with gap prop
+## renders with string width prop
> Snapshot 1
-## renders with string gap prop
+## renders with width prop
+
+> Snapshot 1
+
+
Snapshot 1
\ No newline at end of file
diff --git a/test.js.snap b/test.js.snap
index 21ae2974fed6ce9e47489e60dbddf86a34a096b5..c780f66385aeb0d7373364bb57b286c1d2d1df0d 100644
GIT binary patch
delta 317
zcmV-D0mA;61K9&IK~_N^Q*L2!b7*gLAa*ed0RTZf&x`)2sy#X7RdBio;m9A02mk;8
z0000JyT-u4z`>C+MSrl0TXFfr*~15S`%Eo}^!U=s2o~J|#CdOWZ#rFRSN-#7!V*!-
zXc<8gtqS)=)4^Jv
znNpGg<}oulFpfHw9LJ`X`(}Ei;&v>M$6{iTnmc$LoE+j7?mR?7H?6dw(xqUCI5sOk
z+ohP|kYx%6Du^W2p^U^iw7e=U!b2e=yx6DAi-d6Nqkg#YBb-wfmf~21rh%onATbXT
PYK%+(T;gXx9R>gZN6L+T
delta 247
zcmVF)9xHtN
z0H_Bfn##<;U=_FG@`tmB5AODvS`g{+rIisZD#XITkoP9{rqh*n)jy9WED^PgmSF^o
z?gwHf23eq67?JU5RY*^A%=b!1)4^JvnNpGg<}ovY3>+kmP4x{5cMZYkSck#m*o-I-
xFDEzLjs@~qObk+U2akh&LxcSAhVCFr3K>pOjy{e<#j(RJWC28Ix9WQZ008z
Date: Tue, 29 Aug 2017 22:30:29 -0400
Subject: [PATCH 09/14] Edit readme
---
README.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index acd8e11..4a9bf55 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,13 @@
# React CSS Grid
-React layout component based on [CSS Grid Layout][spec] and built with [styled-components][sc] ([Demo][demo])
+React layout component based on [CSS Grid Layout][spec] and built with [styled-components][sc]
[![Build Status][travis-badge]][travis]
-[travis-badge]: https://travis-ci.org/jxnblk/react-css-grid.svg?branch=master
+http://jxnblk.com/react-css-grid
+
+[travis-badge]: https://img.shields.io/travis/jxnblk/react-css-grid/master.svg?style=flat-square
[travis]: https://travis-ci.org/jxnblk/react-css-grid
```sh
From d3913d20716bbc7928c9b93e02c9749f28974bcc Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 22:31:26 -0400
Subject: [PATCH 10/14] Edit version
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index fa51098..65b2500 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "react-css-grid",
- "version": "1.0.0",
+ "version": "2.0.0-0",
"description": "React layout component based on CSS Grid Layout and built with styled-components",
"main": "dist/index.js",
"scripts": {
From 6a6911278b000e10e55527d3e09ac11087493f42 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 22:34:39 -0400
Subject: [PATCH 11/14] Clean up
---
src/index.js | 11 +++--------
test.js.md | 34 +++++++++++++++++-----------------
test.js.snap | Bin 473 -> 476 bytes
3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/src/index.js b/src/index.js
index 3c8d5ef..61ff39f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -4,9 +4,7 @@ import PropTypes from 'prop-types'
const px = n => typeof n === 'number' ? n + 'px' : n
const width = props => ({
- // ['@media screen and (min-width:320px)']: {
- gridTemplateColumns: `repeat(auto-fit, minmax(${px(props.width)}, 1fr))`
- // }
+ gridTemplateColumns: `repeat(auto-fit, minmax(${px(props.width)}, 1fr))`
})
const gap = props => ({
@@ -22,8 +20,7 @@ const span = props => props.span ? ({
}) : null
const Grid = styled.div([], {
- display: 'grid',
- maxWidth: '100%'
+ display: 'grid'
},
width,
gap,
@@ -46,8 +43,6 @@ Grid.defaultProps = {
gap: 32
}
-Grid.Item = styled.div([], {
- maxWidth: '100%'
-}, span)
+Grid.Item = styled.div([], span)
export default Grid
diff --git a/test.js.md b/test.js.md
index a3b3c27..32a4157 100644
--- a/test.js.md
+++ b/test.js.md
@@ -9,7 +9,16 @@ Generated by [AVA](https://ava.li).
> Snapshot 1
+
+## Grid.Item renders with span prop
+
+> Snapshot 1
+
+
## renders
@@ -17,7 +26,7 @@ Generated by [AVA](https://ava.li).
> Snapshot 1
@@ -26,7 +35,7 @@ Generated by [AVA](https://ava.li).
> Snapshot 1
@@ -35,7 +44,7 @@ Generated by [AVA](https://ava.li).
> Snapshot 1
@@ -44,7 +53,7 @@ Generated by [AVA](https://ava.li).
> Snapshot 1
@@ -53,7 +62,7 @@ Generated by [AVA](https://ava.li).
> Snapshot 1
@@ -62,15 +71,6 @@ Generated by [AVA](https://ava.li).
> Snapshot 1
Snapshot 1
-
-
\ No newline at end of file
+ />
diff --git a/test.js.snap b/test.js.snap
index c780f66385aeb0d7373364bb57b286c1d2d1df0d..c9e883680ceb65b55b92c8c9c1953abe15746662 100644
GIT binary patch
delta 233
zcmV4
z1H*ThHeW}E=!|QdCA8JQ{)uD+iwdwXFo<+19QyA5YxTc=JG+9e_$o%Q=qw-(SF3t^
z-!(axd4u}}i7S<+j9^h$k?3*laV-gmRF@kcqo*HR5*tZ
jg5(HsO;TW{cYX$%4wmAA#5_o-F){%Frv9q}8wLOXJ(+1Y
delta 230
zcmV1K9&2K~_N^Q*L2!b7*gLAa*ed0RTZf&x`)2sy#X7RdBio;mDC9fJQ1a
z1H*ThHeW}E=!|QdCA8JQ{)uD+iwdzYFo<+19QyA5YxTc=JG+9e_$o%Q=v*KUSF3t^
z-!(axd4u}}i7S<+j9^iBk?3*<$SMu33im~mVF43mmiuOUq~dlgkjG+TkeWMq9Go2D
z7VbPmLN~3npwgvah&VPYKij34;*ezu1}cao)uD{UIkdbgEy6<~BfQwB%!`C@>!W_S
g@gtm57M9{zgrR
From a733a519078c30c325b2626407e64525203fbe20 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 22:36:42 -0400
Subject: [PATCH 12/14] Adjust prop types
---
src/index.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/index.js b/src/index.js
index 61ff39f..24fffe0 100644
--- a/src/index.js
+++ b/src/index.js
@@ -35,7 +35,8 @@ Grid.propTypes = {
gap: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
- ]).isRequired
+ ]).isRequired,
+ align: PropTypes.string
}
Grid.defaultProps = {
From cacfe5517eb91974c7ccc1521600ddcdbed7991d Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 22:37:27 -0400
Subject: [PATCH 13/14] Remove storybook
---
package.json | 1 -
storybook/Grid.js | 27 ---------------------------
storybook/config.js | 29 -----------------------------
3 files changed, 57 deletions(-)
delete mode 100644 storybook/Grid.js
delete mode 100644 storybook/config.js
diff --git a/package.json b/package.json
index 65b2500..7d6256d 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,6 @@
"styled-components": "^2.1.2"
},
"devDependencies": {
- "@storybook/react": "^3.2.8",
"ava": "^0.22.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
diff --git a/storybook/Grid.js b/storybook/Grid.js
deleted file mode 100644
index 5294b9e..0000000
--- a/storybook/Grid.js
+++ /dev/null
@@ -1,27 +0,0 @@
-import React from 'react'
-import styled from 'styled-components'
-import { storiesOf } from '@storybook/react'
-import Grid from '../src'
-
-const Col = styled.div`
- box-shadow: inset 0 0 0 1px cyan;
-`
-
-storiesOf('Grid', module)
- .add('Demo', () => (
-
-
- React CSS Grid
-
-
- With varying height columns
- React layout component for simple grids using CSS Grid
-
-
- React layout component for simple grids using CSS Grid
-
-
- React layout component for simple grids using CSS Grid
-
-
- ))
diff --git a/storybook/config.js b/storybook/config.js
deleted file mode 100644
index 3f88d0d..0000000
--- a/storybook/config.js
+++ /dev/null
@@ -1,29 +0,0 @@
-import React from 'react'
-import { configure, addDecorator } from '@storybook/react'
-import { injectGlobal } from 'styled-components'
-import Grid from '../src'
-
-injectGlobal([], {
- '*': {
- boxSizing: 'border-box'
- },
- body: {
- fontFamily: '-apple-system, BlinkMacSystemFont, sans-serif',
- lineHeight: 1.5,
- margin: 0
- }
-})
-
-addDecorator(story => (
-
- {story()}
-
-))
-
-const req = require.context('.', true, /\.js$/)
-
-const load = () => {
- req.keys().forEach(req)
-}
-
-configure(load, module)
From 8054de42762770a67ea5911ef5d0648fe38328b0 Mon Sep 17 00:00:00 2001
From: Brent Jackson
Date: Tue, 29 Aug 2017 22:38:14 -0400
Subject: [PATCH 14/14] Edit ignore
---
.npmignore | 1 -
1 file changed, 1 deletion(-)
diff --git a/.npmignore b/.npmignore
index 60a7634..237b716 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,6 +1,5 @@
src
docs
-storybook
webpack.config.js
.nyc_output
coverage