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

[CardHeader] Make avatar prop optional #1879

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions src/card/card-header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ const CardHeader = React.createClass({
let titleStyle = this.prepareStyles(styles.title, this.props.titleStyle);
let subtitleStyle = this.prepareStyles(styles.subtitle, this.props.subtitleStyle);

let avatar = this.props.avatar;
let avatar = this.props.avatar || null;
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to use the getDefaultProps

Choose a reason for hiding this comment

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

What if you don't set a default at all and just check on line 102 for
else if (typeof this.props.avatar === 'string') {

Seems to express the intention of the if-statement better, imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

@oliviertassinari did you have more feedback for @thataustin ?

if (React.isValidElement(this.props.avatar)) {
let avatarMergedStyle = this.mergeStyles(styles.avatar, avatar.props.style);
avatar = React.cloneElement(avatar, {style:avatarMergedStyle});
}
else
else if (avatar !== null) {
avatar = <Avatar src={this.props.avatar} style={styles.avatar}/>;

}

return (
<div {...this.props} style={rootStyle}>
{avatar}
Expand Down