/** * Cart item-style cards — a radio group where each option shows a mini diagram * of the cart line it produces (thumbnail block + text lines) rather than an * icon, so Cards / Table / Compact read at a glance. Same idea as * `SidebarLayoutCards`, for the one other place in the admin where the choice * is a shape rather than a value: the diagram is derived from the option's * `value`, and an unrecognised one falls back to the Cards shape so a new * server-side style still renders a card rather than an empty box. * * The active card carries a tick badge in its corner on top of the usual ring, * since a thumbnail's own borders make a plain outline harder to pick out than * it is on an icon card. */ import { Check } from 'lucide-react'; export interface CartStyleOption { value: string; label: string; description?: string; } interface CartStyleCardsProps { label?: string; value: string; options: CartStyleOption[]; onChange: ( value: string ) => void; disabled?: boolean; help?: string; } /** * How many line rows the diagram draws, and how tall its thumbnail sits. * `table` drops the thumbnail-beside-text shape for a column grid; `compact` * is the card shape at a denser rhythm, i.e. more rows, smaller blocks. * * @param value The style value. */ function rowsFor( value: string ): number { switch ( value ) { case 'table': return 3; case 'compact': return 4; default: return 2; } } export default function CartStyleCards( { label, value, options, onChange, disabled = false, help, }: CartStyleCardsProps ) { const move = ( delta: number ) => { const index = options.findIndex( ( option ) => option.value === value ); const next = options[ ( index + delta + options.length ) % options.length ]; if ( next ) { onChange( next.value ); } }; return (
{ label && ( { label } ) }
{ options.map( ( option ) => { const checked = option.value === value; const rows = rowsFor( option.value ); return ( ); } ) }
{ help && (

{ help }

) }
); }