Image Gallery
Image gallary displays images in sequence.
INFO
Note: Use Tailwind CSS to view Gallary properly.
Import $render utilities
js
import { $render, stringify } from "@codingnninja/koras";
Gallery component
js
const Gallary = () => {
const images = [
{
src: "https://flowbite.s3.amazonaws.com/docs/gallery/square/image-1.jpg",
alt: "",
},
{
src: "https://flowbite.s3.amazonaws.com/docs/gallery/square/image-2.jpg",
alt: "",
},
{
src: "https://flowbite.s3.amazonaws.com/docs/gallery/square/image-3.jpg",
alt: "",
},
];
return `
<div
class="grid gap-4"
id="gallary">
<CurrentImage image=${images[0]} />
<Pagination images=${images}/>
</div>
`;
};
Pagination component
js
const Pagination = (images) => {
return `
<div
class="grid grid-cols-5 gap-4"
id="pagination">
${images.map((image, key) => {
return `
<div id="${key}">
<img
onClick="$render(CurrentImage, ${image})"
class="h-auto max-w-full rounded-lg"
src=${image.src}
/>
</div>
`;
})}
</div>
`;
};
CurrentImage component
js
const CurrentImage = ({ src, alt }) => {
return `
<div id="current-image">
<img class="h-auto max-w-full rounded-lg" src="${src}" alt="${alt}">
</div>
`;
};
Render Gallery
js
$render(Gallery);
- Playground