Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
ethanselzer committed Sep 26, 2016
0 parents commit 4ae7277
Showing 27 changed files with 1,859 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-2", "react"]
}
51 changes: 51 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"es6": true
},
"ecmaFeatures": {
"modules": true
},
"rules": {
"no-bitwise": 2,
"no-else-return": 2,
"no-eq-null": 2,
"no-extra-parens": 0,
"no-floating-decimal": 2,
"no-inner-declarations": [2, "both"],
"no-lonely-if": 2,
"no-multiple-empty-lines": [2, {"max": 3}],
"no-self-compare": 2,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"no-unused-expressions": 0,
"no-void": 2,
"brace-style": [2, "1tbs"],
"camelcase": [1, {"properties": "never"}],
"consistent-return": 0,
"comma-style": [2, "last"],
"complexity": [1, 12],
"func-names": 0,
"guard-for-in": 2,
"indent": [2, 4],
"max-len": [0, 120, 4],
"new-cap": [2, {"newIsCap": true, "capIsNew": false}],
"quotes": [2, "single"],
"keyword-spacing": [2, {"before": true, "after": true}],
"space-before-blocks": [2, "always"],
"array-bracket-spacing": [2, "never"],
"space-in-parens": [2, "never"],
"strict": [0],
"valid-jsdoc": 2,
"wrap-iife": [2, "any"],
"yoda": [1, "never"]
},
"plugins": [
// "react"
],
"globals": {

}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
dist/
npm-debug.log
node_modules
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.swp
*~
*.iml
.*.haste_cache.*
.DS_Store
.idea
.babelrc
.eslintrc
npm-debug.log
lib
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Ethan Selzer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# react-image-magnify

A React component displaying side by side enlarged image view, with tinted control-image mask.

Intended for desktop, but will be updated with touch experience soon.

Supports arbitrary image sizes. Scales magnification automatically.

Supports delaying hover and hover-off, which can help reduce unintentional triggering.


## Installation

```sh
npm install --save react-image-magnify
```

## Usage

```JSX
import ReactImageMagnify from 'react-image-magnify';
...
<ReactImageMagnify {...{
largeImage: {
alt: 'large image description goes here',
src: 'https://example.com/large/image.jpg',
width: 1200,
height: 1800
},
smallImage: {
alt: 'small image description goes here',
src: 'https://example.com/small/image.jpg',
width: 400,
height: 600
}
}}/>
...
```

### Props API

`className` : String [optional] - A CSS class to be applied to the container element rendered by react-image-magnify.

`style` : Object [optional] - Style to be applied to the container element rendered by react-image-magnify.

`hoverDelayInMs` : Number [optional] - Milliseconds to delay hover trigger. Defaults to 250.

`hoverOffDelayInMs` : Number [optional] - Milliseconds to delay hover-off trigger. Defaults to 150.

`fadeDurationInMs` : Number [optional] - Milliseconds duration of magnified image fade in/fade out. Defaults to 300.

`smallImage` : Object - Image struct.

`largeImage` : Object - Image struct.

Image struct shape:
```
{
alt: String,
src: String,
width: Number,
height: Number
}
```

## Support

Please [open an issue](https://github.com/ethanselzer/react-image-zoom/issues).

## Development

```ssh
git clone https://github.com/ethanselzer/react-image-zoom.git
cd react-image-zoom
npm install
```
See available commands:
```ssh
npm run
```

## Contributing

Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch,
add commits, and [open a pull request](https://github.com/ethanselzer/react-image-zoom/compare/).

## License

MIT
15 changes: 15 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
node_modules

# testing
coverage

# production
build

# misc
.DS_Store
.env
npm-debug.log
941 changes: 941 additions & 0 deletions example/README.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "example",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.6.0"
},
"dependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added example/public/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions example/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favico.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
24 changes: 24 additions & 0 deletions example/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 80px;
}

.App-header {
background-color: #222;
height: 150px;
padding: 20px;
color: white;
}

.App-intro {
font-size: large;
}

@keyframes App-logo-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
36 changes: 36 additions & 0 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import ReactImageZoom from '../../dist/ImageZoom';

