2017-04-17 17:14:17 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-05-20 22:05:03 +03:00
|
|
|
import classnames from 'classnames';
|
|
|
|
import { themr } from 'react-css-themr';
|
2017-01-26 20:05:32 +03:00
|
|
|
import { CARD } from '../identifiers';
|
|
|
|
import InjectAvatar from '../avatar/Avatar';
|
2015-11-18 00:24:22 +03:00
|
|
|
|
2016-05-28 20:15:12 +03:00
|
|
|
const factory = (Avatar) => {
|
2017-01-26 20:05:32 +03:00
|
|
|
const CardTitle = ({ avatar, children, className, subtitle, theme, title, ...other }) => {
|
2016-05-28 20:15:12 +03:00
|
|
|
const classes = classnames(theme.cardTitle, {
|
|
|
|
[theme.small]: avatar,
|
2017-01-26 20:05:32 +03:00
|
|
|
[theme.large]: !avatar,
|
2016-05-28 20:15:12 +03:00
|
|
|
}, className);
|
2015-11-22 04:43:18 +03:00
|
|
|
|
2016-05-28 20:15:12 +03:00
|
|
|
return (
|
|
|
|
<div className={classes} {...other}>
|
2016-09-07 14:11:56 +03:00
|
|
|
{typeof avatar === 'string' ? <Avatar image={avatar} theme={theme} /> : avatar}
|
2016-05-28 20:15:12 +03:00
|
|
|
<div>
|
|
|
|
{title && <h5 className={theme.title}>{title}</h5>}
|
|
|
|
{children && typeof children === 'string' && (
|
|
|
|
<h5 className={theme.title}>{children}</h5>
|
|
|
|
)}
|
|
|
|
{subtitle && <p className={theme.subtitle}>{subtitle}</p>}
|
|
|
|
{children && typeof children !== 'string' && children}
|
|
|
|
</div>
|
2015-11-18 00:24:22 +03:00
|
|
|
</div>
|
2016-05-28 20:15:12 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
CardTitle.propTypes = {
|
|
|
|
avatar: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
PropTypes.element,
|
2016-05-28 20:15:12 +03:00
|
|
|
]),
|
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.element,
|
2017-01-26 20:05:32 +03:00
|
|
|
PropTypes.array,
|
2016-05-28 20:15:12 +03:00
|
|
|
]),
|
|
|
|
className: PropTypes.string,
|
|
|
|
subtitle: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
PropTypes.element,
|
2016-05-28 20:15:12 +03:00
|
|
|
]),
|
2016-06-04 00:44:33 +03:00
|
|
|
theme: PropTypes.shape({
|
|
|
|
large: PropTypes.string,
|
|
|
|
title: PropTypes.string,
|
|
|
|
small: PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
subtitle: PropTypes.string,
|
2016-05-28 20:15:12 +03:00
|
|
|
}),
|
|
|
|
title: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
2017-01-26 20:05:32 +03:00
|
|
|
PropTypes.element,
|
|
|
|
]),
|
2016-05-28 20:15:12 +03:00
|
|
|
};
|
2015-11-22 04:43:18 +03:00
|
|
|
|
2016-05-28 20:15:12 +03:00
|
|
|
return CardTitle;
|
2015-11-22 04:43:18 +03:00
|
|
|
};
|
2015-11-18 00:24:22 +03:00
|
|
|
|
2016-05-28 20:15:12 +03:00
|
|
|
const CardTitle = factory(InjectAvatar);
|
|
|
|
export default themr(CARD)(CardTitle);
|
|
|
|
export { CardTitle };
|
|
|
|
export { factory as cardTitleFactory };
|