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

Add cardZIndex prop #41

Merged
merged 1 commit into from
Mar 26, 2019
Merged
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
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ component as the back of the card.

### Properties

| Props | Type | Description | Default |
| -------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------- | ---------- |
| isFlipped | bool | False to show the front of the card, true to show the back | undefined |
| flipSpeedBackToFront | number | The speed of the flip animation when the card flips from back to front, the higher the number the slower the flip animation | 0.6 |
| flipSpeedFrontToBack | number | The speed of the flip animation when the card flips from front to back, the higher the number the slower the flip animation | 0.6 |
| infinite | bool | False to rotate in opposite directions on both sides of the card, true to rotate in the same direction | false |
| flipDirection | string | Direction of the card flip (options are: 'horizontal' or 'vertical' ) | horizontal |
| Props | Type | Description | Default |
| -------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------- | ------------ |
| cardZIndex | string | z-Index for the flip card. Used to help solve context stack issues while using multiple flip cards. | empty string |
| isFlipped | bool | False to show the front of the card, true to show the back | undefined |
| flipSpeedBackToFront | number | The speed of the flip animation when the card flips from back to front, the higher the number the slower the flip animation | 0.6 |
| flipSpeedFrontToBack | number | The speed of the flip animation when the card flips from front to back, the higher the number the slower the flip animation | 0.6 |
| infinite | bool | False to rotate in opposite directions on both sides of the card, true to rotate in the same direction | false |
| flipDirection | string | Direction of the card flip (options are: 'horizontal' or 'vertical' ) | horizontal |

## Development (`src`, `lib` and the build process)

Expand Down
31 changes: 23 additions & 8 deletions src/ReactCardFlip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ReactCardFlip extends React.Component {
infinite,
flipSpeedFrontToBack,
flipSpeedBackToFront,
cardStyles: { front, back }
cardStyles: { front, back },
cardZIndex
} = this.props;
const { isFlipped, rotation } = this.state;

Expand All @@ -49,7 +50,8 @@ class ReactCardFlip extends React.Component {
const styles = {
container: {
perspective: '1000px',
transformStyle: 'preserve-3d'
transformStyle: 'preserve-3d',
zIndex: `${cardZIndex}`
},
flipper: {
position: 'relative',
Expand Down Expand Up @@ -105,6 +107,7 @@ ReactCardFlip.propTypes = {
front: PropTypes.object,
back: PropTypes.object
}),
cardZIndex: PropTypes.string,
children: (props, propName, componentName) => {
if (React.Children.count(props[propName]) !== 2) {
return new Error(`${componentName} requires two children.`);
Expand All @@ -115,30 +118,42 @@ ReactCardFlip.propTypes = {
return;
}

if (!(typeof props[propName] === 'string' || props[propName] instanceof String)) {
if (
!(
typeof props[propName] === 'string' || props[propName] instanceof String
)
) {
return new Error(`${propName} requires a string.`);
}

if (props[propName].toLowerCase() !== 'horizontal' && props[propName].toLowerCase() !== 'vertical') {
return new Error(`${propName} expects (horizontal|vertical), got ${props[propName].toLowerCase()}`);
if (
props[propName].toLowerCase() !== 'horizontal' &&
props[propName].toLowerCase() !== 'vertical'
) {
return new Error(
`${propName} expects (horizontal|vertical), got ${props[
propName
].toLowerCase()}`
);
}
},
flipSpeedBackToFront: PropTypes.number,
flipSpeedFrontToBack: PropTypes.number,
infinite: PropTypes.bool,
isFlipped: PropTypes.bool,
isFlipped: PropTypes.bool
};

ReactCardFlip.defaultProps = {
cardStyles: {
front: {},
back: {}
},
cardZIndex: 'auto',
flipDirection: 'horizontal',
flipSpeedBackToFront: 0.6,
flipSpeedFrontToBack: 0.6,
infinite: false,
isFlipped: false,
flipDirection: 'horizontal'
isFlipped: false
};

export default ReactCardFlip;