import React from 'react'; import Navigation from '../navigation'; import Ripple from '../ripple'; import style from './style'; class Card extends React.Component { static propTypes = { actions: React.PropTypes.array, className: React.PropTypes.string, color: React.PropTypes.string, image: React.PropTypes.string, loading: React.PropTypes.bool, onClick: React.PropTypes.func, text: React.PropTypes.string, title: React.PropTypes.string, type: React.PropTypes.oneOf(['wide', 'event', 'image']) }; static defaultProps = { className: '', loading: false }; handleMouseDown = (event) => { if (this.props.onClick) { event.preventDefault(); this.refs.ripple.start(event); this.props.onClick(event, this); } }; renderActions () { if (this.props.actions) { return ( ); } } renderTitle () { const styleFigure = {}; const styleOverflow = {}; if (this.props.image) styleFigure.backgroundImage = `url(${this.props.image})`; if (this.props.color) { styleFigure.backgroundColor = this.props.color; styleOverflow.backgroundColor = this.props.color; } if (this.props.title || this.props.image) { return (
{ this.props.title ?
{this.props.title}
: null } { this.props.subtitle ? {this.props.subtitle} : null } { this.props.color ?
: null }
); } } render () { let className = style.root; if (this.props.type) className += ` ${style[this.props.type]}`; if (this.props.onClick) className += ` ${style.touch}`; if (this.props.image || this.props.color) className += ` ${style.contrast}`; if (this.props.color) className += ` ${style.color}`; if (this.props.loading) className += ` ${style.loading}`; if (this.props.className) className += ` ${this.props.className}`; return (
{ this.renderTitle() } { this.props.text ?

{this.props.text}

: null } { this.renderActions() }
); } } export default Card;