Skip to content

Commit f1a4383

Browse files
committed
Adjust tests
1 parent 60b60aa commit f1a4383

File tree

14 files changed

+220
-218
lines changed

14 files changed

+220
-218
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
dist

.npmignore

Whitespace-only changes.

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- 6.2

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11

22
# React CSS Grid
33

4+
**Experimental**
45
Responsive CSS-based React grid component
56

7+
[![Build Status](https://travis-ci.org/jxnblk/understyle.svg?branch=master)](https://travis-ci.org/jxnblk/understyle)
8+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
9+
610
```sh
711
npm i react-css-grid
812
```
913

10-
```js
14+
```jsx
1115
// Example usage
1216
import React from 'react'
1317
import Grid from 'react-css-grid'
@@ -26,7 +30,35 @@ class App extends React.Component {
2630
}
2731
```
2832

33+
```jsx
34+
// Higher order component
35+
import React from 'react'
36+
import { createGrid } from 'react-css-grid'
37+
38+
const CustomGrid = (props) => <div {...props} />
39+
40+
export default createGrid(CustomGrid)
41+
```
42+
43+
## Features
44+
- Simple, encapsulated grid layout API
45+
- Uses CSS for native @media-rule-based responsive styles
46+
- Works with server-side rendering
47+
48+
## Grid component props
49+
- `col` (number 0–12) sets width across all breakpoints based on a 12 column grid.
50+
- `sm` (number 0–12) sets width from the `sm` breakpoint up
51+
- `md` (number 0–12) sets width from the `md` breakpoint up
52+
- `lg` (number 0–12) sets width from the `lg` breakpoint up
53+
- `align` (string, `top`, `middle`, `bottom`, or `baseline`) - sets vertical align
54+
55+
## How it works
56+
2957
The Grid component creates CSS rules based on props and insert 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.
3058

59+
## Caveats
60+
- Produces an inline style tag within the body
61+
- Similar component instances create duplicative CSS rules – this may or may not affect performance
62+
- Atomic class selectors are global
3163

3264
MIT License

demo/App.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11

22
import React from 'react'
3-
import Grid from '..'
4-
3+
import Grid from '../src/Grid'
54

65
class App extends React.Component {
76
render () {
87
return (
9-
<Grid p={3}>
10-
<h1>Hello react-css-grid</h1>
8+
<div className=''>
9+
<h1 className='p3'>React CSS Grid</h1>
1110
<div>
12-
<Grid sm={6} md={3} p={2}>
13-
sm6 md3
11+
<Grid className='p3' sm={6} md={3}>
12+
<h2 className='m0'>sm6 md3</h2>
1413
</Grid>
15-
<Grid sm={6} md={3} p={2}>
16-
sm6 md3
14+
<Grid className='p3' sm={6} md={3}>
15+
<h2 className='m0'>sm6 md3</h2>
1716
</Grid>
18-
<Grid sm={6} md={3} p={2}>
19-
sm6 md3
17+
<Grid className='p3' sm={6} md={3}>
18+
<h2 className='m0'>sm6 md3</h2>
2019
</Grid>
21-
<Grid sm={6} md={3} p={2}>
22-
sm6 md3
20+
<Grid className='p3' sm={6} md={3}>
21+
<h2 className='m0'>sm6 md3</h2>
2322
</Grid>
2423
</div>
25-
</Grid>
24+
</div>
2625
)
2726
}
2827
}

demo/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
font-family: -apple-system, sans-serif;
66
margin: 0;
77
}
8+
.m0 { margin: 0 }
9+
.p3 { padding: 32px }
810
.debug, .debug * {
911
outline: 1px solid rgba(0, 127, 255, .5);
1012
}

dist/Grid.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

dist/create-styles.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

dist/createGrid.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"description": "Responsive CSS-based React grid component",
55
"main": "index.js",
66
"scripts": {
7+
"build": "webpack -p",
78
"start": "webpack-dev-server",
8-
"prepublish": "babel src --out-dir dist",
9-
"test": "ava -v"
9+
"gh-pages": "gh-pages -d demo",
10+
"prepublish": "mkdir -p dist && babel src --out-dir dist",
11+
"test": "standard && ava -v"
1012
},
1113
"keywords": [
1214
"react",
@@ -25,13 +27,18 @@
2527
"babel-preset-stage-0": "^6.5.0",
2628
"babel-register": "^6.11.6",
2729
"enzyme": "^2.4.1",
28-
"react": "^15.2.1",
29-
"react-addons-test-utils": "^15.2.1",
30-
"react-dom": "^15.2.1",
30+
"gh-pages": "^0.11.0",
31+
"react": "^15.3.0",
32+
"react-addons-test-utils": "^15.3.0",
33+
"react-dom": "^15.3.0",
34+
"standard": "^7.1.2",
3135
"webpack": "^1.13.1",
3236
"webpack-dev-server": "^1.14.1"
3337
},
34-
"dependencies": {
35-
"robox": "^1.0.0-beta.1"
38+
"ava": {
39+
"require": [
40+
"babel-register"
41+
],
42+
"babel": "inherit"
3643
}
3744
}

src/create-styles.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11

2-
const width = col => `${col / 12 * 100}%`
2+
export const width = col => `${col / 12 * 100}%`
33

4-
const createClassName = breakpoint => col => `_g${breakpoint}${col}`
4+
export const createClassName = prefix => base => `__${prefix}${base}`
55

6-
const createRule = breakpoints => breakpoint => className => col => {
6+
export const createWidthRule = breakpoints => breakpoint => className => col => {
77
if (typeof col !== 'number') {
88
return ''
99
}
1010
const media = breakpoints[breakpoint]
1111
const rule = `.${className}{width:${width(col)}}`
12-
if (!media) {
13-
return rule
14-
}
15-
return `@media ${media}{${rule}}`
12+
13+
return media ? `@media ${media}{${rule}}` : rule
14+
}
15+
16+
export const createRule = className => prop => val => {
17+
return `.${className}{${prop}:${val}}`
1618
}
1719

18-
const createStyles = breakpoints => props => {
19-
const createBreakpointRule = createRule(breakpoints)
20+
const createStyles = breakpoints => ({
21+
align = 'top',
22+
...rest
23+
}) => {
24+
const createBreakpointRule = createWidthRule(breakpoints)
2025

21-
const styles = Object.keys(props).map(key => {
22-
const val = props[key]
26+
const styles = Object.keys(rest).map(key => {
27+
const val = rest[key]
2328
if (!val) {
2429
return false
2530
}
@@ -32,6 +37,24 @@ const createStyles = breakpoints => props => {
3237
}
3338
}).filter(s => s !== false)
3439

40+
const boxSizingClassName = createClassName('b')('b')
41+
styles.push({
42+
className: boxSizingClassName,
43+
rule: createRule(boxSizingClassName)('box-sizing')('border-box')
44+
})
45+
46+
const displayClassName = createClassName('d')('ib')
47+
styles.push({
48+
className: displayClassName,
49+
rule: createRule(displayClassName)('display')('inline-block')
50+
})
51+
52+
const alignClassName = createClassName('a')(align)
53+
styles.push({
54+
className: alignClassName,
55+
rule: createRule(alignClassName)('vertical-align')(align)
56+
})
57+
3558
const css = styles.reduce((a, b) => {
3659
return a + b.rule
3760
}, '')

0 commit comments

Comments
 (0)