Blocks / Cover picker

Cover picker

A page's banner: generated pixel patterns, an uploaded or linked picture, its position, removal.

import { CoverPicker, CoverArt, STRUCTURE_COVER_PATTERNS } from "@forgeron/ui";
/01 → Default
// Patterns are drawn from the tokens in a few tones; a picture is uploaded or linked, then dragged
// (or moved with the arrows) to choose which part shows.
import { CoverArt, CoverPicker, type CoverValue } from "@forgeron/ui";
import { useState } from "react";

export default function Default() {
  const [cover, setCover] = useState<CoverValue | null>({
    type: "pattern",
    pattern: "ember",
    tone: "accent",
  });
  return (
    <div style={{ display: "grid", gap: 16, width: "100%", maxWidth: 440 }}>
      <CoverPicker value={cover} onChange={setCover} />
      {cover ? <CoverArt value={cover} height={72} /> : null}
    </div>
  );
}
/02 → In a popover
// The usual place for it: a popover opened from the page's banner.
import { Button, CoverArt, CoverPicker, Popover, type CoverValue } from "@forgeron/ui";
import { useState } from "react";

export default function InAPopover() {
  const [cover, setCover] = useState<CoverValue | null>({
    type: "pattern",
    pattern: "dusk",
    tone: "ink",
  });
  return (
    <div style={{ width: "100%" }}>
      <div style={{ position: "relative" }}>
        {cover ? (
          <CoverArt value={cover} height={120} />
        ) : (
          <div style={{ height: 120, border: "1px dashed var(--line-strong)" }} />
        )}
        <div style={{ position: "absolute", right: 8, bottom: 8 }}>
          <Popover
            label="Change cover"
            align="end"
            width={380}
            trigger={<Button size="sm">Change cover</Button>}
          >
            <CoverPicker value={cover} onChange={setCover} />
          </Popover>
        </div>
      </div>
    </div>
  );
}
API → Props
PropTypeDefaultDescription
value / defaultValue / onChangeCoverValue | null—{ type: 'pattern', pattern, tone } or { type: 'image', src, alt?, position? }. null: none.
patternsStructureCoverPattern[]all nineember, dusk, hatch, grid, checker, steps, noise, waves, bricks.
tones("accent" | "ink" | "muted")[]all threeDrawn from --accent, --ink and --line-strong, on --bg-raised.
upload / onUploadboolean; (file) => string | Promise<string>trueThe upload tab (FileInput). onUpload stores the file and gives back the address; without it a blob: address of the page is kept.
linkbooleantrueThe tab to paste a picture address. Only https, paths, blob and data images are accepted.
uploadOptions{ accept?, maxSize? }images, 5 MBLimits of the upload.
classNamestring—Extra classes.