react-toolbox/components/card/CardTitle.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-11-22 04:43:18 +03:00
import React, { PropTypes } from 'react';
2015-11-21 22:17:18 +03:00
import ClassNames from 'classnames';
import { Avatar } from '../avatar';
import style from './style';
const CardTitle = ({avatar, children, className, subtitle, title, ...other}) => {
2015-11-22 04:43:18 +03:00
const classes = ClassNames(style.cardTitle, {
[style.small]: avatar,
[style.large]: !avatar
}, 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}>
2015-11-22 04:43:18 +03:00
{avatarComponent && (
<div className={style.avatar}>
{avatarComponent}
</div>
2015-11-22 04:43:18 +03:00
)}
<div>
2015-11-22 09:01:49 +03:00
{title && <h5 className={style.title}>{title}</h5>}
{children && typeof children === 'string' && (
<h5 className={style.title}>{children}</h5>
2015-11-22 04:43:18 +03:00
)}
{subtitle && <p className={style.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
]),
title: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
])
2015-11-22 04:43:18 +03:00
};
export default CardTitle;