Skip to content

Commit

Permalink
Merge pull request #2 from vadymshymko/develop
Browse files Browse the repository at this point in the history
Fix bug with empty item style prop
  • Loading branch information
vadymshymko authored May 28, 2018
2 parents 8d33178 + 8663e63 commit d6d1126
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 22 deletions.
2 changes: 1 addition & 1 deletion dist/Carousel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/Carousel.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ class App extends Component {
backgroundColor: "#000",
color: "#fff",
}}
onClick={() => {
console.log('item click');
}}
key={index}
>
{index}
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": "reactjs-simple-carousel",
"version": "0.0.1",
"version": "0.0.2",
"description": "Simple react.js carousel component",
"main": "dist/index.js",
"scripts": {
Expand Down
20 changes: 6 additions & 14 deletions src/components/Carousel/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ReactJSSimpleCarousel extends Component {

this.slides = [];

this.itemsListPosition = 0;
this.itemsListTransition = null;
this.isItemsListTransitionDisabled = false;

Expand Down Expand Up @@ -182,14 +183,6 @@ class ReactJSSimpleCarousel extends Component {
return 0;
}

getItemsListOffsetFromDOM = () => {
if (this.itemsList) {
return parseInt(this.itemsList.dataset.position || 0, 10);
}

return 0;
}

getSlideIndexByListOffset = (listOffset) => {
const {
activeSlideIndex,
Expand Down Expand Up @@ -316,7 +309,7 @@ class ReactJSSimpleCarousel extends Component {
clearTimeout(this.autoplayTimer);
}

this.itemsList.dataset.position = newItemsListOffset;
this.itemsListPosition = newItemsListOffset;
this.itemsList.style.transform = `translateX(${newItemsListOffset}px)`;
}

Expand Down Expand Up @@ -394,7 +387,7 @@ class ReactJSSimpleCarousel extends Component {
clearTimeout(this.autoplayTimer);
}
} else {
this.itemsList.dataset.position = -this.getItemsListOffsetBySlideIndex(validatedSlideIndex);
this.itemsListPosition = -this.getItemsListOffsetBySlideIndex(validatedSlideIndex);
this.itemsList.style.transform = `translateX(${-this.getItemsListOffsetBySlideIndex(validatedSlideIndex)}px)`;
}
}
Expand Down Expand Up @@ -494,7 +487,7 @@ class ReactJSSimpleCarousel extends Component {

const itemsListOffset = this.state.isInitialized
? `-${this.getItemsListOffsetBySlideIndex(validatedActiveSlideIndex)}px`
: this.getItemsListOffsetFromDOM();
: this.itemsListPosition;

const itemsListWidthByItemsToShow = itemsToShow
? `${(100 * itemsCount) / itemsToShow}%`
Expand Down Expand Up @@ -547,7 +540,6 @@ class ReactJSSimpleCarousel extends Component {
{...itemsListProps}
onTouchStart={this.handleListTouchStart}
onMouseDown={this.handleListMouseDown}
data-position={itemsListOffset}
tabIndex="-1"
role="presentation"
ref={(node) => { this.itemsList = node; }}
Expand All @@ -559,10 +551,10 @@ class ReactJSSimpleCarousel extends Component {
style: {
width: itemWidth = null,
...itemStyle
},
} = {},
role,
...itemComponentProps
},
} = {},
...slideComponentData
}, index) => ({
props: {
Expand Down

0 comments on commit d6d1126

Please sign in to comment.