enoviq-react-document-viewer
Version:
Custom React & Next.js compatible document viewer package
189 lines (145 loc) • 5.21 kB
Markdown
is a package that allows you to easily add document viewer functionality to your React applications.
You can install Enoviq React Document Viewer using npm:
```
npm install enoviq-react-document-viewer
```
or
```
yarn add enoviq-react-document-viewer
```
How to use in your code.
```
import ENDocumentPreview from "enoviq-react-document-viewer";
```
then you can call this in component like this.
```
<ENDocumentPreview file={"/Images/logo.jpg"} />
```
| Prop | Type | Required | Description |
| -------------- | ----------- | -------- | --------------------------------------- |
| `file` | string | ✅ | Path to the document file |
| `openFile` | boolean | ❌ | Controls popup visibility |
| `onClose` | function | ❌ | Callback function to close the popup |
| `customWidget` | JSX.Element | ❌ | Custom content to display in the viewer |
The following file types are supported by Enoviq React Document Viewer.
| File Type | Base64 | URL | Blob |
| ---------------- | ------ | --- | ---- |
| PDF | ✔ | ✔ | ✔ |
| Image | ✔ | ✔ | ✔ |
| Video | ✔ | ✔ | ✔ |
| Office Documents | ✔ | ✔ | ✔ |
| CSV, TXT, etc. | ✔ | ✔ | ✔ |
You can pass a custom widget to replace the default icon.
```jsx
<ENDocumentPreview
file={"/Images/logo.jpg"}
customWidget={<div> Custom Icon </div>}
/>
```
make a useState variable to handle the state.
pass open and onClose for
```jsx
<ENDocumentPreview
file="/Images/loginB2.jpg"
openFile={isOpen}
onClose={handleCloseDocument}
customWidget={
<>
<h1>Document Preview</h1>
<p>Custom header content</p>
</>
}
/>
```
```jsx
import React, { useState } from 'react';
import ENDocumentPreview from "enoviq-react-document-viewer";
function App() {
const [isOpen, setIsOpen] = useState(false);
const handleOpenDocument = () => {
setIsOpen(true);
};
const handleCloseDocument = () => {
setIsOpen(false);
};
return (
<div className="innerBody">
<div className="dataBody">
{/* Custom Trigger Button */}
<button
onClick={handleOpenDocument}
className="open-document-btn"
>
Open Document
</button>
{/* Document Preview */}
<ENDocumentPreview
file="/Images/loginB2.jpg"
openFile={isOpen}
onClose={handleCloseDocument}
customWidget={
<>
<h1>Document Preview</h1>
<p>Custom header content</p>
</>
}
/>
</div>
</div>
);
}
export default App;
````
add this in global css
```css
:global(:root) .body {
/* Primary Brand */
--react-doc-viewer-color-primary:
--react-doc-viewer-color-primary-hover:
/* Base Colors */
--react-doc-viewer-color-white:
--react-doc-viewer-color-black:
/* Text Colors */
--react-doc-viewer-color-text:
--react-doc-viewer-color-text-muted:
--react-doc-viewer-color-text-light:
--react-doc-viewer-color-text-dark:
--react-doc-viewer-color-text-error:
--react-doc-viewer-color-text-error-muted:
/* Backgrounds */
--react-doc-viewer-color-bg:
--react-doc-viewer-color-bg-muted:
--react-doc-viewer-color-bg-overlay: rgba(0, 0, 0, 0.5);
--react-doc-viewer-color-bg-overlay-strong: rgba(0, 0, 0, 0.8);
--react-doc-viewer-color-bg-card:
--react-doc-viewer-color-bg-error:
/* Borders */
--react-doc-viewer-color-border:
--react-doc-viewer-color-border-light:
--react-doc-viewer-color-border-error:
/* Download Section */
--react-doc-viewer-color-download-bg:
--react-doc-viewer-color-download-border:
/* States */
--react-doc-viewer-color-spinner-track:
--react-doc-viewer-color-spinner-active:
/* Shadows */
--react-doc-viewer-shadow-soft: 0 2px 6px rgba(0, 0, 0, 0.08);
--react-doc-viewer-shadow-medium: 0 4px 12px rgba(0, 0, 0, 0.1);
--react-doc-viewer-shadow-strong: 0 25px 50px rgba(0, 0, 0, 0.3);
}
```
1. **State Management**: Always use `useState` to control the popup state
2. **Error Handling**: Implement error handling for file loading failures
3. **Performance**: Consider lazy loading for large documents
4. **Accessibility**: Ensure proper ARIA labels for screen readers
5. **Mobile Responsiveness**: Test on different screen sizes
Enoviq React Document Viewer