2018-05-10 19:23:41 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
2018-08-31 17:19:13 +00:00
|
|
|
import EllipsisMenu from 'components/ellipsis-menu';
|
2018-09-21 15:19:05 +00:00
|
|
|
import { H, Section } from 'components/section';
|
2018-08-31 17:19:13 +00:00
|
|
|
import { validateComponent } from 'lib/proptype-validator';
|
2018-05-10 19:23:41 +00:00
|
|
|
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* A basic card component with a header. The header can contain a title, an action, and an `EllipsisMenu` menu.
|
|
|
|
*/
|
2018-05-10 19:23:41 +00:00
|
|
|
class Card extends Component {
|
|
|
|
render() {
|
|
|
|
const { action, children, menu, title } = this.props;
|
2018-06-01 14:35:18 +00:00
|
|
|
const className = classnames( 'woocommerce-card', this.props.className, {
|
2018-05-10 19:23:41 +00:00
|
|
|
'has-menu': !! menu,
|
|
|
|
'has-action': !! action,
|
|
|
|
} );
|
|
|
|
return (
|
|
|
|
<div className={ className }>
|
2018-10-31 02:07:16 +00:00
|
|
|
{ title && (
|
|
|
|
<div className="woocommerce-card__header">
|
|
|
|
<H className="woocommerce-card__title woocommerce-card__header-item">{ title }</H>
|
|
|
|
{ action && (
|
|
|
|
<div className="woocommerce-card__action woocommerce-card__header-item">
|
|
|
|
{ action }
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
{ menu && (
|
|
|
|
<div className="woocommerce-card__menu woocommerce-card__header-item">{ menu }</div>
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
) }
|
2018-06-20 15:10:06 +00:00
|
|
|
<Section className="woocommerce-card__body">{ children }</Section>
|
2018-05-10 19:23:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Card.propTypes = {
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* One "primary" action for this card, appears in the card header.
|
|
|
|
*/
|
2018-05-10 19:23:41 +00:00
|
|
|
action: PropTypes.node,
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* Additional CSS classes.
|
|
|
|
*/
|
2018-05-10 19:23:41 +00:00
|
|
|
className: PropTypes.string,
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* An `EllipsisMenu`, with filters used to control the content visible in this card
|
|
|
|
*/
|
2018-08-31 17:19:13 +00:00
|
|
|
menu: validateComponent( EllipsisMenu ),
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* The title to use for this card.
|
|
|
|
*/
|
2018-10-31 02:07:16 +00:00
|
|
|
title: PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ),
|
2018-05-10 19:23:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Card;
|