'use client' import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Separator, SizableText, XStack, YStack, } from '@hanzo/gui' import { useState, type ReactNode } from 'react' import { Wedge } from '../read/caret' import { paint } from '../material/paint' import { reach } from '../material/reach' import { press } from './press' /** * The mark, and everywhere else the brand lives behind it. * * Two jobs in one lockup, which is what the mark already is on every Lux * surface: press the letters to come home, press the wedge to leave for another * one. They are written together because the panel hangs off the lockup rather * than off the wedge that opens it, and the lockup is the only box that knows * where its own leading edge is. * * Nothing in the panel is a screen of the surface it sits on. Everything behind * the wedge is another product on another host, so every row leaves in a tab of * its own with the opener withheld — a person who pressed one from a half-filled * form should find the form where they left it. */ /** * What the panel is painted with, in the token layer's own names. * * A text primitive given no colour resolves the engine's `$color`, which the * installed theme row publishes as near-black — on a black page, invisible. So * every readable string names its colour. */ const { plain, quiet, line, subtle: tile } = paint /** How wide the square behind a product's mark stands. Its own box, not a * control's: the row around it is the target and it is taller than this. */ const TILE = 32 /** * How wide one row in the panel wants to be, the air around them, and the width * the two together make. * * The row is the number that matters. Two of them and a gap is what makes the * panel two columns wide; below that they wrap to one, which is the whole of * the narrow layout, and it is flexbox that decides it rather than a breakpoint * in this file. One pixel short and the second row wraps under the first at * every width with nothing on screen to say why, so the width is written as the * sum it has to be rather than as a round number. */ const ENTRY = 191 const GAP = 16 const PANEL = ENTRY * 2 + GAP * 3 + 2 /** * The marks, as strokes on one twenty-square grid. * * Drawn here rather than pulled from an icon set, for the reason the wedge * beside them is: an icon package written for two platforms arrives with a * renderer a web build has to stand in for, and ten strokes on one grid are * less code than the shim. They are also all one weight, which a mixed set is * not. * * Keyed by the product's own name, because the name is what the row already * carries and a second key would be a second thing to keep in step. A product * this set has no drawing for keeps its square and draws nothing in it, so the * names stay lined up down the panel. */ const SHAPES: Record = { // A speech bubble: something to talk to. AI: ['M4 5.5h12A1.5 1.5 0 0 1 17.5 7v6a1.5 1.5 0 0 1-1.5 1.5H9l-4 3v-3H4A1.5 1.5 0 0 1 2.5 13V7A1.5 1.5 0 0 1 4 5.5Z'], // Angle brackets and a slash — how an interface is written down. API: ['M7 6.5 3.5 10 7 13.5', 'M13 6.5 16.5 10 13 13.5', 'M11.2 5 8.8 15'], // A span with a way across it in both directions. Bridge: ['M3 10h14', 'M6 6.5 2.5 10 6 13.5', 'M14 6.5 17.5 10 14 13.5'], Cloud: ['M6 14.5h8.2a3.4 3.4 0 0 0 .2-6.8 5 5 0 0 0-9.5 1.4A3.05 3.05 0 0 0 6 14.5Z'], Credit: ['M4 5.5h12A1.5 1.5 0 0 1 17.5 7v6a1.5 1.5 0 0 1-1.5 1.5H4A1.5 1.5 0 0 1 2.5 13V7A1.5 1.5 0 0 1 4 5.5Z', 'M2.5 8.5h15'], // Two arrows passing: one side out, one side in. DEX: ['M7 16.5v-13', 'M4 6.5 7 3.5l3 3', 'M13 3.5v13', 'M10 13.5l3 3 3-3'], // A roof on columns. Finance: ['M2.5 8.5 10 4l7.5 4.5', 'M5 9v5.5', 'M8.3 9v5.5', 'M11.7 9v5.5', 'M15 9v5.5', 'M3 17h14'], // A sphere with a meridian and an equator. Network: ['M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z', 'M3 10h14', 'M10 3c2.1 2 3.3 4.5 3.3 7s-1.2 5-3.3 7c-2.1-2-3.3-4.5-3.3-7S7.9 5 10 3Z'], // A shield, and the mark of something checked. Safe: ['M10 2.5 16.5 5v5c0 4-2.8 6.4-6.5 7.6C6.3 16.4 3.5 14 3.5 10V5L10 2.5Z', 'M7.4 9.9 9.4 12l3.3-3.5'], // A pouch with a pocket in its edge. Wallet: ['M4.5 4.5h11a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2h-11a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2Z', 'M17.5 8h-3.4a2 2 0 0 0 0 4h3.4'], } function Shape({ of }: { of: string }) { return ( ) } /** Somewhere on another host. */ export interface Away { /** The product's own name, which is also the key its mark is filed under. */ name: string /** Where it is. */ at: string } /** One product: its name, its mark, and what it does where there is a sentence * for one. */ export interface Product extends Away { /** What it does, in the reader's language. A name and a destination is what a * menu is for; a sentence is what a menu affords the few that need one. */ says?: string } /** A column of plain destinations under a word saying what they have in * common. */ export interface Group { head: string of: readonly Away[] } /** * Leaving for another host, in a tab of its own with the opener withheld. * * The page on the other side has no business reaching back into this one. */ function Leave({ at, children }: { at: string; children: ReactNode }) { return ( } alignItems="center" gap="$3" minHeight={reach.dense} flexBasis={ENTRY} flexGrow={1} borderRadius="$4" opacity={1} hoverStyle={{ opacity: 0.72 }} pressStyle={{ opacity: 0.6 }} > {children} ) } /** One product. Name and sentence are one link, so a reader who lands on either * is on the same target. */ function Row({ name, says, at }: Product) { return ( {name} {says ? ( {says} ) : null} ) } function Column({ head, of }: Group) { return ( {head} {of.map((p) => ( } display="flex" alignItems="center" minHeight={reach.dense} size="$3" color={plain} hoverStyle={{ color: quiet }} > {p.name} ))} ) } export function Elsewhere({ mark, home = '/', walk, label = 'Lux', head = 'Products', products = [], groups = [], links = [], children, }: { /** The wordmark. Pressing it goes home. */ mark?: ReactNode /** Where home is. */ home?: string /** What moving to an address means. Absent, the mark is left to the browser * as an ordinary link. */ walk?: (to: string) => void /** What the brand is called. The mark has no text of its own, so this is what * a screen reader says in its place, and it names the panel's landmark. */ label?: string /** The word over the grid, and what pressing the wedge is about. */ head?: string products?: readonly Product[] /** The columns under the grid. */ groups?: readonly Group[] /** The row along the foot: where the work is read, argued about and * announced. */ links?: readonly Away[] /** Anything at the foot's leading edge — what this surface says about * itself. */ children?: ReactNode }) { const [open, setOpen] = useState(false) return ( {/* The panel hangs off the whole lockup rather than off the wedge, so its leading edge is the mark's. Anchored rather than measured: where the lockup's edge is is the lockup's own answer, and arithmetic here would be a second copy of the mark's width. */} } alignItems="center" minHeight={reach.dense} flexShrink={0} > {mark} } alignItems="center" justifyContent="center" width={reach.dense} height={reach.dense} borderRadius="$4" cursor="pointer" rotate={open ? '180deg' : '0deg'} // The engine gives a trigger a filled ground. The wedge stands on // the band's own, with a fill arriving only under a pointer. backgroundColor="transparent" borderWidth={0} hoverStyle={{ backgroundColor: tile }} focusVisibleStyle={paint.focus} > {products.length ? ( {head} {/* One wrapping row rather than two columns. Two rows and a gap fit the panel, so two land per line and each grows to fill it; where the panel is narrower than that, one lands per line. A wrap line is as tall as the tallest row on it, which is what keeps the two sides level when a sentence takes two lines. */} {products.map((p) => ( ))} ) : null} {groups.length ? ( <> {groups.map((g) => ( ))} ) : null} {children || links.length ? ( <> {children} {links.map((s) => ( } display="flex" alignItems="center" justifyContent="center" // A single letter is a target eight pixels wide. The floor // is stated on both axes because one of these is X. minWidth={reach.dense} minHeight={reach.dense} size="$2" color={quiet} hoverStyle={{ color: plain }} > {s.name} ))} ) : null} ) }