Skip to content

Added vertical swipe and incremented version number #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 69 additions & 9 deletions dist/react-image-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return /******/ (function(modules) { // webpackBootstrap
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

'use strict';

Expand Down Expand Up @@ -80,7 +80,7 @@ return /******/ (function(modules) { // webpackBootstrap
function ImageDiff() {
_classCallCheck(this, ImageDiff);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ImageDiff).call(this));
var _this = _possibleConstructorReturn(this, (ImageDiff.__proto__ || Object.getPrototypeOf(ImageDiff)).call(this));

_this.renderFade = function () {
var style = {
Expand Down Expand Up @@ -150,9 +150,9 @@ return /******/ (function(modules) { // webpackBootstrap
key: 'handleImgLoad',
value: function handleImgLoad(e) {
if (!this.props.height && !this.props.width) {
var _e$target = e.target;
var height = _e$target.height;
var width = _e$target.width;
var _e$target = e.target,
height = _e$target.height,
width = _e$target.width;

this.setState({
height: height, width: width
Expand All @@ -167,7 +167,8 @@ return /******/ (function(modules) { // webpackBootstrap
{ className: 'ImageDiff', style: { display: 'inline-block', height: this.state.height, width: this.state.width } },
this.props.type === 'difference' ? this.renderDifference() : null,
this.props.type === 'fade' ? this.renderFade() : null,
this.props.type === 'swipe' ? this.renderSwipe() : null
this.props.type === 'swipe' ? this.renderSwipe() : null,
this.props.type === 'swipev' ? this.renderSwipeVertical() : null
);
}
}, {
Expand Down Expand Up @@ -239,6 +240,65 @@ return /******/ (function(modules) { // webpackBootstrap
width: this.state.width * (1 - this.props.value)
};

return _react2.default.createElement(
'div',
{ className: 'ImageDiff__inner--swipe', style: style },
_react2.default.createElement(
'div',
{ className: 'ImageDiff__before', style: beforeStyle },
_react2.default.createElement('img', {
src: this.props.before,
height: this.props.height,
width: this.props.width,
onLoad: this.handleImgLoad
})
),
_react2.default.createElement(
'div',
{ className: 'ImageDiff--swiper', style: swiperStyle },
_react2.default.createElement(
'div',
{ className: 'ImageDiff__after', style: afterStyle },
_react2.default.createElement('img', {
src: this.props.after,
height: this.props.height,
width: this.props.width,
onLoad: this.handleImgLoad
})
)
)
);
}
}, {
key: 'renderSwipeVertical',
value: function renderSwipeVertical() {
var style = {
backgroundImage: 'url(' + bgImage + ')',
height: this.state.height,
margin: 0,
position: 'absolute',
width: this.state.width
};

var beforeStyle = _extends({
border: '1px solid #f77'
}, style);

var afterStyle = _extends({
border: '1px solid #63c363',
bottom: 0
}, style);

var swiperStyle = {
borderTop: '1px solid #999',
width: this.state.width + 2,
margin: 0,
overflow: 'hidden',
position: 'absolute',
bottom: -2,
height: this.state.height * (1 - this.props.value)
};

return _react2.default.createElement(
'div',
{ className: 'ImageDiff__inner--swipe', style: style },
Expand Down Expand Up @@ -288,13 +348,13 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = ImageDiff;

/***/ },
/***/ }),
/* 1 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

module.exports = __WEBPACK_EXTERNAL_MODULE_1__;

/***/ }
/***/ })
/******/ ])
});
;
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ <h1>react-image-diff</h1>
<br/>
<label>
<input name='type' type='radio' value='swipe' onChange={this.handleRadioChange} />
swipe
horizontal swipe
</label>
<label>
<input name='type' type='radio' value='swipev' onChange={this.handleRadioChange} />
vertical swipe
</label>
<label>
<input name='type' type='radio' value='fade' onChange={this.handleRadioChange} defaultChecked />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-image-diff",
"version": "0.1.0",
"version": "0.1.1",
"description": "Highlight differences between images",
"main": "dist/react-image-diff.js",
"scripts": {
Expand Down
55 changes: 55 additions & 0 deletions src/react-image-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ImageDiff extends Component {
{this.props.type === 'difference' ? this.renderDifference() : null}
{this.props.type === 'fade' ? this.renderFade() : null}
{this.props.type === 'swipe' ? this.renderSwipe() : null}
{this.props.type === 'swipev' ? this.renderSwipeVertical() : null}
</div>
);
}
Expand Down Expand Up @@ -172,6 +173,60 @@ class ImageDiff extends Component {
</div>
);
}

renderSwipeVertical() {
let style = {
backgroundImage: `url(${bgImage})`,
height: this.state.height,
margin: 0,
position: 'absolute',
width: this.state.width
};

let beforeStyle = {
border: '1px solid #f77',
...style
};

let afterStyle = {
border: '1px solid #63c363',
bottom: 0,
...style
};

let swiperStyle = {
borderTop: '1px solid #999',
width: this.state.width + 2,
margin: 0,
overflow: 'hidden',
position: 'absolute',
bottom: -2,
height: this.state.height * (1 - this.props.value)
};

return (
<div className='ImageDiff__inner--swipe' style={style}>
<div className='ImageDiff__before' style={beforeStyle}>
<img
src={this.props.before}
height={this.props.height}
width={this.props.width}
onLoad={this.handleImgLoad}
/>
</div>
<div className='ImageDiff--swiper' style={swiperStyle}>
<div className='ImageDiff__after' style={afterStyle}>
<img
src={this.props.after}
height={this.props.height}
width={this.props.width}
onLoad={this.handleImgLoad}
/>
</div>
</div>
</div>
);
}
}

ImageDiff.propTypes = {
Expand Down