Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacer (merge #129, merge #127) #133

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8061f80
Changed fontsizes to use em units
stevenyuen Mar 16, 2018
5641891
Font-size is set on html element. Font-weights are configurable
stevenyuen Mar 21, 2018
4d6e46a
bug fixes and cleanup
stevenyuen Mar 21, 2018
40a3260
New SmartView
stevenyuen Apr 16, 2018
9f6d556
cleanup
stevenyuen Apr 16, 2018
99e5664
Added min and max width and height props
stevenyuen Apr 16, 2018
0a9041d
Merge branch 'master' of github.com:mother/oio into typography
stevenyuen Apr 17, 2018
0a34077
Added horiztonal and vertical padding props
stevenyuen Apr 21, 2018
c7d24a9
Initial commit
stevenyuen Apr 26, 2018
f2ae22d
Grid overflow is hidden
stevenyuen Apr 26, 2018
ecf7fed
Added offset prop to GridCell component
stevenyuen Apr 26, 2018
69a0b4d
Make sure gridCells wrap onto next line in gridrow component
stevenyuen Apr 26, 2018
b7cafec
Centered grid container. None float
stevenyuen Apr 27, 2018
b2e8dc1
Ability to set height on grid and gridcell
stevenyuen Apr 29, 2018
52064ec
Handle width auto
stevenyuen Apr 29, 2018
86a98a3
Ability to set height on gridCell
stevenyuen May 4, 2018
35893cb
Ability to set minHeight
stevenyuen May 4, 2018
4f14cae
Added float prop
stevenyuen May 16, 2018
17280b2
Added smaller type sizes
stevenyuen May 16, 2018
0c6546a
Added smaller type sizes
stevenyuen May 16, 2018
7a42578
Tweak small font sizes
stevenyuen May 16, 2018
46aff4b
Added float prop to SmartView
stevenyuen May 18, 2018
46b28c9
Added ref prop to smartView
stevenyuen May 19, 2018
0b169a9
Updated default line-height
stevenyuen May 24, 2018
e568c67
Removed debounce from view
stevenyuen May 28, 2018
37adb96
Spacer component can have breakpoint-specific sizes
stevenyuen Jul 24, 2018
b493a26
Merge branch 'typography' of github.com:mother/oio into spacer
stevenyuen Jul 24, 2018
74a9b3b
Fixed spacing
stevenyuen Jul 24, 2018
8df11ab
Merge branch 'grid' of github.com:mother/oio into spacer
stevenyuen Jul 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
"dependencies": {
"blob": "0.0.4",
"classnames": "2.2.5",
"emotion": "9.1.1",
"form-data": "2.1.2",
"moment": "2.22.0",
"react-files": "2.4.5",
"react-router-dom": "4.2.2"
"react-router-dom": "4.2.2",
"throttle-debounce": "1.0.1"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.43",
Expand Down
117 changes: 45 additions & 72 deletions src/components/Grid/index.js
Original file line number Diff line number Diff line change
@@ -1,111 +1,84 @@
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import classNames from 'classnames'
import { getWindowSize, getAttributeForCurrentSize } from '../../utils/size'
import style from './style.less'
import { css, cx } from 'emotion'
import { breakpoints, setAttributeForBreakpoints } from '../../utils/size'

export default class Grid extends Component {
/* eslint-disable */
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
columns: PropTypes.string,
gutter: PropTypes.string,
height: PropTypes.string,
style: PropTypes.object,
width: PropTypes.string
}

static defaultProps = {
columns: '12',
gutter: '6px'
gutter: '6px',
style: {},
width: '100%'
}
/* eslint-enable */

static childContextTypes = {
GridCellStyle: PropTypes.object
}

constructor(props) {
super(props)

this.state = {
size: getWindowSize(),
width: 'auto',
innerWidth: '100%',
cellWidth: 'auto',
cellGutter: 'auto'
}
}

getChildContext() {
const GridCellStyle = {
width: this.state.cellWidth,
gutter: this.state.cellGutter
columns: this.props.columns,
gutter: this.props.gutter
}

return { GridCellStyle }
}

componentDidMount() {
this.updateGrid()
window.addEventListener('resize', this.windowSizeUpdated, false)
}

componentDidUpdate() {
this.updateGrid()
}

componentWillUnmount() {
window.removeEventListener('resize', this.windowSizeUpdated)
}

windowSizeUpdated = () => {
const windowSize = getWindowSize()
this.setState({ size: windowSize })
}

updateGrid() {
const columns = getAttributeForCurrentSize(this.state.size, this.props.columns)
const gutter = getAttributeForCurrentSize(this.state.size, this.props.gutter)

const calculatedGridWidth = this.node.clientWidth
const adjustedGridWidth = parseFloat(calculatedGridWidth) + parseFloat(gutter)
const cellWidth = (adjustedGridWidth) / columns

if (this.state.innerWidth !== adjustedGridWidth) {
this.setState({
innerWidth: adjustedGridWidth
})
}

if (this.state.cellWidth !== cellWidth) {
this.setState({
cellWidth,
cellGutter: gutter
})
}
setGridInnerGutter = (styleObj, breakpoint, attributeValue) => {
styleObj[breakpoint.key].width = `calc(100% + ${parseFloat(attributeValue)}px)`
}

render() {
const classes = classNames(style.gridContainer, this.props.className)
const gutter = parseFloat(getAttributeForCurrentSize(this.state.size, this.props.gutter))

// TODO: Should use setState
if (this.props.width) {
const width = getAttributeForCurrentSize(this.state.size, this.props.width)
const unit = width.endsWith('px') ? 'px' : '%'
this.state.width = parseFloat(width) + unit
const styleProps = ['gutter', 'width', 'height']

const gridStyleObj = {
display: 'block',
overflow: 'hidden',
margin: 'auto',
[breakpoints[0].key]: {},
[breakpoints[1].key]: {},
[breakpoints[2].key]: {},
[breakpoints[3].key]: {},
[breakpoints[4].key]: {},
...this.props.style
// , backgroundColor: 'rgba(0,255,0, 0.1)', // XRAY
}

const gridStyle = {
width: this.state.width
styleProps.forEach((prop) => {
setAttributeForBreakpoints(gridStyleObj, prop, this.props[prop])
})

const gridInnerStyleObj = {
position: 'relative',
top: 0,
left: 0,
[breakpoints[0].key]: {},
[breakpoints[1].key]: {},
[breakpoints[2].key]: {},
[breakpoints[3].key]: {},
[breakpoints[4].key]: {}
}

const gridInnerStyle = {
width: this.state.innerWidth,
marginLeft: `-${gutter}px`
}
setAttributeForBreakpoints(gridInnerStyleObj, 'height', this.props.height)
setAttributeForBreakpoints(
gridInnerStyleObj, null, this.props.gutter, this.setGridInnerGutter
)

return (
<div ref={node => (this.node = node)} className={classes} style={gridStyle}>
<div className={style.gridInnerContainer} style={gridInnerStyle}>
<div className={cx(css(gridStyleObj), this.props.className)}>
<div className={css(gridInnerStyleObj)}>
{this.props.children}
</div>
</div>
Expand Down
7 changes: 0 additions & 7 deletions src/components/Grid/style.less

This file was deleted.

102 changes: 65 additions & 37 deletions src/components/GridCell/index.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,96 @@
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import classNames from 'classnames'
import { getWindowSize, getAttributeForCurrentSize } from '../../utils/size'
import styles from './styles.less'
import { css, cx } from 'emotion'
import { breakpoints, setAttributeForBreakpoints, getAttributeForCurrentSize } from '../../utils/size'

export default class GridCell extends Component {
/* eslint-disable */
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
colspan: PropTypes.string
colspan: PropTypes.string,
float: PropTypes.string,
height: PropTypes.string,
minHeight: PropTypes.string,
offset: PropTypes.string,
style: PropTypes.object,
}

static defaultProps = {
colspan: '1',
float: 'left',
style: {}
}
/* eslint-enable */

static contextTypes = {
GridCellStyle: PropTypes.object
}

constructor(props) {
super(props)

this.state = {
size: getWindowSize(),
width: '0',
gutter: '0'
}
}
setGridCellWidth = (styleObj, props) => {
breakpoints.forEach((breakpoint, index) => {
const columns = getAttributeForCurrentSize(breakpoint.name, props.columns)
const colspan = getAttributeForCurrentSize(breakpoint.name, props.colspan)

componentDidMount() {
window.addEventListener('resize', this.windowResizeListener, false)
styleObj[breakpoint.key].width = `${parseInt(colspan, 10) * parseFloat(100 / columns)}%`
})
}

componentWillUnmount() {
window.removeEventListener('resize', this.windowResizeListener)
setGridCellOffset = (styleObj, props) => {
if (props.offset) {
breakpoints.forEach((breakpoint, index) => {
const columns = getAttributeForCurrentSize(breakpoint.name, props.columns)
const offset = getAttributeForCurrentSize(breakpoint.name, props.offset)
styleObj[breakpoint.key].marginLeft = `${offset * parseFloat(100 / columns)}%`
})
}
}

windowSizeUpdated = () => {
const windowSize = getWindowSize()
this.setState({ size: windowSize })
setGridCellGutter = (styleObj, breakpoint, attributeValue) => {
const gutter = parseFloat(attributeValue)
styleObj[breakpoint.key].paddingRight = `${gutter}px`
styleObj[breakpoint.key].marginBottom = `${gutter}px`
}

render() {
let colspanMultiplier = 1
const classes = classNames(styles.gridCell, this.props.className)

if (this.context.GridCellStyle) {
this.state.width = `${this.context.GridCellStyle.width}px`
this.state.gutter = `${this.context.GridCellStyle.gutter}`
}
const { className, colspan, float, minHeight, height, offset } = this.props
const gridContext = this.context.GridCellStyle

if (this.props.colspan) {
colspanMultiplier = getAttributeForCurrentSize(this.state.size, this.props.colspan)
const gridCellStyleObj = {
float: 'left',
position: 'relative',
[breakpoints[0].key]: {},
[breakpoints[1].key]: {},
[breakpoints[2].key]: {},
[breakpoints[3].key]: {},
[breakpoints[4].key]: {},
...this.props.style
// , backgroundColor: 'rgba(255,0,0,0.1)', // XRAY
}

const gutter = parseFloat(this.state.gutter)
const width = parseFloat(this.state.width) * colspanMultiplier
this.setGridCellWidth(gridCellStyleObj, { ...gridContext, colspan })
this.setGridCellOffset(gridCellStyleObj, { ...gridContext, offset })
setAttributeForBreakpoints(gridCellStyleObj, null, gridContext.gutter, this.setGridCellGutter)
setAttributeForBreakpoints(gridCellStyleObj, 'float', float)
setAttributeForBreakpoints(gridCellStyleObj, 'minHeight', minHeight)
setAttributeForBreakpoints(gridCellStyleObj, 'height', height)

const cellStyle = {
width: `${width}px`,
paddingLeft: `${gutter}px`,
marginBottom: `${gutter}px`
const gridCellInnerStyleObj = {
width: '100%',
[breakpoints[0].key]: {},
[breakpoints[1].key]: {},
[breakpoints[2].key]: {},
[breakpoints[3].key]: {},
[breakpoints[4].key]: {}
}

setAttributeForBreakpoints(gridCellInnerStyleObj, 'minHeight', minHeight)
setAttributeForBreakpoints(gridCellInnerStyleObj, 'height', height)

return (
<div className={classes} style={cellStyle} >
<div className={styles.gridCellInner}>
<div
className={cx(css(gridCellStyleObj), className)}>
<div className={css(gridCellInnerStyleObj)}>
{this.props.children}
</div>
</div>
Expand Down
10 changes: 0 additions & 10 deletions src/components/GridCell/styles.less

This file was deleted.

4 changes: 3 additions & 1 deletion src/components/GridRow/style.less
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.gridRow {
float: left;
display: block;
width: 100%;
position: relative;
display: flex;
align-items: stretch;
flex-flow: row wrap;
}
Loading