Skip to content
react-cards-opening

ScanGrid

ScanGrid is the grid a hunt happens on, and the scan that finds things in it. On its own it draws cells in five levels of a theme's ramp. Through its handle, seek hunts one cell down and hands back what a CardOpening needs to send a card out of it.

Nothing found yet

The grid alone. Press Scan to hunt a cell down.

Usage

tsx
import { ScanGrid, type ScanGridHandle } from "@react-cards-opening/ui";

const scan = useRef<ScanGridHandle>(null);
const [veiled, setVeiled] = useState(true);

<ScanGrid handle={scan} levels={levels} veiled={veiled} onUnveil={() => setVeiled(false)} />;

With CardOpening

seek returns { element, lead, release }, which is exactly what launch on CardOpening takes. The card waits for the scan, then lifts out of the cell.

tsx
<CardOpening
  opening={hunt.opening}
  launch={(card, show) => scan.current?.seek(cellOf(card), show) ?? null}
/>

Props

PropTypeWhat it does
levelsreadonly number[]One number per cell, 0 (unlit) to 4. Cells fill top to bottom, then left to right.
lead?numberEmpty slots before the first cell.
rows?numberCells in a column. 7 by default.
theme?CardThemeThe colours.
tone?stringThe colour of the lock and the crack: the hunted card's tier.
veiled?booleanBlank until the beam has passed.
onUnveil?() => voidThe beam finished its first pass. Stop veiling.
idle?booleanNothing is being hunted: the grid may twitch and sparkle.
markers?ReadonlyMap<number, ScanMarker>Found cells by index: { id, name, colour }.
onMarkerPress?(marker, element) => voidA found cell was pressed.
markersDisabled?booleanFound cells cannot be pressed for now.
markerLabel?(name: string) => stringWhat a screen reader calls a found cell.
handle?Ref<ScanGridHandle>Where seek, reset and cell are handed out.
className?stringAdded to the grid's root.
classNames?ScanGridClassNamesA class of your own for each part of the grid.
style?CSSPropertiesAdded to the grid's root.

The handle

MethodWhat it does
seek(cell, show, options?)Hunts the cell down and returns { element, lead, release }, or null when the grid has no such cell. options.onLock fires when the beam settles; options.flash is an element to flash on a loud find.
reset()Forgets which cells the beam has lit, so a veiled grid is blank again.
cell(index)The element of a cell.

Blank until scanned

A veiled grid shows every cell as unlit until the beam has crossed it. The first seek on a veiled grid sweeps the whole width, and onUnveil fires when it is done. While veiled and idle, a few cells shift by a pixel now and then: something is in there.

Other shapes

tsx
// A board: five rows, twelve columns.
<ScanGrid levels={board} rows={5} />

// A calendar whose first day is a Wednesday.
<ScanGrid levels={year} lead={3} />

Last updated . Read this page as Markdown.