import { Paragraph, SizableText, XStack, YStack } from '@hanzo/gui'
import type { ReactNode } from 'react'
import { away, useWalk } from './link'
import { paint } from '../material/paint'
import { reach } from '../material/reach'
/**
* One entry of a list, and the whole of it is the target.
*
* A list of proposals, of roles, of assets, of bounties, of stakes: each is a
* mark, a name, a line under the name, and a figure or a state at the far end.
* Written per list they diverge by a few pixels each time and a reader scanning
* down a page sees five column edges where there is one list.
*
* The mark's track is a fixed width rather than the mark's own, which is the
* only reason names line up: an auto track is as wide as its widest content, so
* one entry with a two-letter mark and one with a picture start their names in
* different places. An entry with no mark at all drops the track rather than
* leaving a gap, because a list either has marks or does not.
*
* Pressability lives in the element. A row that is a link is an anchor, a row
* that runs a function is a button, and a row that is neither is a box — so the
* keyboard reaches what is reachable, the pointer says so, and nothing has to
* be told twice.
*/
const { plain, quiet } = paint
/** The mark's track, which is a control's own height: an entry is a row, and a
* picture beside a two-line name is as tall as one row of controls. */
const LEAD = reach.plain
/** The two arrangements, named once. `minmax(0, …)` on the name is what lets a
* long one wrap instead of widening its track and shoving the far end off the
* line. */
const WITH = `${LEAD}px minmax(0, 1fr) auto`
const ALONE = 'minmax(0, 1fr) auto'
export function Item({
mark,
title,
note,
aside,
href,
onPress,
children,
}: {
/** The picture, drawn at `LEAD` square. */
mark?: ReactNode
title: ReactNode
/** The line under the name — a state, a date, a holder. One line. */
note?: ReactNode
/** What is true of this entry at the far end: a figure, a badge, a caret. */
aside?: ReactNode
/** What belongs to the entry but not to its row — a summary, a set of
* figures, a progress bar. Under the row, across the whole width. */
children?: ReactNode
} & (
// An address or a function, and never both. Handed both, the row is an
// anchor and the function is dropped on the floor — the caller's second
// answer to "what does pressing this do" silently loses to the first. There
// is no arrangement of the two that a reader could predict, so there is no
// way to spell it.
| {
/**
* Where the entry leads. Given, the whole row is the link, and whether
* it leaves this interface is read off the address rather than asked for
* — the same rule every other link in the package follows.
*/
href: string
onPress?: undefined
}
| {
href?: undefined
/** What pressing the row does where it leads nowhere: choosing it,
* opening what it stands for in place. It makes the row a button. */
onPress: () => void
}
| { href?: undefined; onPress?: undefined }
)) {
const walk = useWalk()
const press = href !== undefined || onPress !== undefined
return (
) : away(href) ? (
) : (
)
}
gap="$3"
padding="$4"
minWidth={0}
// A button and an anchor each arrive with the platform's own fill,
// border, padding and centred text. The box states the first three away
// and the words below state their own alignment, because the row is the
// same row whether or not it is pressable.
borderRadius={paint.corner}
{...paint.card}
cursor={press ? 'pointer' : undefined}
// The line is what draws the entry, so the line is what answers the
// pointer: up from the divider to the ink. There is no shadow on this
// surface to deepen.
hoverStyle={press ? paint.lift : undefined}
pressStyle={press ? paint.lift : undefined}
focusVisibleStyle={press ? paint.focus : undefined}
>
{mark ? (
{mark}
) : null}
{title}
{note ? (
{note}
) : null}
{/* In the last track, so the far end of every entry that has one lands
on the row's right rule. Kept out of the document where there is
none: an `auto` track sized to an empty box is nought pixels wide,
so a placeholder reserves nothing and the name simply runs on. */}
{aside ? (
{aside}
) : null}
{children}
)
}