import NextLink from 'next/link'; import { FlexBox } from '../../atoms/flex-box'; import { GridBox } from '../../atoms/grid-box'; import { Icon } from '../../atoms/icon'; import { Typography } from '../../atoms/typography'; import { Element } from '../../primitives/element'; import { cn } from '../../tools/cn'; import type { ListRowProps } from './types'; import { listRowIconVariants, listRowVariants } from './variants'; /** * One row of a List (DS ListRow): a lead (avatar or a 40px icon tile), the title with an optional * subtitle and meta, an end column (an Amount, a StatusBadge, a caption) and a chevron for a link. * With `href` the whole row is a link, with `onClick` a button (such as one that opens a detail * sheet), otherwise a plain row. Renders its own `li`, so it always sits in a List. Every text * comes from the caller. */ export function ListRow(props: ListRowProps) { const { title, subtitle, meta, children, leading, icon, iconTone, end, keepEnd = false, chevron, unread = false, unreadLabel, dimmed = false, disabled = false, className, } = props; const hasSecondLine = subtitle != null || meta != null || children != null; const showChevron = chevron ?? props.href !== undefined; const classes = cn( listRowVariants({ unread, dimmed, disabled, interactive: props.href !== undefined || props.onClick !== undefined, }), className, ); const layout = { alignItems: hasSecondLine ? 'items-start' : 'items-center', gap: 'gap-3', } as const; const content = ( <> {unread && ( )} {leading ?? (icon && ( ))} {title} {subtitle != null && ( {subtitle} )} {children} {meta != null && ( {meta} )} {end != null && ( {end} )} {showChevron && ( )} ); let row; if (props.href !== undefined && !disabled) { row = ( {content} ); } else if (props.href === undefined && props.onClick !== undefined) { row = ( {content} ); } else { row = ( {content} ); } return ( {row} ); }