-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathModalExample.tsx
115 lines (104 loc) · 3.46 KB
/
ModalExample.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import { Viewer } from '@react-pdf-viewer/core';
import { printPlugin, RenderPrintProps } from '@react-pdf-viewer/print';
import '@react-pdf-viewer/core/lib/styles/index.css';
import '@react-pdf-viewer/print/lib/styles/index.css';
import './modalExample.css';
interface ModalExampleProps {
fileUrl: string;
}
const ModalExample: React.FC<ModalExampleProps> = ({ fileUrl }) => {
const [shown, setShown] = useState(false);
const printPluginInstance = printPlugin();
const { Print } = printPluginInstance;
const modalBody = () => (
<div
className="example-modal"
style={{
backgroundColor: '#fff',
flexDirection: 'column',
overflow: 'hidden',
/* Fixed position */
left: 0,
position: 'fixed',
top: 0,
/* Take full size */
height: '100%',
width: '100%',
/* Displayed on top of other elements */
zIndex: 9999,
}}
>
<div
style={{
alignItems: 'center',
backgroundColor: '#000',
color: '#fff',
display: 'flex',
padding: '.5rem',
}}
>
<div style={{ marginRight: 'auto' }}>sample-file-name.pdf</div>
<Print>
{(props: RenderPrintProps) => (
<button
style={{
backgroundColor: '#357edd',
border: 'none',
borderRadius: '4px',
color: '#ffffff',
cursor: 'pointer',
padding: '8px',
}}
onClick={props.onClick}
>
Print
</button>
)}
</Print>
<button
style={{
backgroundColor: '#357edd',
border: 'none',
borderRadius: '4px',
color: '#ffffff',
cursor: 'pointer',
marginLeft: '12px',
padding: '8px',
}}
onClick={() => setShown(false)}
>
Close
</button>
</div>
<div
style={{
flexGrow: 1,
overflow: 'auto',
}}
>
<Viewer fileUrl={fileUrl} plugins={[printPluginInstance]} />
</div>
</div>
);
return (
<>
<button
style={{
backgroundColor: '#00449e',
border: 'none',
borderRadius: '.25rem',
color: '#fff',
cursor: 'pointer',
padding: '.5rem',
}}
onClick={() => setShown(true)}
>
Open modal
</button>
{shown && ReactDOM.createPortal(modalBody(), document.body)}
</>
);
};
export default ModalExample;