JSFiddle - React, Tailwind, and code Playground

by phsiao2000

HTML

<script src="https://cdn.jsdelivr.net/lodash/4.5.1/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://fb.me/react-with-addons-0.14.6.js"></script>
<script src="https://fb.me/react-dom-0.14.6.js"></script>
<script src="https://rawgit.com/STRML/react-grid-layout/master/dist/react-grid-layout.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/STRML/react-grid-layout/master/css/styles.css">
<link rel="stylesheet" href="https://rawgit.com/STRML/react-grid-layout/master/examples/example-styles.css">
<link rel="stylesheet" href="https://rawgit.com/STRML/react-resizable/master/css/styles.css">
 <script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>

 <h3>React-Grid-Layout Demo 1 - Basic</h3>
  <div id="content"></div>

JavaScript 1.7

'use strict';
const PureRenderMixin = React.addons.PureRenderMixin;
const RGL = ReactGridLayout.WidthProvider(ReactGridLayout);

var BasicLayout = React.createClass({
  mixins: [PureRenderMixin],

  getDefaultProps() {
    return {
      className: "layout",
      items: 20,
      rowHeight: 30,
      cols: 12
    };
  },

  getInitialState() {
    var layout = this.generateLayout();
    return {
      layout: layout
    };
  },

  generateDOM() {
  	debugger
    return _.map(this.state.layout, function(l) {
    	var tot = l.y * 30
      var hrs = Math.trunc(tot / 60)
      var mins = tot - (hrs*60)
      return <div key={l.i}><span className="text">{hrs}:{(mins+"0").substring(0,2)}</span></div>;
    });
  },

  generateLayout() {
    var p = this.props;
    return _.map(new Array(p.items), function(item, i) {
      var y = _.result(p, 'y') || Math.ceil(Math.random() * 4) + 1;
      return {x: i * 2 % 12, y: Math.floor(i / 6) * y, w: 2, h: y, i: i.toString()};
    });
  },

  onLayoutChange: function(layout) {
    console.log('layout updated');
    this.setState({layout: layout});
  },

  render() {
    const {layout} = this.state; 
    return (
      <RGL {...this.props} 
      layout={layout} 
      onLayoutChange={this.onLayoutChange}>
        {this.generateDOM()}
      </RGL>
    );
  }
});

ReactDOM.render(
  <BasicLayout />,
  document.getElementById('content')
);