Skip to content

[feature/issue-1] modify props types about width and height #2

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

Merged
merged 1 commit into from
Mar 30, 2020
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

1.0.3 (March 30, 2018)
- modify props types about width and height. ( number -> string or number )
- can set value like this. '100%' or '100px' or 100

1.0.2 (October 08, 2018)
- add index.d.ts (for typescript).

Expand Down
4 changes: 2 additions & 2 deletions example/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class App extends React.Component {
</AppBar>
<SimpleImageSlider
style={{ margin: "0 auto", marginTop: "50px" }}
width={896}
height={504}
width={200}
height={200}
images={images}
showBullets={this.state.showBullets}
showNavs={this.state.showNavs}
Expand Down
14 changes: 14 additions & 0 deletions example/mobile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>React Simple Image Slider Example</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
<meta name="theme-color" content="#000000">
</head>
<body>
<div id="App"></div>
<script src="index.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface RSISImage {
}

export interface RSISProps {
width: number;
height: number;
width: string;
height: string;
images: RSISImage[],

style?: CSSStyleDeclaration,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-simple-image-slider",
"version": "1.0.2",
"version": "1.0.3",
"description": "simple image slider component for react",
"main": "dist/ImageSlider.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ImageSlider extends React.Component {
idx: 0,
sliding: false,
currentSlideStyle: styles.getImageSlide(this.getImageUrl(0), this.props.slideDuration, 0),
nextSlideStyle: styles.getImageSlide(this.getImageUrl(1), this.props.slideDuration, this.props.width),
nextSlideStyle: styles.getImageSlide(this.getImageUrl(1), this.props.slideDuration, 1),
};
ImagePreLoader.load(this.getImageUrl(2));
}
Expand Down Expand Up @@ -49,8 +49,8 @@ class ImageSlider extends React.Component {
const toNext = (idx > this.state.idx);
const currentUrl = this.getImageUrl(this.state.idx);
const nextUrl = this.getImageUrl(idx);
const nextReadyX = toNext ? this.props.width : -this.props.width;
const currentOffetX = toNext ? -this.props.width : this.props.width;
const nextReadyX = toNext ? 1 : -1;
const currentOffetX = toNext ? -1 : 1;

// ready to animation slides
this.setState({
Expand Down
10 changes: 8 additions & 2 deletions src/ImageSliderPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ const isValidNavStyle = prop => (/[1-2]/.test(prop) && typeof (prop) === "number
export default {
propTypes: {
// Required
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
width: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]).isRequired,
height: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]).isRequired,
images: PropTypes.arrayOf(PropTypes.shape({
url: PropTypes.string.isRequired,
})).isRequired,
Expand Down
4 changes: 2 additions & 2 deletions src/ImageSliderStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export default {
width,
height,
}),
getImageSlide: (url, duration, x, isGpuRender) => assignObjects(basicSlide, {
getImageSlide: (url, duration, idx, isGpuRender) => assignObjects(basicSlide, {
overflow: "hidden",
transition: `${duration}s`,
backgroundImage: `url(${url})`,
transform: isGpuRender ? `translate3d(${x}px, 0px, 0px)` : `translate(${x}px, 0px)`,
transform: isGpuRender ? `translate3d(${idx * 100}%, 0px, 0px)` : `translate(${idx * 100}%, 0px)`,
}),
};