Files
shumai/packages/webui/components/viewers/pdf/pdf-control-bar.tsx
T

92 lines
3.5 KiB
TypeScript

import { ChevronLeft, ChevronRight, Download, Minus, Plus } from 'lucide-react'
import { m } from '@/ui/paraglide/messages.js'
export interface PdfControlBarProps {
currentPage: number
totalPages: number
onPageChange: (newPage: number) => void
zoom: number
onZoomIn: () => void
onZoomOut: () => void
onFit: () => void
onDownload: () => void
canDownload: boolean
}
export function PdfControlBar({
currentPage,
totalPages,
onPageChange,
zoom,
onZoomIn,
onZoomOut,
onFit,
onDownload,
canDownload,
}: PdfControlBarProps) {
return (
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-between gap-2 transition-colors duration-200">
{/* Page Navigation */}
<div className="flex items-center gap-1.5 bg-gray-200/50 dark:bg-white/10 rounded-md p-0.5">
<button
onClick={() => onPageChange(Math.max(1, currentPage - 1))}
disabled={currentPage <= 1}
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors disabled:opacity-40"
title={m.previous_page()}
>
<ChevronLeft size={16} />
</button>
<span className="px-2 text-xs font-mono font-medium text-gray-900 dark:text-gray-100 select-none">
{m.page_of_pages({ current: currentPage, total: totalPages || 1 })}
</span>
<button
onClick={() => onPageChange(Math.min(totalPages, currentPage + 1))}
disabled={currentPage >= totalPages}
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors disabled:opacity-40"
title={m.next_page()}
>
<ChevronRight size={16} />
</button>
</div>
{/* Zoom & Action Controls */}
<div className="flex items-center gap-2">
<div className="flex items-center gap-1 bg-gray-200/50 dark:bg-white/10 rounded-md p-0.5">
<button
onClick={onZoomOut}
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors"
title={m.zoom_out()}
>
<Minus size={16} />
</button>
<span className="w-12 text-center text-xs font-mono font-medium text-gray-900 dark:text-gray-100 select-none">
{Math.round(zoom * 100)}%
</span>
<button
onClick={onZoomIn}
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors"
title={m.zoom_in()}
>
<Plus size={16} />
</button>
</div>
<button
onClick={onFit}
className="text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent"
>
{m.fit()}
</button>
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50"
title={m.download_original_file()}
>
<Download size={14} />
{m.download()}
</button>
</div>
</div>
)
}