-
Notifications
You must be signed in to change notification settings - Fork 84
/
Review.jsx
72 lines (67 loc) · 2.06 KB
/
Review.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import PropTypes from 'prop-types';
import React from 'react';
import ReviewLink from './ReviewLink';
import classNames from 'classnames';
/**
* The `Review` component wraps up the styles and markup required to make a
* single reviewable row. They are designed to be used either alone, as a single
* row, or multiple rows can be combined together one after the other to present
* more information. The component can take text or HTML as row content.
*/
export class Review extends React.PureComponent {
heading() {
const Heading = this.props.headingLevel
? `h${this.props.headingLevel}`
: `h3`;
if (this.props.heading) {
return (
<Heading className="ds-c-review__heading ds-text ds-u-margin-bottom--0 ds-u-font-weight--bold ds-u-display--inline-block">
{this.props.heading}
</Heading>
);
}
}
render() {
const { children, className, editHref, editText, onEditClick } = 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
);
return (
<div className={classes}>
<div className="ds-u-margin-right--2">
{this.heading()}
<div className="ds-c-review__body">{children}</div>
</div>
{editHref && (
<ReviewLink onClick={onEditClick} href={editHref}>
{editText}
</ReviewLink>
)}
</div>
);
}
}
Review.defaultProps = {
editText: 'Edit'
};
Review.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
heading: PropTypes.node,
/**
* Heading type to override default `<h3>`.
*/
headingLevel: PropTypes.number,
/**
* Href for the edit link. If this is undefined, no edit link will be shown.
*/
editHref: PropTypes.string,
editText: PropTypes.node,
/**
* An optional function that is executed on edit link click. The event and
* props.editHref value are passed to this function.
*/
onEditClick: PropTypes.func
};
export default Review;