layout
A React components for flexbox layout written in typescript
Jul 15, 2018

Reflexy
Flexbox layout react components.
Reflexy is a React components for flexbox layout written in typescript.
With Reflexy
-
You don't need to worry about the prefixes of different browsers - Reflexy use an autoprefixer.
-
You don't need to do a concatenation of a lot of css classes:
<div className={classNames(styles['flex'], styles['flex-column'], styles['flex-align-center'], ...)}> {children} </div>
vs
<Flex column alignItems="center" className="custom-class">{children}</Flex>
-
You can replace default output
div
tag:<Flex tagName="header">{children}</Flex>
output:
<header class="...">{children}</header>
-
You can tweak you own react component with flexbox layout (your component must accept className through props):
<Flex component={MyComponent} column alignSelf="center" myProp="myPropValue" className={styles['my-class']} > {children} </Flex>
will be
<MyComponent myProp="myPropValue" className="[reflexy classes] my-class">{children}</MyComponent>
Installation
yarn add react reflexy
or
npm install --save react reflexy
Reflexy has own css files so you need provide loader for css files placed in node_modules folder. With webpack it's maybe css-loader:
{ test: /\.css$/, include: path.join(__dirname, 'node_modules'), // or include: /reflexy/ use: [ { loader: 'style-loader' }, { loader: 'css-loader', options: { modules: true, localIdentName: '[local]', }, }, ], },
Usage
import { Flex } from 'reflexy'; ... <Flex row justifyContent="center"> ... </Flex>
Props
Flex
Default style is just display: flex;
inline?: boolean;
- Setsdisplay
toinline-flex
.alignContent?: 'center' | 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'stretch' | 'initial' | 'inherit';
- Setsalign-content
to corresponding value.alignItems?: 'center' | 'flex-start' | 'flex-end' | 'stretch' | 'baseline' | 'initial' | 'inherit';
- Setsalign-items
to corresponding value.alignSelf?: 'center' | 'flex-start' | 'flex-end' | 'stretch' | 'baseline' | 'auto' | 'initial' | 'inherit';
- Setsalign-self
to corresponding value.justifyContent?: 'center' | 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'initial' | 'inherit';
- Setsjustify-content
to corresponding value.basis?: 'none' | 'auto' | 'fill' | 'content' |fit-content' | 'min-content' | 'max-content';
- Setsflex-basis
to corresponding value.grow?: 0..24;
- Setsflex-grow
to corresponding value. Also accepts boolean value:true
is equals to1
,false
is equals to0
.shrink?: 0..24;
- Setsflex-shrink
to corresponding value. Also accepts boolean value:true
is equals to1
,false
is equals to0
.row?: boolean;
- Setsflow-direction
torow
.column?: boolean;
- Setsflow-direction
tocolumn
. Takes a precedence overrow
.reverse?: boolean;
- Used withrow
orcol
. Setsflow-direction
tocolumn-reverse
orrow-reverse
.wrap?: boolean | 'reverse';
- Setsflex-wrap
towrap
orwrap-reverse
.order?: number;
- Setsorder
to corresponding value.hfill?: boolean;
- Stretch by horizontal.vfill?: boolean;
- Stretch by vertical.fill?: 'v' | 'h' | 'all';
- Stretch by v - vertical or h - horizontal or all - both. Also accepts boolean value:true
is equals toall
.component?: React.ComponentType<any>;
- Sets React component as a container. Component must accept className through props.tagName?: string;
- Html tag name for output container. Takes a precedence overcomponent
.center?: boolean;
- SetsjustifyContent
andalignItems
tocenter
. Takes a precedence overjustifyContent
andalignItems
.className?: string;
- CSS class name.style?: React.CSSProperties;
- Inline styles.- and all other props of html element.
TODO
If you need more features or you find a bug, please, open an issue or make PR.