Photo Picker
A grid of photo thumbnails, one chosen, with a staggered draw wave each time it opens.
Default
Each thumbnail is a button with aria-pressed; the chosen one wears a 2px ring and every image grows a little on hover. The thumbnails rise in a quick wave from the top left when the grid mounts and every time play changes. Here a counter replays it.
duskIn a Popover
The picker is only the grid, so it sits in whatever popover or panel you bring. Pass the open state to play so the wave replays on every open, and to load so no thumbnail is fetched before the first open. Once loaded, thumbnails stay loaded.
In Five Looks
The grid takes its colours and corners from the theme: the resting ring is the theme's border, the chosen ring its key colour (--interactive-primary-bg), and the thumbnails take the theme's corner shape. It draws no surface of its own, so over a photo it sits in a glass panel or popover (see Glass). Here it is in each look on the theme picked in the docs; the Photo looks turn glass on over a photo.
Honcho Backstage
Backstage's Photo menu grid from the theme alone: squircle thumbnails and the pink key ring on the chosen one. Today is the honcho theme; the other four looks are honcho-backstage. Over a photo the grid sits on a glass panel.
Installation
npx visor add photo-pickerThis copies two files into your project:
components/ui/photo-picker/photo-picker.tsx— the componentcomponents/ui/photo-picker/photo-picker.module.css— the styles
Usage
import { PhotoPicker } from '@/components/ui/photo-picker/photo-picker';
const photos = [
{ key: 'dusk', thumb: '/photos/dusk-480.webp', label: 'Dusk at the stage' },
{ key: 'lake', thumb: '/photos/lake-480.webp' },
];
<PhotoPicker aria-label="Pick Your Background" photos={photos} value={photo} onValueChange={setPhoto} play={open} load={open} />Theming
| Variable | Default | Sets |
|---|---|---|
--photo-picker-columns | 5 | Columns above 760px |
--photo-picker-columns-narrow | 3 | Columns at 760px and under |
--photo-picker-gap | --spacing-2 (8px) | Gap between thumbnails |
--photo-picker-padding | --spacing-1 (4px) | Room for the chosen ring inside the scroll box |
--photo-picker-max-height | min(62vh, 560px) | Height before the grid scrolls |
--photo-picker-radius | --radius-xl | Thumbnail corner radius |
--photo-picker-ring | --border-default | The 1px inset ring before a thumbnail loads |
--photo-picker-ring-selected | --interactive-primary-bg | The chosen thumbnail's 2px ring |
--photo-picker-ease | --motion-easing-enter | The wave's and the hover's easing |
--photo-picker-draw-duration | 320ms (--motion-duration-enter, else --motion-duration-800, × 0.4) | Each thumbnail's rise |
--photo-picker-draw-gap | 48ms | The beat between neighbours |
--photo-picker-draw-rise | 10px | How far each thumbnail rises |
Thumbnails are 4:3 and scale to 1.08 on hover. For anything else, target the buttons through your own className.
API Reference
PhotoPickerProps
| Prop | Type | Default | Description |
|---|---|---|---|
photos | { key: string; thumb: string; label?: string }[] | — | The photos, in order. label is the thumbnail's accessible name; it defaults to "Photo N". |
value | string | null | null | The chosen photo's key. |
onValueChange | (key: string) => void | — | Called with a photo's key when it is pressed. |
play | boolean | number | — | The draw wave plays on mount and every time play changes, except to false. Pass the menu's open state, or a counter you bump. |
load | boolean | true | Thumbnails load only once this has been true, and stay loaded after. Pass the menu's open state to wait for the first open. |
...props | React.HTMLAttributes<HTMLDivElement> | — | Standard div attributes are forwarded to the grid (role="group"). Give it an aria-label or aria-labelledby. |
Accessibility
- The grid is
role="group"; give it anaria-labeloraria-labelledby(4.1.2) - Each thumbnail is a native button with
aria-pressed, named by itslabelor "Photo N" (4.1.2) - The chosen thumbnail is marked by a ring as well as by
aria-pressed, and focus draws its own ring at the focus-ring tokens (2.4.7) - With
prefers-reduced-motion: reduce, the wave and the hover zoom are off (2.3.3)