'use strict'; import React from 'react'; import AlertMixin from '../../mixins/alert_mixin'; import TextareaAutosize from 'react-textarea-autosize'; import Button from 'react-bootstrap/lib/Button'; let InputTextAreaToggable = React.createClass({ propTypes: { editable: React.PropTypes.bool.isRequired, submitted: React.PropTypes.bool, rows: React.PropTypes.number.isRequired, onSubmit: React.PropTypes.func.isRequired, required: React.PropTypes.string, defaultValue: React.PropTypes.string }, mixins: [AlertMixin], getInitialState() { return { value: this.props.defaultValue, edited: false, alerts: null // needed in AlertMixin }; }, handleChange(event) { this.setState({ value: event.target.value, edited: true }); }, reset(){ this.setState(this.getInitialState()); }, submit(){ this.props.onSubmit(); this.setState({edited: false}); }, render() { let className = 'form-control ascribe-textarea'; let buttons = null; let textarea = null; if (this.props.editable && this.state.edited){ buttons = (
); } if (this.props.editable){ className = className + ' ascribe-textarea-editable'; textarea = ( ); } else{ textarea =
{this.state.value}
; } let alerts = (this.props.submitted) ? null : this.state.alerts; return (
{alerts} {textarea} {buttons}
); } }); export default InputTextAreaToggable;