office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
39 lines • 1.81 kB
JavaScript
import * as tslib_1 from "tslib";
import * as React from 'react';
import { DefaultButton } from 'office-ui-fabric-react/lib/Button';
import { TextField } from 'office-ui-fabric-react/lib/TextField';
var NumberTextField = /** @class */ (function (_super) {
tslib_1.__extends(NumberTextField, _super);
function NumberTextField(props) {
var _this = _super.call(this, props) || this;
_this._restore = _this._restore.bind(_this);
_this._onChange = _this._onChange.bind(_this);
_this._validateNumber = _this._validateNumber.bind(_this);
_this.state = {
value: props.initialValue
};
return _this;
}
NumberTextField.prototype.render = function () {
return (React.createElement("div", { className: "NumberTextField" },
React.createElement(TextField, { className: "NumberTextField-textField", label: this.props.label, value: this.state.value, onChange: this._onChange, onGetErrorMessage: this._validateNumber }),
React.createElement("div", { className: "NumberTextField-restoreButton" },
React.createElement(DefaultButton, { onClick: this._restore }, "Restore"))));
};
NumberTextField.prototype._validateNumber = function (value) {
return isNaN(Number(value)) ? "The value should be a number, actual is " + value + "." : '';
};
NumberTextField.prototype._onChange = function (ev, value) {
return this.setState({
value: value
});
};
NumberTextField.prototype._restore = function () {
this.setState({
value: this.props.initialValue
});
};
return NumberTextField;
}(React.Component));
export { NumberTextField };
//# sourceMappingURL=NumberTextField.js.map