Patterns

Gallery

One viewer for a set of items, and a trigger for each. A trigger can be any element, usually a button holding the thumbnail. When the viewer closes, it flies back to the trigger of the item it shows and focus returns there.

Loading the live example…

basic.tsx
import { itemLabel } from "@ogdakke/fluidbox";
import { Fluidbox } from "@ogdakke/fluidbox/react";
import { photos } from "./data";

export function Basic() {
  return (
    <Fluidbox.Root items={photos}>
      <div className="pattern-grid">
        {photos.map((photo) => (
          <Fluidbox.Trigger
            key={photo.src}
            item={photo}
            className="pattern-thumb"
          >
            <img src={photo.src} alt={itemLabel(photo)} />
          </Fluidbox.Trigger>
        ))}
      </div>
      {/* Without a Viewer, the viewer has these same three buttons. */}
      <Fluidbox.Viewer>
        <Fluidbox.Previous />
        <Fluidbox.Next />
        <Fluidbox.Close />
      </Fluidbox.Viewer>
    </Fluidbox.Root>
  );
}
  • The viewer has Previous, Next and Close buttons until you give it content of your own. Then the framework Controls part, <fluidbox-controls> or the controls option keeps them.
  • In plain JavaScript, fluidbox.bind(button, index) makes each button a trigger, and fluidbox.destroy() unbinds them all.
  • The trigger's image is where the flight starts and ends. Mark another element with data-fluidbox-origin to fly from it instead (see Rich origins).