1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 21:52:08 +02:00
onion/js/components/ascribe_forms/input_textarea_toggable.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-06-09 13:29:22 +02:00
'use strict';
import React from 'react';
import TextareaAutosize from 'react-textarea-autosize';
let InputTextAreaToggable = React.createClass({
propTypes: {
editable: React.PropTypes.bool.isRequired,
rows: React.PropTypes.number.isRequired,
required: React.PropTypes.string,
defaultValue: React.PropTypes.string
},
2015-06-09 13:29:22 +02:00
getInitialState() {
return {
2015-06-22 23:32:41 +02:00
value: this.props.defaultValue
2015-06-09 13:29:22 +02:00
};
},
handleChange(event) {
2015-06-22 23:32:41 +02:00
this.setState({value: event.target.value});
this.props.onChange(event);
2015-06-09 13:29:22 +02:00
},
render() {
let className = 'form-control ascribe-textarea';
let textarea = null;
if (this.props.editable){
className = className + ' ascribe-textarea-editable';
textarea = (
<TextareaAutosize
className={className}
value={this.state.value}
rows={this.props.rows}
required={this.props.required}
onChange={this.handleChange}
2015-06-22 23:32:41 +02:00
onBlur={this.props.onBlur}
placeholder={this.props.placeholder} />
2015-06-09 13:29:22 +02:00
);
}
else{
textarea = <pre className="ascribe-pre">{this.state.value}</pre>;
}
2015-06-22 23:32:41 +02:00
return textarea;
2015-06-09 13:29:22 +02:00
}
});
2015-06-22 23:32:41 +02:00
2015-06-09 13:29:22 +02:00
export default InputTextAreaToggable;