import React, { PropTypes, Component } from 'react' import { RIETextArea } from 'riek' import Util from '../../Metamaps/Util' class MdTextArea extends RIETextArea { keyDown = (event) => { // we'll handle Enter on our own, thanks const ESC = 27 if (event.keyCode === ESC) { this.cancelEditing() } } renderNormalComponent = () => { // defaultProps MUST use dangerouslySetInnerHTML return } } class Desc extends Component { render = () => { const descHTML = (!this.props.desc && this.props.authorizedToEdit) ? '

Click to add description...

' : Util.mdToHTML(this.props.desc) if (this.props.authorizedToEdit) { return (
{ const ENTER = 13 if (!e.shiftKey && e.which === ENTER) { e.preventDefault() this.props.onChange({ desc: e.target.value }) } } }} defaultProps={{ dangerouslySetInnerHTML: { __html: descHTML } }} />
) } else { return (
{this.props.desc}
) } } } Desc.propTypes = { desc: PropTypes.string, // markdown authorizedToEdit: PropTypes.bool, onChange: PropTypes.func } export default Desc