react-toolbox/components/card/CardTitle.js

64 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

import React from 'react';
import PropTypes from 'prop-types';
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';
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}>
{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>
</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
]),
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
};
2016-05-28 20:15:12 +03:00
const CardTitle = factory(InjectAvatar);
export default themr(CARD)(CardTitle);
export { CardTitle };
export { factory as cardTitleFactory };