React flexbox layout and grid system
npm install reflexbox-modernResponsive React flexbox grid system higher order component



```
npm install reflexbox
`js
// Higher order component example
import React from 'react'
import { withReflex } from 'reflexbox'
const Button = (props) => {
return
}
export default withReflex()(Button)
`
`js`
const App = () => {
return (
flex
p={2}
col={12}
align='center'
justify='space-between'>
Flex
Button
)
}
Usage with the Flex and Box components:
`js
// Basic component example
import React from 'react'
import { Flex, Box } from 'reflexbox'
class Component extends React.Component {
render() {
return (
)
}
}
`
Reflexbox is composed of a higher order component and three React components.
Higher order component that accepts several layout style helper props
that can handle virtually any layout composition.
- col (number 0–12) Sets width based on a 12 column grid.sm
- (number 0-12) Sets width from the sm breakpoint and up.md
- (number 0-12) Sets width from the md breakpoint and up.lg
- (number 0-12) Sets width from the lg breakpoint and up.align
- (string) Sets align-itemsjustify
- (string) Sets justify-contentwrap
- (boolean) Sets flex-wrap: wrapflexColumn
- (boolean) Sets flex-direction: columnflexAuto
- (boolean) Sets flex: 1 1 autoflex
- (boolean) Sets display: flexorder
- (boolean) Sets order
Components wrapped with the withReflex higher order component accept several layout props from
the Robox higher order component, including the following:
- gutter (number) Sets negative left and right margin to compensate for child element padding.m
- (number) Sets margin based on a scale from 0–6.mx
- (number) Sets x-axis margin based on a scale from 0–6.my
- (number) Sets y-axis margin based on a scale from 0–6.mt
- (number) Sets margin-top based on a scale from 0–6.mb
- (number) Sets margin-bottom based on a scale from 0–6.ml
- (number) Sets margin-left based on a scale from 0–6.mr
- (number) Sets margin-right based on a scale from 0–6.p
- (number) Sets padding based on a scale from 0–6.px
- (number) Sets x-axis padding based on a scale from 0–6.py
- (number) Sets y-axis padding based on a scale from 0–6.pt
- (number) Sets padding-top based on a scale from 0–6.pb
- (number) Sets padding-bottom based on a scale from 0–6.pl
- (number) Sets padding-left based on a scale from 0–6.pr
- (number) Sets padding-right based on a scale from 0–6.
The Flex and Box components are created with the withReflex component and use the same set of props.
They are intended to help with the readability of code and
to provide some backwards compatiblity with previous versions
of Reflexbox.
The only difference between the two is that the Flex component has flex prop set to true to set display: flex.
The Grid component is also based on the withReflex component, but sets display inline-block for use as a more widely supported page layout component. It also includes an align prop to set vertical alignment.
`js`
Left column
Right column
By default, Reflexbox listens to window.matchMedia for the configured breakpoints.withReflex
To disable this, pass an options object to the higher-order component.
`js`
const Box = withReflex({
listen: false
})(MyComponent)
Values for the breakpoints can be configured with
React Context.
To configure reflexbox, add childContextTypes and getChildContext to a container component.
`js
class App extends React.Component {
static childContextTypes = {
reflexbox: React.PropTypes.object
}
getChildContext () {
return {
reflexbox: {
breakpoints: {
sm: '(min-width: 30em)',
md: '(min-width: 48em)',
lg: '(min-width: 60em)'
}
}
}
}
render () {
return (
)
}
}
`
To show an 8 ⨉ 8px background grid for layout debugging, add the following to the context object:
`js``
getChildContext () {
return {
reflexbox: {
debug: true
}
}
}
---
- Rebass
- Reline
- Robox
- understyle
- Gx