class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h2>Welcome to React</h2>
</div>
<p className="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p>
<ReactImageZoom {...{
largeImage: {
alt: 'hello large image',
src: 'https://www.hautelookcdn.com/products/KS8K955S/large/5793611.jpg',
width: 1200,
height: 1800
},
smallImage: {
alt: 'hello small image',
src: 'https://www.hautelookcdn.com/products/KS8K955S/large/5793611.jpg?interpolation=lanczos-none&downsize=434:650&output-quality=90&output-format=jpeg',
width: 434,
height: 650
}
}}/>
</div>
);
}
}

export default App;
8 changes: 8 additions & 0 deletions example/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
5 changes: 5 additions & 0 deletions example/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
9 changes: 9 additions & 0 deletions example/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';

ReactDOM.render(
<App />,
document.getElementById('root')
);
7 changes: 7 additions & 0 deletions example/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "react-image-magnify",
"version": "1.0.0",
"description": "A React component displaying side by side enlarged image view, with tinted control-image mask.",
"repository": {
"type": "git",
"url": "https://github.com/ethanselzer/react-image-zoom.git"
},
"author": "Ethan Selzer <ethanselzer@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ethanselzer/react-image-zoom/issues"
},
"homepage": "https://github.com/ethanselzer/react-image-zoom",
"keywords": [
"react-image-zoom",
"photo",
"photograph",
"magnify",
"magnifier",
"enlarge",
"zoomer",
"image magnifier",
"image enlarge",
"image zoomer",
"photo magnifier",
"photo enlarge",
"photo zoom"
],
"main": "dist/ImageZoom.js",
"scripts": {
"prepublish": "babel --plugins 'transform-es2015-modules-umd' src --ignore __tests__ --out-dir ./dist",
"lint": "eslint ./src",
"lintfix": "eslint ./src --fix",
"testonly": "mocha --require scripts/mocha_runner test/*.spec.js",
"test": "npm run lint && npm run testonly",
"test-watch": "npm run testonly -- --watch --watch-extensions js"
},
"devDependencies": {
"babel-cli": "^6.6.4",
"babel-core": "^6.7.4",
"babel-eslint": "^6.0.2",
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-2": "^6.5.0",
"chai": "^3.5.0",
"enzyme": "^2.2.0",
"eslint": "^2.7.0",
"eslint-plugin-babel": "^3.1.0",
"eslint-plugin-react": "^4.2.3",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"nodemon": "^1.9.1",
"react-addons-test-utils": "^15.0.0",
"react": "^15.0.0",
"react-dom": "^15.0.0",
"sinon": "^1.17.3"
},
"peerDependencies": {
"react": "~0.14.8 || ^15.0.0",
"react-dom": "~0.14.8 || ^15.0.0"
},
"dependencies": {
"babel-runtime": "^6.6.1",
"lodash.assign": "^4.2.0",
"lodash.clamp": "^4.0.3",
"react-cursor-position": "^1.1.0",
"react-hover-observer": "^1.1.0"
}
}
21 changes: 21 additions & 0 deletions scripts/mocha_runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var jsdom = require('jsdom').jsdom;

var exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});

global.navigator = {
userAgent: 'node.js'
};

documentRef = document;

require('babel-core/register');
require('babel-polyfill');
104 changes: 104 additions & 0 deletions src/ImageZoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { PropTypes } from 'react';
import ReactCursorPosition from 'react-cursor-position';
import ReactHoverObserver from 'react-hover-observer';
import LensTop from './ImageZoomLensTop';
import LensLeft from './ImageZoomLensLeft';
import LensRight from './ImageZoomLensRight';
import LensBottom from './ImageZoomLensBottom';
import Magnifier from './ImageZoomMagnifier';

