aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/fields/TextField.js
diff options
context:
space:
mode:
authorEmiliano Ciavatta2020-09-26 10:05:27 +0000
committerEmiliano Ciavatta2020-09-26 10:05:27 +0000
commit44af615b32faf53c04cd38cb63782cf1b1332c94 (patch)
treef51d0bd469421eb1aba698bfa4ec0ab2853d26f2 /frontend/src/components/fields/TextField.js
parent05678b74d98247c957faa1ca3d0bafc5f68974d1 (diff)
General refactor
Diffstat (limited to 'frontend/src/components/fields/TextField.js')
-rw-r--r--frontend/src/components/fields/TextField.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/frontend/src/components/fields/TextField.js b/frontend/src/components/fields/TextField.js
new file mode 100644
index 0000000..86b98ed
--- /dev/null
+++ b/frontend/src/components/fields/TextField.js
@@ -0,0 +1,42 @@
+import React, {Component} from 'react';
+import './TextField.scss';
+import {randomClassName} from "../../utils";
+
+const classNames = require('classnames');
+
+class TextField extends Component {
+
+ constructor(props) {
+ super(props);
+
+ this.id = `field-${this.props.name || "noname"}-${randomClassName()}`;
+ }
+
+ render() {
+ const name = this.props.name || null;
+ const error = this.props.error || null;
+ const rows = this.props.rows || 3;
+
+ const handler = (e) => {
+ if (this.props.onChange) {
+ if (e == null) {
+ this.props.onChange("");
+ } else {
+ this.props.onChange(e.target.value);
+ }
+ }
+ };
+
+ return (
+ <div className={classNames("text-field", {"field-active": this.props.active},
+ {"field-invalid": this.props.invalid}, {"field-small": this.props.small})}>
+ {name && <label htmlFor={this.id}>{name}:</label>}
+ <textarea id={this.id} placeholder={this.props.defaultValue} onChange={handler} rows={rows}
+ readOnly={this.props.readonly} value={this.props.value} />
+ {error && <div className="field-error">error: {error}</div>}
+ </div>
+ );
+ }
+}
+
+export default TextField;