import { Grid } from '@hanzo/ui/grid' import type { ComponentProps, ReactNode } from 'react' import { paint } from '../material/paint' /** Where a child goes when it does not say. */ const RULE = '.lux-page > * { grid-column: column }' /** * The page, as a grid: the room on the left, the column, the room on the right. * * A screen is a stack of these — the application's own band across the top, the * route under it, the footer — and what makes them one page is that each lays * the same three tracks, so the column edge does not move from one to the next. * That is the whole of what it is for. * * It replaces `maxWidth` + `paddingHorizontal` + a centring margin, which is how * this gets written when nobody has named it — three properties on every route, * restated on the header and the footer, and each restatement a chance for one * of them to drift a few pixels off the others. The same column edge everywhere * is the point, so it is one object. * * The room either side is a TRACK, which is the whole reason this is a grid and * not a box with padding. A row that has to run the full width — a hairline * under a header, a band behind a section — says `grid-column: bleed` and keeps * its place in the same flow. With padding it cannot: it has to escape the * element it is nested in, and the escape is a negative margin whose number is * a copy of the padding. * * Every direct child lands in the column, and the rule that puts it there ships * with the component rather than in `tokens.css`. A descendant selector has no * prop form, so it has to be a rule somewhere — and a placement rule in a sheet * a caller may not have loaded is a page that silently rearranges: the children * auto-place one per track, so the first one lands in the left margin at a * seventh of the width and nothing reports it. Colour degrades visibly and can * live in the sheet; structure cannot. React hoists and de-duplicates the * element by its `href`, so any number of pages contribute one rule. * * A `Cell` that places itself still wins, because it writes `grid-column` * inline. * * Both tracks come from the ladder and neither is a number written here. The * rails are `1fr` above the gutter and the gutter below it, so the fold is * intrinsic: at a width the column cannot have, the rails give way to their * floor and the column takes what is left. There is no breakpoint in it and * nothing to keep in step with one. */ export interface PageProps extends Omit, 'columns' | 'rows' | 'gap'> { /** How wide the column may get. */ max?: string /** The least room either side of it, which is also the page's own inset. */ inset?: string /** * What stands between the rows, as a length. * * A rung off the spacing ladder rather than a token spelling. `$4` resolves * through the engine's JS resolver, which answers with the custom property * rather than a number — so the grid took the number it falls back to, and a * page whose source said the fourth rung drew the third. And the fallback is * a number, which is a length baked at render: a tenant moving `--space-4` * moved every other gap in the fleet and none of these. */ gap?: string children?: ReactNode } export const Page = ( { max = paint.column, inset = 'var(--gutter)', gap = 'var(--space-4)', style, ...props }: PageProps, ) => ( <> )