• Stars
    star
    337
  • Rank 125,272 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Layout Components for React based on Flexbox

Not actively maintained! This project is not actively maintained anymore. If you'd like to take ownership - feel free to contact me!

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 facebook/react#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

Property Description Options
flex flex-grow flex-shrink flex-basis
flexGrow positive integer >= 0
flexShrink positive integer >= 0
flexBasis base size size value, auto
order  item order
inline display: inline-flex shortcut
column flex-direction: column shortcut
reverse reverse flex-direction shortcut
wrap flex-wrap: wrap shortcut, wrap-reverse
flow row nowrap flex-direction flex-wrap
alignContent line-content align center, flex-start, flex-end, space-around, space-between
justifyContent main-axis align center, flex-start, flex-end, space-around, space-between
alignItems cross-axis align center, flex-start, flex-end, baseline, stretch
alignSelf item self align center, flex-start, flex-end, baseline, stretch
Shortcuts
Property  Description
fit width: 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
fixed position:fixed
absolute position:absolute
 borderTop Adds a border at the top with borderWidth
 borderLeft Adds a border to the left with borderWidth
 borderRight Adds a border to the right with borderWidth
 borderBottom Adds 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

Property Description Options
height container height
width container width
 horizontal  enables horizontal scrollable container  boolean
 initialScrollPos scroll position  number
onScroll gets 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.

More Repositories

1

fela

State-Driven Styling in JavaScript
JavaScript
2,273
star
2

react-look

Advanced & Dynamic Component Styling for React and React Native. Ships with powerful Plugins, Mixins and Developer Tools. (Deprecated: use Fela)
JavaScript
583
star
3

inline-style-prefixer

Autoprefixer for JavaScript style objects
JavaScript
393
star
4

react-controlled-form

React Forms with Zod Validation
TypeScript
118
star
5

react-css-component

Injecting CSS via React Components
JavaScript
94
star
6

alveron

Tiny (0.8kb) Elm-inspired state management for React
JavaScript
74
star
7

css-in-js-utils

Useful utility functions for CSS in JS solutions
TypeScript
74
star
8

bredon

A modern CSS value compiler in JavaScript
JavaScript
40
star
9

elodin

The Elodin Styling Language
JavaScript
30
star
10

fast-loops

Tiny (0.6kb), performant & immutable iteration utilities for arrays and objects
JavaScript
25
star
11

kilvin

Primitive React Layout Components using Fela
JavaScript
22
star
12

alveron-old

Opinionated Elm-inspired Redux Component Architecture for React
JavaScript
17
star
13

inline-style-prefix-all

Static Autoprefixer for inline styles
JavaScript
16
star
14

elodin-old

Quality and Optimisation tools for CSS in JavaScript
JavaScript
16
star
15

inline-style-expand-shorthand

Expanding shorthand properties in JavaScript style objects
JavaScript
13
star
16

brandeur

Convenience tool belt for css-hooks
JavaScript
12
star
17

small-color

Tiny (0.8kb), opinionated & tree-shakable alternative to color
JavaScript
7
star
18

small-date

Tiny (0.8kb) date formatting library with built-in i18n
JavaScript
6
star
19

tehlu

Component System for React and Brandeur
JavaScript
5
star
20

Calculate.js

Calculate.js is kind of an extension to the JavaScript build-in Math-Library.
JavaScript
5
star
21

ambrose

Configurable Design System Skeleton for React
JavaScript
5
star
22

react-markdown-github-renderers

react-markdown renderers for GitHub-like appearance
JavaScript
5
star
23

pogolookup

Ads-free, Privacy-first Pokemon Go Data Lookup & Analysis Fanpage
JavaScript
5
star
24

inline-style-transformer

Transformation tools for inline styles
JavaScript
5
star
25

lorren

A PDF Framework for React based on react-pdf
JavaScript
4
star
26

radium-plugin-prefix-all

Radium plugin that adds all vendor prefixes
JavaScript
4
star
27

react-create-keyframe

Helper to create and render keyframes on-demand in React
TypeScript
3
star
28

Obscene-UI

[Sass] Obscene UI is a responsive, mobile-friendly UI-Template to build stable and beautiful app themes
CSS
3
star
29

assign-styles

ES6 Object.assign() polyfill especially for inline-styles respecting !important notation
JavaScript
3
star
30

radium-plugin-linter

[devTool] Radium plugin that enables style linting with inline-style-linter
JavaScript
2
star
31

read-transform-write

Transform files with ease
JavaScript
2
star
32

doc-badges

Useful badges for Code & API documentation
2
star
33

theme-centric-component-design

Example for theme-centric component design
JavaScript
2
star
34

tokenize-sync

Simple synchronous string tokenizer using Regex
JavaScript
1
star
35

react-onegraph

React Bindings for OneGraph's Authentication Client
JavaScript
1
star
36

unitless-css-property

Helper to check for unitless CSS property names
JavaScript
1
star
37

rofrischmann

My personal portfolio webpage
HTML
1
star
38

speaking

Speaker resources and talk slides
JavaScript
1
star
39

flow-semantic-versioning

Enforced Semantic Versioning for Flow
JavaScript
1
star