React Layout Views
Easy layouts for React & React Native
See live examples
Why
Creating UI layouts should be simple and declarative.
The aim of this library is to provide a simple and intuitive API for composing layouts by abstracting away certain flex concepts like flex-direction and main/cross axis alignment and replacing these with more intuitive terms like horizontal
, bottom
, right
, and center
.
Examples
See live examples
Horizontal
<Layout horizontal spacing='20px'>
<Section grow>Content 1</Section>
<Section>Content 2</Section>
<Section>Content 3</Section>
</Layout>
Nested Layouts
<Layout horizontal spacing='20px'>
<Section grow>Content 1</Section>
<Section>Content 2</Section>
<Section>
<Layout spacing='10px'>
<Section>Content 1</Section>
<Section>Content 2</Section>
<Section>Content 3</Section>
</Layout>
</Section>
</Layout>
Styling
<Layout horizontal spacing='20px' style={{background: 'red'}}>
<Section grow>Content 1</Section>
<Section>Content 2</Section>
<Section style={{padding: '1em'}}>Content 3</Section>
</Layout>
Setup
Install
$ npm install react-layout-views
Import
import { Layout, Section } from 'react-layout-views'
import { Layout, Section } from 'react-layout-views/native'
...
API
<Layout />
The Layout
component wraps multiple Section
components.
Props
grow?: boolean | number
how should the Layout fill its containerspacing?: number (native) / string (web e.g. 20px, 2%, etc.)
spacing between child <Section />
shorizontal?: boolean
are child sections arranged horizontally or verticallystyle?: object
JavaScript style object (on the web this is passed to styled-components and will not produce inline-styles). All platform-specific styling is supported.
Alignment
Alignment props arrange child Sections
accordingly and can be combined (e.g. <Layout bottom right>...</Layout>
).
center?: boolean
centerVertical?: boolean
centerHorizontal?: boolean
top?: boolean
right?: boolean
bottom?: boolean
left?: boolean
<Section />
The Section
component subdivides a Layout
and contains other components or another Layout
.
Props
grow?: boolean | number
how should the Section
fill its containerstyle?: object
JavaScript style object (on the web this is passed to styled-components and will not produce inline-styles). All platform-specific styling is supported.
Alignment
Alignment props arrange child content accordingly and can be combined (e.g. <Section center right>...</Section>
).
center?: boolean
centerVertical?: boolean
centerHorizontal?: boolean
top?: boolean
right?: boolean
bottom?: boolean
left?: boolean
Develop
npm run setup
install project and test app depsnpm run dist
or npm run dist:watch
- buildnpm run apps:run
- start storybook for web and nativenpm run apps:test
- run visual regression tests with loki