Skip to content

Commit 80f5c60

Browse files
committed
initial commit
0 parents  commit 80f5c60

17 files changed

+762
-0
lines changed

Diff for: .babelrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"optional": [
3+
"es7.objectRestSpread"
4+
],
5+
"ignore": [
6+
"node_modules"
7+
]
8+
}

Diff for: .eslintrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": ["standard", "standard-react"],
4+
"env": { "browser": true, "node": true }
5+
}

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
lib

Diff for: .npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src
2+
test
3+
webpack.config.js

Diff for: README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# WARNING: Don't use this unless you know your environment supports CSS Grid Layout!
2+
3+
## react-css-grid-layout
4+
5+
React components for wrapping your other react components in [CSS Grid Layout](http://www.w3.org/TR/css-grid-1/) inline.
6+
7+
### Installation
8+
9+
`npm install react-css-grid-layout`
10+
11+
### Quick Start
12+
13+
Maybe do something like this:
14+
15+
```javascript
16+
import React from 'react'
17+
import { GridContainer, GridItem } from '../src'
18+
19+
export default function Layout () {
20+
return (
21+
<GridContainer rowTemplate='100px 1fr 1fr'
22+
columnTemplate=`300px 25px 300px`
23+
style={{ height: '100%' }}>
24+
<GridItem rows='2 / 3' columns='3 / 4'>
25+
<p>Content</p>
26+
</GridItem>
27+
<GridItem rows='1 / 4' columns='1 / 2' style={{ overflowY: 'scroll' }}>
28+
<h1>Sidebar</h1>
29+
</GridItem>
30+
</GridContainer>
31+
)
32+
}
33+
```
34+
35+
### API
36+
37+
#### `<GridContainer />`
38+
39+
#### props (all optional)
40+
41+
Most of the properties are just one-to-one mappings onto the CSS properties. See [Resources](#resources) for more information on using the spec.
42+
43+
|Component Property | CSS property|
44+
|-------------------|-------------|
45+
|`rowTemplate`: *string* | grid-template-rows|
46+
|`columnTemplate`: *string* | grid-template-columns|
47+
|`areasTemplate`: *string* | grid-area-templates|
48+
49+
50+
`style`: *object*
51+
52+
Will be added to the inline styles of the `<div>` that surrounds your children. Any property you pass will override those set by `react-css-grid-layout`.
53+
54+
#### `<GridItem />`
55+
56+
#### props (all optional)
57+
58+
Most of the properties are just one-to-one mappings onto the CSS properties.
59+
60+
|Component Property | CSS property|
61+
|-------------------|-------------|
62+
|`area`: *string* | grid-area |
63+
|`rowStart`: *number* | grid-row-start |
64+
|`rowEnd`: *number* | grid-row-end |
65+
|`rows`: *string* | grid-row |
66+
|`columnStart`: *number* | grid-column-start |
67+
|`columnEnd`: *number* | grid-column-end |
68+
|`columns`: *string* | grid-column |
69+
70+
`style`: *object*
71+
72+
Will be added to the inline styles of the `<div>` that surrounds your children. Any property you pass will override those set by `react-css-grid-layout`.
73+
74+
### <a name="resources">Resources</a> for information about CSS Grid Layout
75+
76+
* [The Specification](http://www.w3.org/TR/css-grid-1/)
77+
* [The future of layout with CSS: Grid Layouts](https://hacks.mozilla.org/2015/09/the-future-of-layout-with-css-grid-layouts/)
78+
* [Grid by Example: simple usage examples for the CSS3 Grid Layout Module](http://gridbyexample.com/)

Diff for: index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib')

Diff for: package.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "react-css-grid-layout",
3+
"version": "1.0.0",
4+
"description": "The CSS Grid Layout wrapped in React components",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "node test/dev-server.js",
8+
"prepublish": "babel src --out-dir lib"
9+
},
10+
"author": "David Manning",
11+
"license": "ISC",
12+
"dependencies": {},
13+
"devDependencies": {
14+
"babel": "^5.8.23",
15+
"babel-eslint": "^4.1.3",
16+
"babel-loader": "^5.3.2",
17+
"babel-plugin-react-transform": "^1.1.1",
18+
"babel-runtime": "^5.8.25",
19+
"ecstatic": "^1.0.1",
20+
"eslint": "^1.5.1",
21+
"eslint-config-standard": "^4.4.0",
22+
"eslint-config-standard-react": "^1.1.0",
23+
"eslint-plugin-react": "^3.5.0",
24+
"eslint-plugin-standard": "^1.3.1",
25+
"express": "^4.13.3",
26+
"react": "^0.14.0-rc1",
27+
"react-dom": "^0.14.0-rc1",
28+
"react-transform-hmr": "^1.0.1",
29+
"webpack": "^1.12.2",
30+
"webpack-dev-middleware": "^1.2.0",
31+
"webpack-hot-middleware": "^2.3.0"
32+
}
33+
}

Diff for: src/container.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { Component } from 'react'
2+
3+
export default class GridContainer extends Component {
4+
render () {
5+
const { rowTemplate, columnTemplate, areasTemplate } = this.props
6+
7+
const style = {
8+
display: 'grid',
9+
gridTemplateRows: rowTemplate,
10+
gridTemplateColumns: columnTemplate,
11+
gridTemplateAreas: areasTemplate,
12+
...this.props.style
13+
}
14+
15+
return <div style={style}>{this.props.children}</div>
16+
}
17+
}
18+
19+
GridContainer.propTypes = {
20+
rowTemplate: React.PropTypes.string,
21+
columnTemplate: React.PropTypes.string,
22+
areasTemplate: React.PropTypes.string,
23+
children: React.PropTypes.node,
24+
style: React.PropTypes.object
25+
}

Diff for: src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as GridContainer } from './container'
2+
export { default as GridItem } from './item'

Diff for: src/item.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { Component } from 'react'
2+
3+
export default class GridItem extends Component {
4+
render () {
5+
const { rowStart, rowEnd, columnStart, columnEnd } = this.props
6+
7+
const {
8+
columns = `${columnStart} / ${columnEnd}`,
9+
rows = `${rowStart} / ${rowEnd}`,
10+
area
11+
} = this.props
12+
13+
const style = {
14+
gridColumn: columns,
15+
gridRow: rows,
16+
gridArea: area,
17+
...this.props.style
18+
}
19+
20+
return <div style={style}>{this.props.children}</div>
21+
}
22+
}
23+
24+
GridItem.propTypes = {
25+
area: React.PropTypes.string,
26+
rowStart: React.PropTypes.number,
27+
rowEnd: React.PropTypes.number,
28+
columnStart: React.PropTypes.number,
29+
columnEnd: React.PropTypes.number,
30+
columns: React.PropTypes.string,
31+
rows: React.PropTypes.string,
32+
children: React.PropTypes.node,
33+
style: React.PropTypes.object
34+
}

Diff for: test/dev-server.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
// const path = require('path')
4+
const express = require('express')
5+
const webpack = require('webpack')
6+
const ecstatic = require('ecstatic')
7+
const config = require('../webpack.config.js')
8+
9+
const app = express()
10+
const compiler = webpack(config)
11+
12+
app.use(require('webpack-dev-middleware')(compiler, {
13+
noInfo: true,
14+
publicPath: config.output.publicPath
15+
}))
16+
17+
app.use(require('webpack-hot-middleware')(compiler))
18+
19+
// app.get('*', function (req, res) {
20+
// res.sendFile(path.join(__dirname, 'test', 'index.html'))
21+
// })
22+
23+
app.use(ecstatic({ root: __dirname, cache: 0 }))
24+
25+
app.listen(8080, 'localhost', function (err) {
26+
if (err) {
27+
console.log(err)
28+
return
29+
}
30+
31+
console.log('Listening at http://localhost:8080')
32+
})

Diff for: test/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Test</title>
6+
<link rel="stylesheet" href="normalize.css" media="screen" title="no title" charset="utf-8">
7+
<link rel="stylesheet" href="style.css" media="screen" title="no title" charset="utf-8">
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script src="bundle.js" charset="utf-8"></script>
12+
</body>
13+
</html>

Diff for: test/monkey.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import cssProperty from 'react/lib/CSSProperty.js'
2+
3+
cssProperty.isUnitlessNumber = {
4+
...cssProperty.isUnitlessNumber,
5+
gridRowStart: true,
6+
gridRowEnd: true,
7+
gridColumnStart: true,
8+
gridColumnEnd: true
9+
}

0 commit comments

Comments
 (0)