const ImageZoom = ({
className,
fadeDurationInMs,
hoverDelayInMs,
hoverOffDelayInMs,
largeImage,
smallImage,
style
}) => {

const cursorOffset = {
x: Math.round(((smallImage.width / largeImage.width) * smallImage.width) / 2),
y: Math.round(((smallImage.height / largeImage.height) * smallImage.height) / 2)
};

return (
<ReactCursorPosition { ...{
className,
style: Object.assign({
width: `${smallImage.width}px`,
height: `${smallImage.height}px`,
cursor: 'crosshair',
position: 'relative'
}, style)
}}>
<ReactHoverObserver { ...{
hoverDelayInMs,
hoverOffDelayInMs,
onMouseEnter: ({ setIsHovering }) => setIsHovering(),
onMouseLeave: ({ unsetIsHovering }) => unsetIsHovering(),
onMouseOver: ({ e, unsetIsHovering }) => {
if (e.target.getAttribute('data-hover') === 'false') {
unsetIsHovering();
}
}
}}>
<img { ...{
src: smallImage.src,
alt: smallImage.alt
}} />
<LensTop { ...{
fadeDurationInMs,
smallImage,
cursorOffset
}} />
<LensLeft { ...{
fadeDurationInMs,
smallImage,
cursorOffset
}} />
<LensRight { ...{
fadeDurationInMs,
smallImage,
cursorOffset
}} />
<LensBottom { ...{
fadeDurationInMs,
smallImage,
cursorOffset
}} />
<Magnifier { ...{
fadeDurationInMs,
largeImage,
smallImage,
cursorOffset
}}/>
</ReactHoverObserver>
</ReactCursorPosition>
);
}

const Image = PropTypes.shape({
alt: PropTypes.string,
src: PropTypes.string.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired
});

ImageZoom.propTypes = {
fadeDurationInMs: PropTypes.number,
className: PropTypes.string,
hoverDelayInMs: PropTypes.number,
hoverOffDelayInMs: PropTypes.number,
largeImage: Image,
smallImage: Image,
style: PropTypes.object
};

ImageZoom.defaultProps = {
fadeDurationInMs: 300,
hoverDelayInMs: 250,
hoverOffDelayInMs: 150
};

export default ImageZoom;
60 changes: 60 additions & 0 deletions src/ImageZoomLens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { PropTypes } from 'react';

const ImageZoomLens = (props) => {
const {
fadeDurationInMs,
isHovering,
style,
translateX,
translateY
} = props;
const translate = `translate(${translateX}px, ${translateY}px)`;
const defaultStyle = {
position: 'absolute',
transform: translate,
WebkitTransform: translate,
msTransform: translate,
opacity: isHovering ? 1 : 0,
transition: `opacity ${fadeDurationInMs}ms ease-in`
};

return <div style={ Object.assign({}, defaultStyle, style) }/>;
}

ImageZoomLens.propTypes = {
fadeDurationInMs: PropTypes.number,
isHovering: PropTypes.bool,
style: PropTypes.shape({
width: PropTypes.string,
height: PropTypes.string,
top: PropTypes.string,
right: PropTypes.string,
bottom: PropTypes.string,
left: PropTypes.string,
display: PropTypes.string,
backgroundColor: PropTypes.string,
cursor: PropTypes.string,
}),
translateX: PropTypes.number,
translateY: PropTypes.number
};

ImageZoomLens.defaultProps = {
isHovering: false,
fadeDurationInMs: 0,
style: {
width: 'auto',
height: 'auto',
top: 'auto',
right: 'auto',
bottom: 'auto',
left: 'auto',
display: 'block',
backgroundColor: 'transparent',
cursor: 'auto'
},
translateX: 0,
translateY: 0
};

export default ImageZoomLens;
26 changes: 26 additions & 0 deletions src/ImageZoomLensBottom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import clamp from 'lodash.clamp';
import Lens from './ImageZoomLens';

export default ({
cursorOffset,
cursorPosition,
isHovering,
smallImage
}) => {

const maxHeight = smallImage.height - (cursorOffset.y * 2);
const height = clamp(smallImage.height - cursorPosition.y - cursorOffset.y, 0, maxHeight);

return (
<Lens {...{
isHovering,
style: {
height: `${height}px`,
width: '100%',
backgroundColor: 'rgba(0,0,0,.4)',
bottom: '0px'
}
}}/>
);
}
31 changes: 31 additions & 0 deletions src/ImageZoomLensLeft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import clamp from 'lodash.clamp';
import Lens from './ImageZoomLens';

