Spaces:
Running
Running
Update index.html
Browse files- index.html +204 -198
index.html
CHANGED
|
@@ -1,204 +1,210 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
<
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
}, []);
|
| 47 |
-
|
| 48 |
-
const handleDragOut = useCallback((e) => {
|
| 49 |
-
e.preventDefault();
|
| 50 |
-
e.stopPropagation();
|
| 51 |
-
setIsDragging(false);
|
| 52 |
-
}, []);
|
| 53 |
-
|
| 54 |
-
const handleDrop = useCallback((e) => {
|
| 55 |
-
e.preventDefault();
|
| 56 |
-
e.stopPropagation();
|
| 57 |
-
setIsDragging(false);
|
| 58 |
-
|
| 59 |
-
const files = Array.from(e.dataTransfer.files);
|
| 60 |
-
const imageFiles = files.filter(file => file.type.startsWith('image/'));
|
| 61 |
-
|
| 62 |
-
if (imageFiles.length === 0) {
|
| 63 |
-
toast.error('Please drop image files only');
|
| 64 |
-
return;
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
onFilesAdded(imageFiles);
|
| 68 |
-
}, [onFilesAdded]);
|
| 69 |
-
|
| 70 |
-
const handleFileInput = useCallback((e) => {
|
| 71 |
-
const files = Array.from(e.target.files || []);
|
| 72 |
-
const imageFiles = files.filter(file => file.type.startsWith('image/'));
|
| 73 |
-
|
| 74 |
-
if (imageFiles.length === 0) {
|
| 75 |
-
toast.error('Please select image files only');
|
| 76 |
-
return;
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
onFilesAdded(imageFiles);
|
| 80 |
-
e.target.value = '';
|
| 81 |
-
}, [onFilesAdded]);
|
| 82 |
-
|
| 83 |
-
const handleClick = () => {
|
| 84 |
-
fileInputRef.current?.click();
|
| 85 |
-
};
|
| 86 |
-
|
| 87 |
-
return (
|
| 88 |
-
<div
|
| 89 |
-
className={`relative min-h-[200px] rounded-xl border-2 border-dashed transition-all duration-300 ease-in-out cursor-pointer ${
|
| 90 |
-
isDragging
|
| 91 |
-
? 'border-primary bg-primary/5'
|
| 92 |
-
: 'border-gray-200 hover:border-primary/50'
|
| 93 |
-
}`}
|
| 94 |
-
onDragEnter={handleDragIn}
|
| 95 |
-
onDragLeave={handleDragOut}
|
| 96 |
-
onDragOver={handleDrag}
|
| 97 |
-
onDrop={handleDrop}
|
| 98 |
-
onClick={handleClick}
|
| 99 |
-
>
|
| 100 |
-
<input
|
| 101 |
-
ref={fileInputRef}
|
| 102 |
-
type="file"
|
| 103 |
-
className="hidden"
|
| 104 |
-
multiple
|
| 105 |
-
accept="image/*"
|
| 106 |
-
onChange={handleFileInput}
|
| 107 |
-
/>
|
| 108 |
-
<div className="absolute inset-0 flex flex-col items-center justify-center space-y-4 p-6 text-center">
|
| 109 |
-
<div className="rounded-full bg-primary/10 p-4">
|
| 110 |
-
<Upload className="h-6 w-6 text-primary" />
|
| 111 |
-
</div>
|
| 112 |
-
<div>
|
| 113 |
-
<p className="text-lg font-medium text-gray-900">
|
| 114 |
-
Drag & Drop images here
|
| 115 |
-
</p>
|
| 116 |
-
<p className="mt-1 text-sm text-gray-500">or click anywhere to upload</p>
|
| 117 |
-
</div>
|
| 118 |
-
</div>
|
| 119 |
</div>
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
default: 4,
|
| 126 |
-
1100: 3,
|
| 127 |
-
700: 2,
|
| 128 |
-
500: 1,
|
| 129 |
-
};
|
| 130 |
-
|
| 131 |
-
return (
|
| 132 |
-
<Masonry
|
| 133 |
-
breakpointCols={breakpointColumns}
|
| 134 |
-
className="flex w-full gap-4"
|
| 135 |
-
columnClassName="space-y-4"
|
| 136 |
-
>
|
| 137 |
-
{images.map((image, index) => (
|
| 138 |
-
<div
|
| 139 |
-
key={index}
|
| 140 |
-
className="relative overflow-hidden rounded-lg bg-gray-100 shadow-sm transition-all duration-300 hover:shadow-md"
|
| 141 |
-
>
|
| 142 |
-
<img
|
| 143 |
-
src={image}
|
| 144 |
-
alt={`Gallery image ${index + 1}`}
|
| 145 |
-
className="h-auto w-full object-cover"
|
| 146 |
-
loading="lazy"
|
| 147 |
-
/>
|
| 148 |
-
</div>
|
| 149 |
-
))}
|
| 150 |
-
</Masonry>
|
| 151 |
-
);
|
| 152 |
-
};
|
| 153 |
-
|
| 154 |
-
const App = () => {
|
| 155 |
-
const [images, setImages] = useState([]);
|
| 156 |
-
|
| 157 |
-
const handleFilesAdded = useCallback((files) => {
|
| 158 |
-
const newImages = files.map(file => URL.createObjectURL(file));
|
| 159 |
-
setImages(prev => [...prev, ...newImages]);
|
| 160 |
-
toast.success(`${files.length} image${files.length === 1 ? '' : 's'} uploaded`);
|
| 161 |
-
}, []);
|
| 162 |
-
|
| 163 |
-
return (
|
| 164 |
-
<div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
|
| 165 |
-
<div className="space-y-8">
|
| 166 |
-
<div>
|
| 167 |
-
<h1 className="text-4xl font-bold tracking-tight text-gray-900">
|
| 168 |
-
Image Gallery
|
| 169 |
-
</h1>
|
| 170 |
-
<p className="mt-2 text-lg text-gray-600">
|
| 171 |
-
Upload your images by dragging and dropping them below
|
| 172 |
-
</p>
|
| 173 |
-
</div>
|
| 174 |
-
|
| 175 |
-
<DragDropZone onFilesAdded={handleFilesAdded} />
|
| 176 |
-
|
| 177 |
-
<div className="space-y-4">
|
| 178 |
-
<h2 className="text-2xl font-semibold text-gray-900">
|
| 179 |
-
Your Images
|
| 180 |
-
</h2>
|
| 181 |
-
{images.length > 0 ? (
|
| 182 |
-
<ImageGallery images={images} />
|
| 183 |
-
) : (
|
| 184 |
-
<p className="text-center text-gray-500 py-12">
|
| 185 |
-
No images uploaded yet. Start by dropping some images above!
|
| 186 |
-
</p>
|
| 187 |
-
)}
|
| 188 |
-
</div>
|
| 189 |
-
</div>
|
| 190 |
</div>
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Image Gallery</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<style>
|
| 9 |
+
.masonry-grid {
|
| 10 |
+
display: flex;
|
| 11 |
+
gap: 1rem;
|
| 12 |
+
width: 100%;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.masonry-column {
|
| 16 |
+
display: flex;
|
| 17 |
+
flex-direction: column;
|
| 18 |
+
gap: 1rem;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.toast {
|
| 22 |
+
position: fixed;
|
| 23 |
+
bottom: 1rem;
|
| 24 |
+
right: 1rem;
|
| 25 |
+
padding: 1rem;
|
| 26 |
+
border-radius: 0.5rem;
|
| 27 |
+
color: white;
|
| 28 |
+
animation: slideIn 0.3s ease-out;
|
| 29 |
+
z-index: 50;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.toast-success {
|
| 33 |
+
background-color: rgb(34, 197, 94);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.toast-error {
|
| 37 |
+
background-color: rgb(239, 68, 68);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
@keyframes slideIn {
|
| 41 |
+
from {
|
| 42 |
+
transform: translateX(100%);
|
| 43 |
+
opacity: 0;
|
| 44 |
}
|
| 45 |
+
to {
|
| 46 |
+
transform: translateX(0);
|
| 47 |
+
opacity: 1;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
</style>
|
| 51 |
+
</head>
|
| 52 |
+
<body>
|
| 53 |
+
<div class="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
|
| 54 |
+
<div class="space-y-8">
|
| 55 |
+
<div>
|
| 56 |
+
<h1 class="text-4xl font-bold tracking-tight text-gray-900">
|
| 57 |
+
Image Gallery
|
| 58 |
+
</h1>
|
| 59 |
+
<p class="mt-2 text-lg text-gray-600">
|
| 60 |
+
Upload your images by dragging and dropping them below
|
| 61 |
+
</p>
|
| 62 |
+
</div>
|
| 63 |
+
|
| 64 |
+
<div id="dropZone" class="relative min-h-[200px] rounded-xl border-2 border-dashed border-gray-200 hover:border-purple-500/50 transition-all duration-300 ease-in-out cursor-pointer">
|
| 65 |
+
<input type="file" id="fileInput" class="hidden" multiple accept="image/*"/>
|
| 66 |
+
<div class="absolute inset-0 flex flex-col items-center justify-center space-y-4 p-6 text-center">
|
| 67 |
+
<div class="rounded-full bg-purple-500/10 p-4">
|
| 68 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="rgb(147, 51, 234)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
| 69 |
+
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
| 70 |
+
<polyline points="17 8 12 3 7 8"></polyline>
|
| 71 |
+
<line x1="12" y1="3" x2="12" y2="15"></line>
|
| 72 |
+
</svg>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
</div>
|
| 74 |
+
<div>
|
| 75 |
+
<p class="text-lg font-medium text-gray-900">
|
| 76 |
+
Drag & Drop images here
|
| 77 |
+
</p>
|
| 78 |
+
<p class="mt-1 text-sm text-gray-500">or click anywhere to upload</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
</div>
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
<div class="space-y-4">
|
| 84 |
+
<h2 class="text-2xl font-semibold text-gray-900">
|
| 85 |
+
Your Images
|
| 86 |
+
</h2>
|
| 87 |
+
<div id="gallery" class="masonry-grid">
|
| 88 |
+
<!-- Images will be dynamically added here -->
|
| 89 |
+
</div>
|
| 90 |
+
<p id="noImages" class="text-center text-gray-500 py-12">
|
| 91 |
+
No images uploaded yet. Start by dropping some images above!
|
| 92 |
+
</p>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
<script>
|
| 98 |
+
// Initialize variables
|
| 99 |
+
const dropZone = document.getElementById('dropZone');
|
| 100 |
+
const fileInput = document.getElementById('fileInput');
|
| 101 |
+
const gallery = document.getElementById('gallery');
|
| 102 |
+
const noImages = document.getElementById('noImages');
|
| 103 |
+
let images = [];
|
| 104 |
+
|
| 105 |
+
// Toast notification function
|
| 106 |
+
function showToast(message, type = 'success') {
|
| 107 |
+
const toast = document.createElement('div');
|
| 108 |
+
toast.className = `toast toast-${type}`;
|
| 109 |
+
toast.textContent = message;
|
| 110 |
+
document.body.appendChild(toast);
|
| 111 |
+
|
| 112 |
+
setTimeout(() => {
|
| 113 |
+
toast.remove();
|
| 114 |
+
}, 3000);
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
// Setup masonry layout
|
| 118 |
+
function setupMasonryGrid() {
|
| 119 |
+
const columns = window.innerWidth >= 1100 ? 4 :
|
| 120 |
+
window.innerWidth >= 700 ? 3 :
|
| 121 |
+
window.innerWidth >= 500 ? 2 : 1;
|
| 122 |
+
|
| 123 |
+
gallery.innerHTML = '';
|
| 124 |
+
|
| 125 |
+
// Create columns
|
| 126 |
+
const columnDivs = Array.from({ length: columns }, () => {
|
| 127 |
+
const div = document.createElement('div');
|
| 128 |
+
div.className = 'masonry-column';
|
| 129 |
+
return div;
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
// Distribute images among columns
|
| 133 |
+
images.forEach((image, index) => {
|
| 134 |
+
const column = index % columns;
|
| 135 |
+
const imgContainer = document.createElement('div');
|
| 136 |
+
imgContainer.className = 'relative overflow-hidden rounded-lg bg-gray-100 shadow-sm transition-all duration-300 hover:shadow-md';
|
| 137 |
+
|
| 138 |
+
const img = document.createElement('img');
|
| 139 |
+
img.src = image;
|
| 140 |
+
img.alt = `Gallery image ${index + 1}`;
|
| 141 |
+
img.className = 'h-auto w-full object-cover';
|
| 142 |
+
img.loading = 'lazy';
|
| 143 |
+
|
| 144 |
+
imgContainer.appendChild(img);
|
| 145 |
+
columnDivs[column].appendChild(imgContainer);
|
| 146 |
+
});
|
| 147 |
+
|
| 148 |
+
// Add columns to gallery
|
| 149 |
+
columnDivs.forEach(column => gallery.appendChild(column));
|
| 150 |
+
|
| 151 |
+
// Toggle no images message
|
| 152 |
+
noImages.style.display = images.length > 0 ? 'none' : 'block';
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// Handle file addition
|
| 156 |
+
function handleFiles(files) {
|
| 157 |
+
const imageFiles = Array.from(files).filter(file => file.type.startsWith('image/'));
|
| 158 |
+
|
| 159 |
+
if (imageFiles.length === 0) {
|
| 160 |
+
showToast('Please select image files only', 'error');
|
| 161 |
+
return;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
const newImages = imageFiles.map(file => URL.createObjectURL(file));
|
| 165 |
+
images = [...images, ...newImages];
|
| 166 |
+
setupMasonryGrid();
|
| 167 |
+
showToast(`${imageFiles.length} image${imageFiles.length === 1 ? '' : 's'} uploaded`);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// Event Listeners
|
| 171 |
+
dropZone.addEventListener('dragenter', (e) => {
|
| 172 |
+
e.preventDefault();
|
| 173 |
+
e.stopPropagation();
|
| 174 |
+
dropZone.classList.add('border-purple-500', 'bg-purple-500/5');
|
| 175 |
+
});
|
| 176 |
+
|
| 177 |
+
dropZone.addEventListener('dragleave', (e) => {
|
| 178 |
+
e.preventDefault();
|
| 179 |
+
e.stopPropagation();
|
| 180 |
+
dropZone.classList.remove('border-purple-500', 'bg-purple-500/5');
|
| 181 |
+
});
|
| 182 |
+
|
| 183 |
+
dropZone.addEventListener('dragover', (e) => {
|
| 184 |
+
e.preventDefault();
|
| 185 |
+
e.stopPropagation();
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
dropZone.addEventListener('drop', (e) => {
|
| 189 |
+
e.preventDefault();
|
| 190 |
+
e.stopPropagation();
|
| 191 |
+
dropZone.classList.remove('border-purple-500', 'bg-purple-500/5');
|
| 192 |
+
handleFiles(e.dataTransfer.files);
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
dropZone.addEventListener('click', () => {
|
| 196 |
+
fileInput.click();
|
| 197 |
+
});
|
| 198 |
+
|
| 199 |
+
fileInput.addEventListener('change', (e) => {
|
| 200 |
+
handleFiles(e.target.files);
|
| 201 |
+
e.target.value = '';
|
| 202 |
+
});
|
| 203 |
+
|
| 204 |
+
window.addEventListener('resize', setupMasonryGrid);
|
| 205 |
+
|
| 206 |
+
// Initial setup
|
| 207 |
+
setupMasonryGrid();
|
| 208 |
+
</script>
|
| 209 |
+
</body>
|
| 210 |
</html>
|