@iamjariwala/react-doc-viewer 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +568 -0
- package/dist/DocViewer.d.ts +21 -0
- package/dist/components/DocumentNav.d.ts +3 -0
- package/dist/components/FileName.d.ts +3 -0
- package/dist/components/HeaderBar.d.ts +3 -0
- package/dist/components/LoadingTimout.d.ts +3 -0
- package/dist/components/ProxyRenderer.d.ts +3 -0
- package/dist/components/common/Button.d.ts +16 -0
- package/dist/components/common/index.d.ts +1 -0
- package/dist/components/icons/index.d.ts +8 -0
- package/dist/cssStyles.d.ts +1 -0
- package/dist/defaultTheme.d.ts +3 -0
- package/dist/empty-DBAFSQIv.cjs +1 -0
- package/dist/empty-GlqisfcO.js +4 -0
- package/dist/features/annotations/components/AnnotationLayer.d.ts +10 -0
- package/dist/features/annotations/components/AnnotationToolbar.d.ts +3 -0
- package/dist/features/annotations/components/ColorPicker.d.ts +3 -0
- package/dist/features/annotations/components/CommentMarker.d.ts +8 -0
- package/dist/features/annotations/components/CommentPopover.d.ts +9 -0
- package/dist/features/annotations/components/TextHighlight.d.ts +8 -0
- package/dist/features/annotations/components/icons/index.d.ts +13 -0
- package/dist/features/annotations/hooks/useAnnotationExport.d.ts +9 -0
- package/dist/features/annotations/hooks/useDrawingCanvas.d.ts +15 -0
- package/dist/features/annotations/hooks/useTextSelection.d.ts +10 -0
- package/dist/features/annotations/index.d.ts +13 -0
- package/dist/features/annotations/state/actions.d.ts +52 -0
- package/dist/features/annotations/state/index.d.ts +17 -0
- package/dist/features/annotations/state/reducer.d.ts +17 -0
- package/dist/features/annotations/types/index.d.ts +44 -0
- package/dist/features/drag-drop/components/DropZoneOverlay.d.ts +9 -0
- package/dist/features/drag-drop/hooks/useDragDrop.d.ts +11 -0
- package/dist/features/drag-drop/hooks/useFileProcessor.d.ts +13 -0
- package/dist/features/drag-drop/index.d.ts +4 -0
- package/dist/features/drag-drop/types/index.d.ts +19 -0
- package/dist/features/thumbnail-sidebar/components/ThumbnailItem.d.ts +11 -0
- package/dist/features/thumbnail-sidebar/components/ThumbnailSidebar.d.ts +8 -0
- package/dist/features/thumbnail-sidebar/components/ThumbnailToggle.d.ts +7 -0
- package/dist/features/thumbnail-sidebar/hooks/useThumbnailGenerator.d.ts +13 -0
- package/dist/features/thumbnail-sidebar/index.d.ts +6 -0
- package/dist/features/thumbnail-sidebar/state/actions.d.ts +31 -0
- package/dist/features/thumbnail-sidebar/state/index.d.ts +15 -0
- package/dist/features/thumbnail-sidebar/state/reducer.d.ts +11 -0
- package/dist/hooks/useDocumentLoader.d.ts +13 -0
- package/dist/hooks/useRendererSelector.d.ts +5 -0
- package/dist/hooks/useTranslation.d.ts +3 -0
- package/dist/hooks/useWindowSize.d.ts +4 -0
- package/dist/i18n.d.ts +158 -0
- package/dist/index-BW6EMUiE.cjs +797 -0
- package/dist/index-CYjVmFQ0.cjs +10 -0
- package/dist/index-DHMTXjv6.cjs +1 -0
- package/dist/index-Dg8HfAtq.js +21246 -0
- package/dist/index-dGGNa2HA.js +3350 -0
- package/dist/index-nyGAOsVK.js +42 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/locales/ar.json.d.ts +13 -0
- package/dist/locales/de.json.d.ts +13 -0
- package/dist/locales/en.json.d.ts +26 -0
- package/dist/locales/es.json.d.ts +13 -0
- package/dist/locales/fr.json.d.ts +13 -0
- package/dist/locales/it.json.d.ts +13 -0
- package/dist/locales/ja.json.d.ts +13 -0
- package/dist/locales/pl.json.d.ts +13 -0
- package/dist/locales/pt.json.d.ts +13 -0
- package/dist/locales/ru.json.d.ts +13 -0
- package/dist/locales/se.json.d.ts +13 -0
- package/dist/locales/sr.json.d.ts +13 -0
- package/dist/locales/sr_cyr.json.d.ts +13 -0
- package/dist/locales/tr.json.d.ts +13 -0
- package/dist/models.d.ts +122 -0
- package/dist/react-doc-viewer.cjs +1 -0
- package/dist/react-doc-viewer.js +23 -0
- package/dist/renderers/bmp/index.d.ts +4 -0
- package/dist/renderers/csv/index.d.ts +4 -0
- package/dist/renderers/gif/index.d.ts +4 -0
- package/dist/renderers/html/index.d.ts +4 -0
- package/dist/renderers/image/index.d.ts +4 -0
- package/dist/renderers/index.d.ts +15 -0
- package/dist/renderers/jpg/index.d.ts +4 -0
- package/dist/renderers/msdoc/index.d.ts +4 -0
- package/dist/renderers/pdf/components/PDFControls.d.ts +4 -0
- package/dist/renderers/pdf/components/PDFPagination.d.ts +4 -0
- package/dist/renderers/pdf/components/PDFThumbnailGenerator.d.ts +3 -0
- package/dist/renderers/pdf/components/icons/index.d.ts +9 -0
- package/dist/renderers/pdf/components/pages/PDFAllPages.d.ts +7 -0
- package/dist/renderers/pdf/components/pages/PDFPages.d.ts +4 -0
- package/dist/renderers/pdf/components/pages/PDFSinglePage.d.ts +7 -0
- package/dist/renderers/pdf/index.d.ts +4 -0
- package/dist/renderers/pdf/state/actions.d.ts +32 -0
- package/dist/renderers/pdf/state/index.d.ts +13 -0
- package/dist/renderers/pdf/state/reducer.d.ts +15 -0
- package/dist/renderers/png/index.d.ts +4 -0
- package/dist/renderers/tiff/index.d.ts +4 -0
- package/dist/renderers/tiff/tiffToCanvas.d.ts +1 -0
- package/dist/renderers/txt/index.d.ts +4 -0
- package/dist/renderers/video/index.d.ts +4 -0
- package/dist/renderers/webp/index.d.ts +4 -0
- package/dist/store/DocViewerProvider.d.ts +22 -0
- package/dist/store/actions.d.ts +63 -0
- package/dist/store/mainStateReducer.d.ts +23 -0
- package/dist/url-BH2U_nez.cjs +3 -0
- package/dist/url-Dk8Xia2J.js +560 -0
- package/dist/utils/fileLoaders.d.ts +13 -0
- package/dist/utils/getFileName.d.ts +3 -0
- package/package.json +122 -0
package/README.md
ADDED
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@mehuljariwala/react-doc-viewer)
|
|
2
|
+
[](https://www.npmjs.com/package/@mehuljariwala/react-doc-viewer)
|
|
3
|
+
|
|
4
|
+
# @mehuljariwala/react-doc-viewer
|
|
5
|
+
|
|
6
|
+
Universal document viewer for **React v17+** - supports PDF, Office docs, images, videos and more.
|
|
7
|
+
|
|
8
|
+
> Forked from [@cyntler/react-doc-viewer](https://github.com/cyntler/react-doc-viewer) with active maintenance and new features.
|
|
9
|
+
|
|
10
|
+
## Important note!
|
|
11
|
+
|
|
12
|
+
> [!IMPORTANT]
|
|
13
|
+
> This library uses the official MS Office online document viewing service. This means it works on an iframe basis and only supports public file URLs! Therefore, it may not be compatible with all projects. Currently, there is no way to natively render MS Office documents in the browser.
|
|
14
|
+
|
|
15
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
16
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
17
|
+
## Table of Contents
|
|
18
|
+
|
|
19
|
+
- [Supported file types](#supported-file-types)
|
|
20
|
+
- [Storybook Demo](#storybook-demo)
|
|
21
|
+
- [Installation](#installation)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [Required styles](#required-styles)
|
|
24
|
+
- [Basic](#basic)
|
|
25
|
+
- [Initial Active Document](#initial-active-document)
|
|
26
|
+
- [Control over the displayed document](#control-over-the-displayed-document)
|
|
27
|
+
- [Displaying blob/uploaded documents](#displaying-blobuploaded-documents)
|
|
28
|
+
- [Included Renderers](#included-renderers)
|
|
29
|
+
- [Custom Renderer](#custom-renderer)
|
|
30
|
+
- [Custom File Loader](#custom-file-loader)
|
|
31
|
+
- [Theme](#theme)
|
|
32
|
+
- [Custom pre-fetch HTTP Verb](#custom-pre-fetch-http-verb)
|
|
33
|
+
- [Custom Request Headers](#custom-request-headers)
|
|
34
|
+
- [Internationalization (i18n)](#internationalization-i18n)
|
|
35
|
+
- [Styling](#styling)
|
|
36
|
+
- [CSS Class](#css-class)
|
|
37
|
+
- [CSS Class Default Override](#css-class-default-override)
|
|
38
|
+
- [React Inline](#react-inline)
|
|
39
|
+
- [Styled Components](#styled-components)
|
|
40
|
+
- [Using DocViewerRef](#using-docviewerref)
|
|
41
|
+
- [Config](#config)
|
|
42
|
+
- [Overriding Header Component](#overriding-header-component)
|
|
43
|
+
- [Overriding Loading Renderer](#overriding-loading-renderer)
|
|
44
|
+
- [Overriding No Renderer (Error)](#overriding-no-renderer-error)
|
|
45
|
+
|
|
46
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
47
|
+
|
|
48
|
+
## Supported file types
|
|
49
|
+
|
|
50
|
+
| Extension | MIME Type | Comments |
|
|
51
|
+
| --------- | ------------------------------------------------------------------------- | ------------- |
|
|
52
|
+
| bmp | image/bmp | |
|
|
53
|
+
| csv | text/csv | |
|
|
54
|
+
| odt | application/vnd.oasis.opendocument.text | |
|
|
55
|
+
| doc | application/msword | Public URLs only! |
|
|
56
|
+
| docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document | Public URLs only! |
|
|
57
|
+
| gif | image/gif | |
|
|
58
|
+
| htm | text/htm | |
|
|
59
|
+
| html | text/html | |
|
|
60
|
+
| jpg | image/jpg | |
|
|
61
|
+
| jpeg | image/jpeg | |
|
|
62
|
+
| pdf | application/pdf | |
|
|
63
|
+
| png | image/png | |
|
|
64
|
+
| ppt | application/vnd.ms-powerpoint | Public URLs only! |
|
|
65
|
+
| pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation | Public URLs only! |
|
|
66
|
+
| tiff | image/tiff | |
|
|
67
|
+
| txt | text/plain | |
|
|
68
|
+
| xls | application/vnd.ms-excel | Public URLs only! |
|
|
69
|
+
| xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | Public URLs only! |
|
|
70
|
+
| mp4 | video/mp4 | |
|
|
71
|
+
| webp | image/webp | |
|
|
72
|
+
|
|
73
|
+
## Storybook Demo
|
|
74
|
+
|
|
75
|
+
https://mehuljariwala.github.io/react-doc-viewer
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
Use one of the package managers for Node.js.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm i @mehuljariwala/react-doc-viewer
|
|
83
|
+
# or
|
|
84
|
+
yarn add @mehuljariwala/react-doc-viewer
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Usage
|
|
88
|
+
|
|
89
|
+
> **Warning:** _By default the component height will expand and contract to the current loaded file. The width will expand to fill the parent._
|
|
90
|
+
|
|
91
|
+
### Required styles
|
|
92
|
+
|
|
93
|
+
The library exports a CSS file containing classes needed for correct rendering of e.g. PDF files. It is best to include it at the beginning of the application or in the place where you use this library.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import "@mehuljariwala/react-doc-viewer/dist/index.css";
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Basic
|
|
100
|
+
|
|
101
|
+
DocViewer requires at least an array of document objects to function.
|
|
102
|
+
Each document object must have a uri to a file, either a url that returns a file or a local file.
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
import DocViewer, { DocViewerRenderers } from "@mehuljariwala/react-doc-viewer";
|
|
106
|
+
import "@mehuljariwala/react-doc-viewer/dist/index.css";
|
|
107
|
+
|
|
108
|
+
function App() {
|
|
109
|
+
const docs = [
|
|
110
|
+
{ uri: "https://url-to-my-pdf.pdf" }, // Remote file
|
|
111
|
+
{ uri: require("./example-files/pdf.pdf") }, // Local File
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
return <DocViewer documents={docs} pluginRenderers={DocViewerRenderers} />;
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Initial Active Document
|
|
119
|
+
|
|
120
|
+
By default, the first item in your `documents` array will be displayed after the component is rendered. However, there is a prop `initialActiveDocument` that you can point to the initial document that should be displayed.
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
import DocViewer, { DocViewerRenderers } from "@mehuljariwala/react-doc-viewer";
|
|
124
|
+
import "@mehuljariwala/react-doc-viewer/dist/index.css";
|
|
125
|
+
|
|
126
|
+
const App = () => {
|
|
127
|
+
const docs = [
|
|
128
|
+
{ uri: "https://url-to-my-pdf.pdf" }, // Remote file
|
|
129
|
+
{ uri: require("./example-files/pdf.pdf") }, // Local File
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<DocViewer
|
|
134
|
+
documents={docs}
|
|
135
|
+
initialActiveDocument={docs[1]}
|
|
136
|
+
pluginRenderers={DocViewerRenderers}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Control over the displayed document
|
|
143
|
+
|
|
144
|
+
From version **1.11.0** you can control the displayed document through two props: `activeDocument` and `onDocumentChange`.
|
|
145
|
+
|
|
146
|
+
```jsx
|
|
147
|
+
const DocViewerControlOverDisplayedDocument = () => {
|
|
148
|
+
const docs = [
|
|
149
|
+
{ uri: "https://url-to-my-pdf.pdf" }, // Remote file
|
|
150
|
+
{ uri: require("./example-files/pdf.pdf") }, // Local File
|
|
151
|
+
];
|
|
152
|
+
const [activeDocument, setActiveDocument] = useState(docs[0]);
|
|
153
|
+
|
|
154
|
+
const handleDocumentChange = (document) => {
|
|
155
|
+
setActiveDocument(document);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<>
|
|
160
|
+
<DocViewer
|
|
161
|
+
documents={docs}
|
|
162
|
+
activeDocument={activeDocument}
|
|
163
|
+
onDocumentChange={handleDocumentChange}
|
|
164
|
+
/>
|
|
165
|
+
</>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Displaying blob/uploaded documents
|
|
171
|
+
|
|
172
|
+
Since **v1.6.2** you can use documents in the form of blobs, which allows you to e.g. display uploaded files.
|
|
173
|
+
|
|
174
|
+
```jsx
|
|
175
|
+
const DocViewerWithInputApp = () => {
|
|
176
|
+
const [selectedDocs, setSelectedDocs] = useState<File[]>([]);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<>
|
|
180
|
+
<input
|
|
181
|
+
type="file"
|
|
182
|
+
accept=".pdf"
|
|
183
|
+
multiple
|
|
184
|
+
onChange={(el) =>
|
|
185
|
+
el.target.files?.length &&
|
|
186
|
+
setSelectedDocs(Array.from(el.target.files))
|
|
187
|
+
}
|
|
188
|
+
/>
|
|
189
|
+
<DocViewer
|
|
190
|
+
documents={selectedDocs.map((file) => ({
|
|
191
|
+
uri: window.URL.createObjectURL(file),
|
|
192
|
+
fileName: file.name,
|
|
193
|
+
}))}
|
|
194
|
+
pluginRenderers={DocViewerRenderers}
|
|
195
|
+
/>
|
|
196
|
+
</>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Included Renderers
|
|
202
|
+
|
|
203
|
+
To use the included renderers.
|
|
204
|
+
`DocViewerRenderers` is an Array of all the included renderers.
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
import DocViewer, { DocViewerRenderers } from "@mehuljariwala/react-doc-viewer";
|
|
208
|
+
import "@mehuljariwala/react-doc-viewer/dist/index.css";
|
|
209
|
+
|
|
210
|
+
<DocViewer
|
|
211
|
+
pluginRenderers={DocViewerRenderers}
|
|
212
|
+
{/* ... */}
|
|
213
|
+
/>;
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Or you can import individual renderers.
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
import DocViewer, { PDFRenderer, PNGRenderer } from "@mehuljariwala/react-doc-viewer";
|
|
220
|
+
import "@mehuljariwala/react-doc-viewer/dist/index.css";
|
|
221
|
+
|
|
222
|
+
<DocViewer
|
|
223
|
+
pluginRenderers={[PDFRenderer, PNGRenderer]}
|
|
224
|
+
{/* ... */}
|
|
225
|
+
/>;
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Custom Renderer
|
|
229
|
+
|
|
230
|
+
To create a custom renderer, that will just exist for your project.
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
import React from "react";
|
|
234
|
+
import DocViewer from "@mehuljariwala/react-doc-viewer";
|
|
235
|
+
|
|
236
|
+
const MyCustomPNGRenderer: DocRenderer = ({
|
|
237
|
+
mainState: { currentDocument },
|
|
238
|
+
}) => {
|
|
239
|
+
if (!currentDocument) return null;
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<div id="my-png-renderer">
|
|
243
|
+
<img id="png-img" src={currentDocument.fileData as string} />
|
|
244
|
+
</div>
|
|
245
|
+
);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
MyCustomPNGRenderer.fileTypes = ["png", "image/png"];
|
|
249
|
+
MyCustomPNGRenderer.weight = 1;
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
And supply it to `pluginRenderers` inside an `Array`.
|
|
253
|
+
|
|
254
|
+
```tsx
|
|
255
|
+
import DocViewer, { DocViewerRenderers } from "@mehuljariwala/react-doc-viewer";
|
|
256
|
+
import "@mehuljariwala/react-doc-viewer/dist/index.css";
|
|
257
|
+
|
|
258
|
+
<DocViewer
|
|
259
|
+
pluginRenderers={[MyCustomPNGRenderer]}
|
|
260
|
+
documents={
|
|
261
|
+
[
|
|
262
|
+
// ...
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
/>;
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Custom File Loader
|
|
269
|
+
|
|
270
|
+
If you need to prevent the actual loading of the file by `@mehuljariwala/react-doc-viewer`.<br>
|
|
271
|
+
You can decorate your custom renderer with a callback to do as you wish. e.g. Load the file yourself in an iFrame.
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
MyCustomPNGRenderer.fileLoader = ({
|
|
275
|
+
documentURI,
|
|
276
|
+
signal,
|
|
277
|
+
fileLoaderComplete,
|
|
278
|
+
}) => {
|
|
279
|
+
myCustomFileLoaderCode().then(() => {
|
|
280
|
+
// Whenever you have finished you must call fileLoaderComplete() to remove the loading animation
|
|
281
|
+
fileLoaderComplete();
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Theme
|
|
287
|
+
|
|
288
|
+
You can provide a theme object with one or all of the available properties.
|
|
289
|
+
|
|
290
|
+
```xml
|
|
291
|
+
<DocViewer
|
|
292
|
+
documents={docs}
|
|
293
|
+
theme={{
|
|
294
|
+
primary: "#5296d8",
|
|
295
|
+
secondary: "#ffffff",
|
|
296
|
+
tertiary: "#5296d899",
|
|
297
|
+
textPrimary: "#ffffff",
|
|
298
|
+
textSecondary: "#5296d8",
|
|
299
|
+
textTertiary: "#00000099",
|
|
300
|
+
disableThemeScrollbar: false,
|
|
301
|
+
}}
|
|
302
|
+
/>
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Custom pre-fetch HTTP Verb
|
|
306
|
+
|
|
307
|
+
Some services (such as AWS) provide URLs that works only for one pre-configured verb.
|
|
308
|
+
By default, `@mehuljariwala/react-doc-viewer` fetches document metadata through a `HEAD` request in order to guess its `Content-Type`.
|
|
309
|
+
If you need to have a specific verb for the pre-fetching, use the `prefetchMethod` option on the DocViewer:
|
|
310
|
+
|
|
311
|
+
```tsx
|
|
312
|
+
import DocViewer, { DocViewerRenderers } from "@mehuljariwala/react-doc-viewer";
|
|
313
|
+
|
|
314
|
+
<DocViewer prefetchMethod="GET" />;
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Custom Request Headers
|
|
318
|
+
|
|
319
|
+
Provide request headers, i.e. for authenticating with an API etc.
|
|
320
|
+
|
|
321
|
+
```tsx
|
|
322
|
+
const headers = {
|
|
323
|
+
"X-Access-Token": "1234567890",
|
|
324
|
+
"My-Custom-Header": "my-custom-value",
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
<DocViewer documents={docs} prefetchMethod="GET" requestHeaders={headers} />;
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Internationalization (i18n)
|
|
331
|
+
|
|
332
|
+
From **v1.6.0** you can pass the `language` prop to the `DocViewer` component to get translated sentences and words that can be displayed by this library.
|
|
333
|
+
|
|
334
|
+
```xml
|
|
335
|
+
<DocViewer documents={docs} language="pl" />
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
The translations are based on the `.json` files that can be found in the `src/locales` directory.
|
|
339
|
+
|
|
340
|
+
## Styling
|
|
341
|
+
|
|
342
|
+
Any styling applied to the `<DocViewer>` component, is directly applied to the main `div` container.
|
|
343
|
+
|
|
344
|
+
### CSS Class
|
|
345
|
+
|
|
346
|
+
```xml
|
|
347
|
+
<DocViewer documents={docs} className="my-doc-viewer-style" />
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### CSS Class Default Override
|
|
351
|
+
|
|
352
|
+
Each component / div already has a DOM id that can be used to style any part of the document viewer.
|
|
353
|
+
|
|
354
|
+
```css
|
|
355
|
+
#react-doc-viewer #header-bar {
|
|
356
|
+
background-color: #faf;
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### React Inline
|
|
361
|
+
|
|
362
|
+
```xml
|
|
363
|
+
<DocViewer documents={docs} style={{ width: 500, height: 500 }} />
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Styled Components
|
|
367
|
+
|
|
368
|
+
```tsx
|
|
369
|
+
import styled from "styled-components";
|
|
370
|
+
|
|
371
|
+
// ...
|
|
372
|
+
|
|
373
|
+
<MyDocViewer documents={docs} />;
|
|
374
|
+
|
|
375
|
+
// ...
|
|
376
|
+
|
|
377
|
+
const MyDocViewer = styled(DocViewer)`
|
|
378
|
+
border-radius: 10px;
|
|
379
|
+
`;
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
## Using DocViewerRef
|
|
383
|
+
|
|
384
|
+
Since **v1.13.0** you can control the display of the document with `reference`.
|
|
385
|
+
|
|
386
|
+
```tsx
|
|
387
|
+
import DocViewer, { DocViewerRef } from "@mehuljariwala/react-doc-viewer";
|
|
388
|
+
|
|
389
|
+
export const UsingRef = () => {
|
|
390
|
+
const docViewerRef = useRef<DocViewerRef>(null);
|
|
391
|
+
|
|
392
|
+
return (
|
|
393
|
+
<>
|
|
394
|
+
<div>
|
|
395
|
+
<button onClick={() => docViewerRef?.current?.prev()}>
|
|
396
|
+
Prev Document By Ref
|
|
397
|
+
</button>
|
|
398
|
+
<button onClick={() => docViewerRef?.current?.next()}>
|
|
399
|
+
Next Document By Ref
|
|
400
|
+
</button>
|
|
401
|
+
</div>
|
|
402
|
+
<DocViewer
|
|
403
|
+
ref={docViewerRef}
|
|
404
|
+
documents={docs}
|
|
405
|
+
config={{ header: { disableHeader: true } }}
|
|
406
|
+
/>
|
|
407
|
+
</>
|
|
408
|
+
);
|
|
409
|
+
};
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Config
|
|
413
|
+
|
|
414
|
+
You can provide a config object, which configures parts of the component as required.
|
|
415
|
+
|
|
416
|
+
```tsx
|
|
417
|
+
<DocViewer
|
|
418
|
+
documents={docs}
|
|
419
|
+
config={{
|
|
420
|
+
header: {
|
|
421
|
+
disableHeader: false,
|
|
422
|
+
disableFileName: false,
|
|
423
|
+
retainURLParams: false,
|
|
424
|
+
},
|
|
425
|
+
csvDelimiter: ",", // "," as default,
|
|
426
|
+
pdfZoom: {
|
|
427
|
+
defaultZoom: 1.1, // 1 as default,
|
|
428
|
+
zoomJump: 0.2, // 0.1 as default,
|
|
429
|
+
},
|
|
430
|
+
pdfVerticalScrollByDefault: true, // false as default
|
|
431
|
+
}}
|
|
432
|
+
/>
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Overriding Header Component
|
|
436
|
+
|
|
437
|
+
You can pass a callback function to `config.header.overrideComponent` that returns a React Element. The function's parameters will be populated and usable, this function will also be re-called whenever the mainState updates.
|
|
438
|
+
Parameters include the state object from the main component, and document navigation functions for `previousDocument` and `nextDocument`.
|
|
439
|
+
|
|
440
|
+
Example:
|
|
441
|
+
|
|
442
|
+
```tsx
|
|
443
|
+
const MyHeader: IHeaderOverride = (state, previousDocument, nextDocument) => {
|
|
444
|
+
if (!state.currentDocument || state.config?.header?.disableFileName) {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return (
|
|
449
|
+
<>
|
|
450
|
+
<div>{state.currentDocument.uri || ""}</div>
|
|
451
|
+
<div>
|
|
452
|
+
<button onClick={previousDocument} disabled={state.currentFileNo === 0}>
|
|
453
|
+
Previous Document
|
|
454
|
+
</button>
|
|
455
|
+
<button
|
|
456
|
+
onClick={nextDocument}
|
|
457
|
+
disabled={state.currentFileNo >= state.documents.length - 1}
|
|
458
|
+
>
|
|
459
|
+
Next Document
|
|
460
|
+
</button>
|
|
461
|
+
</div>
|
|
462
|
+
</>
|
|
463
|
+
);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
<DocViewer
|
|
467
|
+
pluginRenderers={DocViewerRenderers}
|
|
468
|
+
documents={
|
|
469
|
+
{
|
|
470
|
+
// ...
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
config={{
|
|
474
|
+
header: {
|
|
475
|
+
overrideComponent: MyHeader,
|
|
476
|
+
},
|
|
477
|
+
}}
|
|
478
|
+
/>;
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### Overriding Loading Renderer
|
|
482
|
+
|
|
483
|
+
You can pass a callback function to `config.loadingRenderer.overrideComponent` that returns a React Element.
|
|
484
|
+
|
|
485
|
+
Example:
|
|
486
|
+
|
|
487
|
+
```tsx
|
|
488
|
+
const MyLoadingRenderer = ({ document, fileName }) => {
|
|
489
|
+
const fileText = fileName || document?.fileType || "";
|
|
490
|
+
|
|
491
|
+
if (fileText) {
|
|
492
|
+
return <div>Loading Renderer ({fileText})...</div>;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return <div>Loading Renderer...</div>;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
<DocViewer
|
|
499
|
+
pluginRenderers={DocViewerRenderers}
|
|
500
|
+
documents={
|
|
501
|
+
{
|
|
502
|
+
// ...
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
config={{
|
|
506
|
+
loadingRenderer: {
|
|
507
|
+
overrideComponent: MyLoadingRenderer,
|
|
508
|
+
},
|
|
509
|
+
}}
|
|
510
|
+
/>;
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
By default, the loading component is rendered if document loading process takes more than 500 ms.
|
|
514
|
+
|
|
515
|
+
You can change this time value or disable this feature to make the component display immediately:
|
|
516
|
+
|
|
517
|
+
```tsx
|
|
518
|
+
const MyLoadingRenderer = ({ document, fileName }) => {
|
|
519
|
+
...
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
<DocViewer
|
|
523
|
+
pluginRenderers={DocViewerRenderers}
|
|
524
|
+
documents={
|
|
525
|
+
{
|
|
526
|
+
// ...
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
config={{
|
|
530
|
+
loadingRenderer: {
|
|
531
|
+
overrideComponent: MyLoadingRenderer,
|
|
532
|
+
showLoadingTimeout: false, // false if you want to disable or number to provide your own value (ms)
|
|
533
|
+
},
|
|
534
|
+
}}
|
|
535
|
+
/>;
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### Overriding No Renderer (Error)
|
|
539
|
+
|
|
540
|
+
You can pass a callback function to `config.noRenderer.overrideComponent` that returns a React Element.
|
|
541
|
+
|
|
542
|
+
Example:
|
|
543
|
+
|
|
544
|
+
```tsx
|
|
545
|
+
const MyNoRenderer = ({ document, fileName }) => {
|
|
546
|
+
const fileText = fileName || document?.fileType || "";
|
|
547
|
+
|
|
548
|
+
if (fileText) {
|
|
549
|
+
return <div>No Renderer Error! ({fileText})</div>;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return <div>No Renderer Error!</div>;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
<DocViewer
|
|
556
|
+
pluginRenderers={DocViewerRenderers}
|
|
557
|
+
documents={
|
|
558
|
+
{
|
|
559
|
+
// ...
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
config={{
|
|
563
|
+
noRenderer: {
|
|
564
|
+
overrideComponent: MyNoRenderer,
|
|
565
|
+
},
|
|
566
|
+
}}
|
|
567
|
+
/>;
|
|
568
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { default as React, CSSProperties } from 'react';
|
|
2
|
+
import { AvailableLanguages } from './i18n';
|
|
3
|
+
import { DocRenderer, DocViewerRef, IConfig, IDocument, ITheme } from './models';
|
|
4
|
+
|
|
5
|
+
export interface DocViewerProps {
|
|
6
|
+
documents: IDocument[];
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
config?: IConfig;
|
|
10
|
+
theme?: ITheme;
|
|
11
|
+
pluginRenderers?: DocRenderer[];
|
|
12
|
+
prefetchMethod?: string;
|
|
13
|
+
requestHeaders?: Record<string, string>;
|
|
14
|
+
initialActiveDocument?: IDocument;
|
|
15
|
+
language?: AvailableLanguages;
|
|
16
|
+
activeDocument?: IDocument;
|
|
17
|
+
onDocumentChange?: (document: IDocument) => void;
|
|
18
|
+
jumpToPage?: number;
|
|
19
|
+
}
|
|
20
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<DocViewerProps & React.RefAttributes<DocViewerRef>>>;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IStyledProps } from '../..';
|
|
2
|
+
|
|
3
|
+
interface ButtonProps extends IStyledProps {
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const ButtonPrimaryStyle: import('styled-components').RuleSet<object>;
|
|
7
|
+
export declare const ButtonSecondaryStyle: import('styled-components').RuleSet<object>;
|
|
8
|
+
export declare const Button: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, ButtonProps>> & string;
|
|
9
|
+
export declare const LinkButton: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, never>> & string;
|
|
10
|
+
export declare const ButtonPrimary: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<Omit<import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, keyof ButtonProps> & ButtonProps, "ref"> & {
|
|
11
|
+
ref?: ((instance: HTMLButtonElement | null) => void) | import('react').RefObject<HTMLButtonElement> | null | undefined;
|
|
12
|
+
}, never>> & string;
|
|
13
|
+
export declare const ButtonSecondary: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<Omit<import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, keyof ButtonProps> & ButtonProps, "ref"> & {
|
|
14
|
+
ref?: ((instance: HTMLButtonElement | null) => void) | import('react').RefObject<HTMLButtonElement> | null | undefined;
|
|
15
|
+
}, never>> & string;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Button';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface IIconProps {
|
|
2
|
+
color?: string;
|
|
3
|
+
size?: string | number | string | undefined;
|
|
4
|
+
reverse?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const PrevDocIcon: (props: IIconProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const NextDocIcon: (props: IIconProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const LoadingIcon: (props: IIconProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null;exports.default=e;
|