react-toolbox/components/card/CardTitle.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-11-22 04:43:18 +03:00
import React, { PropTypes } from 'react';
import classnames from 'classnames';
import { themr } from 'react-css-themr';
import { Avatar } from '../avatar';
const CardTitle = ({avatar, children, className, subtitle, theme, title, ...other}) => {
const classes = classnames(theme.cardTitle, {
[theme.small]: avatar,
[theme.large]: !avatar
2015-11-22 04:43:18 +03:00
}, className);
let avatarComponent;
if (typeof avatar === 'string') {
avatarComponent = <Avatar image={avatar} />;
} else {
avatarComponent = avatar;
}
2015-11-22 04:43:18 +03:00
return (
<div className={classes} {...other}>
{avatarComponent}
2015-11-22 04:43:18 +03:00
<div>
{title && <h5 className={theme.title}>{title}</h5>}
2015-11-22 09:01:49 +03:00
{children && typeof children === 'string' && (
<h5 className={theme.title}>{children}</h5>
2015-11-22 04:43:18 +03:00
)}
{subtitle && <p className={theme.subtitle}>{subtitle}</p>}
2015-11-22 09:01:49 +03:00
{children && typeof children !== 'string' && children}
</div>
2015-11-22 04:43:18 +03:00
</div>
);
};
CardTitle.propTypes = {
avatar: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
]),
2015-11-22 09:01:49 +03:00
children: PropTypes.oneOfType([
PropTypes.string,
2015-11-23 07:19:26 +03:00
PropTypes.element,
PropTypes.array
2015-11-22 09:01:49 +03:00
]),
className: PropTypes.string,
subtitle: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
]),
theme: React.PropTypes.shape({
large: React.PropTypes.string.isRequired,
title: React.PropTypes.string.isRequired,
small: React.PropTypes.string.isRequired,
subtitle: React.PropTypes.string.isRequired
}),
title: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
])
2015-11-22 04:43:18 +03:00
};
export default themr('ToolboxCard')(CardTitle);