Patterns

Sheet

The sheet is an optional add-on from @ogdakke/fluidbox/sheet. It is a panel the viewer slides up from the bottom, with snap points, for details, comments or a form.

Loading the live example…

sheet.tsx
import { itemLabel, type FluidboxItem } from "@ogdakke/fluidbox";
import { Fluidbox, useFluidboxSheet } from "@ogdakke/fluidbox/react";
import "@ogdakke/fluidbox/sheet.css";
import { photos } from "./data";

function Details({ item }: { item: FluidboxItem }) {
  const sheet = useFluidboxSheet();
  return (
    <>
      <h3>{itemLabel(item)}</h3>
      <p>
        Stop <output>{sheet.stop}</output>
      </p>
      <button type="button" onClick={() => sheet.set(2)}>
        Expand
      </button>
      <input placeholder="Add a note" aria-label="Note" />
    </>
  );
}

export function Sheet() {
  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>
      {/* Stop 0 rests below the photo; stops 1 and 2 raise it to 40% and 90% of the screen. */}
      <Fluidbox.Sheet snapPoints={["40%", "90%"]} className="pattern-sheet">
        {({ item }) => <Details item={item} />}
      </Fluidbox.Sheet>
      <Fluidbox.Viewer>
        <Fluidbox.SheetStop stop={1} className="pattern-sheet-toggle">
          Details
        </Fluidbox.SheetStop>
        <Fluidbox.Controls />
      </Fluidbox.Viewer>
    </Fluidbox.Root>
  );
}
  • snapPoints: ["40%", "90%"] adds stops above the resting stop 0. Set it in the sheet option in plain JavaScript, as the Sheet part's prop, or as snap-points="40% 90%" on <fluidbox-sheet>.
  • fluidbox.sheet.set(stop) moves the sheet, and a sheetchange event reports each new stop. In the frameworks, useFluidboxSheet() returns { stop, set } and the root takes onSheetChange, @sheetchange or (sheetChange). On custom elements, gallery.sheet is the same handle and the gallery fires sheetchange.
  • Any button with data-fluidbox-sheet-stop="N" in the viewer moves the sheet to stop N, and lowers it again when the sheet is already there. The framework SheetStop part renders one.
  • Keys typed in the sheet's fields stay there, so arrow keys don't change the slide.
  • import "@ogdakke/fluidbox/sheet" once to turn the add-on on (the custom elements load it themselves), and import @ogdakke/fluidbox/sheet.css with it.