-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditableControl.js
42 lines (40 loc) · 1.34 KB
/
EditableControl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from 'react';
import PropTypes from 'prop-types';
import {handleFormUpdate} from '../utils.js';
/**
* EditableControl
*
* An abstraction for the "Editable Control" idea. This control is
* always available on the instructor side, and optionally for the
* student as well.
*/
export default class EditableControl extends React.Component {
render() {
return (
<React.Fragment>
{(this.props.isInstructor || this.props.valueEditable) && (
<label>
{this.props.name}
<input
name={this.props.id}
className="form-control"
type="text"
maxLength={this.props.maxLength || 60}
disabled={this.props.disabled}
value={this.props.value}
onChange={handleFormUpdate.bind(this)} />
</label>
)}
</React.Fragment>
);
}
}
EditableControl.propTypes = {
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
isInstructor: PropTypes.bool.isRequired,
value: PropTypes.string,
valueEditable: PropTypes.bool.isRequired,
disabled: PropTypes.bool,
maxLength: PropTypes.number
};