react-life-design
Version:
Life Design UI components
55 lines • 2.54 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var Select_styled_1 = require("./Select.styled");
var Icons_1 = require("../Icons");
var Select = (function (_super) {
__extends(Select, _super);
function Select() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = {
selectedValue: '',
degree: 180,
};
_this.renderHTMLOptions = function () { return _this.props.options
.map(function (item) { return (React.createElement("option", { value: item.value }, item.label)); }); };
_this.handleSelectChange = function (_a) {
var value = _a.currentTarget.value;
_this.setState({ selectedValue: value });
if (value !== 'hide') {
_this.props.onChange(value);
return;
}
_this.props.onChange(undefined);
};
_this.isInvalid = function () { return _this.state.selectedValue === 'hide'; };
return _this;
}
Select.prototype.render = function () {
var _this = this;
var _a = this.state, selectedValue = _a.selectedValue, degree = _a.degree;
var label = this.props.label;
return (React.createElement(Select_styled_1.Wrapper, null,
React.createElement(Select_styled_1.SelectStyled, { onChange: this.handleSelectChange, onBlur: function () { return _this.setState({ degree: 180 }); } },
React.createElement("option", { value: 'hide' }, label),
this.renderHTMLOptions()),
React.createElement(Select_styled_1.Label, { active: (!this.isInvalid() && selectedValue) }, label),
React.createElement(Icons_1.default.Arrow, { degree: degree, width: 20, height: 20 })));
};
return Select;
}(React.PureComponent));
exports.default = Select;
//# sourceMappingURL=Select.js.map
;