Skip to content

Commit f365fd5

Browse files
committed
add thumbWidth prop to allow specifying thumbnail width
add documentation for new thumbWidth prop
1 parent 06b3c5d commit f365fd5

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ ReactDOM.render(<DemoCarousel />, document.querySelector('.demo-carousel'));
8080
| showStatus | `boolean` | `true` | show index of the current item. i.e: (1/8) |
8181
| showIndicators | `boolean` | `true` | show little dots at the bottom with links for changing the item |
8282
| showThumbs | `boolean` | `true` | show thumbnails of the images |
83+
| 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) |
8384
| infiniteLoop | `boolean` | `false` | infinite loop sliding |
8485
| selectedItem | `number` | `0` | selects an item though props / defines the initial selected item |
8586
| axis | `string` | `horizontal` | changes orientation - accepts `horizontal` and `vertical` |

src/components/Carousel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Carousel extends Component {
2222
showIndicators: PropTypes.bool,
2323
infiniteLoop: PropTypes.bool,
2424
showThumbs: PropTypes.bool,
25+
thumbWidth: PropTypes.number,
2526
selectedItem: PropTypes.number,
2627
onClickItem: PropTypes.func.isRequired,
2728
onClickThumb: PropTypes.func.isRequired,
@@ -464,7 +465,7 @@ class Carousel extends Component {
464465
}
465466

466467
return (
467-
<Thumbs onSelectItem={this.handleClickThumb} selectedItem={this.state.selectedItem} transitionTime={this.props.transitionTime}>
468+
<Thumbs onSelectItem={this.handleClickThumb} selectedItem={this.state.selectedItem} transitionTime={this.props.transitionTime} thumbWidth={this.props.thumbWidth}>
468469
{this.props.children}
469470
</Thumbs>
470471
);

src/components/Thumbs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class Thumbs extends Component {
1212
static propsTypes = {
1313
children: PropTypes.element.isRequired,
1414
transitionTime: PropTypes.number,
15-
selectedItem: PropTypes.number
15+
selectedItem: PropTypes.number,
16+
thumbWidth: PropTypes.number
1617
};
1718

1819
static defaultProps = {
@@ -96,7 +97,7 @@ class Thumbs extends Component {
9697

9798
const total = this.props.children.length;
9899
this.wrapperSize = this.itemsWrapper.clientWidth;
99-
this.itemSize = outerWidth(this.refs.thumb0);
100+
this.itemSize = this.props.thumbWidth ? this.props.thumbWidth : outerWidth(this.refs.thumb0);
100101
this.visibleItems = Math.floor(this.wrapperSize / this.itemSize);
101102
this.lastPosition = total - this.visibleItems;
102103
this.showArrows = this.visibleItems < total;

0 commit comments

Comments
 (0)