/**
* Design gallery.
*
* A thumbnail picker for the product-card designs, shaped like the palette
* gallery but selecting a single value rather than applying a bundle. Each card
* draws a miniature wireframe of the layout it represents — built from divs the
* gallery stylesheet sizes, not bitmaps — so the store owner picks by sight
* instead of decoding a dropdown label.
*
* The wireframes are keyed off the design value. A value with no wireframe still
* renders as a selectable card with a neutral placeholder, so adding a design
* server-side never breaks this control.
*
* A card is wireframe + label and nothing else: the pane it lives in is 320px
* wide, and two designs to a row only leave room for the picture and its name.
* The current pick is marked by a tick in the card's own corner rather than a
* "Selected" button along its bottom edge — the button doubled the height of
* every card to say what the tick and the highlight already say.
*/
import { Check } from '../icons';
export interface DesignOption {
value: string;
label: string;
description?: string;
}
interface DesignGalleryProps {
label: string;
/**
* Suppress the visible label text while keeping it as the radiogroup's
* accessible name — for a caller whose own heading already introduces
* the gallery (e.g. Product Card's "Card Design" field group).
*/
hideLabel?: boolean;
value: string;
options: DesignOption[];
onChange: ( value: string ) => void;
/**
* Which wireframe vocabulary the values belong to — the product-card
* designs (the default) or the category-tile layouts. `category` also
* narrows the grid's min track, since a one-cell wireframe stays readable
* at three to a row where a 2x2 one does not.
*/
variant?: 'card' | 'category';
}
// One wireframe cell: an image block plus however many text bars the design
// shows beneath it. `modifier` selects the layout rules in the stylesheet.
const Cell = ( { modifier }: { modifier: string } ) => (
);
// Wireframe per design: how many cells, and which modifier they carry.
const WIREFRAMES: Record< string, { cells: number; modifier: string } > = {
grid: { cells: 4, modifier: 'grid' },
list: { cells: 2, modifier: 'list' },
'inline-price': { cells: 4, modifier: 'inline' },
tall: { cells: 4, modifier: 'tall' },
overlay: { cells: 4, modifier: 'overlay' },
bordered: { cells: 4, modifier: 'bordered' },
detail: { cells: 4, modifier: 'detail' },
showcase: { cells: 4, modifier: 'showcase' },
};
// Placeholder for a design the server offers but this control has no wireframe
// for, so a new design value degrades to a plain selectable card.
const EmptyWire = () => (
);
// The category-tile vocabulary is a different set of *layouts* from the
// product-card designs above, and one value ('overlay') is a member of both
// while meaning a different picture — so it gets its own map, selected by the
// `variant` prop rather than sharing WIREFRAMES' keyspace. One cell each:
// a tile is a single thing, where a card design is a grid of them.
const CATEGORY_WIREFRAMES: Record< string, string > = {
stacked: 'catstack',
inline: 'catinline',
overlay: 'catoverlay',
text: 'cattext',
};
const CategoryWireframe = ( { style }: { style: string } ) => {
const modifier = CATEGORY_WIREFRAMES[ style ];
if ( ! modifier ) {
return