@zerohive/hive-viewer 0.2.1 → 0.2.3
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/README.md +123 -6
- package/dist/index.cjs +618 -424
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +620 -423
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +620 -423
- package/dist/styles.css +75 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
+
# ModalViewer Usage Example
|
|
2
|
+
|
|
3
|
+
You can use the ModalViewer component to display any content (such as DocumentViewer) in a modal dialog. Here is a simple example:
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
import { ModalViewer } from './src/components/ModalViewer';
|
|
8
|
+
import { DocumentViewer } from './src/components/DocumentViewer';
|
|
9
|
+
import './src/components/ModalViewer.css';
|
|
10
|
+
|
|
11
|
+
export default function App() {
|
|
12
|
+
const [open, setOpen] = useState(false);
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<button onClick={() => setOpen(true)}>Open Document Modal</button>
|
|
16
|
+
<ModalViewer open={open} onClose={() => setOpen(false)}>
|
|
17
|
+
<DocumentViewer url="/path/to/document.pdf" />
|
|
18
|
+
</ModalViewer>
|
|
19
|
+
</>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Props:**
|
|
25
|
+
|
|
26
|
+
- `open` (boolean): Whether the modal is visible.
|
|
27
|
+
- `onClose` (function): Called when the modal requests to close (overlay click, ESC, close button).
|
|
28
|
+
- `children` (ReactNode): Content to display inside the modal.
|
|
29
|
+
- `ariaLabel` (optional string): Accessibility label for the modal dialog.
|
|
30
|
+
|
|
31
|
+
**Styling:**
|
|
32
|
+
|
|
33
|
+
Import `ModalViewer.css` for default modal styles, or customize as needed.
|
|
1
34
|
# @zerohive/hive-viewer
|
|
2
35
|
|
|
3
36
|
A self-hostable, browser-first document viewer/editor for React and Next.js.
|
|
@@ -11,13 +44,15 @@ npm i @zerohive/hive-viewer
|
|
|
11
44
|
Import styles once in your app:
|
|
12
45
|
|
|
13
46
|
```ts
|
|
14
|
-
import
|
|
47
|
+
import "@zerohive/hive-viewer/styles.css";
|
|
15
48
|
```
|
|
16
49
|
|
|
17
50
|
## Usage
|
|
18
51
|
|
|
52
|
+
### Basic Usage
|
|
53
|
+
|
|
19
54
|
```tsx
|
|
20
|
-
import { DocumentViewer } from
|
|
55
|
+
import { DocumentViewer } from "@zerohive/hive-viewer";
|
|
21
56
|
|
|
22
57
|
export default function Page() {
|
|
23
58
|
return (
|
|
@@ -28,17 +63,99 @@ export default function Page() {
|
|
|
28
63
|
fileType="pdf"
|
|
29
64
|
allowSigning
|
|
30
65
|
onSignRequest={async () => ({
|
|
31
|
-
signatureImageUrl:
|
|
32
|
-
signedBy:
|
|
66
|
+
signatureImageUrl: "https://.../sig.png",
|
|
67
|
+
signedBy: "Jane Doe",
|
|
33
68
|
dateSigned: new Date().toISOString(),
|
|
34
|
-
comment:
|
|
69
|
+
comment: "Approved",
|
|
35
70
|
})}
|
|
36
|
-
onSave={(b64, meta) => {
|
|
71
|
+
onSave={(b64, meta) => {
|
|
72
|
+
/* persist */
|
|
73
|
+
}}
|
|
37
74
|
/>
|
|
38
75
|
);
|
|
39
76
|
}
|
|
40
77
|
```
|
|
41
78
|
|
|
79
|
+
### Using in a Modal (Recommended)
|
|
80
|
+
|
|
81
|
+
Most consumers use the viewer in a modal dialog. Here is a recommended pattern:
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import React, { useState } from "react";
|
|
85
|
+
import { DocumentViewer } from "@zerohive/hive-viewer";
|
|
86
|
+
|
|
87
|
+
function ModalDocViewer({ open, onClose, fileUrl, fileName, fileType }) {
|
|
88
|
+
if (!open) return null;
|
|
89
|
+
return (
|
|
90
|
+
<div
|
|
91
|
+
style={{
|
|
92
|
+
position: "fixed",
|
|
93
|
+
inset: 0,
|
|
94
|
+
background: "rgba(0,0,0,0.45)",
|
|
95
|
+
zIndex: 1000,
|
|
96
|
+
display: "flex",
|
|
97
|
+
alignItems: "center",
|
|
98
|
+
justifyContent: "center",
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
<div
|
|
102
|
+
style={{
|
|
103
|
+
background: "#fff",
|
|
104
|
+
borderRadius: 16,
|
|
105
|
+
maxWidth: "90vw",
|
|
106
|
+
maxHeight: "90vh",
|
|
107
|
+
overflow: "auto",
|
|
108
|
+
position: "relative",
|
|
109
|
+
padding: 0,
|
|
110
|
+
boxShadow: "0 8px 32px rgba(0,0,0,0.25)",
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<button
|
|
114
|
+
onClick={onClose}
|
|
115
|
+
aria-label="Close"
|
|
116
|
+
style={{
|
|
117
|
+
position: "absolute",
|
|
118
|
+
top: 12,
|
|
119
|
+
right: 16,
|
|
120
|
+
background: "none",
|
|
121
|
+
border: "none",
|
|
122
|
+
fontSize: "2rem",
|
|
123
|
+
color: "#888",
|
|
124
|
+
cursor: "pointer",
|
|
125
|
+
zIndex: 1,
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
×
|
|
129
|
+
</button>
|
|
130
|
+
<DocumentViewer
|
|
131
|
+
mode="view"
|
|
132
|
+
fileUrl={fileUrl}
|
|
133
|
+
fileName={fileName}
|
|
134
|
+
fileType={fileType}
|
|
135
|
+
/>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Usage example:
|
|
142
|
+
export default function Example() {
|
|
143
|
+
const [open, setOpen] = useState(false);
|
|
144
|
+
return (
|
|
145
|
+
<>
|
|
146
|
+
<button onClick={() => setOpen(true)}>Open Document</button>
|
|
147
|
+
<ModalDocViewer
|
|
148
|
+
open={open}
|
|
149
|
+
onClose={() => setOpen(false)}
|
|
150
|
+
fileUrl="https://example.com/my.pdf"
|
|
151
|
+
fileName="my.pdf"
|
|
152
|
+
fileType="pdf"
|
|
153
|
+
/>
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
42
159
|
## Signing Workflow (decoupled)
|
|
43
160
|
|
|
44
161
|
- If `allowSigning={true}`, the toolbar shows **Sign Document**.
|