feat: sticky copy-reply button on chat code-snippets

This commit is contained in:
Akhileshrangani4 2024-11-30 01:33:54 -05:00
parent 42305d67b9
commit e7d9989931

View File

@ -25,39 +25,40 @@ export const createMarkdownComponents = (
const match = /language-(\w+)/.exec(className || "") const match = /language-(\w+)/.exec(className || "")
return match ? ( return match ? (
<div className="relative border border-input rounded-md my-4"> <div className="relative border border-input rounded-md mt-8 my-2 translate-y-[-1rem]">
<div className="absolute top-0 left-0 px-2 py-1 text-xs font-semibold text-gray-200 bg-#1e1e1e rounded-tl"> <div className="absolute top-0 left-0 px-2 py-1 text-xs font-semibold text-gray-200 rounded-tl">
{match[1]} {match[1]}
</div> </div>
<div className="absolute top-0 right-0 flex"> <div className="sticky top-0 right-0 flex justify-end z-10">
{renderCopyButton(children)} <div className="flex border border-input shadow-lg bg-background rounded-md">
<Button {renderCopyButton(children)}
onClick={(e) => { <div className="w-px bg-input"></div>
e.preventDefault() <Button
e.stopPropagation() onClick={(e) => {
askAboutCode(children) e.preventDefault()
}} e.stopPropagation()
size="sm" askAboutCode(children)
variant="ghost" }}
className="p-1 h-6" size="sm"
> variant="ghost"
<CornerUpLeft className="w-4 h-4" /> className="p-1 h-6"
</Button> >
</div> <CornerUpLeft className="w-4 h-4" />
<div className="pt-6"> </Button>
<SyntaxHighlighter </div>
style={vscDarkPlus as any}
language={match[1]}
PreTag="div"
customStyle={{
margin: 0,
padding: "0.5rem",
fontSize: "0.875rem",
}}
>
{stringifyContent(children)}
</SyntaxHighlighter>
</div> </div>
<SyntaxHighlighter
style={vscDarkPlus as any}
language={match[1]}
PreTag="div"
customStyle={{
margin: 0,
padding: "0.5rem",
fontSize: "0.875rem",
}}
>
{stringifyContent(children)}
</SyntaxHighlighter>
</div> </div>
) : ( ) : (
<code className={className} {...props}> <code className={className} {...props}>