Skip to content

Commit

Permalink
add thumbWidth prop to allow specifying thumbnail width
Browse files Browse the repository at this point in the history
add documentation for new thumbWidth prop
  • Loading branch information
dlong500 committed Sep 22, 2017
1 parent 06b3c5d commit f365fd5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -80,6 +80,7 @@ ReactDOM.render(<DemoCarousel />, document.querySelector('.demo-carousel'));
| showStatus | `boolean` | `true` | show index of the current item. i.e: (1/8) |
| showIndicators | `boolean` | `true` | show little dots at the bottom with links for changing the item |
| showThumbs | `boolean` | `true` | show thumbnails of the images |
| thumbWidth | `number` | `undefined` | optionally specify pixel width (as an integer) of a thumbnail (including any padding) to avoid calculating values (helps with server-side renders or page cache issues) |
| infiniteLoop | `boolean` | `false` | infinite loop sliding |
| selectedItem | `number` | `0` | selects an item though props / defines the initial selected item |
| axis | `string` | `horizontal` | changes orientation - accepts `horizontal` and `vertical` |
Expand Down
3 changes: 2 additions & 1 deletion src/components/Carousel.js
Expand Up @@ -22,6 +22,7 @@ class Carousel extends Component {
showIndicators: PropTypes.bool,
infiniteLoop: PropTypes.bool,
showThumbs: PropTypes.bool,
thumbWidth: PropTypes.number,
selectedItem: PropTypes.number,
onClickItem: PropTypes.func.isRequired,
onClickThumb: PropTypes.func.isRequired,
Expand Down Expand Up @@ -464,7 +465,7 @@ class Carousel extends Component {
}

return (
<Thumbs onSelectItem={this.handleClickThumb} selectedItem={this.state.selectedItem} transitionTime={this.props.transitionTime}>
<Thumbs onSelectItem={this.handleClickThumb} selectedItem={this.state.selectedItem} transitionTime={this.props.transitionTime} thumbWidth={this.props.thumbWidth}>
{this.props.children}
</Thumbs>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/Thumbs.js
Expand Up @@ -12,7 +12,8 @@ class Thumbs extends Component {
static propsTypes = {
children: PropTypes.element.isRequired,
transitionTime: PropTypes.number,
selectedItem: PropTypes.number
selectedItem: PropTypes.number,
thumbWidth: PropTypes.number
};

static defaultProps = {
Expand Down Expand Up @@ -96,7 +97,7 @@ class Thumbs extends Component {

const total = this.props.children.length;
this.wrapperSize = this.itemsWrapper.clientWidth;
this.itemSize = outerWidth(this.refs.thumb0);
this.itemSize = this.props.thumbWidth ? this.props.thumbWidth : outerWidth(this.refs.thumb0);
this.visibleItems = Math.floor(this.wrapperSize / this.itemSize);
this.lastPosition = total - this.visibleItems;
this.showArrows = this.visibleItems < total;
Expand Down

0 comments on commit f365fd5

Please sign in to comment.