react-layout-manager
Layout manager not to give margins to components
Table of Contents
Installation
To install, you can use npm or yarn:
$ npm install -S react-layout-manager
$ yarn add react-layout-manager
Usage
Example:
import RLM from 'react-layout-manager'; { const EmailStyle = width: 100 '100%' horizontalSpace: 5 responsive: breakpoint: 480 settings: wrap: true wrapVerticalSpace: 5 ; const EmailInnerStyle = width: '65%' 16 '35%' horizontalSpace: 5 ; return <RLM > <Label>Email</Label> <RLM > <Input ="react-layout-manager" /> <Unit>@</Unit> <Input ="gmail.com" /> </RLM> </RLM> ;}
Props
Props | Type | Default Value | Description |
---|---|---|---|
horizontalSpace |
string \| number \| Array<string \| number> |
0 |
Horizontal space of element and element |
verticalSpace |
string \| number \| Array<string \| number> |
0 |
Vertical space of element and element |
wrapVerticalSpace |
string \| number \| Array<string \| number> |
0 |
Vertical space of element and element when wrap |
width |
string \| number \| Array<string \| number> |
null |
Width of elements |
innerWidth |
string \| number \| Array<string \| number> |
null |
Width in element |
verticalAlign |
string \| number \| Array<string \| number> |
null |
Vertical align |
align |
'left' \| 'center' \| 'right' \| Array<'left' \| 'center' \| 'right'> |
null |
Align inner element |
visible |
boolean \| Array<boolean> |
true |
Whether the elements are displayed or not |
wrap |
boolean |
false |
Whether to wrap or not |
responsive
property
Array of objects in the form of { breakpoint: int, settings: { ... } }
The breakpoint number is the maxWidth
so the settings will be applied when resolution is below this value.
Example: [ { breakpoint: 1024, settings: { wrap: true, width: ['20%', 100, '80%'] } }, { breakpoint: 768, settings: { visible: false } }]
Examples
Demo Source:
import React Component from 'react';import styled from 'styled-components';import RLM from 'react-layout-manager'; const Input = styledinput` ...`;const Unit = styleddiv` ...`;const Label = styleddiv` ...`; { const EmailStyle = width: 100 '100%' horizontalSpace: 5 responsive: breakpoint: 480 settings: wrap: true wrapVerticalSpace: 5 ; const EmailInnerStyle = width: '65%' 16 '35%' horizontalSpace: 5 ; return <RLM > <Label>Email</Label> <RLM > <Input ="react-layout-manager" /> <Unit>@</Unit> <Input ="gmail.com" /> </RLM> </RLM> ;} { const TelStyle = width: 100 160 horizontalSpace: 5 responsive: breakpoint: 480 settings: width: '100%' wrap: true wrapVerticalSpace: 5 ; return <RLM > <Label>Tel</Label> <Input ="090XXXXXXXX" /> </RLM> ;} { const PasswordStyle = width: 100 240 horizontalSpace: 5 responsive: breakpoint: 480 settings: width: '100%' wrap: true wrapVerticalSpace: 5 ; return <RLM > <Label>Password</Label> <Input ="rEaCtLaYoUtMaNaGeR"/> </RLM> ;} { const BirthdayStyle = width: 100 '100%' horizontalSpace: 5 responsive: breakpoint: 480 settings: wrap: true wrapVerticalSpace: 5 ; const BirthdayInnerStyle = width: 56 16 44 16 44 horizontalSpace: 5 responsive: breakpoint: 480 settings: width: '40%' 16 '30%' 16 '30%' ; return <RLM > <Label>Birthday</Label> <RLM > <Input ="YYYY" /> <Unit>ー</Unit> <Input ="MM" /> <Unit>ー</Unit> <Input ="DD" /> </RLM> </RLM> ;} { const PostalCodeStyle = width: 100 '100%' horizontalSpace: 5 responsive: breakpoint: 480 settings: wrap: true wrapVerticalSpace: 5 ; const PostalCodeInnerStyle = width: 64 16 80 horizontalSpace: 5 responsive: breakpoint: 480 settings: width: '50%' 16 '50%' ; return <RLM > <Label>PostalCode</Label> <RLM > <Input ="XXX" /> <Unit>ー</Unit> <Input ="XXXX" /> </RLM> </RLM> ;} { const CardNumberStyle = width: 100 '100%' horizontalSpace: 5 responsive: breakpoint: 480 settings: wrap: true wrapVerticalSpace: 5 ; const CardNumberInnerStyle = width: '50%' 16 '50%' horizontalSpace: 5 wrapVerticalSpace: 10 responsive: breakpoint: 480 settings: width: '100%' null '100%' wrap: true visible: true false true ; const CardNumberCellStyle = width: '50%' 16 '50%' horizontalSpace: 5 ; return <RLM > <Label>CardNumber</Label> <RLM > <RLM > <Input ="XXXX" /> <Unit>ー</Unit> <Input ="XXXX" /> </RLM> <Unit>ー</Unit> <RLM > <Input ="XXXX" /> <Unit>ー</Unit> <Input ="XXXX" /> </RLM> </RLM> </RLM> ;} { const MainStyle = width: '100%' verticalSpace: 10 innerWidth: 500 align: 'center' ; return <RLM > <Email /> <Tel /> <Password /> <Birthday /> <PostalCode /> <CardNumber /> </RLM> ;} { return <Main /> ; } ;