All files / react_grid_layout_modified/test/examples 20-resizable-handles.jsx

82.35% Statements 14/17
75% Branches 3/4
77.77% Functions 7/9
87.5% Lines 14/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70        1x     1x                 21x   21x 21x       21x 420x                 21x 21x   21x 420x 420x                               21x                       1x      
import React from "react";
import _ from "lodash";
import RGL, { WidthProvider } from "react-grid-layout";
 
const ReactGridLayout = WidthProvider(RGL);
 
export default class ResizableHandles extends React.PureComponent {
  static defaultProps = {
    className: "layout",
    items: 20,
    rowHeight: 30,
    onLayoutChange: function() {},
    cols: 12
  };
 
  constructor(props) {
    super(props);
 
    const layout = this.generateLayout();
    this.state = { layout };
  }
 
  generateDOM() {
    return _.map(_.range(this.props.items), function(i) {
      return (
        <div key={i}>
          <span className="text">{i}</span>
        </div>
      );
    });
  }
 
  generateLayout() {
    const p = this.props;
    const availableHandles = ["s", "w", "e", "n", "sw", "nw", "se", "ne"];
 
    return _.map(new Array(p.items), function(item, i) {
      const 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(),
        resizeHandles: availableHandles
      };
    });
  }
 
  onLayoutChange(layout) {
    this.props.onLayoutChange(layout);
  }
 
  render() {
    return (
      <ReactGridLayout
        layout={this.state.layout}
        onLayoutChange={this.onLayoutChange}
        {...this.props}
      >
        {this.generateDOM()}
      </ReactGridLayout>
    );
  }
}
 
Iif (process.env.STATIC_EXAMPLES === true) {
  import("../test-hook.jsx").then(fn => fn.default(ResizableHandles));
}