- Added support for rendering markdown in chat messages using ReactMarkdown with custom renderers. - Integrated a default format prompt for the chat system, improving user experience by initializing with a predefined prompt. - Updated the prompt generator to handle model selection more robustly, including loading states and fallback options for model selection. - Enhanced UI components for better accessibility and user feedback during prompt generation.
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Check, Copy } from "lucide-react";
|
|
import { useState } from "react";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
interface CodeBlockProps {
|
|
language: string;
|
|
children: string;
|
|
}
|
|
|
|
export function CodeBlock({ language, children }: CodeBlockProps) {
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
const handleCopy = () => {
|
|
navigator.clipboard.writeText(children);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2000);
|
|
};
|
|
|
|
return (
|
|
<div className="my-4 rounded-lg border bg-muted/50 overflow-hidden">
|
|
<div className="flex items-center justify-between px-4 py-2 bg-muted/80 border-b">
|
|
<span className="text-xs font-medium text-muted-foreground uppercase">
|
|
{language || "text"}
|
|
</span>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-6 w-6 hover:bg-background/50"
|
|
onClick={handleCopy}
|
|
title="Copiar código"
|
|
>
|
|
{copied ? (
|
|
<Check className="h-3.5 w-3.5 text-green-500" />
|
|
) : (
|
|
<Copy className="h-3.5 w-3.5 text-muted-foreground" />
|
|
)}
|
|
</Button>
|
|
</div>
|
|
<div className="p-4 overflow-x-auto">
|
|
<code className="text-sm font-mono whitespace-pre">{children}</code>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|