@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
42 lines (41 loc) • 1.2 kB
JavaScript
import { jsxs as f, jsx as m } from "react/jsx-runtime";
import { createContext as d, useRef as x, useContext as C } from "react";
import { useDocumentContext as F } from "./RPDocumentContext.js";
import { useDocumentPasswordContext as h } from "./DocumentPasswordContext.js";
const s = d(null), y = ({ children: t }) => {
const { setFilename: i, setPdfSrc: c } = F(), o = x(null), {
setPassword: l
} = h(), u = () => {
var e;
(e = o.current) == null || e.click();
}, p = (e) => {
var r;
const n = (r = e.target.files) == null ? void 0 : r[0];
if (!n || n.type !== "application/pdf")
return;
const a = URL.createObjectURL(n);
i(n.name), c(a), e.target.value = "", l("");
};
return /* @__PURE__ */ f(s.Provider, { value: { openFile: u }, children: [
t,
/* @__PURE__ */ m(
"input",
{
accept: "application/pdf",
type: "file",
ref: o,
style: { display: "none" },
onChange: p
}
)
] });
}, I = () => {
const t = C(s);
if (!t)
throw new Error("useOpenFileContext must be used within FileInputProvider");
return t;
};
export {
y as FileInputProvider,
I as useOpenFileContext
};