export default ({
cursorOffset,
cursorPosition,
isHovering,
smallImage,
}) => {

const height = cursorOffset.y * 2;
const maxHeight = smallImage.height - height;
const maxWidth = smallImage.width - (cursorOffset.x * 2);
const width = clamp(cursorPosition.x - cursorOffset.x, 0, maxWidth);
const translateY = clamp(cursorPosition.y - cursorOffset.y, 0, maxHeight);

return (
<Lens {...{
isHovering,
style: {
height: `${height}px`,
width: `${width}px`,
backgroundColor: 'rgba(0,0,0,.4)',
top: '0px',
left: '0px'
},
translateY
}}/>
);
}
31 changes: 31 additions & 0 deletions src/ImageZoomLensRight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import clamp from 'lodash.clamp';
import Lens from './ImageZoomLens';

export default ({
cursorOffset,
cursorPosition,
isHovering,
smallImage,
}) => {

const height = cursorOffset.y * 2;
const maxHeight = smallImage.height - height;
const maxWidth = smallImage.width - (cursorOffset.x * 2);
const width = clamp(smallImage.width - cursorPosition.x - cursorOffset.x, 0, maxWidth);
const translateY = clamp(Math.round(cursorPosition.y - cursorOffset.y), 0, maxHeight);

return (
<Lens {...{
isHovering,
style: {
height: `${height}px`,
width: `${width}px`,
backgroundColor: 'rgba(0,0,0,.4)',
top: '0px',
right: '0px'
},
translateY
}}/>
);
}
26 changes: 26 additions & 0 deletions src/ImageZoomLensTop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import clamp from 'lodash.clamp';
import Lens from './ImageZoomLens';

export default ({
cursorOffset,
cursorPosition,
isHovering,
smallImage
}) => {

const maxHeight = smallImage.height - (cursorOffset.y * 2);
const height = clamp(cursorPosition.y - cursorOffset.y, 0, maxHeight);

return (
<Lens {...{
isHovering,
style: {
height: `${height}px`,
width: '100%',
backgroundColor: 'rgba(0,0,0,.4)',
top: '0px'
}
}}/>
);
}
132 changes: 132 additions & 0 deletions src/ImageZoomMagnifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React from 'react';
import clamp from 'lodash.clamp';

export default React.createClass({

displayName: 'ImageZoomMagnifier',

getInitialState() {
return {
isTransitionEntering: false,
isTransitionActive: false,
isTransitionLeaving: false,
isTransitionDone: false
};
},

getDefaultPRops() {
return {
fadeDurationInMs: 0
};
},

componentWillReceiveProps(nextProps) {
const { isHovering } = nextProps;

if (isHovering) {
this.setState({
isTransitionEntering: true
});

setTimeout(() => {
this.setState({
isTransitionEntering: false,
isTransitionActive: true
});
}, 0);
} else {
this.setState({
isTransitionActive: false,
isTransitionLeaving: true
});

setTimeout(() => {
this.setState({
isTransitionLeaving: false,
isTransitionDone: true
});
}, this.props.fadeDurationInMs);
}
},

render() {
const {
className,
cursorOffset,
cursorPosition,
fadeDurationInMs,
isHovering,
largeImage,
smallImage
} = this.props;

const {
isTransitionEntering,
isTransitionActive,
isTransitionLeaving
} = this.state;

const offsetRatio = {
x: largeImage.width / smallImage.width,
y: largeImage.height / smallImage.height
};

const differentiatedImageCoordinates = {
x: (Math.round((cursorPosition.x - cursorOffset.x) * offsetRatio.x) * -1),
y: (Math.round((cursorPosition.y - cursorOffset.y) * offsetRatio.y) * -1)
};

const minCoordinates = {
x: ((largeImage.width - smallImage.width) * -1),
y: ((largeImage.height - smallImage.height) * -1)
};

const maxCoordinate = 0;

const imageCoordinates = {
x: clamp(differentiatedImageCoordinates.x, minCoordinates.x, maxCoordinate),
y: clamp(differentiatedImageCoordinates.y, minCoordinates.y, maxCoordinate)
};

const translate = `translate(${imageCoordinates.x}px, ${imageCoordinates.y}px)`;

let isVisible;
if (isTransitionEntering || isTransitionActive || isTransitionLeaving) {
isVisible = true;
} else {
isVisible = false;
}

const component = (
<div { ...{
className,
key: 'zoom',
style: {
width: smallImage.width,
height: smallImage.height,
marginLeft: '10px',
position: 'absolute',
left: '100%',
top: '0px',
border: '1px solid #d6d6d6',
overflow: 'hidden',
opacity: this.state.isTransitionActive ? 1 : 0,
transition: `opacity ${fadeDurationInMs}ms ease-in`
}
}}>
<img data-hover="false" { ...{
src: largeImage.src,
style: {
width: largeImage.width,
height: largeImage.height,
transform: translate,
WebkitTransform: translate,
msTransform: translate
}
}}/>
</div>
);

return isVisible ? component : null;
}
});
84 changes: 84 additions & 0 deletions test/image-zoom-lens.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react';
import { shallow, mount, render } from 'enzyme';
import { expect } from 'chai';
import ImageZoomLens from '../src/ImageZoomLens';

