| 1 | /** |
| 2 | * AI Elements' Message (registry.ai-sdk.dev/message.json), in g1t's |
| 3 | * tokens: a person's words as a bubble on the right, g1t's as text on the |
| 4 | * page, and a row of quiet actions under an answer. The Markdown itself is |
| 5 | * response.tsx. |
| 6 | */ |
| 7 | import type { ComponentProps, ReactNode } from "react"; |
| 8 | |
| 9 | import { cn } from "../../lib/cn"; |
| 10 | import { Button } from "../ui/button"; |
| 11 | import { Hint } from "../ui/hint"; |
| 12 | |
| 13 | export function Message({ from, className, ...props }: ComponentProps<"div"> & { from: "user" | "assistant" }) { |
| 14 | return <div data-from={from} className={cn("group/message flex w-full flex-col gap-1.5", from === "user" ? "items-end" : "items-start", className)} {...props} />; |
| 15 | } |
| 16 | |
| 17 | /** A person's words: a bubble, their line breaks kept. */ |
| 18 | export function MessageContent({ className, ...props }: ComponentProps<"div">) { |
| 19 | return <div className={cn("w-fit max-w-[85%] rounded-2xl rounded-br-md bg-raised px-3.5 py-2 text-[0.9375rem] leading-[1.55] wrap-break-word whitespace-pre-wrap text-fg", className)} {...props} />; |
| 20 | } |
| 21 | |
| 22 | /** What can be done with an answer, shown under it; brighter on hover. */ |
| 23 | export function MessageActions({ className, ...props }: ComponentProps<"div">) { |
| 24 | return <div className={cn("flex min-h-7 flex-wrap items-center gap-0.5 text-xs text-faint", className)} {...props} />; |
| 25 | } |
| 26 | |
| 27 | export function MessageAction({ label, children, className, ...props }: ComponentProps<typeof Button> & { label: string; children: ReactNode }) { |
| 28 | return ( |
| 29 | <Hint label={label}> |
| 30 | <Button type="button" variant="ghost" size="icon-xs" aria-label={label} className={cn("size-7 text-faint hover:text-fg", className)} {...props}> |
| 31 | {children} |
| 32 | </Button> |
| 33 | </Hint> |
| 34 | ); |
| 35 | } |