Skip to content

Commit

Permalink
Introduce Positive Space Lens
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanselzer committed Apr 20, 2018
1 parent ba242dd commit 80325b9
Show file tree
Hide file tree
Showing 20 changed files with 518 additions and 57 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ See more usage examples in the [example project](https://github.com/ethanselzer/
| isHintEnabled | Boolean| false | Enable hint feature. |
| hintTextMouse | String |Hover to Zoom| Hint text for mouse. |
| hintTextTouch | String |Long-Touch to Zoom| Hint text for touch. |
| shouldUsePositiveSpaceLens | Boolean| false | Specify a positive space lens in place of the default negative space lens. |
| lensComponent | Function | (Provided) | Specify a custom lens component. |

### Small Image
```
Expand Down Expand Up @@ -179,6 +181,13 @@ Thanks to the following community members for opening Issues and Pull Requests.
@spiderbites
@Akarshit
@eddy20vt
@evannoronha
@benjaminadk
@nilsklimm
@m4recek
@yaser-ali-vp
@carlgunderson
@tojvan

You are awesome! ✨💫

Expand Down
3 changes: 3 additions & 0 deletions example/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Navigation extends React.Component {
return 2.5;
case '/external' :
return 2.6;
case '/lens' :
return 2.7;
case '/image-magnify' :
return 3.1;
case '/support' :
Expand Down Expand Up @@ -69,6 +71,7 @@ class Navigation extends React.Component {
<MenuItem eventKey={2.4} href="#/dimensions">Enlarged Image Container Dimensions</MenuItem>
<MenuItem eventKey={2.5} href="#/react-slick">Carousel Integration</MenuItem>
<MenuItem eventKey={2.6} href="#/external">External Enlarged Image</MenuItem>
<MenuItem eventKey={2.7} href="#/lens">Alternate Lens</MenuItem>
</NavDropdown>
<NavItem href="https://github.com/ethanselzer/react-image-magnify#required-props">
Docs
Expand Down
62 changes: 62 additions & 0 deletions example/src/components/Lens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { Component } from 'react';
import ReactImageMagnify from '../pkg-lnk/ReactImageMagnify';
import SpacedSpan from '../components/SpacedSpan';

import '../styles/examples.css';

import watchImg687 from '../images/wristwatch_687.jpg';
import watchImg1200 from '../images/wristwatch_1200.jpg';

export default class BasicExample extends Component {
render() {
return (
<div className="fluid">
<div className="fluid__image-container">
<ReactImageMagnify {...{
smallImage: {
alt: 'Wristwatch by Ted Baker London',
isFluidWidth: true,
src: watchImg687,
},
largeImage: {
src: watchImg1200,
width: 1200,
height: 1800
},
shouldUsePositiveSpaceLens: true
}} />
</div>
<div className="fluid__instructions">
<h3>Alternate Lens</h3>
<p>
Specify a positive space design
in place of the default negative space design.
</p>
<p>
Optionally override the default appearance by specifying a custom style, for example:
</p>
<pre>
lensStyle: &#123;<br />
&nbsp;&nbsp;background: 'hsla(0, 0%, 100%, .3)',<br />
&nbsp;&nbsp;border: '1px solid #ccc'<br />
&#125;
</pre>
<p>
Support for a custom lens is provided by
the <span className="code">lensComponent</span> prop.
</p>
<p>
Please see
<SpacedSpan>
<a href="https://github.com/ethanselzer/react-image-magnify/blob/master/example/src/components/Lens.js">
source code
</a>
</SpacedSpan>
for details.
</p>
</div>
<div style={{height: '500px'}} />
</div>
);
}
}
1 change: 1 addition & 0 deletions example/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class extends Component {
<NavItem href="#/dimensions">Enlarged Image Container Dimensions</NavItem>
<NavItem href="#/react-slick">Carousel Integration</NavItem>
<NavItem href="#/external">External Enlarged Image</NavItem>
<NavItem href="#/lens">Alternate Lens</NavItem>
</Nav>
</Panel>
</Col>
Expand Down
40 changes: 40 additions & 0 deletions example/src/pages/Lens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { Component } from 'react';
import {
Col,
Grid,
Jumbotron,
Row
} from 'react-bootstrap';
import Helmet from 'react-helmet';

import Header from '../components/Header';
import Lens from '../components/Lens';

import 'bootstrap/dist/css/bootstrap.css';
import '../styles/app.css';

export default class extends Component {
render() {
return (
<div>
<Helmet title="Image Magnify | React Cursor Position" />
<Header {...this.props}/>
<Jumbotron>
<Grid>
<Row>
<Col sm={12}>
</Col>
</Row>
</Grid>
</Jumbotron>
<Grid>
<Row>
<Col sm={12}>
<Lens />
</Col>
</Row>
</Grid>
</div>
);
}
}
2 changes: 2 additions & 0 deletions example/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ResponsiveImages from './pages/ResponsiveImages';
import Hint from './pages/Hint';
import ReactSlickIntegration from './pages/ReactSlickIntegration';
import EnlargedImageContainerDimensions from './pages/EnlargedImageContainerDimensions';
import Lens from './pages/Lens';
import FixedWidthSmallImage from './pages/FixedWidthSmallImage';
import ExternalEnlargedImage from './pages/ExternalEnlargedImage';
import Support from './pages/Support';
Expand All @@ -19,6 +20,7 @@ const Routes = (props) => (
<Route path="/hint" component={Hint} />
<Route path="/react-slick" component={ReactSlickIntegration} />
<Route path="/dimensions" component={EnlargedImageContainerDimensions} />
<Route path="/lens" component={Lens} />
<Route path="/fixed" component={FixedWidthSmallImage} />
<Route path="/external" component={ExternalEnlargedImage} />
<Route path="/support" component={Support} />
Expand Down
30 changes: 26 additions & 4 deletions src/ReactImageMagnify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import React from 'react';
import ReactCursorPosition from 'react-cursor-position';

import RenderEnlargedImage from './RenderEnlargedImage';
import ShadedLens from './shaded-lens';
import NegativeSpaceLens from './lens/negative-space';
import PositiveSpaceLens from './lens/positive-space';
import DisplayUntilActive from './hint/DisplayUntilActive';
import Hint from './hint/DefaultHint';

Expand Down Expand Up @@ -66,6 +67,8 @@ class ReactImageMagnify extends React.Component {
imageClassName: PropTypes.string,
imageStyle: PropTypes.object,
lensStyle: PropTypes.object,
lensComponent: PropTypes.func,
shouldUsePositiveSpaceLens: PropTypes.bool,
smallImage: SmallImageShape,
largeImage: LargeImageShape,
enlargedImageContainerClassName: PropTypes.string,
Expand Down Expand Up @@ -96,7 +99,8 @@ class ReactImageMagnify extends React.Component {
hintTextMouse: 'Hover to Zoom',
hintTextTouch: 'Long-Touch to Zoom',
hoverDelayInMs: 250,
hoverOffDelayInMs: 150
hoverOffDelayInMs: 150,
shouldUsePositiveSpaceLens: false
};

componentDidMount() {
Expand Down Expand Up @@ -249,6 +253,23 @@ class ReactImageMagnify extends React.Component {
);
}

get lensComponent() {
const {
shouldUsePositiveSpaceLens,
lensComponent
} = this.props;

if (lensComponent) {
return lensComponent
}

if (shouldUsePositiveSpaceLens) {
return PositiveSpaceLens;
}

return NegativeSpaceLens;
}

render() {
const {
className,
Expand Down Expand Up @@ -293,6 +314,8 @@ class ReactImageMagnify extends React.Component {
this.enlargedImageContainerDimensions
);

const Lens = this.lensComponent;

return (
<ReactCursorPosition { ...{
className,
Expand Down Expand Up @@ -328,10 +351,9 @@ class ReactImageMagnify extends React.Component {
</DisplayUntilActive>
}
{this.shouldShowLens &&
<ShadedLens {...{
<Lens {...{
cursorOffset,
fadeDurationInMs,
enlargedImageContainerDimensions: this.enlargedImageContainerDimensions,
smallImage,
style: lensStyle
}} />
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import objectAssign from 'object-assign';
import clamp from 'clamp';
import Lens from './Lens';
import LensPropTypes from '../prop-types/Lens';
import LensPropTypes from '../../prop-types/Lens';

const LensBottom = ({
cursorOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import objectAssign from 'object-assign';
import clamp from 'clamp';
import Lens from './Lens';
import LensPropTypes from '../prop-types/Lens';
import LensPropTypes from '../../prop-types/Lens';

const LensLeft = ({
cursorOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import objectAssign from 'object-assign';
import clamp from 'clamp';
import Lens from './Lens';
import LensPropTypes from '../prop-types/Lens';
import LensPropTypes from '../../prop-types/Lens';

const LensRight = ({
cursorOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import clamp from 'clamp';
import objectAssign from 'object-assign';
import Lens from './Lens';
import LensPropTypes from '../prop-types/Lens';
import LensPropTypes from '../../prop-types/Lens';

const LensTop = ({
cursorOffset,
Expand Down
6 changes: 3 additions & 3 deletions src/shaded-lens/index.js → src/lens/negative-space/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import LensLeft from './LensLeft';
import LensRight from './LensRight';
import LensBottom from './LensBottom';

import LensPropTypes from '../prop-types/Lens';
import LensPropTypes from '../../prop-types/Lens';

export default function ImageLensShaded(inputProps) {
export default function NegativeSpaceLens(inputProps) {
const { style: userSpecifiedStyle } = inputProps;

const compositLensStyle = objectAssign(
Expand All @@ -32,4 +32,4 @@ export default function ImageLensShaded(inputProps) {
);
}

ImageLensShaded.propTypes = LensPropTypes;
NegativeSpaceLens.propTypes = LensPropTypes;
Binary file added src/lens/positive-space/assets/texture.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/lens/positive-space/assets/textured-lens-data-uri.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 80325b9

Please sign in to comment.