-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: View PDF document preview when adding a document
And add react-pdf to deps. The version number is intended to be synchronized with the version present in cozy-viewer.
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { useEffect, useRef, useState } from 'react' | ||
import { Document, Page } from 'react-pdf' | ||
|
||
interface PdfOverviewProps { | ||
file: File | ||
} | ||
|
||
const styles = { | ||
container: { | ||
width: '100%', | ||
display: 'flex', | ||
justifyContent: 'center' | ||
} | ||
} | ||
|
||
export const PdfOverview: React.FC<PdfOverviewProps> = ({ | ||
file | ||
}: PdfOverviewProps) => { | ||
const parentRef = useRef<HTMLDivElement | null>(null) | ||
const [parentWidth, setParentWidth] = useState(0) | ||
|
||
useEffect(() => { | ||
const updateSize = (): void => { | ||
if (parentRef.current) { | ||
const width = parentRef.current.getBoundingClientRect().width | ||
setParentWidth(width) | ||
} | ||
} | ||
updateSize() | ||
}, []) | ||
|
||
return ( | ||
<div style={styles.container} ref={parentRef}> | ||
<Document file={file}> | ||
<Page pageNumber={1} width={parentWidth} /> | ||
</Document> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3052,6 +3052,14 @@ | |
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.4.tgz#15925414e0ad2cd765bfef58842f7e26a7accb24" | ||
integrity sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug== | ||
|
||
"@types/react-pdf@^5.0.0": | ||
version "5.7.4" | ||
resolved "https://registry.yarnpkg.com/@types/react-pdf/-/react-pdf-5.7.4.tgz#031a46a13f82390f84f490e66b0d263c8b7b3728" | ||
integrity sha512-Im/HY4QhkhYcG+FJoGCy0WoGvdgYcpm+89W1lK5K9KBEQCy1YqTxhmWey5UkdnIPymmEDyeVJXdK0lPjtcvMyA== | ||
dependencies: | ||
"@types/react" "*" | ||
pdfjs-dist "^2.10.377" | ||
|
||
"@types/react-transition-group@^4.2.0": | ||
version "4.4.1" | ||
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.1.tgz#e1a3cb278df7f47f17b5082b1b3da17170bd44b1" | ||
|
@@ -6387,6 +6395,11 @@ domhandler@^4.0.0, domhandler@^4.2.0: | |
dependencies: | ||
domelementtype "^2.2.0" | ||
|
||
dommatrix@^1.0.3: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/dommatrix/-/dommatrix-1.0.3.tgz#e7c18e8d6f3abdd1fef3dd4aa74c4d2e620a0525" | ||
integrity sha512-l32Xp/TLgWb8ReqbVJAFIvXmY7go4nTxxlWiAFyhoQw9RKEOHBZNnyGvJWqDVSPmq3Y9HlM4npqF/T6VMOXhww== | ||
|
||
[email protected]: | ||
version "1.0.8" | ||
resolved "https://registry.yarnpkg.com/domready/-/domready-1.0.8.tgz#91f252e597b65af77e745ae24dd0185d5e26d58c" | ||
|
@@ -12400,6 +12413,14 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/pdfjs-dist/-/pdfjs-dist-2.12.313.tgz#62f2273737bb956267ae2e02cdfaddcb1099819c" | ||
integrity sha512-1x6iXO4Qnv6Eb+YFdN5JdUzt4pAkxSp3aLAYPX93eQCyg/m7QFzXVWJHJVtoW48CI8HCXju4dSkhQZwoheL5mA== | ||
|
||
pdfjs-dist@^2.10.377: | ||
version "2.16.105" | ||
resolved "https://registry.yarnpkg.com/pdfjs-dist/-/pdfjs-dist-2.16.105.tgz#937b9c4a918f03f3979c88209d84c1ce90122c2a" | ||
integrity sha512-J4dn41spsAwUxCpEoVf6GVoz908IAA3mYiLmNxg8J9kfRXc2jxpbUepcP0ocp0alVNLFthTAM8DZ1RaHh8sU0A== | ||
dependencies: | ||
dommatrix "^1.0.3" | ||
web-streams-polyfill "^3.2.1" | ||
|
||
performance-now@^2.1.0: | ||
version "2.1.0" | ||
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" | ||
|
@@ -15912,6 +15933,11 @@ web-resource-inliner@^4.2.1: | |
valid-data-url "^2.0.0" | ||
xtend "^4.0.2" | ||
|
||
web-streams-polyfill@^3.2.1: | ||
version "3.3.3" | ||
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz#2073b91a2fdb1fbfbd401e7de0ac9f8214cecb4b" | ||
integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw== | ||
|
||
webidl-conversions@^5.0.0: | ||
version "5.0.0" | ||
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff" | ||
|