Download react-grid-layout/test/examples/04-grid-property.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-grid-layout/test/examples/04-grid-property.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-grid-layout/test/examples/04-grid-property.jsx
-
curl -L -o 04-grid-property.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-grid-layout/test/examples/04-grid-property.jsx
1.48 kB
| import React from "react"; | |
| import _ from "lodash"; | |
| import RGL, { WidthProvider } from "react-grid-layout"; | |
| const ReactGridLayout = WidthProvider(RGL); | |
| export default class GridPropertyLayout extends React.PureComponent { | |
| static defaultProps = { | |
| isDraggable: true, | |
| isResizable: true, | |
| items: 20, | |
| rowHeight: 30, | |
| onLayoutChange: function() {}, | |
| cols: 12 | |
| }; | |
| generateDOM() { | |
| // Generate items with properties from the layout, rather than pass the layout directly | |
| const layout = this.generateLayout(); | |
| return _.map(_.range(this.props.items), function(i) { | |
| return ( | |
| <div key={i} data-grid={layout[i]}> | |
| <span className="text">{i}</span> | |
| </div> | |
| ); | |
| }); | |
| } | |
| generateLayout() { | |
| const p = this.props; | |
| return _.map(new Array(p.items), function(item, i) { | |
| var w = _.result(p, "w") || Math.ceil(Math.random() * 4); | |
| var y = _.result(p, "y") || Math.ceil(Math.random() * 4) + 1; | |
| return { | |
| x: (i * 2) % 12, | |
| y: Math.floor(i / 6) * y, | |
| w: w, | |
| h: y, | |
| i: i.toString() | |
| }; | |
| }); | |
| } | |
| onLayoutChange(layout) { | |
| this.props.onLayoutChange(layout); | |
| } | |
| render() { | |
| return ( | |
| <ReactGridLayout onLayoutChange={this.onLayoutChange} {...this.props}> | |
| {this.generateDOM()} | |
| </ReactGridLayout> | |
| ); | |
| } | |
| } | |
| if (process.env.STATIC_EXAMPLES === true) { | |
| import("../test-hook.jsx").then(fn => fn.default(GridPropertyLayout)); | |
| } | |