ukelli-ui
Version:
Base on React's UI lib. Make frontend's dev simpler and faster.
105 lines (104 loc) • 4.34 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 __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
/* eslint-disable max-len */
import React from 'react';
import Input from './input';
import Selector from '../selector/dropdown-menu';
import FormControlBasic from './form-control-basic';
/**
* 选择器 + 输入控件
*
* @export
* @class InputSelector
* @extends {Component}
*/
var InputSelector = /** @class */ (function (_super) {
__extends(InputSelector, _super);
function InputSelector(props) {
var _this = _super.call(this, props) || this;
_this.changeRef = function (selectorVal) {
if (!selectorVal)
return;
// console.log(...args)
var inputVal = _this.getValue();
_this.setState({
selectRef: selectorVal
});
_this.props.onChange(inputVal, selectorVal);
};
_this.changeInput = function (val) {
var selectRef = _this.state.selectRef;
if (!_this.isControl) {
_this.setState({
inputVal: val
});
_this.emitChange(_this._input.value, selectRef);
}
else {
_this.emitChange(val, selectRef);
}
};
_this.emitChange = function (inputVal, selectRef) {
if (selectRef === void 0) { selectRef = _this.state.selectRef; }
var onChange = _this.props.onChange;
onChange && onChange(inputVal, selectRef);
};
_this.saveInput = function (e) { _this._input = e; };
var defaultSelectorIdx = props.defaultSelectorIdx, value = props.value, defaultValue = props.defaultValue, values = props.values;
_this.state = {
selectRef: defaultSelectorIdx || Object.keys(values)[0],
inputVal: _this.isControl ? value : defaultValue || ''
};
_this.stateValueMark = 'inputVal';
return _this;
}
InputSelector.prototype.focus = function () {
this._input.focus();
};
InputSelector.prototype.render = function () {
var _a = this.props, inputProps = _a.inputProps, values = _a.values, onChange = _a.onChange, outputType = _a.outputType, other = __rest(_a, ["inputProps", "values", "onChange", "outputType"]);
var selectRef = this.state.selectRef;
var inputVal = this.getValue();
return (React.createElement("div", { className: "input-selector" },
React.createElement(Selector, __assign({ needAction: false }, other, { values: values, onChange: this.changeRef, value: selectRef })),
React.createElement(Input, __assign({}, inputProps, { ref: this.saveInput, outputType: outputType, onChange: this.changeInput, value: inputVal, onBlur: this.emitChange }))));
};
InputSelector.defaultProps = {
inputProps: {},
};
return InputSelector;
}(FormControlBasic));
export default InputSelector;