Skip to content

Commit 49e08f5

Browse files
Fixed Zoomout & Zoomin button disable issue
1 parent b78ff8d commit 49e08f5

7 files changed

Lines changed: 33 additions & 9 deletions

File tree

dist/pdf-viewer-reactjs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"husky": {
6363
"hooks": {
64-
"pre-commit": "npm run lint && npm run build"
64+
"pre-commit": "npm run lint && npm run build && git add -A"
6565
}
6666
}
6767
}

src/components/NavigationBar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const Navigation = ({
4141
<ZoomOut
4242
scale={scale}
4343
minScale={minScale}
44+
defaultScale={defaultScale}
4445
css={css.zoomOutBtn}
4546
handleZoomOut={handleZoomOut}
4647
/>
@@ -53,6 +54,7 @@ const Navigation = ({
5354
<ZoomIn
5455
scale={scale}
5556
maxScale={maxScale}
57+
defaultScale={defaultScale}
5658
css={css.zoomInBtn}
5759
handleZoomIn={handleZoomIn}
5860
/>

src/components/navigationComponents/ResetZoom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ResetZoom = ({ css, scale, defaultScale, handleResetZoom }) => {
66
css ||
77
'button is-black is-marginless has-margin-left-5 has-margin-right-5'
88

9-
if (scale === defaultScale) {
9+
if (scale.toFixed(2) === defaultScale.toFixed(2)) {
1010
return (
1111
<button className={resetZoomClass} disabled>
1212
<span className='icon is-small'>

src/components/navigationComponents/ZoomIn.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33

4-
const ZoomIn = ({ css, scale, maxScale, handleZoomIn }) => {
4+
const ZoomIn = ({ css, scale, defaultScale, maxScale, handleZoomIn }) => {
55
const zoomInClass =
66
css ||
77
'button is-black is-marginless has-margin-left-5 has-margin-right-5'
88

9-
if (scale === maxScale) {
9+
let checkScale = maxScale
10+
if (defaultScale > maxScale) {
11+
checkScale = defaultScale
12+
}
13+
14+
if (scale.toFixed(2) === checkScale.toFixed(2)) {
1015
return (
1116
<button className={zoomInClass} disabled>
1217
<span className='icon is-small'>
@@ -28,6 +33,7 @@ const ZoomIn = ({ css, scale, maxScale, handleZoomIn }) => {
2833
ZoomIn.propTypes = {
2934
css: PropTypes.string,
3035
scale: PropTypes.number.isRequired,
36+
defaultScale: PropTypes.number.isRequired,
3137
maxScale: PropTypes.number.isRequired,
3238
handleZoomIn: PropTypes.func.isRequired,
3339
}

src/components/navigationComponents/ZoomOut.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33

4-
const ZoomOut = ({ css, scale, minScale, handleZoomOut }) => {
4+
const ZoomOut = ({ css, scale, defaultScale, minScale, handleZoomOut }) => {
55
const zoomOutClass =
66
css ||
77
'button is-black is-marginless has-margin-left-5 has-margin-right-5'
88

9-
if (scale === minScale) {
9+
let checkScale = minScale
10+
if (defaultScale < minScale) {
11+
checkScale = defaultScale
12+
}
13+
14+
if (scale.toFixed(2) === checkScale.toFixed(2)) {
1015
return (
1116
<button className={zoomOutClass} disabled>
1217
<span className='icon is-small'>
@@ -28,6 +33,7 @@ const ZoomOut = ({ css, scale, minScale, handleZoomOut }) => {
2833
ZoomOut.propTypes = {
2934
css: PropTypes.string,
3035
scale: PropTypes.number.isRequired,
36+
defaultScale: PropTypes.number.isRequired,
3137
minScale: PropTypes.number.isRequired,
3238
handleZoomOut: PropTypes.func.isRequired,
3339
}

src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ class PDFViewer extends React.Component {
6161
}
6262

6363
handleZoomIn() {
64-
if (this.state.scale < this.props.maxScale) {
64+
let checkScale = this.props.maxScale
65+
if (this.state.defaultScale > this.props.maxScale) {
66+
checkScale = this.state.defaultScale
67+
}
68+
69+
if (this.state.scale < checkScale) {
6570
this.setState({
6671
scale: this.state.scale + this.props.scaleStep,
6772
})
@@ -83,7 +88,12 @@ class PDFViewer extends React.Component {
8388
}
8489

8590
handleZoomOut() {
86-
if (this.state.scale > this.props.minScale) {
91+
let checkScale = this.props.minScale
92+
if (this.state.defaultScale < this.props.minScale) {
93+
checkScale = this.state.defaultScale
94+
}
95+
96+
if (this.state.scale > checkScale) {
8797
this.setState({
8898
scale: this.state.scale - this.props.scaleStep,
8999
})

0 commit comments

Comments
 (0)