Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadErrorBanner.tsx

37 lines1.2 KB

1import { memo } from "react";
2import { Alert, AlertAction, AlertDescription } from "../ui/alert";
3import { Button } from "../ui/button";
4import { CircleAlertIcon, XIcon } from "lucide-react";
5import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
6​
7export const ThreadErrorBanner = memo(function ThreadErrorBanner({
8 error,
9 onDismiss,
10}: {
11 error: string | null;
12 onDismiss?: () => void;
13}) {
14 if (!error) return null;
15 return (
16 <div className="mx-auto w-fit max-w-[min(48rem,calc(100%-2rem))] pt-3">
17 <Alert variant="error" controlAlignment="first-line">
18 <CircleAlertIcon />
19 <AlertDescription>
20 <Tooltip>
21 <TooltipTrigger render={<div className="line-clamp-3" />}>{error}</TooltipTrigger>
22 <TooltipPopup side="top" className="max-w-96 whitespace-pre-wrap">
23 {error}
24 </TooltipPopup>
25 </Tooltip>
26 </AlertDescription>
27 {onDismiss && (
28 <AlertAction>
29 <Button variant="ghost" size="icon-xs" aria-label="Dismiss error" onClick={onDismiss}>
30 <XIcon className="text-destructive" />
31 </Button>
32 </AlertAction>
33 )}
34 </Alert>
35 </div>
36 );
37});