-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fi1osof
committed
May 14, 2019
1 parent
f104198
commit 1066ae7
Showing
5 changed files
with
200 additions
and
1 deletion.
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
188 changes: 188 additions & 0 deletions
188
src/components/Renderer/pages/Root/components/PdfView/index.js
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,188 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
|
||
import EditorComponent from "@prisma-cms/front-editor/lib/components/App/components/"; | ||
|
||
|
||
import { Document, Page } from 'react-pdf'; | ||
import { Button } from 'material-ui'; | ||
import { Typography } from 'material-ui'; | ||
|
||
|
||
class PdfView extends EditorComponent { | ||
|
||
static defaultProps = { | ||
...EditorComponent.defaultProps, | ||
pages: 1, | ||
page_width: 800, | ||
scale: 1, | ||
show_pages: true, | ||
style: { | ||
...EditorComponent.defaultProps.style, | ||
overflow: "auto", | ||
maxWidth: 805, | ||
marginLeft: "auto", | ||
marginRight: "auto", | ||
} | ||
} | ||
|
||
static Name = "PdfView" | ||
|
||
|
||
constructor(props) { | ||
|
||
super(props); | ||
|
||
this.state = { | ||
...this.state, | ||
numPages: null, | ||
pageNumber: 1, | ||
showAll: false, | ||
} | ||
|
||
} | ||
|
||
onDocumentLoadSuccess(state) { | ||
|
||
const { | ||
numPages, | ||
} = state; | ||
|
||
this.setState({ | ||
numPages, | ||
}); | ||
} | ||
|
||
renderPanelView() { | ||
|
||
const { | ||
classes, | ||
} = this.getEditorContext(); | ||
|
||
return super.renderPanelView(<div | ||
className={classes.panelButton} | ||
> | ||
PdfView | ||
</div>); | ||
} | ||
|
||
|
||
renderChildren() { | ||
|
||
// return <MyApp /> | ||
|
||
const { | ||
pageNumber, | ||
numPages, | ||
showAll, | ||
} = this.state; | ||
|
||
const { | ||
pages, | ||
src: file, | ||
page_width, | ||
scale, | ||
show_pages, | ||
...other | ||
} = this.getComponentProps(this); | ||
|
||
|
||
const { | ||
inEditMode, | ||
} = this.getEditorContext(); | ||
|
||
|
||
if (!file) { | ||
|
||
if (inEditMode) { | ||
return <Typography | ||
color="error" | ||
> | ||
src property required | ||
</Typography> | ||
} | ||
else { | ||
return null; | ||
} | ||
|
||
} | ||
|
||
|
||
let pagesList = []; | ||
|
||
if (pageNumber > 0) { | ||
|
||
for (var i = pageNumber; i < numPages; i++) { | ||
|
||
pagesList.push(<Page | ||
key={i} | ||
pageNumber={i} | ||
{...this.getPageProps()} | ||
/>); | ||
|
||
if (!showAll && pages > 0 && pagesList.length >= pages) { | ||
break; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
return <Fragment> | ||
|
||
<Document | ||
file={file} | ||
onLoadSuccess={state => this.onDocumentLoadSuccess(state)} | ||
{...this.getDocumentProps()} | ||
> | ||
{pagesList} | ||
</Document> | ||
|
||
{show_pages && !showAll ? | ||
<div | ||
style={{ | ||
textAlign: "center", | ||
}} | ||
> | ||
Page {pageNumber} of {numPages}. <Button | ||
size="small" | ||
onClick={event => { | ||
this.setState({ | ||
showAll: true, | ||
}); | ||
}} | ||
> | ||
Show all | ||
</Button> | ||
</div> | ||
: null | ||
} | ||
|
||
</Fragment> | ||
|
||
} | ||
|
||
|
||
getDocumentProps() { | ||
return {}; | ||
} | ||
|
||
|
||
getPageProps() { | ||
|
||
const { | ||
page_width: width, | ||
scale, | ||
} = this.getComponentProps(this); | ||
|
||
return { | ||
width, | ||
scale, | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
export default PdfView; |
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