Skip to content
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

Default selected image props added (pass image index) #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<CoverFlow handleSelect={(index)=>{alert(index);}} imagesArr={imagesArr} />
```
Expand Down
5 changes: 3 additions & 2 deletions src/CoverFlow/Container/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can make it const.

this.state = {
selectedIndex: index,
prevIndex: index,
Expand Down Expand Up @@ -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;
6 changes: 4 additions & 2 deletions src/CoverFlow/CoverFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} />;
}
}

Expand All @@ -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 = {
Expand Down