Roo-Code/webview-ui/src/components/chat/OpenMarkdownPreviewButton.tsx
Bruno Bergher 9bf7173725
feat: add button to open markdown in VSCode preview (#10773)
Co-authored-by: Roo Code <roomote@roocode.com>
2026-01-16 10:56:19 -05:00

38 lines
1,015 B
TypeScript

import React, { memo } from "react"
import { SquareArrowOutUpRight } from "lucide-react"
import { vscode } from "@src/utils/vscode"
import { hasComplexMarkdown } from "@src/utils/markdown"
import { StandardTooltip } from "@src/components/ui"
interface OpenMarkdownPreviewButtonProps {
markdown: string | undefined
className?: string
}
export const OpenMarkdownPreviewButton = memo(({ markdown, className }: OpenMarkdownPreviewButtonProps) => {
if (!hasComplexMarkdown(markdown)) {
return null
}
const handleClick = (e: React.MouseEvent) => {
e.stopPropagation()
if (markdown) {
vscode.postMessage({
type: "openMarkdownPreview",
text: markdown,
})
}
}
return (
<StandardTooltip content="Open in preview">
<button
onClick={handleClick}
className={`opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer ${className ?? ""}`}
aria-label="Open markdown in preview">
<SquareArrowOutUpRight className="w-4 h-4" />
</button>
</StandardTooltip>
)
})