Home Reference Source

application/metaproperties/longtext-meta-property.js

  1. import React from 'react';
  2. import TextField from 'material-ui/TextField';
  3.  
  4. class LongtextMetaProperty extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. this.displayName = 'LongtextMetaProperty';
  8. }
  9.  
  10. rando() {
  11. const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  12.  
  13. let str = [];
  14. for (let i=0; i<5; i++) {
  15. str.push(chars.charAt(Math.floor(Math.random() * chars.length)));
  16. }
  17.  
  18. return str.join('');
  19. }
  20.  
  21. shouldComponentUpdate(nextProps, nextState) {
  22. if (nextProps.value != this.props.value) {
  23. return true;
  24. }
  25. if (nextProps.disabled != this.props.disabled) {
  26. return true;
  27. }
  28. return false;
  29. }
  30.  
  31. render() {
  32. const name = this.props.name ? this.props.name : 'textfield_' + this.rando();
  33. return (
  34. <TextField
  35. name={name}
  36. multiLine={true}
  37. rows={2}
  38. rowsMax={6}
  39. {...this.props}
  40. />
  41. );
  42. }
  43. }
  44.  
  45. export default LongtextMetaProperty;