2018-05-25 19:34:35 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import { cloneElement, Component } from '@wordpress/element';
|
2018-07-16 13:53:38 +00:00
|
|
|
import Gridicon from 'gridicons';
|
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';
|
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() {
|
2018-07-16 13:53:38 +00:00
|
|
|
const { actions, className, children, date, icon, subtitle, title, unread } = this.props;
|
2018-06-01 14:35:18 +00:00
|
|
|
const cardClassName = classnames( 'woocommerce-activity-card', className );
|
2018-09-03 15:09:09 +00:00
|
|
|
const actionsList = Array.isArray( actions ) ? actions : [ actions ];
|
2018-05-25 19:34:35 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<section className={ cardClassName }>
|
2018-07-16 13:53:38 +00:00
|
|
|
{ unread && <span className="woocommerce-activity-card__unread" /> }
|
|
|
|
<span className="woocommerce-activity-card__icon" aria-hidden>
|
|
|
|
{ icon }
|
|
|
|
</span>
|
2018-06-01 14:35:18 +00:00
|
|
|
<header className="woocommerce-activity-card__header">
|
2018-07-16 13:53:38 +00:00
|
|
|
<H className="woocommerce-activity-card__title">{ title }</H>
|
|
|
|
{ subtitle && <div className="woocommerce-activity-card__subtitle">{ subtitle }</div> }
|
|
|
|
{ date && (
|
|
|
|
<span className="woocommerce-activity-card__date">{ moment( date ).fromNow() }</span>
|
|
|
|
) }
|
2018-05-25 19:34:35 +00:00
|
|
|
</header>
|
2018-07-16 13:53:38 +00:00
|
|
|
<Section className="woocommerce-activity-card__body">{ children }</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-07-16 13:53:38 +00:00
|
|
|
{ actionsList.map( ( item, i ) => cloneElement( item, { key: i } ) ) }
|
2018-05-25 19:34:35 +00:00
|
|
|
</footer>
|
|
|
|
) }
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivityCard.propTypes = {
|
2018-07-16 13:53:38 +00:00
|
|
|
actions: PropTypes.oneOfType( [ PropTypes.arrayOf( PropTypes.element ), PropTypes.element ] ),
|
2018-05-25 19:34:35 +00:00
|
|
|
className: PropTypes.string,
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
date: PropTypes.string,
|
|
|
|
icon: PropTypes.node,
|
2018-07-16 13:53:38 +00:00
|
|
|
subtitle: PropTypes.node,
|
2018-08-01 12:21:51 +00:00
|
|
|
title: PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ).isRequired,
|
2018-07-16 13:53:38 +00:00
|
|
|
unread: PropTypes.bool,
|
2018-05-25 19:34:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ActivityCard.defaultProps = {
|
2018-07-16 13:53:38 +00:00
|
|
|
icon: <Gridicon icon="notice-outline" size={ 48 } />,
|
|
|
|
unread: false,
|
2018-05-25 19:34:35 +00:00
|
|
|
};
|
|
|
|
|
2018-07-20 18:41:39 +00:00
|
|
|
export { ActivityCard };
|
|
|
|
export { default as ActivityCardPlaceholder } from './placeholder';
|