2018-05-25 19:34:35 +00:00
|
|
|
|
/** @format */
|
|
|
|
|
/**
|
|
|
|
|
* External dependencies
|
|
|
|
|
*/
|
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
import { cloneElement, Component } from '@wordpress/element';
|
|
|
|
|
import { Dashicon } from '@wordpress/components';
|
2018-06-07 16:05:22 +00:00
|
|
|
|
import { moment } from '@wordpress/date';
|
2018-05-25 19:34:35 +00:00
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Internal dependencies
|
|
|
|
|
*/
|
|
|
|
|
import './style.scss';
|
|
|
|
|
import { EllipsisMenu } from '../ellipsis-menu';
|
2018-06-20 15:10:06 +00:00
|
|
|
|
import { H, Section } from 'layout/section';
|
2018-05-25 19:34:35 +00:00
|
|
|
|
|
|
|
|
|
class ActivityCard extends Component {
|
|
|
|
|
render() {
|
|
|
|
|
const { actions, className, date, icon, image, label, menu, children } = this.props;
|
2018-06-01 14:35:18 +00:00
|
|
|
|
const cardClassName = classnames( 'woocommerce-activity-card', className );
|
2018-05-25 19:34:35 +00:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<section className={ cardClassName }>
|
2018-06-01 14:35:18 +00:00
|
|
|
|
<header className="woocommerce-activity-card__header">
|
|
|
|
|
<span className="woocommerce-activity-card__icon">{ icon }</span>
|
2018-06-20 15:10:06 +00:00
|
|
|
|
<H className="woocommerce-activity-card__label">
|
2018-05-25 19:34:35 +00:00
|
|
|
|
{ label }
|
2018-06-07 16:05:22 +00:00
|
|
|
|
{ date && (
|
|
|
|
|
<span className="woocommerce-activity-card__date">
|
|
|
|
|
– { moment( date ).fromNow() }
|
|
|
|
|
</span>
|
|
|
|
|
) }
|
2018-06-20 15:10:06 +00:00
|
|
|
|
</H>
|
2018-06-01 14:35:18 +00:00
|
|
|
|
{ menu && <div className="woocommerce-activity-card__menu">{ menu }</div> }
|
2018-05-25 19:34:35 +00:00
|
|
|
|
</header>
|
2018-06-20 15:10:06 +00:00
|
|
|
|
<Section className="woocommerce-activity-card__body">
|
2018-06-01 14:35:18 +00:00
|
|
|
|
<div className="woocommerce-activity-card__content">{ children }</div>
|
|
|
|
|
{ image && <div className="woocommerce-activity-card__image">{ image }</div> }
|
2018-06-20 15:10:06 +00:00
|
|
|
|
</Section>
|
2018-05-25 19:34:35 +00:00
|
|
|
|
{ actions && (
|
2018-06-01 14:35:18 +00:00
|
|
|
|
<footer className="woocommerce-activity-card__actions">
|
2018-05-25 19:34:35 +00:00
|
|
|
|
{ actions.map( ( item, i ) => cloneElement( item, { key: i } ) ) }
|
|
|
|
|
</footer>
|
|
|
|
|
) }
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActivityCard.propTypes = {
|
|
|
|
|
actions: PropTypes.oneOfType( [ PropTypes.array, PropTypes.element ] ),
|
|
|
|
|
className: PropTypes.string,
|
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
|
date: PropTypes.string,
|
|
|
|
|
icon: PropTypes.node,
|
|
|
|
|
image: PropTypes.node,
|
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
|
menu: PropTypes.shape( {
|
|
|
|
|
type: PropTypes.oneOf( [ EllipsisMenu ] ),
|
|
|
|
|
} ),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ActivityCard.defaultProps = {
|
|
|
|
|
icon: <Dashicon icon="warning" />,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ActivityCard;
|