igniteui-react-inputs
Version:
Ignite UI React input components.
595 lines (594 loc) • 20.6 kB
JavaScript
import { __extends, __values } from "tslib";
import * as React from 'react';
import { ColorEditor } from "./ColorEditor";
import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, 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 { TypeRegistrar } from "igniteui-react-core";
import { ControlDisplayDensity_$type } from "igniteui-react-core";
import { BaseControlTheme_$type } from "igniteui-react-core";
import { IgrColorEditorPanelSelectedValueChangedEventArgs } from "./igr-color-editor-panel-selected-value-changed-event-args";
import { IgrColorEditorLostFocusEventArgs } from "./igr-color-editor-lost-focus-event-args";
import { IgrColorEditorGotFocusEventArgs } from "./igr-color-editor-got-focus-event-args";
var IgrColorEditor = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrColorEditor, _super);
function IgrColorEditor(props) {
var _this = _super.call(this, props) || this;
_this._wrapper = null;
_this.mounted = false;
_this.__p = null;
_this._hasUserValues = new Set();
_this._stylingContainer = null;
_this._stylingParent = null;
_this._inStyling = false;
_this._valueChanged = null;
_this._valueChanged_wrapped = null;
_this._valueChanging = null;
_this._valueChanging_wrapped = null;
_this._gotFocus = null;
_this._gotFocus_wrapped = null;
_this._lostFocus = null;
_this._lostFocus_wrapped = null;
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("colorEditorContent", _this.requestRender);
var ren = new ReactRenderer(root, document, true, {}, _this._portalManager);
_this._wrapper = ren;
_this._container = _this._wrapper.rootWrapper;
_this._container.setStyleProperty("display", "block");
var colorEditor = _this.i;
_this._colorEditor = colorEditor;
colorEditor.provideContainer(ren);
if (props) {
_this.initializeProperties();
}
return _this;
}
IgrColorEditor.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
IgrColorEditor.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-color-editor igr-color-editor",
ref: this._getMainRef,
children: children
});
return div;
};
IgrColorEditor.prototype.requestRender = function () {
if (this._initialized) {
this.setState({});
}
};
//private _getLabelPortal(element: DomWrapper, portalCallback: (portal: DomPortal) => void): void {
// this._portalManager.getPortal(element, "TemplateContent", portalCallback);
//}
IgrColorEditor.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;
};
IgrColorEditor.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
IgrColorEditor.prototype.updateStyle = function () {
this._styling(this._elRef, this);
};
IgrColorEditor.prototype.destroy = function () {
this._colorEditor.destroy();
this._wrapper.destroy();
};
IgrColorEditor.prototype.componentWillUnmount = function () {
};
IgrColorEditor.prototype.componentDidMount = function () {
this._elRef.appendChild(this._container.getNativeElement());
this.initializeContent();
};
IgrColorEditor.prototype.initializeContent = function () {
this._styling(this._container.getNativeElement(), this);
this.updateStyle();
};
IgrColorEditor.prototype.createImplementation = function () {
return new ColorEditor();
};
Object.defineProperty(IgrColorEditor.prototype, "nativeElement", {
get: function () {
return this._implementation.nativeElement;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
} /**
* @hidden
*/,
enumerable: false,
configurable: true
});
IgrColorEditor._createFromInternal = function (internal) {
if (!internal) {
return null;
}
if (!internal.$type) {
return null;
}
var name = internal.$type.name;
var externalName = "Igr" + name;
if (!TypeRegistrar.isRegistered(externalName)) {
return null;
}
return TypeRegistrar.create(externalName);
};
Object.defineProperty(IgrColorEditor.prototype, "value", {
/**
* Gets or Sets color value of the editor.
*/
get: function () {
return brushToString(this.i.value);
},
set: function (v) {
this.i.value = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "label", {
/**
* Gets or Sets the property name that contains the label.
*/
get: function () {
return this.i.az;
},
set: function (v) {
this.i.az = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "labelTextColor", {
/**
* Gets or sets the color to use for the text.
*/
get: function () {
return brushToString(this.i.cn);
},
set: function (v) {
this.i.cn = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "labelTextStyle", {
/**
* Gets or sets the font to use for the input.
*/
get: function () {
if (this.i.o == null) {
return null;
}
return this.i.o.fontString;
},
set: function (v) {
var fi = new FontInfo();
fi.fontString = v;
this.i.o = fi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "density", {
/**
* Gets or sets the display density to use for the date pcicker.
*/
get: function () {
return this.i.k;
},
set: function (v) {
this.i.k = ensureEnum(ControlDisplayDensity_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "baseTheme", {
/**
* Gets or sets the base built in theme to use for the date picker.
*/
get: function () {
return this.i.i;
},
set: function (v) {
this.i.i = ensureEnum(BaseControlTheme_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "textStyle", {
/**
* Gets or sets the font to use for the combobox.
*/
get: function () {
if (this.i.p == null) {
return null;
}
return this.i.p.fontString;
},
set: function (v) {
var fi = new FontInfo();
fi.fontString = v;
this.i.p = fi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "textColor", {
/**
* Gets or Sets the text color
*/
get: function () {
return brushToString(this.i.co);
},
set: function (v) {
this.i.co = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "iconColor", {
/**
* Gets or Sets the text color
*/
get: function () {
return brushToString(this.i.cm);
},
set: function (v) {
this.i.cm = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "showClearButton", {
/**
* Gets or sets the ShowClearButton property to detirmine if the clear button is shown
*/
get: function () {
return this.i.am;
},
set: function (v) {
this.i.am = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "allowTextInput", {
/**
* Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed
*/
get: function () {
return this.i.ag;
},
set: function (v) {
this.i.ag = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "openOnFocus", {
/**
* Gets or sets the AllowTextInput property to detirmine if entering text into the input is allowed
*/
get: function () {
return this.i.ak;
},
set: function (v) {
this.i.ak = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "isDisabled", {
get: function () {
return this.i.ah;
},
set: function (v) {
this.i.ah = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "isFixed", {
/**
* Indicates that the editor dropdown will position itself relative to the window instead of the document.
*/
get: function () {
return this.i.ai;
},
set: function (v) {
this.i.ai = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "openAsChild", {
/**
* Indicates that the dropdown should open as a child of the color editor.
*/
get: function () {
return this.i.aj;
},
set: function (v) {
this.i.aj = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "useTopLayer", {
/**
* Indicates that the dropdown will place itself into the browser top layer.
*/
get: function () {
return this.i.an;
},
set: function (v) {
this.i.an = ensureBool(v);
},
enumerable: false,
configurable: true
});
IgrColorEditor.prototype.findByName = function (name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
return null;
};
Object.defineProperty(IgrColorEditor.prototype, "hasUserValues", {
get: function () {
return this._hasUserValues;
},
enumerable: false,
configurable: true
});
IgrColorEditor.prototype.__m = function (propertyName) {
if (!this._inStyling) {
this._hasUserValues.add(propertyName);
}
};
IgrColorEditor.prototype._styling = function (container, component, parent) {
if (this._inStyling) {
return;
}
this._inStyling = true;
this._stylingContainer = container;
this._stylingParent = component;
var genericPrefix = "";
var typeName = this.i.$type.name;
if (typeName.indexOf("Xam") === 0) {
typeName = typeName.substring(3);
}
genericPrefix = toSpinal("ColorEditor");
var additionalPrefixes = [];
var prefix = toSpinal(typeName);
additionalPrefixes.push(prefix + "-");
var b = this.i.$type.baseType;
while (b && b.name != "Object" &&
b.name != "Base" &&
b.name != "Control" &&
b.Name != "DependencyObject" &&
b.Name != "FrameworkElement") {
typeName = b.name;
if (typeName.indexOf("Xam") === 0) {
typeName = typeName.substring(3);
}
var basePrefix = toSpinal(typeName);
additionalPrefixes.push(basePrefix + "-");
b = b.baseType;
}
if (parent) {
var parentTypeName = parent.i.$type.name;
if (parentTypeName.indexOf("Xam") === 0) {
parentTypeName = parentTypeName.substring(3);
}
var parentPrefix = toSpinal(parentTypeName);
additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-");
additionalPrefixes.push(parentPrefix + "-" + prefix + "-");
}
initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes);
if (this._otherStyling) {
this._otherStyling(container, component, parent);
}
this._inStyling = false;
};
IgrColorEditor.prototype.select = function () {
this.i.b8();
};
Object.defineProperty(IgrColorEditor.prototype, "valueChanged", {
/**
* Called when color is selected.
*/
get: function () {
return this._valueChanged;
},
set: function (ev) {
var _this = this;
if (this._valueChanged_wrapped !== null) {
this.i.valueChanged = delegateRemove(this.i.valueChanged, this._valueChanged_wrapped);
this._valueChanged_wrapped = null;
this._valueChanged = null;
}
this._valueChanged = ev;
this._valueChanged_wrapped = function (o, e) {
var outerArgs = new IgrColorEditorPanelSelectedValueChangedEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeValueChanged) {
_this.beforeValueChanged(_this, outerArgs);
}
if (_this._valueChanged) {
_this._valueChanged(_this, outerArgs);
}
};
this.i.valueChanged = delegateCombine(this.i.valueChanged, this._valueChanged_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "valueChanging", {
/**
* Called when color is selected.
*/
get: function () {
return this._valueChanging;
},
set: function (ev) {
var _this = this;
if (this._valueChanging_wrapped !== null) {
this.i.valueChanging = delegateRemove(this.i.valueChanging, this._valueChanging_wrapped);
this._valueChanging_wrapped = null;
this._valueChanging = null;
}
this._valueChanging = ev;
this._valueChanging_wrapped = function (o, e) {
var outerArgs = new IgrColorEditorPanelSelectedValueChangedEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeValueChanging) {
_this.beforeValueChanging(_this, outerArgs);
}
if (_this._valueChanging) {
_this._valueChanging(_this, outerArgs);
}
};
this.i.valueChanging = delegateCombine(this.i.valueChanging, this._valueChanging_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "gotFocus", {
get: function () {
return this._gotFocus;
},
set: function (ev) {
var _this = this;
if (this._gotFocus_wrapped !== null) {
this.i.gotFocus = delegateRemove(this.i.gotFocus, this._gotFocus_wrapped);
this._gotFocus_wrapped = null;
this._gotFocus = null;
}
this._gotFocus = ev;
this._gotFocus_wrapped = function (o, e) {
var outerArgs = new IgrColorEditorGotFocusEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeGotFocus) {
_this.beforeGotFocus(_this, outerArgs);
}
if (_this._gotFocus) {
_this._gotFocus(_this, outerArgs);
}
};
this.i.gotFocus = delegateCombine(this.i.gotFocus, this._gotFocus_wrapped);
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrColorEditor.prototype, "lostFocus", {
get: function () {
return this._lostFocus;
},
set: function (ev) {
var _this = this;
if (this._lostFocus_wrapped !== null) {
this.i.lostFocus = delegateRemove(this.i.lostFocus, this._lostFocus_wrapped);
this._lostFocus_wrapped = null;
this._lostFocus = null;
}
this._lostFocus = ev;
this._lostFocus_wrapped = function (o, e) {
var outerArgs = new IgrColorEditorLostFocusEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeLostFocus) {
_this.beforeLostFocus(_this, outerArgs);
}
if (_this._lostFocus) {
_this._lostFocus(_this, outerArgs);
}
};
this.i.lostFocus = delegateCombine(this.i.lostFocus, this._lostFocus_wrapped);
;
},
enumerable: false,
configurable: true
});
return IgrColorEditor;
}(React.Component));
export { IgrColorEditor };