import React from 'react'; import v4 from 'uuid/v4'; import _ from 'lodash'; import { faker } from '@faker-js/faker/locale/fr'; import { Container, FloatGrid as Grid, Button, Card, CardHeader, CardBody, UncontrolledDropdown, DropdownMenu, DropdownToggle, DropdownItem } from './../../../components'; import { applyColumn } from './../../../components/FloatGrid'; import { HeaderMain } from './../../components/HeaderMain'; export class DragAndDropLayout extends React.Component { constructor(props) { super(props); this._lastLayout = this._generateLayout(); this.state = { layouts: this._lastLayout, compactType: 'vertical', fluid: false, texts: this._generateTexts(this._lastLayout) } this.generateLayoutHandler = this.generateLayoutHandler.bind(this); this.resetLayoutHandler = this.resetLayoutHandler.bind(this); } generateLayoutHandler() { this._lastLayout = this._generateLayout(); this.setState({ layouts: this._lastLayout, texts: this._generateTexts(this._lastLayout) }); } resetLayoutHandler() { this.setState({ layouts: this._lastLayout }); } selectCompactType(compactType) { this.setState({ compactType }); } selectFluid(fluid) { this.setState({ fluid }); } render() { const { compactType, fluid, texts } = this.state; return (

React-Grid Layout is a grid layout system much like Packery or Gridster for React. Unlike those systems, it is responsive and supports breakpoints. These breakpoints can be provided in the same way as in Reactstrap's Grid system.

Change Compaction Type:  { !compactType && "No Compactions" } { compactType === "vertical" && "Vertical" } { compactType === "horizontal" && "Horizontal" } this.selectCompactType(null)} > No Compactions this.selectCompactType("vertical")} > Vertical this.selectCompactType("horizontal")} > Horizontal Layout:  { !fluid && "Container" } { fluid && "Fluid" } this.selectFluid(false)} > Container this.selectFluid(true)} > Fluid
this.setState({ layouts }) } columnSizes={ this.state.layouts } rowHeight={ 55 } > { _.chain(this.state.layouts) .keys() .map((layoutKey) => ( { texts[layoutKey].title } { texts[layoutKey].desc } )) .value() }
); } _generateLayout = (rowsCount = 3) => { const TOTAL_ROWS = 12; const HEIGHT = 5; let output = {}; for (let i = 0; i < rowsCount; i++) { let availableRow = TOTAL_ROWS; while (availableRow > 0) { const newCol = availableRow < TOTAL_ROWS ? availableRow : _.random(3, 9); availableRow -= newCol; output = { ...output, [v4()]: { md: newCol, h: HEIGHT } } } } return output; } _generateTexts = (layouts) => _.mapValues(layouts, () => ({ title: faker.commerce.productName(), desc: faker.lorem.paragraph() })) }