UNPKG

igniteui-react-inputs

Version:

Ignite UI React input components.

803 lines (800 loc) 24.3 kB
import { __extends, __values } from "tslib"; import * as React from 'react'; import { XIcon } from "./XIcon"; import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps, fromBrushCollection, toBrushCollection } from "igniteui-react-core"; import { FontInfo } from "igniteui-react-core"; import { ReactRenderer, PortalManager } from "igniteui-react-core"; import { BaseControlTheme_$type } from "igniteui-react-core"; var IgrXIcon = /** @class */ /*@__PURE__*/ (function (_super) { __extends(IgrXIcon, _super); function IgrXIcon(props) { var _this = _super.call(this, props) || this; _this._wrapper = null; _this._implementation = null; _this.__p = null; _this._hasUserValues = new Set(); _this._stylingContainer = null; _this._stylingParent = null; _this._inStyling = false; 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("iconContent", _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 icon = _this.i; _this._icon = icon; icon.provideContainer(ren); if (props) { _this.initializeProperties(); } return _this; } IgrXIcon.prototype._getMainRef = function (ref) { this._elRef = ref; }; IgrXIcon.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-icon igr-x-icon", ref: this._getMainRef, children: children }); return div; }; IgrXIcon.prototype.requestRender = function () { if (this._initialized) { this.setState({}); } }; //private _getLabelPortal(element: DomWrapper, portalCallback: (portal: DomPortal) => void): void { // this._portalManager.getPortal(element, "TemplateContent", portalCallback); //} IgrXIcon.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; }; IgrXIcon.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 IgrXIcon.prototype.updateStyle = function () { this._styling(this._elRef, this); }; IgrXIcon.prototype.destroy = function () { this._icon.destroy(); this._wrapper.destroy(); }; IgrXIcon.prototype.componentWillUnmount = function () { }; IgrXIcon.prototype.componentDidMount = function () { this._elRef.appendChild(this._container.getNativeElement()); this.initializeContent(); }; IgrXIcon.prototype.initializeContent = function () { this._styling(this._container.getNativeElement(), this); this.updateStyle(); }; IgrXIcon.prototype.createImplementation = function () { return new XIcon(); }; Object.defineProperty(IgrXIcon.prototype, "i", { get: function () { return this._implementation; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "baseTheme", { /** * Gets or sets the base built in theme to use for the button. */ get: function () { return this.i.m; }, set: function (v) { this.i.m = ensureEnum(BaseControlTheme_$type, v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualFill", { /** * Gets the fill color currently used by the icon. */ get: function () { return brushToString(this.i.du); }, set: function (v) { this.i.du = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualStroke", { /** * Gets the stroke color currently used by the icon. */ get: function () { return brushToString(this.i.dv); }, set: function (v) { this.i.dv = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualTextColor", { /** * Gets the text color currently used by the icon. */ get: function () { return brushToString(this.i.dw); }, set: function (v) { this.i.dw = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualStrokeWidth", { /** * Gets the stroke width currently used by the icon. */ get: function () { return this.i.aq; }, set: function (v) { this.i.aq = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "fill", { /** * Gets or sets the fill color to use for the icon. */ get: function () { return brushToString(this.i.fill); }, set: function (v) { this.i.fill = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "stroke", { /** * Gets or sets the stroke color to use for the icon. */ get: function () { return brushToString(this.i.ea); }, set: function (v) { this.i.ea = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "strokeWidth", { /** * Gets or sets the stroke thickness to use for the icon. */ get: function () { return this.i.a4; }, set: function (v) { this.i.a4 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "textColor", { /** * Gets or sets the text color to use for the icon. */ get: function () { return brushToString(this.i.eb); }, set: function (v) { this.i.eb = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "hoverFill", { /** * Gets or sets the fill color to use when the icon is hovered. */ get: function () { return brushToString(this.i.d3); }, set: function (v) { this.i.d3 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "hoverStroke", { /** * Gets or sets the stroke color to use when the icon is hovered. */ get: function () { return brushToString(this.i.d4); }, set: function (v) { this.i.d4 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "hoverStrokeThickness", { /** * Gets or sets the stroke thickness to use when the icon is hovered. */ get: function () { return this.i.a2; }, set: function (v) { this.i.a2 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "hoverTextColor", { /** * Gets or sets the text color to use when the icon is hovered. */ get: function () { return brushToString(this.i.d5); }, set: function (v) { this.i.d5 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "fillColors", { /** * Gets or sets a collection of fill colors to use in the icon. * These colors can be used by SVG elements that have been marked with the * ig-icon-fill-# * class where # is a number from 0 to count - 1. */ get: function () { return fromBrushCollection(this.i.e); }, set: function (v) { this.i.e = toBrushCollection(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "strokeColors", { /** * Gets or sets a collection of stroke colors to use in the icon. * These colors can be used by SVG elements that have been marked with the * ig-icon-stroke-# * class where # is a number from 0 to count - 1. */ get: function () { return fromBrushCollection(this.i.f); }, set: function (v) { this.i.f = toBrushCollection(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "primaryFillColor", { /** * Gets or sets a primary fill color for the icon. * This color is used by SVG elements that have been marked * with the * ig-icon-primary-fill * class. */ get: function () { return brushToString(this.i.d6); }, set: function (v) { this.i.d6 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "primaryStrokeColor", { /** * Gets or sets a primary stroke color for the icon. * This color is used by SVG elements that have been marked * with the * ig-icon-primary-stroke * class. */ get: function () { return brushToString(this.i.d7); }, set: function (v) { this.i.d7 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "secondaryFillColor", { /** * Gets or sets a secondary fill color for the icon. * This color is used by SVG elements that have been marked * with the * ig-icon-secondary-fill * class. */ get: function () { return brushToString(this.i.d8); }, set: function (v) { this.i.d8 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "secondaryStrokeColor", { /** * Gets or sets a secondary stroke color for the icon. * This color is used by SVG elements that have been marked * with the * ig-icon-secondary-stroke * class. */ get: function () { return brushToString(this.i.d9); }, set: function (v) { this.i.d9 = stringToBrush(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "source", { /** * Gets or sets the image source for the icon. Used if none of the other icon types are not used. */ get: function () { return this.i.bh; }, set: function (v) { this.i.bh = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "dataURL", { /** * Gets or sets data url for the icon to use. */ get: function () { return this.i.b0; }, set: function (v) { this.i.b0 = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "svgPath", { /** * Gets or sets path data for the icon to use. */ get: function () { return this.i.svgPath; }, set: function (v) { this.i.svgPath = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "svg", { /** * Gets or sets svg text for the icon to use. */ get: function () { return this.i.svg; }, set: function (v) { this.i.svg = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "sVGPaths", { /** * Gets or sets an array of path data for the icon to use. */ get: function () { return this.i.b; }, set: function (v) { if (v && !Array.isArray(v) && typeof (v) == "string") { var re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.b = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "textStyle", { /** * Gets or sets the use for the button. */ 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(IgrXIcon.prototype, "id", { /** * Gets or sets the id to use for the checkbox. */ get: function () { return this.i.ca; }, set: function (v) { this.i.ca = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "tabIndex", { /** * Gets or sets TabIndex to use for the checkbox. */ get: function () { return this.i.bb; }, set: function (v) { this.i.bb = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "ariaLabel", { /** * Gets or sets the value of the aria-label attribute. */ get: function () { return this.i.bv; }, set: function (v) { this.i.bv = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "isHover", { /** * Gets or sets whether the icon is hovered. */ get: function () { return this.i.v; }, set: function (v) { this.i.v = ensureBool(v); }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.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(IgrXIcon.prototype, "opacity", { get: function () { return this.i.a3; }, set: function (v) { this.i.a3 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualViewBoxLeft", { /** * Gets the actual viewbox left for the svg icon. */ get: function () { return this.i.as; }, set: function (v) { this.i.as = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "viewBoxLeft", { /** * Gets or sets the viewbox left for the svg icon. */ get: function () { return this.i.a6; }, set: function (v) { this.i.a6 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualViewBoxTop", { /** * Gets the actual viewbox top for the svg icon. */ get: function () { return this.i.at; }, set: function (v) { this.i.at = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "viewBoxTop", { /** * Gets or sets the viewbox top for the svg icon. */ get: function () { return this.i.a7; }, set: function (v) { this.i.a7 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualViewBoxWidth", { /** * Gets the actual viewbox width for the svg icon. */ get: function () { return this.i.au; }, set: function (v) { this.i.au = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "viewBoxWidth", { /** * Gets or sets the viewbox width for the svg icon. */ get: function () { return this.i.a8; }, set: function (v) { this.i.a8 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "actualViewBoxHeight", { /** * Gets the actual viewbox height for the svg icon. */ get: function () { return this.i.ar; }, set: function (v) { this.i.ar = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "viewBoxHeight", { /** * Gets or sets the viewbox height for the svg icon. */ get: function () { return this.i.a5; }, set: function (v) { this.i.a5 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "width", { /** * Gets or sets the width of the icon. */ get: function () { return this.i.a9; }, set: function (v) { this.i.a9 = +v; }, enumerable: false, configurable: true }); Object.defineProperty(IgrXIcon.prototype, "height", { /** * Gets or sets the height of the icon. */ get: function () { return this.i.a1; }, set: function (v) { this.i.a1 = +v; }, enumerable: false, configurable: true }); IgrXIcon.prototype.findByName = function (name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } return null; }; Object.defineProperty(IgrXIcon.prototype, "hasUserValues", { get: function () { return this._hasUserValues; }, enumerable: false, configurable: true }); IgrXIcon.prototype.__m = function (propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } }; IgrXIcon.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("XIcon"); 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; }; IgrXIcon.prototype.onDetachedFromUI = function () { this.i.onDetachedFromUI(); }; IgrXIcon.prototype.onAttachedToUI = function () { this.i.onAttachedToUI(); }; /** * Exports visual information about the current state of the grid. */ IgrXIcon.prototype.exportVisualModel = function () { var iv = this.i.bg(); return (iv); }; /** * Returns a serialized copy of the exported visual model */ IgrXIcon.prototype.exportSerializedVisualModel = function () { var iv = this.i.b2(); return (iv); }; return IgrXIcon; }(React.Component)); export { IgrXIcon };