Skip to content

Commit

Permalink
incorporate react grid layout
Browse files Browse the repository at this point in the history
  • Loading branch information
5e-Cleric committed Feb 21, 2024
1 parent e6d4a52 commit 1eb48b4
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 56 deletions.
84 changes: 84 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.2.0",
"react-grid-layout": "^1.4.4",
"react-router-dom": "^6.22.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
Expand Down
12 changes: 3 additions & 9 deletions src/components/draggables/labelInput.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import React from 'react';
import { useDrag } from 'react-dnd';

const DraggableItem = ({ name }) => {
const [{ isDragging }, drag] = useDrag({
item: { name },
type: 'draggable',
collect: (monitor) => ({
isDragging: !!monitor.isDragging(),
}),
});
const LabelInput = () => {

return (
<div
className='item'
Expand All @@ -24,4 +18,4 @@ const DraggableItem = ({ name }) => {
)
};

export default DraggableItem;
export default LabelInput;
40 changes: 16 additions & 24 deletions src/components/dropDiv.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import React from 'react';
import { useDrop } from "react-dnd";
import GridLayout from "react-grid-layout";

const DropDiv = ({type, items}) => {
const [{ isOver }, drop] = useDrop(() => ({
accept: type,
collect: (monitor) => ({
isOver: !!monitor.isOver(),
}),
}));
console.log(items);
if (items.length === 0) {
<div
ref={drop}
className={`drop-div ${isOver ? "drop-over" : ""}`}
>
</div>
}

const DropDiv = () => {
const layout = [
{ i: 'a', x: 0, y: 0, w: 2, h: 2 },
{ i: 'b', x: 2, y: 0, w: 2, h: 2 },
{ i: 'c', x: 4, y: 0, w: 2, h: 2 }
];

return (
<div
ref={drop}
className={`drop-div ${isOver ? "drop-over" : ""}`}
>
{items.map((item) => {
return <div className="item" key={item.id}>{item.content}</div>
})}
</div>
<div>
<GridLayout className="layout" layout={layout} cols={6} rowHeight={100} width={1200}>
<div key="a">A</div>
<div key="b">B</div>
<div key="c">C</div>
</GridLayout>
</div>
);
};

Expand Down
29 changes: 7 additions & 22 deletions src/components/sheets.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import '../styles/main.css'; // Import CSS/LESS file directly
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

import DropDiv from './dropDiv.jsx';
import DraggableItem from './draggables/labelInput.jsx';
import '../../node_modules/react-grid-layout/css/styles.css';
import '../../node_modules/react-resizable/css/styles.css';
import '../styles/sheet.css';
import DropDiv from './dropDiv';


const Sheets = () => {
let items = [];

function handleDrop(item) {
const id = items.length+1;
const draggable = {id:id , content: item};

items.push(draggable);
}


return (
<div className="Sheets page">
<nav className="nav">
Expand All @@ -29,19 +18,15 @@ const Sheets = () => {
<aside className='sidebar'>
<h2>Pick your draggable component</h2>
<div className="picker">
<DndProvider backend={HTML5Backend}>
<DraggableItem name="Item1" />
</DndProvider>

</div>
</aside>
<section id="create">
<h1>Create your own</h1>
<div className="drop">
<DndProvider backend={HTML5Backend}>
<DropDiv type="item" onDrop={handleDrop(<DraggableItem/>)} items={items}/>
</DndProvider>
<DropDiv></DropDiv>
</div>
<button>Export as pdf {items.length}</button>
<button>Export as pdf</button>

</section>
</main>
Expand Down
7 changes: 6 additions & 1 deletion src/styles/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
body {
background: #413939;
color:white;
}

.page {
padding-block: 100px;
width: clamp(600px, 33%, 900px);
Expand Down Expand Up @@ -33,7 +38,7 @@
padding-left: 20px;

.picker {
background: #eee;
background: #3b3b3b;
border:1px solid #ccc;
border-radius: 10px;
padding: 10px;
Expand Down
9 changes: 9 additions & 0 deletions src/styles/sheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.drop {

.react-grid-item {
display:grid;
place-items:center;
background: #ff7f503d;
border: 1px solid red;
}
}

0 comments on commit 1eb48b4

Please sign in to comment.