reflay
: React Flexbox Layout is a set of React components that implements
CSS3 Flexbox and are inspired by the awesome
Angular Material library. It's built with ES6, SASS
and WebPack and provides sugar to enable developers to more easily create modern, responsive layouts on top of
CSS3 Flexbox.
Reflay has 2 main React components: Layout
and Box
. Using these components props
as the API provides an easy
way to set value (eg. direction='row'
) and helps with separation of concerns: Attributes in form of React props
define layout, while CSS classes assign styling.
- Documentation and Demos: https://beplus.github.io/reflay (still work in progress)
- Example usage: https://github.com/beplus/reflay-example
The recommended way to use the library is to integrate it to your WebPack workflow with Babel Loader, CSS Loader and SASS Loader. A good starting point is reflay-example.
Take a look at the official example of using reflay
in the reflay-example
repository.
To install the stable version:
npm install --save reflay
This assumes you are using npm as your package manager.
Once you have the WebPack workflow ready, you can just require and use the components:
import React from 'react'
import { Layout, Box } from 'reflay'
// Do not forget to load SCSS style
import 'reflay/lib/styles/layout.scss'
React.render(<Layout direction='column' />, document.querySelector('#root'))
Prop | Allowed values | Default value -- | Breakpoint specific* |
---|---|---|---|
direction |
row or column |
row |
Yes |
align |
`start | center | end |
fill |
bool |
No | |
wrap |
bool |
No | |
nowrap |
bool |
No | |
margin |
bool |
No | |
padding |
bool |
No |
direction
- specifies theLayouts
direction.align
- specifies howBox
children will be aligned inside theLayout
container.fill
- forces theLayout
element to fill its parent container.wrap
- allowsBox
children to wrap within theLayout
container.nowrap
- do not allowBox
children to wrap within theLayout
container.margin
- adds margin around eachBox
child.padding
- adds padding inside eachBox
child.
Prop | Allowed values | Breakpoint specific* |
---|---|---|
flex |
integer (increments of 5 for 0% -> 100%, 100%/3) |
Yes |
order |
integer (values from -20 to 20) |
Yes |
offset |
integer (increments of 5 for 0% -> 95%, 100%/3) |
Yes |
hide |
bool |
Yes |
show |
bool |
Yes |
flex
- defines how theBox
element will adjust its size with respect to its parentLayout
container and the other elements within the container.order
- setsBox
order position within theLayout
container.offset
- setsBox
offset percentage within theLayout
container.hide
- hide theBox
elements - responsively with the use of Breakpoint specific aliases.show
- show theBox
elements - responsively with the use of Breakpoint specific aliases.
* Breakpoint specific: These Props can be used in combination with the following Responsive UI Breakpoints:
Breakpoint | MediaQuery (pixel range) | |
---|---|---|
xs |
'(max-width: 599px)' | extra small |
gt-xs |
'(min-width: 600px)' | greater than extra small |
sm |
'(min-width: 600px) and (max-width: 959px)' | small |
gt-sm |
'(min-width: 960px)' | greater than small |
md |
'(min-width: 960px) and (max-width: 1279px)' | medium |
gt-md |
'(min-width: 1280px)' | greater than medium |
lg |
'(min-width: 1280px) and (max-width: 1919px)' | large |
gt-lg |
'(min-width: 1920px)' | greater than large |
xl |
'(min-width: 1920px)' | extra large |
resulting in the following props
(just a few examples):
direction-xs='row'
- specifyrow
direction forxs
viewport.direction-gt-xs='column'
- specifycolumn
direction forgt-xs
viewport.align-sm='start start'
-start start
align type forsm
viewport.align-gt-sm='start end'
-start end
align type forgt-sm
viewport.flex-md={50}
- 50 % size of the parent container formd
viewport.flex-gt-md={75}
- 75 % size of the parent container forgt-md
viewport.order-lg={1}
- specifyorder
value of1
forlg
viewport.order-gt-lg={2}
- specifyorder
value of2
forgt-lg
viewport.offset-md={10}
- set 10 %offset
formd
viewport.offset-gt-md={5}
- set 5 %offset
forgt-md
viewport.hide-sm
- hide theBox
element forsm
viewport.hide-gt-sm
- hide theBox
element forgt-sm
viewport.show-xs
- show theBox
element forxs
viewport.show-gt-xs
- show theBox
element forgt-xs
viewport.
import React from 'react'
import { Layout, Box } from 'reflay'
// Do not forget to load SCSS style
import 'reflay/lib/styles/layout.scss'
// 3 identical sized boxes appear next to each other on devices with viewport of `960px` min.
// 4 boxes stretched in width apper below each other on devices with viewport of `959px` max.
const ResponsiveComponent = () => (
<Layout direction='column' direction-gt-sm='row' align='start stretch' align-gt-sm='center start'>
<Box flex={100} flex-gt-sm={33} order={1}>
Box #1 - still visible
</Box>
<Box flex={100} flex-gt-sm={33} order={2}>
Box #2 - still visible
</Box>
<Box flex={100} flex-gt-sm={33} order={3}>
Box #3 - still visible
</Box>
<Box flex={100} hide-gt-sm order={-1}>
Box #4 - shown as first and only on devices with up to small viewport size.
</Box>
</Layout>
)
export default ResponsiveComponent
Copyright © 2016 BePlus s.r.o.
Licensed under the MIT License.
Give us a star if reflay
provides you some value.