2016-03-22 00:25:23 +01:00
|
|
|
import React from 'react';
|
2016-03-30 05:38:34 +02:00
|
|
|
import SilverStripeComponent from 'silverstripe-component';
|
2016-03-22 00:25:23 +01:00
|
|
|
|
|
|
|
class TextFieldComponent extends SilverStripeComponent {
|
|
|
|
|
2016-03-30 23:45:54 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="field text">
|
|
|
|
{this.props.label &&
|
|
|
|
<label className="left" htmlFor={`gallery_${this.props.name}`}>
|
|
|
|
{this.props.label}
|
|
|
|
</label>
|
2016-03-22 00:25:23 +01:00
|
|
|
}
|
2016-03-30 23:45:54 +02:00
|
|
|
<div className="middleColumn">
|
|
|
|
<input {...this.getInputProps()} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getInputProps() {
|
|
|
|
return {
|
|
|
|
className: ['text', this.props.extraClass].join(' '),
|
|
|
|
id: `gallery_${this.props.name}`,
|
|
|
|
name: this.props.name,
|
|
|
|
onChange: this.props.onChange,
|
|
|
|
type: 'text',
|
|
|
|
value: this.props.value,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange() {
|
|
|
|
if (typeof this.props.onChange === 'undefined') {
|
|
|
|
return;
|
2016-03-22 00:25:23 +01:00
|
|
|
}
|
2016-03-30 23:45:54 +02:00
|
|
|
|
|
|
|
this.props.onChange();
|
|
|
|
}
|
2016-03-22 00:25:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TextFieldComponent.propTypes = {
|
2016-03-30 23:45:54 +02:00
|
|
|
label: React.PropTypes.string,
|
|
|
|
extraClass: React.PropTypes.string,
|
|
|
|
name: React.PropTypes.string.isRequired,
|
|
|
|
onChange: React.PropTypes.func,
|
|
|
|
value: React.PropTypes.string,
|
2016-03-22 00:25:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default TextFieldComponent;
|