igniteui-react-inputs
Version:
Ignite UI React input components.
746 lines (743 loc) • 24.1 kB
JavaScript
import { __extends, __values } from "tslib";
import * as React from 'react';
import { XInput } from "./XInput";
import { ensureEnum, brushToString, stringToBrush, ensureBool, NamePatcher, isValidProp, getModifiedProps } from "igniteui-react-core";
import { FontInfo } from "igniteui-react-core";
import { ReactRenderer, PortalManager } from "igniteui-react-core";
import { delegateCombine, delegateRemove } from "igniteui-react-core";
import { IgrXInputGroupItem } from './igr-x-input-group-item';
import { IgrInputChangeEventArgs } from './igr-input-change-event-args';
import { ControlDisplayDensity_$type } from "igniteui-react-core";
import { IgrKeyEventArgs } from "igniteui-react-core";
import { BaseControlTheme_$type } from "igniteui-react-core";
import { HorizontalAlignment_$type } from "igniteui-react-core";
var requiredStyle = "\n\n";
var pending = [];
var checked = /*@__PURE__*/ new WeakMap(); // TODO why not WeakSet?
function ensureCss() {
if (!document) {
return;
}
if (checked.has(document)) {
return;
}
injectCss(requiredStyle, "data-ig-input-style", function () {
var temp = pending;
pending = null;
temp.forEach(function (v, i, a) {
//v.styleUpdated();
});
});
checked.set(document, true);
}
function injectCss(style, attributeName, onload) {
if (onload === void 0) {
onload = null;
}
for (var i = 0; i < document.head.children.length; i++) {
var child = document.head.children[i];
if (child.tagName &&
child.tagName.toLowerCase() == "style" && child.hasAttribute(attributeName)) {
return;
}
}
var styleEle = document.createElement("style");
styleEle.textContent = style;
styleEle.setAttribute(attributeName, 'true');
if (onload) {
var onloadResolved = function () {
styleEle.onload = null;
onload();
};
styleEle.onload = onloadResolved;
}
document.head.appendChild(styleEle);
}
var IgrXInput = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrXInput, _super);
function IgrXInput(props) {
var _this = _super.call(this, props) || this;
_this._wrapper = null;
_this._keyDown = null;
_this._keyDown_wrapped = null;
_this._keyUp = null;
_this._keyUp_wrapped = null;
_this._keyPress = null;
_this._keyPress_wrapped = null;
_this._change = null;
_this._change_wrapped = null;
_this._changing = null;
_this._changing_wrapped = null;
_this._compositionEnd = null;
_this._compositionEnd_wrapped = null;
ensureCss();
if (_this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
}
_this._implementation = _this.createImplementation();
_this._implementation.externalObject = _this;
_this._getMainRef = _this._getMainRef.bind(_this);
var container;
if (document) {
container = document.createElement("div");
}
var root;
root = container;
if (container != null) {
root = container;
}
_this.requestRender = _this.requestRender.bind(_this);
_this._portalManager = new PortalManager("inputContent", _this.requestRender);
var ren = new ReactRenderer(root, document, true, {}, _this._portalManager);
_this._wrapper = ren;
_this._container = _this._wrapper.rootWrapper;
_this._container.setStyleProperty("display", "inline-block");
_this._container.setStyleProperty("vertical-align", "middle");
var input = _this.i;
_this._input = input;
input.provideContainer(ren);
if (props) {
_this.initializeProperties();
}
return _this;
}
IgrXInput.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
IgrXInput.prototype.render = function () {
var propChildren = this.props.children;
var children = [];
React.Children.forEach(propChildren, function (ch) {
children.push(React.cloneElement(ch));
});
this._portalManager.onRender(children);
var div = React.createElement("div", {
className: "ig-x-input igr-x-input",
ref: this._getMainRef,
children: children
});
return div;
};
IgrXInput.prototype.requestRender = function () {
if (this._initialized) {
this.setState({});
}
};
//private _getLabelPortal(element: DomWrapper, portalCallback: (portal: DomPortal) => void): void {
// this._portalManager.getPortal(element, "TemplateContent", portalCallback);
//}
IgrXInput.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var e_1, _a;
var mod = getModifiedProps(this.props, nextProps);
try {
for (var _b = __values(Object.keys(mod)), _c = _b.next(); !_c.done; _c = _b.next()) {
var p = _c.value;
if (isValidProp(this, p)) {
this[p] = mod[p];
}
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
return true;
};
IgrXInput.prototype.initializeProperties = function () {
var e_2, _a;
try {
for (var _b = __values(Object.keys(this.props)), _c = _b.next(); !_c.done; _c = _b.next()) {
var p = _c.value;
if (isValidProp(this, p)) {
this[p] = this.props[p];
}
}
}
catch (e_2_1) {
e_2 = { error: e_2_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_2)
throw e_2.error;
}
}
};
// supports angular themes or custom properties set in CSS
IgrXInput.prototype.updateStyle = function () {
this._styling(this._elRef, this);
};
IgrXInput.prototype.destroy = function () {
this._input.destroy();
this._wrapper.destroy();
};
IgrXInput.prototype.componentWillUnmount = function () {
};
IgrXInput.prototype.componentDidMount = function () {
this._elRef.appendChild(this._container.getNativeElement());
this.initializeContent();
};
IgrXInput.prototype.initializeContent = function () {
this._styling(this._container.getNativeElement(), this);
this.updateStyle();
};
IgrXInput.prototype.createImplementation = function () {
return new XInput();
};
Object.defineProperty(IgrXInput.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "baseTheme", {
/**
* Gets or sets the base built in theme to use for the button.
*/
get: function () {
return this.i.w;
},
set: function (v) {
this.i.w = ensureEnum(BaseControlTheme_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "density", {
/**
* Gets or sets the display density to use for the input.
*/
get: function () {
return this.i.aa;
},
set: function (v) {
this.i.aa = ensureEnum(ControlDisplayDensity_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "actualDensity", {
/**
* Gets the actual display density to use for the label.
*/
get: function () {
return this.i.z;
},
set: function (v) {
this.i.z = ensureEnum(ControlDisplayDensity_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "mask", {
/**
* Gets/Sets the input mask for the input.
*/
get: function () {
return this.i.ce;
},
set: function (v) {
this.i.ce = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "promptChar", {
/**
* Gets/Sets the character representing a fillable spot in the input mask
*/
get: function () {
return this.i.ci;
},
set: function (v) {
this.i.ci = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "includeLiterals", {
/**
* Specifies if the bound value includes the formatting symbols.
*/
get: function () {
return this.i.au;
},
set: function (v) {
this.i.au = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "showSpinner", {
get: function () {
return this.i.a1;
},
set: function (v) {
this.i.a1 = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "actualTextColor", {
/**
* Gets the actual color to use for the text color.
*/
get: function () {
return brushToString(this.i.d4);
},
set: function (v) {
this.i.d4 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "actualHoverTextColor", {
/**
* Gets the actual hover color to use for the text.
*/
get: function () {
return brushToString(this.i.d3);
},
set: function (v) {
this.i.d3 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "textColor", {
/**
* Gets or sets the color to use for the text.
*/
get: function () {
return brushToString(this.i.d8);
},
set: function (v) {
this.i.d8 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "textStyle", {
/**
* Gets or sets the use for the button.
*/
get: function () {
if (this.i.af == null) {
return null;
}
return this.i.af.fontString;
},
set: function (v) {
var fi = new FontInfo();
fi.fontString = v;
this.i.af = fi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "inputType", {
/**
* Gets or sets the type to use for the input.
*/
get: function () {
return this.i.b8;
},
set: function (v) {
this.i.b8 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "placeholder", {
/**
* Gets or sets the placeholder to use for the input.
*/
get: function () {
return this.i.cg;
},
set: function (v) {
this.i.cg = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "hoverTextColor", {
/**
* Gets or sets the color to use for the hovered text of the button regardless of type.
*/
get: function () {
return brushToString(this.i.d7);
},
set: function (v) {
this.i.d7 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "id", {
/**
* Gets or sets the id to use for the checkbox.
*/
get: function () {
return this.i.b5;
},
set: function (v) {
this.i.b5 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "tabIndex", {
/**
* Gets or sets TabIndex to use for the checkbox.
*/
get: function () {
return this.i.be;
},
set: function (v) {
this.i.be = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "for", {
/**
* Gets or sets the for attribute to use for the input.
*/
get: function () {
return this.i.b2;
},
set: function (v) {
this.i.b2 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "ariaLabel", {
/**
* Gets or sets the value of the aria-label attribute.
*/
get: function () {
return this.i.bx;
},
set: function (v) {
this.i.bx = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "isHover", {
/**
* Gets or sets whether the input is hovered.
*/
get: function () {
return this.i.aw;
},
set: function (v) {
this.i.aw = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "value", {
/**
* Gets or sets the value for the input.
*/
get: function () {
return this.i.cq;
},
set: function (v) {
this.i.cq = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "hasValue", {
get: function () {
return this.i.at;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "disabled", {
/**
* Gets or sets whether the checkbox is disabled.
*/
get: function () {
return this.i.disabled;
},
set: function (v) {
this.i.disabled = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "readonly", {
/**
* Gets or sets whether the checkbox is readonly.
*/
get: function () {
return this.i.readonly;
},
set: function (v) {
this.i.readonly = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "textAlignment", {
/**
* Gets or sets the alignment of the text.
*/
get: function () {
return this.i.dy;
},
set: function (v) {
this.i.dy = ensureEnum(HorizontalAlignment_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "selectionStart", {
/**
* Returns / Sets the beginning index of the selected text. When nothing is selected, this returns the position of the text input cursor (caret) inside of the input.
*/
get: function () {
return this.i.selectionStart;
},
set: function (v) {
this.i.selectionStart = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "selectionEnd", {
/**
* Returns / Sets the end index of the selected text. When nothing is selected, this returns the position of the text input cursor (caret) inside of the input.
*/
get: function () {
return this.i.selectionEnd;
},
set: function (v) {
this.i.selectionEnd = +v;
},
enumerable: false,
configurable: true
});
IgrXInput.prototype.onDetachedFromUI = function () {
this.i.onDetachedFromUI();
};
IgrXInput.prototype.onAttachedToUI = function () {
this.i.onAttachedToUI();
};
/**
* Exports visual information about the current state of the grid.
*/
IgrXInput.prototype.exportVisualModel = function () {
var iv = this.i.bg();
return (iv);
};
/**
* Returns a serialized copy of the exported visual model
*/
IgrXInput.prototype.exportSerializedVisualModel = function () {
var iv = this.i.b1();
return (iv);
};
IgrXInput.prototype.setSelectionRange = function (selectionStart, selectionEnd) {
this.i.dr(selectionStart, selectionEnd);
};
IgrXInput.prototype.blur = function () {
this.i.ct();
};
IgrXInput.prototype.select = function () {
this.i.dp();
};
Object.defineProperty(IgrXInput.prototype, "keyDown", {
get: function () {
return this._keyDown;
},
set: function (ev) {
var _this = this;
if (this._keyDown_wrapped !== null) {
this.i.keyDown = delegateRemove(this.i.keyDown, this._keyDown_wrapped);
this._keyDown_wrapped = null;
this._keyDown = null;
}
this._keyDown = ev;
this._keyDown_wrapped = function (o, e) {
var outerArgs = new IgrKeyEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeKeyDown) {
_this.beforeKeyDown(_this, outerArgs);
}
if (_this._keyDown) {
_this._keyDown(_this, outerArgs);
}
};
this.i.keyDown = delegateCombine(this.i.keyDown, this._keyDown_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "keyUp", {
get: function () {
return this._keyUp;
},
set: function (ev) {
var _this = this;
if (this._keyUp_wrapped !== null) {
this.i.keyUp = delegateRemove(this.i.keyUp, this._keyUp_wrapped);
this._keyUp_wrapped = null;
this._keyUp = null;
}
this._keyUp = ev;
this._keyUp_wrapped = function (o, e) {
var outerArgs = new IgrKeyEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeKeyUp) {
_this.beforeKeyUp(_this, outerArgs);
}
if (_this._keyUp) {
_this._keyUp(_this, outerArgs);
}
};
this.i.keyUp = delegateCombine(this.i.keyUp, this._keyUp_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "keyPress", {
get: function () {
return this._keyPress;
},
set: function (ev) {
var _this = this;
if (this._keyPress_wrapped !== null) {
this.i.keyPress = delegateRemove(this.i.keyPress, this._keyPress_wrapped);
this._keyPress_wrapped = null;
this._keyPress = null;
}
this._keyPress = ev;
this._keyPress_wrapped = function (o, e) {
var outerArgs = new IgrKeyEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeKeyPress) {
_this.beforeKeyPress(_this, outerArgs);
}
if (_this._keyPress) {
_this._keyPress(_this, outerArgs);
}
};
this.i.keyPress = delegateCombine(this.i.keyPress, this._keyPress_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "change", {
get: function () {
return this._change;
},
set: function (ev) {
var _this = this;
if (this._change_wrapped !== null) {
this.i.change = delegateRemove(this.i.change, this._change_wrapped);
this._change_wrapped = null;
this._change = null;
}
this._change = ev;
this._change_wrapped = function (o, e) {
var outerArgs = new IgrInputChangeEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeChange) {
_this.beforeChange(_this, outerArgs);
}
if (_this._change) {
_this._change(_this, outerArgs);
}
};
this.i.change = delegateCombine(this.i.change, this._change_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "changing", {
get: function () {
return this._changing;
},
set: function (ev) {
var _this = this;
if (this._changing_wrapped !== null) {
this.i.changing = delegateRemove(this.i.changing, this._changing_wrapped);
this._changing_wrapped = null;
this._changing = null;
}
this._changing = ev;
this._changing_wrapped = function (o, e) {
var outerArgs = new IgrInputChangeEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeChanging) {
_this.beforeChanging(_this, outerArgs);
}
if (_this._changing) {
_this._changing(_this, outerArgs);
}
};
this.i.changing = delegateCombine(this.i.changing, this._changing_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXInput.prototype, "compositionEnd", {
get: function () {
return this._compositionEnd;
},
set: function (ev) {
var _this = this;
if (this._compositionEnd_wrapped !== null) {
this.i.compositionEnd = delegateRemove(this.i.compositionEnd, this._compositionEnd_wrapped);
this._compositionEnd_wrapped = null;
this._compositionEnd = null;
}
this._compositionEnd = ev;
this._compositionEnd_wrapped = function (o, e) {
var outerArgs = new IgrInputChangeEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeCompositionEnd) {
_this.beforeCompositionEnd(_this, outerArgs);
}
if (_this._compositionEnd) {
_this._compositionEnd(_this, outerArgs);
}
};
this.i.compositionEnd = delegateCombine(this.i.compositionEnd, this._compositionEnd_wrapped);
;
},
enumerable: false,
configurable: true
});
return IgrXInput;
}(IgrXInputGroupItem));
export { IgrXInput };