import { Heading, Paragraph, SizableText, XStack, YStack } from '@hanzo/gui' import type { ReactNode } from 'react' import { paint } from '../material/paint' /** * A task with steps, laid out as one. * * Opening a position is not a form, it is a sequence: choose a pair, then say * how much. Drawn as a single centred card it reads as a small form that has * inexplicably asked for two tokens and stopped — a person cannot see that * anything follows, so the screen looks broken rather than partly done. * * The steps are down the left because that is where the shape of the task * lives: what is done, what is being done, what is still to come. On a phone * they stack above the card, which is the same order read differently. * * It draws nothing about the work itself. What goes in the card is the * caller's, so one wizard serves three generations of the same task without * knowing which it is looking at. */ /** * How wide the task is set. * * Narrower than the page it stands on. The design reference measures 1080 here * at 1440 and at 1920, inside a workspace whose own reading width is 1120, and * below that cap it fills what the page gives it — which is what a maximum says * and a second inset would not. */ const COLUMN = 1080 /** * The two tracks, and why they are not thirds. * * Measured at 1440: the list of steps takes 360 and the work takes 700, either * side of a 20 gutter. Three equal tracks with the work on two of them gives * 347 and 713 — close enough to look right and 14 pixels out on every row of * the reading column, because the work's own inset is measured from its left * edge. * * Stated as a basis rather than a track list so the pair also wraps: below the * width that holds both, the work drops under the list and each grows to the * whole of the line, which is the same order read down instead of across. */ const LIST = 360 const WORK = 700 /** What runs between them, and the least the list may be squeezed to before it * drops under the work. Off the rung ladder both: the gutter is the * reference's own 20 and the floor is where two lines of a step name still * fit. */ const GUTTER = 20 const NARROW = 260 /** What the two lines of a step read as, and what the heading over the work * measures: 18 over 20 in the list, 40 for the title, which is what puts the * row's controls level with its words. */ const NAME = 20 const LABEL = 18 const TITLE = 40 /** The disc carrying the step's number, and the rule joining one to the next: * how far it runs, and how thick it is drawn. */ const DISC = 32 const JOIN = 32 const RULE = 2 export interface Step { /** What this step is for, in the words the screen uses elsewhere. */ name: string /** * The small line over the name — its rank in the sequence, said in words. * * The words are the caller's, because they are copy and this package ships * none. A wizard that numbered its own steps would be writing English into * every language. */ note?: ReactNode /** * True once the step's answers are all given. * * Not the same question as "is it behind the one in hand". A person can be * sent back to fix an answer three steps along, and every step after the one * they are on is still answered — so position says where you are and this * says what is settled. Drawn in the number: the disc carries three rungs, * and answered reads quieter than the step in hand and louder than one * nobody has reached. */ done?: boolean } export function Wizard({ trail, title, steps, now, go, aside, top = 0, children, }: { /** * Where this came from, named. * * A rendered trail rather than a route and a word: navigation is the * application's, and a component that took an href would need the * application's router to follow it. A wizard with no way back is a trap, so * pass one. */ trail?: ReactNode title: ReactNode steps: readonly Step[] /** Which step is being worked, counting from zero. */ now: number /** * Back to a step already worked. * * The list is the map of the task, so it is also the way through it: a step * behind the one in hand becomes the control that returns to it. Absent, the * list is a list. Nothing ahead is ever pressable — a step is reached by * answering the one before it, which is what makes it a step. */ go?: (step: number) => void /** The controls that belong to the task rather than to a step — a reset, a * version, a setting. Top right, out of the reading order of the work. */ aside?: ReactNode /** * How far down the page the list of steps comes to rest. * * The height of whatever the application floats over its own scroll, which is * a fact about the page rather than about the task — so it is given rather * than guessed. Left unsaid the list rests against the top of the viewport, * which is right for a page with nothing floating over it. */ top?: number children: ReactNode }) { return ( {/* Not a landmark. The trail and the heading are the subject of the page rather than a band around it, and wrapping them in one puts every mark in the row — the reset, the version, the setting — inside the header region. */} {trail ? ( {trail} ) : null} {title} {aside ? ( // Shrinkable, and wrapping inside itself. Held at its natural width // it is three controls a phone cannot fit beside a heading, and the // row pushes the document wider than the screen holding it. {aside} ) : null} {steps.map((s, i) => { const behind = go !== undefined && i < now const on = i === now // Answered but not in hand. The ink rung between the step being // worked and one nobody has reached, which is what lets a reader // see at a glance how much of the task is settled. const done = !on && s.done === true return ( // A sequence, so the element is one: a reader stepping by list // hears how many steps there are and which of them this is, // which the ink rungs below say to nobody who cannot see them. // `aria-current` is the same kind of statement as the notice's // role — a token the platform already has a word for in every // language, rather than copy this package would be writing in // English. {/* The rule between one step and the next, centred under the disc. It is what makes two rows read as a sequence rather than as a list of two things. */} {i === 0 ? null : ( )} go(i)} /> ) : undefined } gap="$3" alignItems="center" // A button element arrives with the platform's own fill, // border, padding and centred text. All four are stated away // here rather than left to whatever the browser thinks a // button looks like, because the row is a row whether or not // it is pressable. backgroundColor="transparent" borderWidth={0} padding={0} cursor={behind ? 'pointer' : undefined} focusVisibleStyle={behind ? paint.focus : undefined} > {/* The number is drawn rather than listed, because its filled or empty state is what says where you are. */} {i + 1} {s.note ? ( {s.note} ) : null} {/* Two rungs, not three. What is settled is said by the number in the disc, which has the room for a third; the name is the step itself and reads at the tier running text is legible at either way. Drawn faint it measured 2.5 against the page in light and 3.3 in dark, under the 4.5 a sentence is asked for, so a step nobody has reached had a name a reader could not make out. */} {s.name} ) })} {children} ) }