Components
Gallery

Image Gallery

Image gallary displays images in sequence.

ℹ️

Note: Use Tailwind CSS to view Gallary properly.

Import $render utilities

const { $render, stringify } = render;

Gallery component

Gallery.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=${stringify(images[0])} />
        <Pagination images=${stringify(images)}/>
      </div>
    `;
  }

Pagination component

Pagination.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, '${stringify(image)}')"
              class="h-auto max-w-full rounded-lg" 
              src="${image.src}"
            />
          </div>
        `})}
      </div>
    `;
  }

CurrentImage component

CurrentImage.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

$render(Gallery);
  • Playground