import { SizableText, YStack } from '@hanzo/gui' import type { ReactNode } from 'react' import { paint } from '../material/paint' import { reach } from '../material/reach' /** * A line you open to read what is under it. * * The browser already has this. `details` holds the state, `summary` is the * control, the keyboard reaches it, and a screen reader says whether it is open * before reading the line — none of which a box with a click handler gets for * free, and most of which it gets wrong. So the behaviour is the element's and * what is written here is the paint. * * The elements themselves rather than boxes rendered as them: a `summary` is a * `list-item`, which is where its marker comes from, and a box that is not one * has no marker to turn. * * It is a card. The fold used to draw a line AND fill itself from the recessed * ground, which is the two faces at once and belongs to neither — a card frames * on the page's own ground, a well recedes and draws no line. */ const { plain } = paint /** The name and whatever stands at the far end of it. A grid rather than a row * pushed apart: a count that appears on one fold and not the next must not * move where the names end. * * Two lists, because an empty track still costs the gutter beside it: a fold * with nothing at the far end drew a nought-wide second track and spent the * gap anyway, so its name stopped twelve pixels short of the rule everything * under it runs to. */ const WITH = 'minmax(0, 1fr) auto' const ALONE = 'minmax(0, 1fr)' /** The room the marker hangs in, which the line and everything under it are * indented by. A rung rather than a measurement, because the triangle is the * browser's and every browser draws it a pixel or two differently — this is * the room it is given, not its width. */ const MARKER = '$4' export function Fold({ summary, aside, open, children, }: { /** The line itself, which is what the fold is called. */ summary: ReactNode /** What is true of what is inside, said without opening it — how many rows * are folded away, whether any of them needs attention. */ aside?: ReactNode /** Open on arrival, for the one somebody came to read. */ open?: boolean children?: ReactNode }) { return ( } gap="$3" paddingHorizontal="$4" paddingVertical="$3" borderRadius={paint.corner} minWidth={0} {...paint.card} > } display="list-item" marginLeft={MARKER} minHeight={reach.dense} cursor="pointer" size="$3" color={plain} focusVisibleStyle={paint.focus} > {summary} {aside ? {aside} : null} {children} ) }