The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** @jsxRuntime automatic */ |
| 2 | /** @jsxImportSource @alchemy.run/sigil */ |
| 3 | import type { ReactNode } from "react"; |
| 4 | import { Box } from "./Layout.tsx"; |
| 5 | import { Text } from "./Typography.tsx"; |
| 6 | |
| 7 | export interface DescriptionItem { |
| 8 | readonly label: ReactNode; |
| 9 | readonly value: ReactNode; |
| 10 | } |
| 11 | |
| 12 | type DescriptionListProps = { |
| 13 | readonly items: ReadonlyArray<DescriptionItem>; |
| 14 | readonly labelWidth?: number; |
| 15 | /** Put values on their own line when horizontal space must not truncate them. */ |
| 16 | readonly stacked?: boolean; |
| 17 | }; |
| 18 | |
| 19 | export function DescriptionList({ items, labelWidth = 16, stacked = false }: DescriptionListProps) { |
| 20 | return ( |
| 21 | <Box flexDirection="column" gap={stacked ? 1 : 0}> |
| 22 | {items.map((item, index) => ( |
| 23 | <Box key={index} flexDirection={stacked ? "column" : "row"}> |
| 24 | <Box width={stacked ? undefined : labelWidth} paddingRight={1}> |
| 25 | <Text tone="muted">{item.label}</Text> |
| 26 | </Box> |
| 27 | <Box paddingLeft={stacked ? 1 : 0}> |
| 28 | {/* Element values render bare: a Box (e.g. multi-line AnsiText |
| 29 | output) cannot nest inside Text. */} |
| 30 | {typeof item.value === "string" || typeof item.value === "number" ? ( |
| 31 | <Text>{item.value}</Text> |
| 32 | ) : ( |
| 33 | item.value |
| 34 | )} |
| 35 | </Box> |
| 36 | </Box> |
| 37 | ))} |
| 38 | </Box> |
| 39 | ); |
| 40 | } |