8x8 pixel editor with palette, drag painting, and erase
A game studio wants a tiny in-browser editor for drawing 8×8 item icons (a sword, a potion, a coin). Build a pixel painter: a grid of square pixels, a color palette, a Draw/Erase tool switch, and a Clear button. Users paint by clicking a pixel, or by pressing the mouse button on a pixel and dragging across others.
The starter code includes the grid size and the palette:
const GRID_SIZE = 8;
const PALETTE = [
{ name: 'Black', hex: '#111827' },
{ name: 'Red', hex: '#ef4444' },
{ name: 'Yellow', hex: '#facc15' },
{ name: 'Green', hex: '#22c55e' },
{ name: 'Blue', hex: '#3b82f6' },
{ name: 'White', hex: '#ffffff' },
];
GRID_SIZE × GRID_SIZE canvas (64 pixels), row by row. Every pixel starts empty.<button> with an aria-label of the form Row R, column C: Color, where R and C start at 1 and Color is the palette name of its paint, or Empty. For example, Row 1, column 1: Empty or Row 3, column 5: Red. Fill painted pixels with the color’s hex.aria-pressed="true"; the others have aria-pressed="false". Black is selected by default.aria-pressed. Draw is active by default.
Start: all 64 pixels "Empty", Black and Draw pressed
Click Row 1, column 1: Row 1, column 1: Black
Click Red, then Row 1, column 2:
Row 1, column 2: Red (Red pressed, Black not pressed)
Press on Row 2, column 1, drag through Row 2, column 2 and Row 2, column 3, release.
Row 2, columns 1–3 are painted.
Then move over Row 4, column 4 with the button up.
Row 4, column 4 stays Empty.
Click Erase, then click a Black pixel: it becomes Empty (Erase pressed, Draw not pressed)
Click Green: Draw is pressed again, clicks paint Green
The tests click your buttons, press and drag over pixels, and read labels like a user (or a screen reader) would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
aria-label reads Row R, column C: Color, in row order, and the Color part is correct after every action.aria-pressed.pointerdown/mousedown, pointerup/mouseup, click). A drag is a press on one pixel, then moves to the next pixels with the button held, then pointerup/mouseup. Each move fires what a browser fires: pointerout/pointerleave on the previous pixel and pointerover/pointerenter on the next, then the same mouse* events. Pointer or mouse handlers, enter or over, all work.Capitalization and extra spacing don’t matter.