import { Col, Input, Row, Space } from 'antd' import React, { useState } from 'react' import styled from 'styled-components' import { DndProvider, useDrop } from 'react-dnd' import { HTML5Backend } from 'react-dnd-html5-backend' import DraggableButton from './draggable-button' import { useImmer } from 'use-immer' export const ComponentBuildPage2: React.FC = () => { const [width, setWidth] = useState(1) const [height, setHeight] = useState(1) const [droppedList, setDroppedList] = useImmer([]) const [buttons, setButtons] = useImmer([ { label: "Widget", id: 1, width: 3, height: 1, }, { label: "Widget", id: 2, width: 2, height: 1, }, { label: "Widget", id: 3, width: 1, height: 1, }, { label: "Widget", id: 4, width: 1, height: 1, }, ]) const [{ isOver }, drop] = useDrop(() => ({ accept: "buton", drop: (droppedItem) => { dropImageToBoard(droppedItem) }, collect: (monitor) => ({ isOver: !!monitor.isOver(), }) })); let dropImageToBoard = (droppedItem) => { if (droppedItem?.id) { setButtons(buttons=>{ return buttons }) const newButton = buttons.find(b => b.id == droppedItem.id) setDroppedList((list) => [...list, newButton]) setButtons(btns => btns.filter(btn => btn.id !== droppedItem.id)) } } const createWidget = () => { setButtons(btns => [...btns, { label: "Widgett", id: generateUniqueId(), width, height, }]) } const generateUniqueId = () => { const combinedArray = [...buttons, ...droppedList]; let id = 1; while (combinedArray.some(obj => obj.id === id)) { id++; } return id; } return
{[...Array(8)].map((e, j) => {[...Array(24)].map((e, i) =>
{ droppedList[(((i + 1) + (j * 24)) - 1)] ? {`${droppedList[(((i + 1) + (j * 24)) - 1)].width} x ${droppedList[(((i + 1) + (j * 24)) - 1)].height}`} : {((i + 1) + (j * 24))} }
)}
)}
<Input.Group compact> <Input disabled width: '15%' }} value={"Width"} /> <Input => { setWidth(parseInt(e.target.value)) }} width: '15%' }} value={width} /> <Input disabled width: '15%' }} value={"Height"} /> <Input => { setHeight(parseInt(e.target.value)) }} width: '15%' }} value={height} /> </Input.Group>
{buttons.map((btn, i) => {`${btn.width} x ${btn.height}`})}
} const Wrapper = styled('div')` padding: 0 50px; font-family: 'Roboto'; .ant-col{ padding: 0 !important; } .cell{ width: 100%; height: 100%; min-height: 60px; background-color: aliceblue; border: 1px solid lightgrey; display: flex; align-items: center; justify-content: center; } .tools{ margin-top: 16px; display: flex; flex-flow: column; align-items: start; justify-content: start; gap: 16px; } `