Git Product home page Git Product logo

react-layout's Introduction

React Layout

Dynamic subview layout for React

Define layout of nested views with fixed and flexible dimensions in a declarative manner.

Why? Because if you still have to support IE8 and 9 then flexbox is off the table, but dynamic flexibly sized elements are necessary for many complex layouts.

Example

var React = require('react');
var Layout = require('react-layout');
var AppViews = require('./app-views')

var AppLayout = React.createClass({
  getInitialState: function() {
    // a resizable sidebar could be implemented by updating this value
    return {sidebarWidth: 330}
  },
  render: function() {
    var scrollable = {
      'overflow-y': 'scroll',
      'overflow-x': 'hidden',
    }

    return (
      <Layout layoutWidth={this.props.width} layoutHeight={this.props.height}>
        <Layout className="sidebar" layoutWidth={this.state.sidebarWidth}>
          <AppViews.Sidebar />
        </Layout>
        <Layout className="main" layoutWidth="flex" style={scrollable}>
          <AppViews.Main />
        </Layout>
      </Layout>
    )
  },
})

function render() {
  var appView = (
    <AppLayout
      width={window.innerWidth}
      height={window.innerHeight}
    />
  )
  React.render(appView, document.body)
}

window.addEventListener('resize', render)

render()

This example implements a two-panel app layout with a sidebar and main viewport. The sidebar gets its width from a state value and the main view fills the remaining width.

When the window is resized, the app is rerendered and the new window dimensions flow down the layout hierarchy.

API

The Layout component provided by this module can be parametised with the props layoutWidth and layoutHeight, both which take a layoutDef value, which can be any of the following:

  • numeric pixel value: will apply a fixed size in pixels for that dimension
  • "flex": will fill the remaining space left by fixed size sibling Layout elements components taking part in layout for that dimension. If there are multiple 'flex' components, they will share the available space evenly.
  • "omit": the element will not be given any size value for this dimension

If no layoutDef value is provided for a particular dimension, the Layout component will inherit the size for that dimension from the parent component (or the closest parent Layout component) as a fixed size.

Other props:

  • component: a React component class to use for the layout element (defaults to div)

react-layout's People

Contributors

jsdf avatar

Watchers

Prashanth Acharya M avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.