6.0.1 • Published 4 years ago

react-flexview v6.0.1

Weekly downloads
8,394
License
ISC
Repository
github
Last release
4 years ago

FlexView

A powerful React component to abstract over flexbox and create any layout on any browser.

Install

yarn add react-flexview

Why

The flexbox API is powerful but far from being perfect. The API is complex and there are still many inconsistencies between browsers that force developers to overuse vendor prefixes and literally do magic tricks to achieve the desired layout.

For these reasons, we asked ourselves: is there a way to simplify the API and handle any browser inconsistency in a single place? Our attempt to answer "yes!" to that question gave birth to FlexView.

// flex row
<FlexView />

// flex column
<FlexView column />

// grow, shrink and basis
<FlexView grow shrink basis={100} />
<FlexView grow={2} shrink={1} basis='auto' />
<FlexView basis={100} /> // shrink is set to `false` by default so you're certain to a have it `100px` wide/tall

// wrap
<FlexView wrap />

Remember how difficult it was to center a div inside another div? flexbox definitely improved it, but still having to switch from align-items to justify-content based on flex-direction of the parent is confusing and error prone.

FlexView lets you align and center children with two intuitive props: vAlignContent and hAlignContent.

<FlexView hAlignContent='center' vAlignContent='center'>
  <FlexView>the center of the Earth</FlexView>
</FlexView>

How to use

In your component:

import React from 'react';
import FlexView from 'react-flexview';

export default class Component extends React.Component {
  render() {
    return (
      <FlexView vAlignContent='center'>
        I'm vertically centered!
      </FlexView>
    );
  }
}

Props

NameTypeDefaultDescription
childrenReactChildrenrequired. FlexView content
columnBooleanoptional. Flex-direction: column
vAlignContentenum("top" | "center" | "bottom")optional. Align content vertically
hAlignContentenum("left" | "center" | "right")optional. Align content horizontally
marginLeftunion(String | Number)optional. Margin-left property ("auto" to align self right)
marginTopunion(String | Number)optional. Margin-top property ("auto" to align self bottom)
marginRightunion(String | Number)optional. Margin-right property ("auto" to align self left)
marginBottomunion(String | Number)optional. Margin-bottom property ("auto" to align self top)
growunion(Boolean | Number)optional. Property (for parent primary axis)
shrinkunion(Boolean | Number)optional. Flex-shrink property
basisunion(String | Number)optional. Flex-basis property
wrapBooleanoptional. Wrap content
heightunion(String | Number)optional. Height property (for parent secondary axis)
widthunion(String | Number)optional. Width property (for parent secondary axis)
classNameStringoptional. Additional className for wrapper element
styleObjectoptional. Inline-style overrides for wrapper element

Demo

Here's a live playground

Documentation

Refer to the Book of FlexView

Supported browsers

We removed vendor prefixes in #66, since than we only supports browsers that don't require prefixes for flexbox CSS properties which are most browsers:

  • IE 11
  • Edge (any version)
  • Google Chrome 29+
  • Firefox 28+
  • Safari 9+

If you need to support older browsers, try with FlexView 3.x.

Used By

At buildo we've been using FlexView in production in every web application we built since July 2015 (it was in a different repo back then).

As of today, FlexView has replaced the div as the brick of our projects and, thanks to it, our developers can finally build without too much trouble complex layouts that work the same on Chrome, Firefox, Safari and Internet Explorer 11.

You can see it in action here:

6.0.1

4 years ago

6.0.0

4 years ago

5.0.0

4 years ago

5.0.0-1

4 years ago

5.0.0-2

4 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.1

8 years ago