Skip to content

Commit

Permalink
External Enlarged Image
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanselzer committed Mar 22, 2018
1 parent e5a4458 commit da2fafa
Show file tree
Hide file tree
Showing 16 changed files with 536 additions and 222 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Designed for shopping site product detail.

Supports in-place and side-by-side image enlargement.

Supports react-slick carousel.

Features tinted guide lens, interaction hint, hover intent, long-press gesture, and fade transitions.

## Status
Expand All @@ -18,7 +20,9 @@ Features tinted guide lens, interaction hint, hover intent, long-press gesture,

[Integration with react-slick carousel](https://ethanselzer.github.io/react-image-magnify/#/react-slick)

[Specify Enlarged Image Container Dimensions](https://ethanselzer.github.io/react-image-magnify/#/dimensions)
[Enlarged Image Container Dimensions](https://ethanselzer.github.io/react-image-magnify/#/dimensions)

[External Enlarged Image](https://ethanselzer.github.io/react-image-magnify/#/external)

Experiment with react-image-magnify [live on CodePen](https://codepen.io/ethanselzer/full/oePMNY/).
Use the Change View button to select editing mode or for different layout options.
Expand Down Expand Up @@ -69,7 +73,7 @@ If you would like more information on responsive images, please try these resour

### Desktop and Touch
| Prop | Type | Required | Default | Description |
|-------------------------------|--------|----------|---------|------------------------------------------------------------|
|-------------------------------|--------|----------|---------|-----------------------|
| `smallImage` | Object | Yes | | Small image information. See [Small Image](#small-image) below.|
| `largeImage` | Object | Yes | | Large image information. See [Large Image](#large-image) below.|
| `className` | String | No | | CSS class applied to root container element. |
Expand All @@ -80,25 +84,27 @@ If you would like more information on responsive images, please try these resour
| `enlargedImageContainerClassName`| String | No | | CSS class applied to enlarged image container element. |
| `enlargedImageContainerStyle` | Object | No | | Style applied to enlarged image container element. |
| `enlargedImageClassName` | String | No | | CSS class applied to enlarged image element. |
| `enlargedImageStyle` | Object | No | | Style applied to enlarged image element. |
| `enlargedImageStyle` | Object | No | | Style applied to enlarged image element.|
| `enlargedImageContainerDimensions` | Object | No | {width: '100%', height: '100%'} | Specify enlarged image container dimensions as an object with `width` and `height` properties. Values may be expressed as a percentage (e.g. '150%') or a number (e.g. 200). Percentage is based on small image dimension. Number is pixels. Not applied when `enlargedImagePosition` is set to 'over', the default for touch input. |
| `enlargedImagePortalId` | String | No | | Render enlarged image into an HTML element of your choosing by specifying the target element id. Requires React v16. Ignored for touch input by default - see `isEnlargedImagePortalEnabledForTouch`.|
| `isEnlargedImagePortalEnabledForTouch` | Boolean | No | false | Specify portal rendering should be honored for touch input. |
| `hintComponent` |Function| No |(Provided)| Reference to a component class or functional component. A Default is provided.|
| `shouldHideHintAfterFirstActivation`| Boolean | No | true | Only show hint until the first interaction begins. |
| `isHintEnabled` | Boolean| No | false | Enable hint feature. |
| `hintTextMouse` | String | No |Hover to Zoom| Hint text for mouse. |
| `hintTextTouch` | String | No |Long-Touch to Zoom| Hint text for touch. |
| `isHintEnabled` | Boolean| No | false | Enable hint feature. |
| `hintTextMouse` | String | No |Hover to Zoom| Hint text for mouse. |
| `hintTextTouch` | String | No |Long-Touch to Zoom| Hint text for touch. |

### Mouse Specific
| Prop | Type | Required | Default | Description |
|-------------------------------|--------|----------|---------|------------------------------------------------------------|
|-------------------------------|--------|----------|---------|------------------------|
| `hoverDelayInMs` | Number | No | 250 | Milliseconds to delay hover trigger. |
| `hoverOffDelayInMs` | Number | No | 150 | Milliseconds to delay hover-off trigger. |
| `lensStyle` | Object | No | | Style applied to tinted lens. |
| `enlargedImagePosition` | String | No | beside | Enlarged image position. Can be 'beside' or 'over'. |
| `enlargedImageContainerDimensions` | Object | No | {width: '100%', height: '100%'} | Specify enlarged image container dimensions as an object with `width` and `height` properties. Values may be expressed as a percentage (e.g. '150%') or a number (e.g. 200). Percentage is based on small image dimension. Number is pixels. Not applied when `enlargedImagePosition` is set to 'over'. |

### Touch Specific
| Prop | Type | Required | Default | Description |
|-------------------------------|--------|----------|---------|------------------------------------------------------------|
|-------------------------------|--------|----------|---------|------------------------|
| `isActivatedOnTouch` | Boolean| No | false | Activate magnification immediately on touch. May impact scrolling.|
| `pressDuration` | Number | No | 500 | Milliseconds to delay long-press activation (long touch). |
| `pressMoveThreshold` | Number | No | 5 | Pixels of movement allowed during long-press activation. |
Expand Down
93 changes: 93 additions & 0 deletions example/src/components/ReactSlick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React, { Component } from 'react';
import ReactImageMagnify from '../pkg-lnk/ReactImageMagnify';
import ReactSlick from 'react-slick';

import front_500 from '../images/versace-blue/front-500.jpg'
import front_779 from '../images/versace-blue/front-779.jpg';
import front_1020 from '../images/versace-blue/front-1020.jpg';
import front_1200 from '../images/versace-blue/front-1200.jpg';
import front_1426 from '../images/versace-blue/front-1426.jpg';

import back_500 from '../images/versace-blue/back-500.jpg'
import back_779 from '../images/versace-blue/back-779.jpg';
import back_1020 from '../images/versace-blue/back-1020.jpg';
import back_1200 from '../images/versace-blue/back-1200.jpg';
import back_1426 from '../images/versace-blue/back-1426.jpg';

const frontSrcSet = [
{ src: front_500, setting: '500w' },
{ src: front_779, setting: '779w' },
{ src: front_1020, setting: '1020w' },
{ src: front_1200, setting: '1200w' },
{ src: front_1426, setting: '1426w' }
]
.map(item => `${item.src} ${item.setting}`)
.join(', ');

const backSrcSet = [
{ src: back_500, setting: '500w' },
{ src: back_779, setting: '779w' },
{ src: back_1020, setting: '1020w' },
{ src: back_1200, setting: '1200w' },
{ src: back_1426, setting: '1426w' }
]
.map(item => `${item.src} ${item.setting}`)
.join(', ');

const dataSource = [
{
srcSet: frontSrcSet,
small: front_500,
large: front_1426
},
{
srcSet: backSrcSet,
small: back_500,
large: back_1426
}
];

export default class ReactSlickExample extends Component {
render() {
const {
rimProps,
rsProps
} = this.props;

return (
<ReactSlick
{...{
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1
}}
{...rsProps}
>
{dataSource.map((src, index) => (
<div key={index}>
<ReactImageMagnify
{...{
largeImage: {
alt: '',
src: src.large,
width: 1426,
height: 2000
},
smallImage: {
isFluidWidth: true,
alt: 'Wristwatch by Versace',
src: src.small,
srcSet: src.srcSet,
sizes: '(max-width: 480px) 100vw, (max-width: 1200px) 30vw, 360px'
}
}}
{...rimProps}
/>
</div>
))}
</ReactSlick>
);
}
}
2 changes: 1 addition & 1 deletion example/src/components/SpacedSpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
export default function SpacedSpan({ className, children }) {
return (
<span className={className}>
&nbsp;{children}&nbsp;
{' '}{children}{' '}
</span>
);
}
60 changes: 60 additions & 0 deletions example/src/pages/ExternalEnlargedImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { Component } from 'react';
import ReactSlick from '../components/ReactSlick';
import SpacedSpan from '../components/SpacedSpan';

import './app.css';
import './react-slick.css';

export default class ReactSlickExample extends Component {
render() {
return (
<div className="fluid react-slick">
<div className="fluid__image-container">
<ReactSlick {...{
rimProps: {
isHintEnabled: true,
shouldHideHintAfterFirstActivation: false,
enlargedImagePortalId: 'portal',
enlargedImageContainerDimensions: {
width: '150%',
height: '100%'
},
lensStyle: { backgroundColor: 'rgba(0,0,0,.6)' }
}
}}/>
</div>
<div className="fluid__instructions" style={{position: 'relative'}}>
<div
id="portal"
className="portal"
/>
<h3>External Enlarged Image Example</h3>
<p>
Render enlarged image into an HTML element of your choosing.
</p>
<p>
Ignored for touch input by default but will be honored if
isEnlargedImagePortalEnabledForTouch is implemented.
</p>
<p>
Use cases include a scenario where an ancestor element of
react-image-magnify implements overflow hidden.
</p>
<p>
Requires React v16.
</p>
<p>
Please see
<SpacedSpan>
<a href="https://github.com/ethanselzer/react-image-magnify/blob/master/example/src/pages/ExternalEnlargedImage.js">
example source code
</a>
</SpacedSpan>
for details.
</p>
</div>
<div style={{height: '1000px'}} />
</div>
);
}
}
93 changes: 15 additions & 78 deletions example/src/pages/ReactSlick.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,22 @@
import React, { Component } from 'react';
import ReactImageMagnify from '../pkg-lnk/ReactImageMagnify';
import ReactSlick from 'react-slick';
import ReactSlick from '../components/ReactSlick';
import SpacedSpan from '../components/SpacedSpan';

import front_500 from '../images/versace-blue/front-500.jpg'
import front_779 from '../images/versace-blue/front-779.jpg';
import front_1020 from '../images/versace-blue/front-1020.jpg';
import front_1200 from '../images/versace-blue/front-1200.jpg';
import front_1426 from '../images/versace-blue/front-1426.jpg';

import back_500 from '../images/versace-blue/back-500.jpg'
import back_779 from '../images/versace-blue/back-779.jpg';
import back_1020 from '../images/versace-blue/back-1020.jpg';
import back_1200 from '../images/versace-blue/back-1200.jpg';
import back_1426 from '../images/versace-blue/back-1426.jpg';

import './app.css';
import './react-slick.css';

const frontSrcSet = [
{ src: front_500, setting: '500w' },
{ src: front_779, setting: '779w' },
{ src: front_1020, setting: '1020w' },
{ src: front_1200, setting: '1200w' },
{ src: front_1426, setting: '1426w' }
]
.map(item => `${item.src} ${item.setting}`)
.join(', ');

const backSrcSet = [
{ src: back_500, setting: '500w' },
{ src: back_779, setting: '779w' },
{ src: back_1020, setting: '1020w' },
{ src: back_1200, setting: '1200w' },
{ src: back_1426, setting: '1426w' }
]
.map(item => `${item.src} ${item.setting}`)
.join(', ');

const dataSource = [
{
srcSet: frontSrcSet,
small: front_500,
large: front_1426
},
{
srcSet: backSrcSet,
small: back_500,
large: back_1426
}
];

export default class ReactSlickExample extends Component {
render() {
return (
<div className="fluid react-slick">
<div className="fluid__image-container">
<ReactSlick {...{
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1
}}>
{dataSource.map((src, index) => (
<div key={index}>
<ReactImageMagnify {...{
largeImage: {
alt: '',
src: src.large,
width: 1426,
height: 2000
},
smallImage: {
isFluidWidth: true,
alt: 'Wristwatch by Versace',
src: src.small,
srcSet: src.srcSet,
sizes: '(max-width: 480px) 100vw, (max-width: 1200px) 30vw, 360px'
},
isHintEnabled: true,
shouldHideHintAfterFirstActivation: false,
enlargedImagePosition: 'over'
}} />
</div>
))}
</ReactSlick>
rimProps: {
isHintEnabled: true,
shouldHideHintAfterFirstActivation: false,
enlargedImagePosition: 'over'
}
}} />
</div>
<div className="fluid__instructions">
<h3>Carousel Example</h3>
Expand All @@ -100,7 +31,13 @@ export default class ReactSlickExample extends Component {
In-place enlargement for mouse and touch input.
</p>
<p>
Side-by-side enlargement not yet compatible with react-slick.
Side-by-side enlargement supported, please see&nbsp;
<a
href="https://ethanselzer.github.io/react-image-magnify/#/external"
>
External Enlarged Image Demo
</a>
.
</p>
<p>
Responsive and fluid between breakpoints.
Expand All @@ -120,7 +57,7 @@ export default class ReactSlickExample extends Component {
Please see
<SpacedSpan>
<a href="https://github.com/ethanselzer/react-image-magnify/blob/master/example/src/pages/ReactSlick.js">
source code
example source code
</a>
</SpacedSpan>
for details.
Expand Down
7 changes: 7 additions & 0 deletions example/src/pages/app.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body {
font-family: Arial;
line-height: 1.3;
}

.fluid {
Expand Down Expand Up @@ -50,4 +51,10 @@ a:hover {
padding-top: 30px;
margin: 0 10px;
}

.portal {
position: absolute;
top: 40px;
left: -30px;
}
}
2 changes: 2 additions & 0 deletions example/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import SideBySide from './pages/SideBySide';
import ReactSlick from './pages/ReactSlick';
import EnlargedImageContainerDimensions from './pages/EnlargedImageContainerDimensions';
import FixedWidthSmallImage from './pages/FixedWidthSmallImage';
import ExternalEnlargedImage from './pages/ExternalEnlargedImage';

const Routes = (props) => (
<Router {...props}>
<Route path="/" component={SideBySide} />
<Route path="/react-slick" component={ReactSlick} />
<Route path="/dimensions" component={EnlargedImageContainerDimensions} />
<Route path="/fixed" component={FixedWidthSmallImage} />
<Route path="/external" component={ExternalEnlargedImage} />
</Router>
);

Expand Down
Loading

0 comments on commit da2fafa

Please sign in to comment.