3.0.6 • Published 7 years ago

react-layout-components v3.0.6

Weekly downloads
1,166
License
MIT
Repository
github
Last release
7 years ago

React Layout Components

npm install react-layout-components

Useful, Modern and universal layout Components for React.js based on flexbox.

The basis <Box> Component is highly inspired by React Native's Flexbox implementation and though accepts almost the same props. It supports all flexbox specifications and automatically adds alternative values and prefixes thanks to inline-style-prefix-all if needed.

npm downloads

Note: If you're not familiar with Flexbox at all, I recommend css-tricks 'Complete Guide to Flexbox' which is an awesome source for beginners as well as a nice refreshment for experts.

Components

To be able to use any of those Components below, make sure you have added the following CSS class somewhere. Personally I just inline it inside the <head> of the index.html.

.react-layout-components--box {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

Note: This is a temporary fix and will hopefully be removed if React merges https://github.com/facebook/react/pull/6701.

Shortcuts

Box

Box is an universal container component based on flexbox. You can most likely use this Component for everything as is helps recreating almost any possible layout.

import React from 'react'
import Box from 'react-layout-components'

const Example = () => (
  // This acts as some kind of container
  <Box width={300} height={500}>
      //This acts as an actual flexbox container
      <Box justifyContent="center" alignItems="flex-start">
        <Box flex={3}>Flex 3</Box>
        <Box flex="1 0 auto" alignSelf="baseline">Flex 1</Box>
    </Box>
  </Box>
)

Props

PropertyDescriptionOptions
flexflex-grow flex-shrink flex-basis
flexGrowpositive integer >= 0
flexShrinkpositive integer >= 0
flexBasisbase sizesize value, auto
order item order
inlinedisplay: inline-flexshortcut
columnflex-direction: columnshortcut
reversereverse flex-directionshortcut
wrapflex-wrap: wrapshortcut, wrap-reverse
flowrow nowrapflex-direction flex-wrap
alignContentline-content aligncenter, flex-start, flex-end, space-around, space-between
justifyContentmain-axis aligncenter, flex-start, flex-end, space-around, space-between
alignItemscross-axis aligncenter, flex-start, flex-end, baseline, stretch
alignSelfitem self aligncenter, flex-start, flex-end, baseline, stretch
Shortcuts
Property Description
fitwidth: 100%; height: 100%
center justify-content: center; align-items: center
Size

Box lets you also define size properties which are width, height, minWidth, maxWidth, minHeight and maxHeight.

Defaults

Browser default values don't need to be set explicit and are defined as

{
  display: flex;
  flex: 0 1 auto;
  flex-direction: row;
  justify-content: flex-start;
  align-items: stretch;
  align-content: stretch;
  flex-wrap: nowrap;
}

Container

Container is a Component to style box-model properties.

Props

  • Padding: padding, paddingLeft, paddingTop, paddingRight, paddingBottom
  • Margin: margin, marginLeft, marginTop, marginRight, marginBottom
  • Border: border, borderColor, borderWidth, borderStyle, borderTop, borderLeft, borderBottom, borderRight
  • Size: width, height, minWidth, maxWidth, minHeight, maxHeight
  • Position: top, left, bottom, right
  • Flow: overflow, overflowX, overflowY, textOverflow, whiteSpace

You may also set boxSizing which defines how the size of a box is calculated. You may use border-box, content-box or padding-box.

Shortcuts

There are some shortcut properties. They do not accept a value. e.g. <Container fixed></Container>.

Property Description
fixedposition:fixed
absoluteposition:absolute
 borderTopAdds a border at the top with borderWidth
 borderLeftAdds a border to the left with borderWidth
 borderRightAdds a border to the right with borderWidth
 borderBottomAdds a border at the bottom with borderWidth

Page

Page is just a shortcut for a page-filling Component. It also is fixed to the edges of your WebView.

ScrollView

ScrollView is a scrollable container. It is build on the <Box>-Component, which let's you either use default box-model sizing or flexbox sizing.

Props

PropertyDescriptionOptions
heightcontainer height
widthcontainer width
 horizontal enables horizontal scrollable container boolean
 initialScrollPosscroll position number
onScrollgets fired on scrolling function

Methods

  • getScrollPosition() Returns the actual scroll position.

  • scrollTo(scrollPosition) Scrolls to the scrollPosition.

  • scrollToStart() Scrolls to the container start.

  • scrollToEnd() Scrolls to the container end.

Shortcuts

VBox

Box with flex-direction: column. (vertical flow)

Flex

Box with flex: 1 0 auto.

Center

Box centerering its children with justify-content: center; align-items: center.

Demo

To run the included demo, run the following command: $ npm run build:demo && open demo/index.html

License

react-layout-components is licensed under the MIT License. Created with by @rofrischmann.

Contributing

I would love to see people getting involved. If you have a feature request please create an issue. Also if you're even improving one of the Components by any kind please don't be shy and send a pull request to let everyone benefit.

Issues

If you're having any issue please let me know as fast as possible to find a solution a hopefully fix the issue. Try to add as much information as possible such as your environment, exact case, the line of actions to reproduce the issue.

Pull Requests

If you are creating a pull request, try to use commit messages that are self-explanatory.

3.0.6

7 years ago

3.0.5

7 years ago

3.0.4

7 years ago

3.0.3

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.2.0

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago