From 55f4ae025fba41c3187c84f600e3510efb5c6853 Mon Sep 17 00:00:00 2001 From: Omar Flores Grimontt Date: Fri, 13 Sep 2019 11:26:10 -0500 Subject: [PATCH] Added download support, and validations for print and download --- package.json | 2 +- src/components/Pdf.jsx | 6 +++++- src/components/PdfMenu.jsx | 35 +++++++++++++++++++++++++++-------- src/components/Viewer.jsx | 12 ++++++++++++ 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 3fadd7d..00fa4b9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@omarefg/react-file-preview", - "version": "0.1.15", + "version": "0.1.17", "description": "Component to render and preview some kind of documents", "main": "lib/index.js", "private": false, diff --git a/src/components/Pdf.jsx b/src/components/Pdf.jsx index f191162..b50fa76 100644 --- a/src/components/Pdf.jsx +++ b/src/components/Pdf.jsx @@ -6,7 +6,7 @@ import { ErrorBoundary } from './ErrorBoundary' import { PdfMenu } from './PdfMenu' import { INCREASE_PERCENTAGE } from '../utils' -export const Pdf = ({ path, ErrorComponent, onError, showPdfMenu, style, onPrint }) => { +export const Pdf = ({ path, ErrorComponent, onError, showPdfMenu, style, onPrint, allowPrint, allowDownload, onDownload }) => { const { state, container, @@ -39,6 +39,10 @@ export const Pdf = ({ path, ErrorComponent, onError, showPdfMenu, style, onPrint print={print} page={page} onPrint={onPrint} + pdf={pdf} + allowDownload={allowDownload} + allowPrint={allowPrint} + onDownload={onDownload} /> )} {!pdf && ( diff --git a/src/components/PdfMenu.jsx b/src/components/PdfMenu.jsx index da292fd..abef52d 100644 --- a/src/components/PdfMenu.jsx +++ b/src/components/PdfMenu.jsx @@ -7,6 +7,7 @@ import { faChevronLeft, faChevronRight, faPrint, + faDownload, } from '@fortawesome/free-solid-svg-icons' import styles from '../styles/PdfMenu.module.scss' @@ -21,8 +22,14 @@ export const PdfMenu = props => { print, page, onPrint, + pdf, + allowPrint, + allowDownload, + onDownload, } = props + const printHandler = () => (onPrint ? onPrint(pdf) : print()) + return (
- + {allowPrint && ( + + )} + {allowDownload && ( + + )}
) } diff --git a/src/components/Viewer.jsx b/src/components/Viewer.jsx index 46486dd..0842c9d 100644 --- a/src/components/Viewer.jsx +++ b/src/components/Viewer.jsx @@ -26,6 +26,9 @@ export const Viewer = props => { onPrint, isLoading, supportXlsx, + allowDownload, + allowPrint, + onDownload, } = props if (isLoading) { @@ -101,6 +104,9 @@ export const Viewer = props => { showPdfMenu={showPdfMenu} style={style} onPrint={onPrint} + allowDownload={allowDownload} + allowPrint={allowPrint} + onDownload={onDownload} /> ) } @@ -167,6 +173,9 @@ Viewer.propTypes = { className: string, isLoading: bool, supportXlsx: bool, + allowPrint: bool, + allowDownload: bool, + onDownload: func, } Viewer.defaultProps = { @@ -182,4 +191,7 @@ Viewer.defaultProps = { className: null, isLoading: false, supportXlsx: false, + allowPrint: false, + allowDownload: false, + onDownload: null, }