import { createPortal } from 'react-dom' import type { ReactNode } from 'react' import { useEffect, useLayoutEffect, useRef, useState } from 'react' import { Icon } from '../lib/icons' /** One row of a menu: an action, a submenu (`label ▸`), or a section heading. */ export type MenuItem = // `title` explains a disabled item (shown on hover). Such an item is NOT a // disabled ) } if ('swatches' in item) { return ( setOpen(null)} onPicked={onClose} /> ) } if ('heading' in item) { return (
{item.heading}
{item.empty &&
{item.empty}
}
) } if ('submenu' in item) { return ( ) } return ( ) })} {open && openItem && 'submenu' in openItem && ( )} ) } function SwatchGrid({ item, onEnter, onPicked, }: { item: Extract onEnter: () => void onPicked: () => void }) { const selected = item.selected?.toUpperCase() ?? null const pick = (color: string | null) => { item.onPick(color) onPicked() } // An outline, not a ring: a ring is a box-shadow, which the swatch's glow overrides. const ring = (on: boolean) => on ? 'outline outline-2 outline-offset-2 outline-white' : 'enabled:hover:scale-110' return (
{item.swatches.map((color, i) => (
) }