layout-builder / index.html
hrmkmdtv's picture
create for me a app where i can create on a mockup desktop dimension or mock phone screen dimension grid layout builder. Allow for the adding major colums into the grid 1 or more, then allow for row sectons to be added to each column desired by an add row button. the rows added in one column should not effect the other columns, also make all row lines and major column lines dragable and resizeable. ultimately allowing you to create ui layouts - Initial Deployment
01236e0 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grid Layout Builder</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js"></script>
<style>
.grid-container {
touch-action: none;
position: relative;
}
.column {
position: relative;
min-width: 50px;
min-height: 100%;
}
.column-resize-handle {
position: absolute;
top: 0;
right: -5px;
width: 10px;
height: 100%;
cursor: col-resize;
background-color: rgba(59, 130, 246, 0.3);
z-index: 10;
}
.row-resize-handle {
position: absolute;
left: 0;
bottom: -5px;
width: 100%;
height: 10px;
cursor: row-resize;
background-color: rgba(59, 130, 246, 0.3);
z-index: 10;
}
.row {
position: relative;
min-height: 30px;
background-color: rgba(249, 250, 251, 0.8);
border: 1px dashed #d1d5db;
}
.device-frame {
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
background-color: white;
overflow: hidden;
}
.desktop-frame {
width: 1200px;
height: 800px;
border-radius: 12px;
}
.mobile-frame {
width: 375px;
height: 667px;
border-radius: 40px;
border: 12px solid #1f2937;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto p-6">
<header class="mb-8 text-center">
<h1 class="text-3xl font-bold text-gray-800 mb-2">Grid Layout Builder</h1>
<p class="text-gray-600">Create responsive UI layouts with drag-and-drop columns and rows</p>
</header>
<div class="bg-white rounded-xl shadow-lg p-6 mb-6">
<div class="flex flex-wrap gap-4 justify-center mb-6">
<button id="desktop-mode" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors flex items-center gap-2">
<i data-feather="monitor"></i> Desktop Mode
</button>
<button id="mobile-mode" class="px-4 py-2 bg-purple-500 text-white rounded-lg hover:bg-purple-600 transition-colors flex items-center gap-2">
<i data-feather="smartphone"></i> Mobile Mode
</button>
<button id="add-column" class="px-4 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600 transition-colors flex items-center gap-2">
<i data-feather="plus"></i> Add Column
</button>
<button id="reset-grid" class="px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-2">
<i data-feather="trash-2"></i> Reset Grid
</button>
</div>
<div id="device-container" class="flex justify-center">
<div id="desktop-frame" class="device-frame desktop-frame">
<div id="grid-container" class="grid-container w-full h-full flex"></div>
</div>
</div>
</div>
<div class="bg-white rounded-xl shadow-lg p-6">
<h2 class="text-xl font-semibold mb-4">Instructions</h2>
<ul class="list-disc list-inside space-y-2 text-gray-700">
<li>Select Desktop or Mobile mode to change the canvas size</li>
<li>Click "Add Column" to create new layout columns</li>
<li>Click the "+" button on any column to add rows</li>
<li>Drag column edges to resize columns</li>
<li>Drag row edges to resize rows</li>
<li>Create your perfect UI layout structure</li>
</ul>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
AOS.init();
const gridContainer = document.getElementById('grid-container');
const desktopModeBtn = document.getElementById('desktop-mode');
const mobileModeBtn = document.getElementById('mobile-mode');
const addColumnBtn = document.getElementById('add-column');
const resetGridBtn = document.getElementById('reset-grid');
const deviceContainer = document.getElementById('device-container');
const desktopFrame = document.getElementById('desktop-frame');
let currentDeviceMode = 'desktop';
let columnCount = 0;
// Set up device mode switching
desktopModeBtn.addEventListener('click', () => switchDeviceMode('desktop'));
mobileModeBtn.addEventListener('click', () => switchDeviceMode('mobile'));
function switchDeviceMode(mode) {
currentDeviceMode = mode;
deviceContainer.innerHTML = '';
if (mode === 'desktop') {
const frame = desktopFrame.cloneNode(true);
deviceContainer.appendChild(frame);
gridContainer = frame.querySelector('#grid-container');
} else {
const mobileFrame = document.createElement('div');
mobileFrame.className = 'device-frame mobile-frame';
mobileFrame.innerHTML = '<div id="grid-container" class="grid-container w-full h-full flex"></div>';
deviceContainer.appendChild(mobileFrame);
gridContainer = mobileFrame.querySelector('#grid-container');
}
// Reinitialize interact.js for the new container
initInteract();
}
// Add column functionality
addColumnBtn.addEventListener('click', addColumn);
function addColumn() {
columnCount++;
const column = document.createElement('div');
column.className = 'column bg-gray-50 border border-gray-200 relative';
column.id = `column-${columnCount}`;
// Add column resize handle
const resizeHandle = document.createElement('div');
resizeHandle.className = 'column-resize-handle';
column.appendChild(resizeHandle);
// Add row container
const rowContainer = document.createElement('div');
rowContainer.className = 'row-container h-full';
column.appendChild(rowContainer);
// Add add row button
const addRowBtn = document.createElement('button');
addRowBtn.className = 'absolute top-2 right-2 p-1 bg-blue-500 text-white rounded-full hover:bg-blue-600 transition-colors z-20';
addRowBtn.innerHTML = '<i data-feather="plus" width="16" height="16"></i>';
addRowBtn.addEventListener('click', () => addRow(column.id));
column.appendChild(addRowBtn);
gridContainer.appendChild(column);
feather.replace();
// Make column resizable
initColumnResize(column);
}
function addRow(columnId) {
const column = document.getElementById(columnId);
const rowContainer = column.querySelector('.row-container');
const row = document.createElement('div');
row.className = 'row mb-2 rounded';
// Add row resize handle
const resizeHandle = document.createElement('div');
resizeHandle.className = 'row-resize-handle';
row.appendChild(resizeHandle);
rowContainer.appendChild(row);
// Make row resizable
initRowResize(row);
}
// Reset grid functionality
resetGridBtn.addEventListener('click', () => {
gridContainer.innerHTML = '';
columnCount = 0;
});
// Initialize interact.js for resizing
function initInteract() {
document.querySelectorAll('.column').forEach(initColumnResize);
document.querySelectorAll('.row').forEach(initRowResize);
}
function initColumnResize(column) {
interact(column).resizable({
edges: { right: true },
listeners: {
move: function (event) {
let target = event.target;
let x = (parseFloat(target.getAttribute('data-x')) || 0);
// Update the element's style
target.style.width = event.rect.width + 'px';
// Translate when resizing from top or left edges
x += event.deltaRect.left;
target.style.transform = 'translate(' + x + 'px)';
target.setAttribute('data-x', x);
}
},
modifiers: [
interact.modifiers.restrictEdges({
outer: 'parent'
}),
interact.modifiers.restrictSize({
min: { width: 50 }
})
],
inertia: true
});
}
function initRowResize(row) {
interact(row).resizable({
edges: { bottom: true },
listeners: {
move: function (event) {
let target = event.target;
let y = (parseFloat(target.getAttribute('data-y')) || 0);
// Update the element's style
target.style.height = event.rect.height + 'px';
// Translate when resizing from top or left edges
y += event.deltaRect.top;
target.style.transform = 'translate(' + y + 'px)';
target.setAttribute('data-y', y);
}
},
modifiers: [
interact.modifiers.restrictEdges({
outer: 'parent'
}),
interact.modifiers.restrictSize({
min: { height: 30 }
})
],
inertia: true
});
}
// Initialize with one column
addColumn();
});
</script>
</body>
</html>