Gathering detailed insights and metrics for @react-league/react-file-previewer
Gathering detailed insights and metrics for @react-league/react-file-previewer
Gathering detailed insights and metrics for @react-league/react-file-previewer
Gathering detailed insights and metrics for @react-league/react-file-previewer
A browser/device-agnostic file previewer for PDF, JPG, and PNG filetypes built on top of React-PDF
npm install @react-league/react-file-previewer
Typescript
Module System
Node Version
NPM Version
47.1
Supply Chain
91.7
Quality
71.5
Maintenance
50
Vulnerability
96.4
License
JavaScript (89.48%)
CSS (10.52%)
Total Downloads
721
Last Day
1
Last Week
2
Last Month
8
Last Year
217
1 Stars
99 Commits
1 Watching
1 Branches
2 Contributors
Latest Version
1.0.5
Package Id
@react-league/react-file-previewer@1.0.5
Unpacked Size
207.47 kB
Size
47.38 kB
File Count
33
NPM Version
9.6.2
Node Version
16.19.1
Publised On
29 Nov 2023
Cumulative downloads
Total Downloads
Last day
-50%
1
Compared to previous day
Last week
0%
2
Compared to previous week
Last month
-11.1%
8
Compared to previous month
Last year
-56.9%
217
Compared to previous year
24
A browser/device-agnostic file previewer for PDF and image file types built on top of React-PDF.
npm i @react-league/react-file-previewer
This component supports URLs and base64 encoded data.
1import FilePreviewer from '@react-league/react-file-previewer'; 2 3export const App = () => ( 4 <div> 5 <h1>My App</h1> 6 <FilePreviewer file={{ 7 url: "https://cors-anywhere.herokuapp.com/http://africau.edu/images/default/sample.pdf"}} 8 /> 9 </div> 10);
1import FilePreviewer from '@react-league/react-file-previewer'; 2 3export const App = () => ( 4 <div> 5 <h1>My App</h1> 6 <FilePreviewer 7 file={{ 8 data: "<base64 string>", 9 mimeType: 'application/pdf', 10 name: 'sample.pdf' // for download 11 }} 12 /> 13 </div> 14);
1import { useState } from 'react'; 2import FilePreviewer from '@react-league/react-file-previewer'; 3 4const PDF1_URL = 5 'https://cors-anywhere.herokuapp.com/http://africau.edu/images/default/sample.pdf'; 6 7export const App = () => { 8 const [file, setFile] = useState({ url: PDF1_URL }); 9 10 const onFileChange = event => { 11 const fileReader = new window.FileReader(); 12 const file = event.target.files[0]; 13 14 fileReader.onload = fileLoad => { 15 const { result } = fileLoad.target; 16 setFile({ url: result }); 17 }; 18 19 fileReader.readAsDataURL(file); 20 }; 21 22 return ( 23 <div> 24 <h1>My App</h1> 25 <input type="file" onChange={onFileChange} /> 26 <FilePreviewer 27 file={file} 28 /> 29 </div> 30 ) 31};
This will render the first page of the file as a thumbnail. It takes the exact same props as the default export
FilePreviewer
.
1import {FilePreviewerThumbnail} from '@react-league/react-file-previewer'; 2 3export const App = () => ( 4 <div> 5 <h1>My App</h1> 6 <FilePreviewerThumbnail 7 file={{ 8 data: "<base64 string>", 9 mimeType: 'application/pdf', 10 name: 'sample.pdf' // for download 11 }} 12 /> 13 -or- 14 <FilePreviewerThumbnail file={{ 15 url: "https://cors-anywhere.herokuapp.com/http://africau.edu/images/default/sample.pdf"}} 16 /> 17 </div> 18);
Prop name | Type | Description |
---|---|---|
file | object | Refer to file object |
onClick | function | Event handler for when viewer is clicked |
hideControls | bool | If 'true', viewer won't display the zoom, page up/down, and fit-to-screen controls |
Prop name | Type | Description |
---|---|---|
file | object | Refer to file object |
onClick | function | Event handler for when viewer is clicked |
hideControls | bool | If 'true', viewer won't display the zoom, page up/down, and fit-to-screen controls |
style | object | Any css style overrides |
Prop name | Type | Description |
---|---|---|
url | string | This can be used by itself with no other prop |
data | string | Base64 encoded string of file. If used, mimeType must also be provided |
mimeType | string | Type of the file |
name | string | Used to specify the filename when download button is clicked |
No vulnerabilities found.
No security vulnerabilities found.