'use client' import { Button, SizableText, XStack } from '@hanzo/gui' import type { ReactElement, ReactNode } from 'react' import { Caret } from './caret' import { CARET, type Size } from './coin' import { paint } from '../material/paint' import { reach } from '../material/reach' import { weight } from '../material/weight' /** * The control at the end of a field that says what has been chosen, and opens * the chooser. * * The list it opens belongs to whoever calls this — a venue's tokens, a * network, a delegate — and is a different list in every product. What is the * same everywhere is the closed control: four boxes, each measured, each with * its own ground, its own corner and its own answer to what a mark on it is * drawn at. Written per screen those four came apart at all of it. * * It is a button, and the primitive is the button one rather than a stack with * a button substituted underneath: a press is made one way in this family, and * the two spellings do not stay identical — a stack handed somebody else's * element forwards DOM props to it and leaves the engine's own press behind. * A caller wiring this to a dialog substitutes that dialog's own trigger with * `render`, which is how this engine swaps an element everywhere else. */ const { plain, surface } = paint /** * Where the closed control sits, which is the whole of what differs between the * four of them — the box, its height, its corner, its inset and its ground. * * Beside a figure it is a pill on that field's own line, sized to the symbol it * carries: an ordinary control, standing where every other one in the row * stands. Under a panel it is the width of the card and stands at the height of * the action below it, which is the only other thing on the card as wide as * this; the name and the mark that says it opens go to opposite ends. One word * at the call site, because the alternative is five style props repeated * wherever the second box is wanted, and five props are five chances for two * rows to disagree. * * The fourth is a name and its mark and no box at all, which is how the asset a * limit price is quoted in is drawn: that control states the unit of the figure * beside it rather than offering a second decision, and a filled pill with a * caret beside a price reads as the other side of the order. It presses, so it * stands at the rung an inline control takes — the same one the prices beside * it are drawn at, where the design reference draws twenty-one and no target * may go under twenty-four. */ export type Form = 'pill' | 'row' | 'pair' | 'bare' /** * `ground` is what the control is painted once it carries something and `empty` * before it does. * * They differ on the pair and only there. Two of those sit side by side, and * the one still to be answered is painted solid while the one already answered * goes quiet, swapping the moment either is filled — so the eye lands on the * question rather than on the answer already given. Quiet is a shade off the * card and not the card itself: the answered half stands a tenth of white above * the page it is on, and a pill painted in the card's own fill has no edge left * to read. * * A control standing alone has no second one to be the unanswered half of, so * its empty state is drawn on the card's own ground. */ const FORM = { pill: { width: undefined, justifyContent: 'center', minHeight: reach.plain, paddingHorizontal: '$3', borderRadius: '$12', ground: surface, empty: surface, // A pill sits on a card painted the same shade, so the fill alone leaves no // edge to read and the control disappears into the panel behind it. The // hairline is what separates them: one pixel of the ink at a tenth, around // the filled pill and the empty one alike. Only this form carries it — a // row and a pair stand on the page rather than on a card, and the fourth // has no box at all. borderWidth: 1, borderColor: paint.line, // Beside a figure, after the symbol: the pill is sized to the pair and the // caret is the second half of the control, drawn in the same ink as the // ticker beside it. caret: { to: 'down', size: CARET, quiet: false }, scale: 'pill', }, row: { width: '100%', justifyContent: 'space-between', minHeight: reach.major, paddingHorizontal: '$3', borderRadius: paint.roundest, borderWidth: 0, borderColor: 'transparent', ground: surface, empty: surface, // Across a card it stands at the far end and leads on. A step under the // pill's, and under the words rather than level with them: `mark` is the // rung a glyph that is not itself a target is drawn at, which is what a // sign saying "next" is — it is not half of the control the way a // chooser's caret is. caret: { to: 'right', size: reach.mark, quiet: true }, scale: 'pill', }, pair: { width: '100%', justifyContent: 'space-between', minHeight: reach.major, // Sixteen, where the other three take twelve: both halves of a pair are // inset 16 and the mark stands there, so a twelve puts the disc and the // ticker four pixels inside where a reader met them. paddingHorizontal: '$4', borderRadius: paint.roundest, borderWidth: 0, borderColor: 'transparent', ground: paint.subtle, empty: paint.solid, caret: { to: 'down', size: CARET, quiet: false }, scale: 'pill', }, bare: { width: undefined, justifyContent: 'flex-end', minHeight: reach.dense, paddingHorizontal: '$3', borderRadius: '$12', borderWidth: 0, borderColor: 'transparent', ground: 'transparent', empty: 'transparent', // A control that states the unit of the figure beside it opens quietly, and // wears the smallest mark for the same reason: it is naming what the figure // is in, not offering a second thing to choose. caret: null, scale: 'unit', }, } as const export function Picker({ form = 'pill', chosen, empty, label, open = false, render = ) }