reflay v1.0.3
reflay: React Flexbox Layout
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
Usage
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.
Example
Take a look at the official example of using reflay in the reflay-example
repository.
Installation and Usage
To install the stable version:
npm install --save reflayThis 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'))API
Layout Component
| Prop | Allowed values | Default value -- | Breakpoint specific* |
|---|---|---|---|
direction | row or column | row | Yes |
align | start|center|end|space-around|space-between start|center|end|stretch | start stretch | Yes |
fill | bool | No | |
wrap | bool | No | |
nowrap | bool | No | |
margin | bool | No | |
padding | bool | No |
direction- specifies theLayoutsdirection.align- specifies howBoxchildren will be aligned inside theLayoutcontainer.fill- forces theLayoutelement to fill its parent container.wrap- allowsBoxchildren to wrap within theLayoutcontainer.nowrap- do not allowBoxchildren to wrap within theLayoutcontainer.margin- adds margin around eachBoxchild.padding- adds padding inside eachBoxchild.
Box Component
| 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 theBoxelement will adjust its size with respect to its parentLayoutcontainer and the other elements within the container.order- setsBoxorder position within theLayoutcontainer.offset- setsBoxoffset percentage within theLayoutcontainer.hide- hide theBoxelements - responsively with the use of Breakpoint specific aliases.show- show theBoxelements - 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'- specifyrowdirection forxsviewport.direction-gt-xs='column'- specifycolumndirection forgt-xsviewport.align-sm='start start'-start startalign type forsmviewport.align-gt-sm='start end'-start endalign type forgt-smviewport.flex-md={50}- 50 % size of the parent container formdviewport.flex-gt-md={75}- 75 % size of the parent container forgt-mdviewport.order-lg={1}- specifyordervalue of1forlgviewport.order-gt-lg={2}- specifyordervalue of2forgt-lgviewport.offset-md={10}- set 10 %offsetformdviewport.offset-gt-md={5}- set 5 %offsetforgt-mdviewport.hide-sm- hide theBoxelement forsmviewport.hide-gt-sm- hide theBoxelement forgt-smviewport.show-xs- show theBoxelement forxsviewport.show-gt-xs- show theBoxelement forgt-xsviewport.
Code Snippets
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 ResponsiveComponentContributors
License
Copyright © 2016 BePlus s.r.o.
Licensed under the MIT License.
Give us a star if reflay provides you some value.
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago