-
Notifications
You must be signed in to change notification settings - Fork 1
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
37 additions
and
4 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,37 @@ | ||
import React from 'react'; | ||
import { Button } from "@/components/ui/button" | ||
import { Textarea } from './ui/textarea'; | ||
|
||
|
||
type Props = { | ||
content: string; | ||
}; | ||
const DocumentPreview: React.FC<Props> = ({ content }) => { | ||
const handleCopyContent = () => { | ||
navigator.clipboard.writeText(content); | ||
}; | ||
|
||
const handleDownload = () => { | ||
const blob = new Blob([content], { type: 'text/plain' }); | ||
const url = URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = 'generated_document.txt'; | ||
document.body.appendChild(a); | ||
a.click(); | ||
document.body.removeChild(a); | ||
URL.revokeObjectURL(url); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Textarea className="min-h-64" readOnly value={content} /> | ||
<div className='flex justify-between mt-4'> | ||
<Button onClick={handleCopyContent}>Copy to Clipboard</Button> | ||
<Button onClick={handleDownload}>Download Document</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DocumentPreview; |
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