Skip to content

Commit 767374b

Browse files
authored
Merge pull request #2 from kimcoder/feature/issue-1
[feature/issue-1] modify props types about width and height
2 parents 59cb2a4 + 197ec97 commit 767374b

8 files changed

+36
-12
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
1.0.3 (March 30, 2018)
4+
- modify props types about width and height. ( number -> string or number )
5+
- can set value like this. '100%' or '100px' or 100
6+
37
1.0.2 (October 08, 2018)
48
- add index.d.ts (for typescript).
59

example/App.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class App extends React.Component {
9393
</AppBar>
9494
<SimpleImageSlider
9595
style={{ margin: "0 auto", marginTop: "50px" }}
96-
width={896}
97-
height={504}
96+
width={200}
97+
height={200}
9898
images={images}
9999
showBullets={this.state.showBullets}
100100
showNavs={this.state.showNavs}

example/mobile.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>React Simple Image Slider Example</title>
5+
<meta charset="utf-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"">
7+
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
8+
<meta name="theme-color" content="#000000">
9+
</head>
10+
<body>
11+
<div id="App"></div>
12+
<script src="index.js"></script>
13+
</body>
14+
</html>

index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export interface RSISImage {
66
}
77

88
export interface RSISProps {
9-
width: number;
10-
height: number;
9+
width: string;
10+
height: string;
1111
images: RSISImage[],
1212

1313
style?: CSSStyleDeclaration,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-simple-image-slider",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "simple image slider component for react",
55
"main": "dist/ImageSlider.js",
66
"scripts": {

src/ImageSlider.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ImageSlider extends React.Component {
1313
idx: 0,
1414
sliding: false,
1515
currentSlideStyle: styles.getImageSlide(this.getImageUrl(0), this.props.slideDuration, 0),
16-
nextSlideStyle: styles.getImageSlide(this.getImageUrl(1), this.props.slideDuration, this.props.width),
16+
nextSlideStyle: styles.getImageSlide(this.getImageUrl(1), this.props.slideDuration, 1),
1717
};
1818
ImagePreLoader.load(this.getImageUrl(2));
1919
}
@@ -49,8 +49,8 @@ class ImageSlider extends React.Component {
4949
const toNext = (idx > this.state.idx);
5050
const currentUrl = this.getImageUrl(this.state.idx);
5151
const nextUrl = this.getImageUrl(idx);
52-
const nextReadyX = toNext ? this.props.width : -this.props.width;
53-
const currentOffetX = toNext ? -this.props.width : this.props.width;
52+
const nextReadyX = toNext ? 1 : -1;
53+
const currentOffetX = toNext ? -1 : 1;
5454

5555
// ready to animation slides
5656
this.setState({

src/ImageSliderPropTypes.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ const isValidNavStyle = prop => (/[1-2]/.test(prop) && typeof (prop) === "number
55
export default {
66
propTypes: {
77
// Required
8-
width: PropTypes.number.isRequired,
9-
height: PropTypes.number.isRequired,
8+
width: PropTypes.oneOfType([
9+
PropTypes.string,
10+
PropTypes.number,
11+
]).isRequired,
12+
height: PropTypes.oneOfType([
13+
PropTypes.string,
14+
PropTypes.number,
15+
]).isRequired,
1016
images: PropTypes.arrayOf(PropTypes.shape({
1117
url: PropTypes.string.isRequired,
1218
})).isRequired,

src/ImageSliderStyle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ export default {
7272
width,
7373
height,
7474
}),
75-
getImageSlide: (url, duration, x, isGpuRender) => assignObjects(basicSlide, {
75+
getImageSlide: (url, duration, idx, isGpuRender) => assignObjects(basicSlide, {
7676
overflow: "hidden",
7777
transition: `${duration}s`,
7878
backgroundImage: `url(${url})`,
79-
transform: isGpuRender ? `translate3d(${x}px, 0px, 0px)` : `translate(${x}px, 0px)`,
79+
transform: isGpuRender ? `translate3d(${idx * 100}%, 0px, 0px)` : `translate(${idx * 100}%, 0px)`,
8080
}),
8181
};

0 commit comments

Comments
 (0)