-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"use client"; | ||
|
||
import { type Poem, type Author } from "@prisma/client"; | ||
import { Check, ClipboardCopy } from "lucide-react"; | ||
import { Button } from "~/components/ui/button"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from "~/components/ui/popover"; | ||
import { MyHost, cn } from "~/utils"; | ||
|
||
interface Props { | ||
data: Poem & { author: Author }; | ||
className?: string; | ||
} | ||
|
||
const CopyButton = (props: Props) => { | ||
const { data: poem } = props; | ||
|
||
return ( | ||
<Popover> | ||
<PopoverTrigger asChild> | ||
<Button | ||
variant={"secondary"} | ||
size={"icon"} | ||
className={cn(props.className)} | ||
onClick={() => { | ||
const text = `<p>${poem.content.replaceAll( | ||
"\n", | ||
"<br/>", | ||
)}</p> <p>—— 《<a href="${MyHost}/poem/${poem.id}"><b>${ | ||
poem.title | ||
}</b></a>》${poem.author.dynasty} · <a href="${MyHost}/author/${ | ||
poem.author.id | ||
}"><b>${poem.author.name}</b></a></p>`; | ||
|
||
const blobHtml = new Blob([text], { type: "text/html" }); | ||
const data = [ | ||
new ClipboardItem({ | ||
["text/html"]: blobHtml, | ||
}), | ||
]; | ||
|
||
void navigator.clipboard.write(data); | ||
}} | ||
> | ||
<ClipboardCopy className="h-4 w-4" /> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<div className="flex items-center space-x-2"> | ||
<Check className="h-4 w-4 text-primary" /> | ||
<span>已复制</span> | ||
</div> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default CopyButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters