Skip to content
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

Adding srcset to images and containerStyle,containerClass to the container #43

Open
wants to merge 2 commits 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ import ReactCompareImage from 'react-compare-image';
| handleSize | number (px) | 40 | diameter of slider handle (by pixel) |
| hover | boolean | false | Whether to slide at hover |
| leftImage \* | string | null | left image's url |
| leftImageSrcSet | string | null | left image's srcset url |
| leftImageAlt | string | `''` | alt props for left image |
| leftImageCss | object | {} | Additional css for left image |
| leftImageLabel | string | null | Label for the image (e.g. `before`) |
| onSliderPositionChange | function | null | Callback function called each time the slider changes. The position (0 to 1) of the slider is passed as arg |
| rightImage \* | string | null | right image's url |
| rightImageSrcSet | string | null | right image's srcset url |
| rightImageAlt | string | `''` | alt props for right image |
| rightImageCss | object | {} | Additional css for right image |
| rightImageLabel | string | null | Label for the image (e.g. `after`) |
| skeleton | element | null | Element displayed while image is loading |
| containerStyle | object | {} | Container's style |
| containerClass | string | `''` | Container's className |
| sliderLineColor | string | `'#ffffff'` | line color of slider |
| sliderLineWidth | number (px) | 2 | line width of slider (by pixel) |
| sliderPositionPercentage | number (float) | 0.5 | Default line position (from 0 to 1) |
Expand Down
16 changes: 16 additions & 0 deletions src/ReactCompareImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ const propTypes = {
handleSize: PropTypes.number,
hover: PropTypes.bool,
leftImage: PropTypes.string.isRequired,
leftImageSrcSet: PropTypes.string,
leftImageAlt: PropTypes.string,
leftImageCss: PropTypes.object, // eslint-disable-line
leftImageLabel: PropTypes.string,
onSliderPositionChange: PropTypes.func,
rightImage: PropTypes.string.isRequired,
rightImageSrcSet: PropTypes.string,
rightImageAlt: PropTypes.string,
rightImageCss: PropTypes.object, // eslint-disable-line
rightImageLabel: PropTypes.string,
skeleton: PropTypes.element,
containerStyle: PropTypes.object, // eslint-disable-line
containerClass: PropTypes.string,
sliderLineColor: PropTypes.string,
sliderLineWidth: PropTypes.number,
sliderPositionPercentage: PropTypes.number,
Expand All @@ -28,14 +32,18 @@ const defaultProps = {
handle: null,
handleSize: 40,
hover: false,
leftImageSrcSet: null,
leftImageAlt: '',
leftImageCss: {},
leftImageLabel: null,
onSliderPositionChange: () => {},
rightImageSrcSet: null,
rightImageAlt: '',
rightImageCss: {},
rightImageLabel: null,
skeleton: null,
containerStyle: {},
containerClass: '',
sliderLineColor: '#ffffff',
sliderLineWidth: 2,
sliderPositionPercentage: 0.5,
Expand All @@ -49,15 +57,19 @@ function ReactCompareImage(props) {
handleSize,
hover,
leftImage,
leftImageSrcSet,
leftImageAlt,
leftImageCss,
leftImageLabel,
onSliderPositionChange,
rightImage,
rightImageSrcSet,
rightImageAlt,
rightImageCss,
rightImageLabel,
skeleton,
containerStyle,
containerClass,
sliderLineColor,
sliderLineWidth,
sliderPositionPercentage,
Expand Down Expand Up @@ -399,9 +411,11 @@ function ReactCompareImage(props) {
<div
style={{
...styles.container,
...containerStyle,
display: allImagesLoaded ? 'block' : 'none',
}}
ref={containerRef}
className={containerClass}
data-testid="container"
>
<img
Expand All @@ -410,6 +424,7 @@ function ReactCompareImage(props) {
data-testid="right-image"
ref={rightImageRef}
src={rightImage}
srcSet={rightImageSrcSet}
style={styles.rightImage}
/>
<img
Expand All @@ -418,6 +433,7 @@ function ReactCompareImage(props) {
data-testid="left-image"
ref={leftImageRef}
src={leftImage}
srcSet={leftImageSrcSet}
style={styles.leftImage}
/>
<div style={styles.slider}>
Expand Down