import { BOOK_PATTERNS, type BookPattern, type BookPatternPaint } from '@trek/shared'; import { useMemo } from 'react'; import { PATTERN_ANGLE } from './paintEdit'; import { patternGeometry } from './patterns'; /** * The twelve repeats, each drawn as a tile in the paint's own colours. * * Drawn by the same generator the page uses, at a smaller scale, so a tile * is a true preview of what choosing it does rather than an icon of it, and * a repeat that looks wrong in the tile looks wrong on the page too. */ const TILE = 24; function PatternTile({ pattern, fg, bg }: { pattern: BookPattern; fg: string; bg: string | null }) { const geo = useMemo( () => patternGeometry({ pattern, scale: 0.42, angle: PATTERN_ANGLE[pattern] ?? 0 }, { x: 0, y: 0, w: TILE, h: TILE }), [pattern] ); return ( {bg && } {geo.layers.map((layer, i) => ( ))} ); } export function PatternSwatches({ value, onPick, label, }: { value: BookPatternPaint; onPick: (pattern: BookPattern) => void; label: (pattern: BookPattern) => string; }) { return (
{BOOK_PATTERNS.map((pattern) => ( ))}
); }