diff --git a/README.md b/README.md index a9cf3fa..6bfceb2 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ const imagesArr = [ * **border** - a css border property. The default is 'none'. You can assign any valid css border. * **boxShadow** - a css box-shadow property. The default is 'none'. You can assign any valid css box-shadow. * **handleSelect** - you can pass a callback function. The function has an index parameter. +* **defaultSelectedItem** - select an image by index, default is middle image. ```jsx {alert(index);}} imagesArr={imagesArr} /> ``` diff --git a/src/CoverFlow/Container/Container.js b/src/CoverFlow/Container/Container.js index 52a6acc..eaf9f89 100644 --- a/src/CoverFlow/Container/Container.js +++ b/src/CoverFlow/Container/Container.js @@ -14,7 +14,7 @@ class Container extends React.Component { this.calcIndex = this.calcIndex.bind(this); this.calcItemDimensions = this.calcItemDimensions.bind(this); this.calcItemsAmountToRender = this.calcItemsAmountToRender.bind(this); - let index = this.calcIndex(); + let index = this.props.defaultSelectedItem || this.props.defaultSelectedItem == 0 ? this.props.defaultSelectedItem : this.calcIndex(); this.state = { selectedIndex: index, prevIndex: index, @@ -205,7 +205,8 @@ Container.propTypes = { border: PropTypes.string, boxShadow: PropTypes.string, itemRatio: PropTypes.string, - handleSelect: PropTypes.func + handleSelect: PropTypes.func, + defaultSelectedItem: PropTypes.number }; export default Container; \ No newline at end of file diff --git a/src/CoverFlow/CoverFlow.js b/src/CoverFlow/CoverFlow.js index bc837ea..b637c9c 100644 --- a/src/CoverFlow/CoverFlow.js +++ b/src/CoverFlow/CoverFlow.js @@ -53,7 +53,8 @@ class CoverFlow extends React.Component { background={this.props.background} border={this.props.border} boxShadow={this.props.boxShadow} - direction={this.props.direction} />; + direction={this.props.direction} + defaultSelectedItem={this.props.defaultSelectedItem} />; } } @@ -68,7 +69,8 @@ CoverFlow.propTypes = { emptyMessage: PropTypes.string, itemRatio: PropTypes.string, handleSelect: PropTypes.func, - labelsArr: PropTypes.array + labelsArr: PropTypes.array, + defaultSelectedItem: PropTypes.number }; CoverFlow.defaultProps = {