Skip to content

Commit 1b07def

Browse files
committed
feat: add print functionality to note dropdown menu
- Add print option to note editor dropdown menu with printer icon - Implement handlePrint function that opens note content in new print window - Apply clean print-optimized CSS styling for better paper output - Include note title as document title in print view - Auto-trigger browser print dialog and cleanup print window
1 parent 1c8e724 commit 1b07def

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/components/editor/index.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
MoreHorizontal,
77
FolderInput,
88
Paperclip,
9+
Printer,
910
} from 'lucide-react';
1011
import { Button } from '@/components/ui/button';
1112
import {
@@ -176,6 +177,53 @@ export default function Index({
176177
[userId]
177178
);
178179

180+
const handlePrint = useCallback(() => {
181+
if (!note) return;
182+
183+
const printWindow = window.open('', '_blank');
184+
if (!printWindow) return;
185+
186+
const printContent = `
187+
<!DOCTYPE html>
188+
<html>
189+
<head>
190+
<title>${note.title || 'Untitled Note'}</title>
191+
<style>
192+
body {
193+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
194+
line-height: 1.6;
195+
max-width: 800px;
196+
margin: 0 auto;
197+
padding: 20px;
198+
color: #333;
199+
}
200+
h1 { color: #2d3748; margin-bottom: 0.5rem; }
201+
h2 { color: #4a5568; }
202+
h3 { color: #718096; }
203+
pre { background: #f7fafc; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; }
204+
code { background: #edf2f7; padding: 0.2rem 0.4rem; border-radius: 0.25rem; }
205+
blockquote { border-left: 4px solid #e2e8f0; margin: 1rem 0; padding-left: 1rem; color: #4a5568; }
206+
ul, ol { margin: 1rem 0; }
207+
@media print {
208+
body { margin: 0; padding: 1cm; }
209+
.no-print { display: none; }
210+
}
211+
</style>
212+
</head>
213+
<body>
214+
<h1>${note.title || 'Untitled Note'}</h1>
215+
${note.content}
216+
</body>
217+
</html>
218+
`;
219+
220+
printWindow.document.write(printContent);
221+
printWindow.document.close();
222+
printWindow.focus();
223+
printWindow.print();
224+
printWindow.close();
225+
}, [note]);
226+
179227

180228
const formatDate = (date: Date) => {
181229
return new Intl.DateTimeFormat('en-US', {
@@ -262,6 +310,10 @@ export default function Index({
262310
<FolderInput className="mr-2 h-4 w-4" />
263311
Move
264312
</DropdownMenuItem>
313+
<DropdownMenuItem onClick={handlePrint}>
314+
<Printer className="mr-2 h-4 w-4" />
315+
Print
316+
</DropdownMenuItem>
265317
<DropdownMenuItem onClick={() => onArchiveNote(note.id)}>
266318
<Archive className="mr-2 h-4 w-4" />
267319
Archive

0 commit comments

Comments
 (0)