From 9f8c79fcea7fdbb14a307b1a003878c3299412d9 Mon Sep 17 00:00:00 2001 From: Bojan Mihelac Date: Thu, 30 Aug 2018 10:11:21 +0200 Subject: [PATCH] fix(card): add missing hasRipple (#248) --- packages/card/PrimaryContent.js | 54 +++++++++++++++++++++++++++------ packages/card/README.md | 8 ++++- packages/card/package.json | 1 + test/screenshot/card/index.js | 6 ++-- test/unit/card/Content.test.js | 26 +++++++++++++--- 5 files changed, 77 insertions(+), 18 deletions(-) diff --git a/packages/card/PrimaryContent.js b/packages/card/PrimaryContent.js index 96fe8c38e..70f6aa106 100644 --- a/packages/card/PrimaryContent.js +++ b/packages/card/PrimaryContent.js @@ -24,33 +24,67 @@ import React from 'react'; import classnames from 'classnames'; import PropTypes from 'prop-types'; +import withRipple from '@material/react-ripple'; + export default class PrimaryContent extends React.Component { render() { const { - className, - children, + hasRipple, ...otherProps } = this.props; - const classes = classnames('mdc-card__primary-action', className); - + if (hasRipple) { + return (); + } return ( -
- {children} -
+ ); } } + +const PrimaryContentDefault = (props) => { + const { + className, + initRipple, + children, + ...otherProps + } = props; + + const classes = classnames('mdc-card__primary-action', className); + return ( +
+ {children} +
+ ); +}; + +export const RipplePrimaryContent = withRipple(PrimaryContentDefault); + PrimaryContent.propTypes = { className: PropTypes.string, children: PropTypes.node, + hasRipple: PropTypes.bool, }; PrimaryContent.defaultProps = { className: '', children: null, + hasRipple: false, +}; + +PrimaryContentDefault.propTypes = { + className: PropTypes.string, + children: PropTypes.node, + initRipple: PropTypes.func, +}; + +PrimaryContentDefault.defaultProps = { + className: '', + initRipple: () => {}, + children: null, }; diff --git a/packages/card/README.md b/packages/card/README.md index 2bca1b88d..62fbfb455 100644 --- a/packages/card/README.md +++ b/packages/card/README.md @@ -87,12 +87,18 @@ This component is used as the container for primary tappable content. import Card, {CardPrimaryContent} from '@material/react-card'; - +

Content

``` +#### Props +Prop Name | Type | Description +--- | --- | --- +hasRipple | n/a | If present on element, it will enable the ripple on the primary content. + + ### CardMedia This component is a container for an image on the card. Optionally, any children of the `` component is wrapped with an element with the className `.mdc-card__media-content`. diff --git a/packages/card/package.json b/packages/card/package.json index 61ab7cb30..7033b8fc8 100644 --- a/packages/card/package.json +++ b/packages/card/package.json @@ -16,6 +16,7 @@ "url": "https://github.com/material-components/material-components-web-react.git" }, "dependencies": { + "@material/react-ripple": "^0.4.2", "@material/card": "^0.39.0", "classnames": "^2.2.5", "prop-types": "^15.6.1", diff --git a/test/screenshot/card/index.js b/test/screenshot/card/index.js index cba54a3f0..320680f6a 100644 --- a/test/screenshot/card/index.js +++ b/test/screenshot/card/index.js @@ -18,7 +18,7 @@ const imageUrl = './../images/1-1.jpg'; const BasicCard = () => { return ( - + @@ -37,7 +37,7 @@ const BasicCard = () => { const HorizontalCard = () => { return ( - +
@@ -106,7 +106,7 @@ const NewsRow = ({title, snippet, index}) => { const ContentOnMediaCard = () => { return ( - + { - const wrapper = shallow(); - assert.isTrue(wrapper.hasClass('test-class-name')); - assert.isTrue(wrapper.hasClass('mdc-card__primary-action')); + const wrapper = mount(); + const primaryContentDiv = wrapper.find('.mdc-card__primary-action'); + assert.isTrue(primaryContentDiv.hasClass('test-class-name')); + assert.equal(primaryContentDiv.length, 1); +}); + +const rippledPrimaryContent = ; + +test('if hasRipple true, then it should contain RipplePrimaryContent', () => { + const wrapper = mount( + + ); + assert.isTrue(wrapper.contains(rippledPrimaryContent)); +}); + +test('if hasRipple false, then it should not contain RipplePrimaryContent', () => { + const wrapper = mount( + + ); + assert.isFalse(wrapper.contains(rippledPrimaryContent)); });