Skip to content

Commit 7718119

Browse files
committed
feat(md): copy feature
1 parent f75afb0 commit 7718119

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/components/release-result.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Card } from "@/components/ui/card"
22
// import { Rocket } from "lucide-react"
33
import { MarkdownRenderer } from "./markdown-renderer"
44
import { useMarkdown } from "@/context/ReleaseNoteContext"
5+
import { Copy } from "lucide-react";
6+
import { copyText } from "@/lib/helpers/copyText";
57

68

79
export function ReleasePreview() {
@@ -10,6 +12,13 @@ export function ReleasePreview() {
1012
<div className="space-y-4">
1113
<div className="flex items-center justify-between">
1214
<h2 className="text-2xl font-bold text-foreground">Preview</h2>
15+
{
16+
markdown && (
17+
<button onClick={() => copyText(markdown)}>
18+
<Copy />
19+
</button>
20+
)
21+
}
1322
</div>
1423

1524
<Card className="p-6 bg-card shadow-elevation min-h-[500px]">

src/lib/helpers/copyText.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { toast } from "sonner";
2+
export async function copyText(text: string) {
3+
const promise = async () => {
4+
await navigator.clipboard.writeText(text);
5+
}
6+
7+
toast.promise(promise(), {
8+
loading: "Copying text...",
9+
success: "Text copied to clipboard",
10+
error: "Failed to copy text",
11+
});
12+
}

0 commit comments

Comments
 (0)