describe('Image Zoom Lens', () => {
it('applies default inline style', () => {
const expected = 'position:absolute;transform:translate(0px, 0px);-webkit-transform:translate(0px, 0px);-ms-transform:translate(0px, 0px);opacity:0;transition:opacity 0ms ease-in;width:auto;height:auto;top:auto;right:auto;bottom:auto;left:auto;display:block;background-color:transparent;cursor:auto;';

const c = render(<ImageZoomLens />);

expect(c.find('div').attr('style')).to.equal(expected);
});

it('applies supplied inline style', () => {
const expected = 'width:1px;height:2px;top:3px;right:4px;bottom:5px;left:6px;display:inline-block;background-color:#fff;cursor:pointer;'

const c = render(
<ImageZoomLens {...{
style: {
width: '1px',
height: '2px',
top: '3px',
right: '4px',
bottom: '5px',
left: '6px',
display: 'inline-block',
backgroundColor: '#fff',
cursor: 'pointer'
}
}}/>
);

expect(c.find('div').attr('style').endsWith(expected)).to.be.true;
});

it('applies translateX and translateY props to CSS transform translate function', () => {
const c = render(
<ImageZoomLens {...{
translateX: 1,
translateY: 2
}}/>
);

expect(c.find('div').css('transform')).to.equal('translate(1px, 2px)');
});

it('applies vendor prefixes to inline CSS transform property', () => {
const c = render(
<ImageZoomLens {...{
translateX: 1,
translateY: 2
}}/>
);

expect(c.find('div').css('transform')).to.equal('translate(1px, 2px)');
expect(c.find('div').css('-ms-transform')).to.equal('translate(1px, 2px)');
expect(c.find('div').css('-webkit-transform')).to.equal('translate(1px, 2px)');
});

it('applies a value of 0 to CSS opacity property when isHovering is unset', () => {
const c = render(<ImageZoomLens />);

expect(c.find('div').css('opacity')).to.equal('0');
});

it('applies a value of 1 to CSS opacity property when isHovering is set', () => {
const c = render(<ImageZoomLens isHovering />);

expect(c.find('div').css('opacity')).to.equal('1');
});

it('applies default CSS opacity transition of 0 milliseconds', () => {
const c = render(<ImageZoomLens />);

expect(c.find('div').css('transition')).to.equal('opacity 0ms ease-in');
});

it('applies supplied CSS opacity transition', () => {
const c = render(<ImageZoomLens fadeDurationInMs={ 100 } />);

expect(c.find('div').css('transition')).to.equal('opacity 100ms ease-in');
});
});

0 comments on commit 4ae7277

Please sign in to comment.