/**
* External dependencies
*/
import PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';
/*eslint lodash/import-scope: [2, "method"]*/
import assign from 'lodash/assign';
/*eslint lodash/import-scope: [2, "method"]*/
import omit from 'lodash/omit';
/**
* Internal dependencies
*/
import { Gridicon } from '@automattic/jetpack-components';
import './style.scss';
class CardSection extends React.Component {
static propTypes = {
title: PropTypes.any,
vertical: PropTypes.any,
style: PropTypes.object,
className: PropTypes.string,
device: PropTypes.oneOf( [ 'desktop', 'tablet', 'phone' ] ),
};
static defaultProps = { vertical: null };
render() {
return (
{ this.props.title ? this._renderWithTitle() : this.props.children }
);
}
_renderWithTitle = () => {
const orientation = this.props.vertical ? 'vertical' : 'horizontal';
const wrapperClassName = 'dops-card-section-orient-' + orientation;
return (
{ this.props.title }
{ this.props.children }
);
};
}
class CardFooter extends React.Component {
render() {
return { this.props.children }
;
}
}
class Card extends React.Component {
static propTypes = {
meta: PropTypes.any,
icon: PropTypes.string,
iconLabel: PropTypes.any,
iconColor: PropTypes.string,
style: PropTypes.object,
className: PropTypes.string,
href: PropTypes.string,
onClick: PropTypes.func,
title: PropTypes.string,
tagName: PropTypes.string,
target: PropTypes.string,
compact: PropTypes.bool,
children: PropTypes.node,
};
static defaultProps = {
iconColor: '#787878',
className: '',
tagName: 'div',
onClick: () => {},
};
render() {
const className = classnames( 'dops-card', this.props.className, {
'is-card-link': !! this.props.href,
'is-compact': this.props.compact,
} );
const omitProps = [ 'compact', 'tagName', 'meta', 'iconColor' ];
let linkIndicator;
if ( this.props.href ) {
linkIndicator = (
);
} else {
omitProps.push( 'href', 'target' );
}
let fancyTitle;
if ( this.props.title ) {
fancyTitle = (
{ this.props.title }
{ this.props.meta && { this.props.meta } }
{ ( this.props.icon || this.props.iconLabel ) && this._renderIcon() }
);
}
return React.createElement(
this.props.href ? 'a' : this.props.tagName,
assign( omit( this.props, omitProps ), { className } ),
linkIndicator,
fancyTitle,
this.props.children
);
}
_renderIcon = () => {
return (
{ this.props.icon && (
) }
{ this.props.iconLabel }
);
};
}
Card.Section = CardSection;
Card.Footer = CardFooter;
export default Card;