Skip to content

Commit 82d7b6a

Browse files
Added onPrevBtnClick and onNextBtnClick functions for page navigation
1 parent 313a006 commit 82d7b6a

7 files changed

Lines changed: 91 additions & 2036 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ React component prop. types:
100100
- Required: **false**
101101
- Description: A function that will be called only on clicking the PDF page itself, NOT on the navbar
102102

103+
- `onPrevBtnClick`:
104+
105+
- Type: _Function_
106+
- Required: **false**
107+
- Description: A function that will be called on clicking on the previous page button, page number can be accessed in the function.
108+
109+
- `onNextBtnClick`:
110+
111+
- Type: _Function_
112+
- Required: **false**
113+
- Description: A function that will be called on clicking on the next page button, page number can be accessed in the function.
114+
103115
- `css`:
104116

105117
- Type: _String_

dist/pdf-viewer-reactjs.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,12 +524,14 @@ var PDFViewer = function (_React$Component) {
524524
_this.setState({
525525
page: _this.state.page - 1
526526
});
527+
_this.props.onPrevBtnClick(_this.state.page - 1);
527528
}, _this.handleNextClick = function () {
528529
if (_this.state.page === _this.state.pages) return;
529530

530531
_this.setState({
531532
page: _this.state.page + 1
532533
});
534+
_this.props.onNextBtnClick(_this.state.page + 1);
533535
}, _this.handleZoomIn = function () {
534536
if (_this.state.scale < _this.state.maxScale) {
535537
_this.setState({
@@ -718,6 +720,8 @@ PDFViewer.propTypes = {
718720
canvasCss: PropTypes.string,
719721
rotationAngle: PropTypes.number,
720722
onDocumentClick: PropTypes.func,
723+
onPrevBtnClick: PropTypes.func,
724+
onNextBtnClick: PropTypes.func,
721725
hideNavbar: PropTypes.bool,
722726
navbarOnTop: PropTypes.bool,
723727
hideZoom: PropTypes.bool,

example/package-lock.json

Lines changed: 66 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ const WithCustomNavigation = () => (
127127
const WithOnDocumentClick = () => (
128128
<div className="col-md-auto text-center">
129129
<h1 className="text-white bg-info rounded">
130-
With onDocumentClick handler
130+
With onDocumentClick, onPrevBtnClick and onNextBtnClick handler
131131
</h1>
132132
<div className="border rounded">
133133
<PDFViewer
134134
document={{
135135
url: sources.url
136136
}}
137137
onDocumentClick={() => alert('Document was clicked')}
138+
onPrevBtnClick={page => alert(`Page ${page} was selected`)}
139+
onNextBtnClick={page => alert(`Page ${page} was selected`)}
138140
/>
139141
</div>
140142
</div>

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"pdf",
4444
"pdf viewer",
4545
"rotate",
46+
"rotate pdf",
4647
"zoom",
48+
"zoom pdf",
4749
"react",
4850
"reactjs"
4951
]

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PDFViewer extends React.Component {
4242
this.setState({
4343
page: this.state.page - 1
4444
});
45+
this.props.onPrevBtnClick(this.state.page - 1);
4546
};
4647

4748
handleNextClick = () => {
@@ -50,6 +51,7 @@ class PDFViewer extends React.Component {
5051
this.setState({
5152
page: this.state.page + 1
5253
});
54+
this.props.onNextBtnClick(this.state.page + 1);
5355
};
5456

5557
handleZoomIn = () => {
@@ -228,6 +230,8 @@ PDFViewer.propTypes = {
228230
canvasCss: PropTypes.string,
229231
rotationAngle: PropTypes.number,
230232
onDocumentClick: PropTypes.func,
233+
onPrevBtnClick: PropTypes.func,
234+
onNextBtnClick: PropTypes.func,
231235
hideNavbar: PropTypes.bool,
232236
navbarOnTop: PropTypes.bool,
233237
hideZoom: PropTypes.bool,

0 commit comments

Comments
 (0)