import { YStack } from '@hanzo/gui'; import { type ComponentProps, type ReactNode } from 'react'; import { type Rank } from './order'; export interface Column { /** Identity: React's key, and the field a sort names. */ key: string; /** The heading. */ head: ReactNode; /** What this column shows for a row. */ cell: (row: R) => ReactNode; /** Figures. Right edge, so a column of numbers can be read down. */ numeric?: boolean; /** * How this column orders rows. Given, the heading becomes a control; absent, * the column does not sort. One prop says both, so there is no way to declare * a sortable column without saying what it sorts on. */ sort?: (row: R) => Rank; } /** * What we know about the rows. * * Three constructors, because there are three different facts and one of them * is routinely reported as another: a request that failed renders as a venue * with nothing in it, and a reader who cannot tell the difference believes a * fabrication. A rows array plus a loading flag makes that mistake reachable — * `[]` is the same value whether we asked and got nothing or never found out. * Here `failed` carries the reason and cannot be spelled as an empty list. * * Empty is not a fourth state. It is `read` with no rows: we asked, and the * answer was nothing. That is a fact about the venue, and it is the one case a * caller has to put into its own words. */ export type Rows = { at: 'reading'; } | { at: 'read'; rows: R[]; } | { at: 'failed'; why: string; }; /** * A reading, from something that answers. * * `Rows` is what a table takes and nothing in this package made one, so every * screen wrote the same effect: a flag so a late answer cannot set state on a * screen somebody has left, a reset to `reading` when the question changes, and * a rejection turned into a sentence. Three lines, three chances, and the one * that gets missed is the flag — which shows up as a warning in development and * as a stale list in production. * * @param of what the question is about, as one string. The read runs again * when it changes — a pool id, a venue key, an address. Stated * rather than inferred from the reader, because a function literal * is a new value on every render and a dependency on one is a read * that never stops. * @param ask how to read. Called with no arguments; whatever it closes over is * the caller's business. * @param why what to say about a rejection, where the caller has better words * than the error's own — a refusal that answered and a request that * never completed are not the same failure. */ export declare function useRows(of: string, ask: () => Promise, why?: (e: unknown) => string): Rows; export interface TableProps { /** * What this table lists, as a plural noun in the reader's words — "markets", * "pools", "positions". It names the scrolling region for a screen reader, * which is the whole of what it does: it is prose, so it is translated, and * an address built out of it is an address that moves with the language. */ name: string; columns: Column[]; /** Row identity, stable across a re-read. */ id: (row: R) => string; rows: Rows; /** * The four sentences the table says about its own state. * * `name` and `empty` are what the caller says about its venue; these are what * the table says about itself, and they are the same four on every table in * an application. They are props and not English written into this file * because a surface that reads a chain in one language and says "Loading" in * another has published a sentence nobody translated — and a component that * reaches into a catalog has taken that dependency on the caller's behalf. */ words: { /** Said in a live region rather than drawn, while a read is running. */ reading: string; /** The label on the search box, where the table asks for itself. */ search: string; /** When a search matched none of the rows there are. The rows are all * still here; only the query is hiding them. */ none: string; /** The title over a read that failed. The reason is the reading's own. */ failed: string; }; /** * What "nothing" means here. Required, because "No results" over an empty * table is the sentence a reader mistakes for a broken page — and because * only the caller knows whether nothing means nobody has opened a market yet * or this wallet holds none. */ empty: { title: ReactNode; note?: ReactNode; }; /** * A summary of a list rather than the list. * * A full list stands under a ruled row of tracked capitals; a summary stands * under a filled band in the running register. The difference is not paint: a * summary shows the first few of something, so a heading that sorts would * order rows the reader cannot see the rest of. One prop, so the band and the * absence of the control cannot come apart. */ brief?: boolean; /** The text a row is found by. Given, a search box appears above the table — * unless `query` says the box is somewhere else. */ find?: (row: R) => string; /** * What the reader is looking for, where the field that asks is not this * table's. * * A screen with four lists on four tabs has one place for that field, and it * is the row the tabs are on. The filtering stays here: the table is what * knows which rows matched, what to say when none did, and how that differs * from a venue that holds none — moving the box out must not move any of * that with it. Absent, the table asks for itself. */ query?: string; /** * Where a row leads, or what can be done to it: a link into the thing, a * button that prepares a call. It renders in a trailing column of its own, * which is why it is not a `Column` — an action is not a value, so it has no * heading and nothing to sort on. */ action?: (row: R) => ReactNode; /** * What a row opens to: a chart, a set of terms — anything too tall for a * cell and too particular to be a column every row pays for. * * It rides in the trailing cell beside the action rather than in a column of * its own, so a table that has one is the same table with one more control in * it. What it opens is a row of its own under the row it belongs to, which is * what keeps a screen reader inside the table and a keyboard on the control * it pressed. * * `name` is the word on every one of them; `label` is what this row's control * is called, since a page of controls that all read "Chart" is a page a * screen reader reads out as a dozen identical links. */ detail?: { name: string; label: (row: R) => string; of: (row: R) => ReactNode; }; } /** * Where a row's detail is addressed. * * `aria-controls` is a list of ids separated by spaces, and a row is identified * by whatever the caller identifies it by — a pair, a name, an address. `LUX / * USDC` carries two spaces, so the attribute named four ids, none of them an * element, and the control announced itself as expanding something a reader * could not be taken to. Nothing reports that: the attribute is well formed and * the row it should point at is right there in the markup. * * So the identity is percent-encoded, which removes every space and stays one * key per row — two rows cannot collide the way replacing the spaces would let * them. The prefix is the table's own, from `useId`, because a screen holding a * summary and the full list of the same thing has two tables that would * otherwise agree on every id in both. */ export declare const anchor: (of: string, row: string) => string; /** * Whether a query is what is hiding the rows. * * There are two absences and one of them is a fabrication if it is drawn as the * other. A query hides rows only where there are rows to hide: with a venue * that holds nothing and something typed in the field, "no market matches that" * says markets exist and none of them answered — which is precisely the reading * this component was built to keep off a screen, one level down from the one it * catches. */ export declare const hiding: (asked: string, of: number) => boolean; /** * What the table has to say when it has no rows to draw. * * A failure is an alert and carries a rule in the colour of a refusal; an empty * answer is neither. That difference is the whole point of the three states, so * it is one prop and the two cannot be spelled alike by accident. * * Exported because a screen can fail before there is a table to fail in — an * endpoint nothing was configured with is the same shape of statement, and * writing it a second way would give one page two voices for "here is why * there is nothing". */ export declare function Answer({ title, alert, children, }: { title: ReactNode; alert?: boolean; children?: ReactNode; }): import("react").JSX.Element; /** * The one line a list puts where its rows would be. * * A line, not a card. A frame around one sentence makes the sentence the * subject of the screen, and the screen's subject is the list that is missing * from it — so the headings stay, the line sits in the middle of the room the * rows would have taken, and nothing is drawn around either. * * Exported because a screen can have nothing to list before there is a table to * list it in — no indexer, no market, no register — and writing that a second * way gives one page two voices for "there is nothing here". */ export declare function Nothing({ air, children, }: { /** * How deep the room around the line is, as a rung of the engine's own spacing * scale. * * Numbers are excluded from what the prop takes. The engine accepts one and * draws it as pixels, so a raw `20` typechecks, renders, and is off the scale * a tenant retunes — a literal that nothing reports. Excluding them is what * makes it unspellable rather than discouraged. */ air?: Exclude['paddingVertical'], number>; children: ReactNode; }): import("react").JSX.Element; /** * The sort is client-side over the rows handed in, and there is no default one: * rows arrive in the order the caller read them and stay there until somebody * asks otherwise. A table that opens sorted by volume has published an opinion * about what matters, in a place the reader will take for the natural order. * * Clicking a heading cycles ascending, descending, and back to the order it * came in — the third click exists so the given order is reachable again rather * than lost for the session. */ export declare function Table({ name, columns, id, rows, words, empty, brief, find, query, action, detail, }: TableProps): import("react").JSX.Element; //# sourceMappingURL=table.d.ts.map