From b054480f8cfe0f5dbadfb9146ce37d41117153b4 Mon Sep 17 00:00:00 2001 From: Bernard Date: Tue, 25 Sep 2018 16:49:31 -0500 Subject: [PATCH] Add editContent prop to Review, update tests and example (#279) --- .../src/components/Review/Review.example.jsx | 25 ++++++++++++----- .../core/src/components/Review/Review.jsx | 27 ++++++++++++++----- .../src/components/Review/Review.test.jsx | 9 +++++++ packages/core/yarn.lock | 4 --- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/packages/core/src/components/Review/Review.example.jsx b/packages/core/src/components/Review/Review.example.jsx index 4d1f2ff334..afd6389a33 100644 --- a/packages/core/src/components/Review/Review.example.jsx +++ b/packages/core/src/components/Review/Review.example.jsx @@ -2,25 +2,38 @@ import React from 'react'; import ReactDOM from 'react-dom'; import Review from './Review'; +const editButtonHref = 'javascript:void(0);'; ReactDOM.render(
- + This is an example of a single React Review component. Multiple Review components can be combined together one after another. - + + Edit + | + Remove +
+ } + > + The edit link can be replaced to customize the component. + + John Doe - + October 11, 1980 - +
  • Milk
  • Eggs
  • @@ -28,7 +41,7 @@ ReactDOM.render(
  • Sugar
- The heading is not required. + The heading is not required. , document.getElementById('js-example') ); diff --git a/packages/core/src/components/Review/Review.jsx b/packages/core/src/components/Review/Review.jsx index 8472780f92..afa45d7104 100644 --- a/packages/core/src/components/Review/Review.jsx +++ b/packages/core/src/components/Review/Review.jsx @@ -24,7 +24,14 @@ export class Review extends React.PureComponent { } render() { - const { children, className, editHref, editText, onEditClick } = this.props; + const { + children, + className, + editHref, + editText, + onEditClick, + editContent + } = this.props; const classes = classNames( 'ds-c-review ds-u-border-bottom--2 ds-u-padding-y--2 ds-u-justify-content--between ds-u-display--flex', className && className @@ -35,11 +42,13 @@ export class Review extends React.PureComponent { {this.heading()}
{children}
- {editHref && ( - - {editText} - - )} + {editContent} + {!editContent && + editHref && ( + + {editText} + + )} ); } @@ -66,7 +75,11 @@ Review.propTypes = { * An optional function that is executed on edit link click. The event and * props.editHref value are passed to this function. */ - onEditClick: PropTypes.func + onEditClick: PropTypes.func, + /** + * An optional node in place of the edit link. If this defined, no edit link will be shown. + */ + editContent: PropTypes.node }; export default Review; diff --git a/packages/core/src/components/Review/Review.test.jsx b/packages/core/src/components/Review/Review.test.jsx index 0e488cd011..963bab65bc 100644 --- a/packages/core/src/components/Review/Review.test.jsx +++ b/packages/core/src/components/Review/Review.test.jsx @@ -53,6 +53,15 @@ describe('Review', function() { expect(reviewLink.length).toBe(0); }); + it('it renders the edit content', () => { + const content =
; + const { wrapper } = render({ editContent: content }); + const editContent = wrapper.find('#editContent'); + const reviewLink = wrapper.find(ReviewLink); + expect(editContent.length).toBe(1); + expect(reviewLink.length).toBe(0); + }); + it('renders HTML children', () => { const { wrapper } = render({},

{text}

); const p = wrapper.find('.my-p'); diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock index 12a42f00db..0e622f5730 100644 --- a/packages/core/yarn.lock +++ b/packages/core/yarn.lock @@ -30,10 +30,6 @@ focus-trap@^2.0.1: dependencies: tabbable "^1.0.3" -lodash.chunk@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/lodash.chunk/-/lodash.chunk-4.2.0.tgz#66e5ce1f76ed27b4303d8c6512e8d1216e8106bc" - lodash.uniqueid@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/lodash.uniqueid/-/lodash.uniqueid-4.0.1.tgz#3268f26a7c88e4f4b1758d679271814e31fa5b26"