application/metaproperties/richtext-meta-property.js
import React from 'react';
import TextField from 'material-ui/TextField';
import RichEditor from './../components/common/rich-editor';
import {rawToHtml} from './../util/rawToHtml';
class RichtextMetaProperty extends React.Component {
constructor(props) {
super(props);
this.displayName = 'RichtextMetaProperty';
}
rando() {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let str = [];
for (let i=0; i<5; i++) {
str.push(chars.charAt(Math.floor(Math.random() * chars.length)));
}
return str.join('');
}
shouldComponentUpdate(nextProps, nextState) {
if (nextProps.value != this.props.value) {
return true;
}
if (nextProps.disabled != this.props.disabled) {
return true;
}
return false;
}
handleEditorChange(raw, state, name) {
const propName = this.props.name;
let fakeEvent = {
target: {
getAttribute: function() {
return propName;
},
value: rawToHtml(state.getCurrentContent())
}
};
this.props.onChange(fakeEvent);
}
render() {
const name = this.props.name ? this.props.name : 'textfield_' + this.rando();
return (
<div className='editor-container'>
<RichEditor
label={this.props.floatingLabelText}
name={name}
enableComments={false}
unlinkedValue={this.props.value ? this.props.value : ''}
onChange={this.handleEditorChange.bind(this)}
/>
</div>
);
}
}
export default RichtextMetaProperty;