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";// 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>
);
}// 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
| Prop | Type | Default | Description |
|---|---|---|---|
value / defaultValue / onChange | CoverValue | null | — | { type: 'pattern', pattern, tone } or { type: 'image', src, alt?, position? }. null: none. |
patterns | StructureCoverPattern[] | all nine | ember, dusk, hatch, grid, checker, steps, noise, waves, bricks. |
tones | ("accent" | "ink" | "muted")[] | all three | Drawn from --accent, --ink and --line-strong, on --bg-raised. |
upload / onUpload | boolean; (file) => string | Promise<string> | true | The upload tab (FileInput). onUpload stores the file and gives back the address; without it a blob: address of the page is kept. |
link | boolean | true | The tab to paste a picture address. Only https, paths, blob and data images are accepted. |
uploadOptions | { accept?, maxSize? } | images, 5 MB | Limits of the upload. |
className | string | — | Extra classes. |