UNPKG

igniteui-webcomponents-inputs

Version:

Ignite UI Web Components inputs components.

665 lines (662 loc) 22.2 kB
import { XIcon } from "./XIcon"; import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, toSpinal, fromBrushCollection, toBrushCollection, brushCollectionToString, enumToString, getAllPropertyNames, fromSpinal } from "igniteui-webcomponents-core"; import { FontInfo } from "igniteui-webcomponents-core"; import { WebComponentRenderer, PortalManager } from "igniteui-webcomponents-core"; import { TypeRegistrar } from "igniteui-webcomponents-core"; import { RegisterElementHelper } from "igniteui-webcomponents-core"; import { IgcHTMLElement } from "igniteui-webcomponents-core"; import { BaseControlTheme_$type } from "igniteui-webcomponents-core"; export let IgcXIconComponent = /*@__PURE__*/ (() => { class IgcXIconComponent extends IgcHTMLElement { constructor() { super(); this._disconnected = false; this._settingAttributes = false; this._attached = false; this._queuedSetAttributes = []; this._updatingFromAttribute = false; 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._portalManager = new PortalManager("iconContent"); this._renderer = new WebComponentRenderer(this, document, true, {}, this._portalManager); this._container = this._renderer.createElement("div"); this._renderer.updateRoot(this._container); this._implementation = this.createImplementation(); this._implementation.externalObject = this; //this._container.setStyleProperty("width", "100%"); //this._container.setStyleProperty("height", "100%"); var root; root = this._container; if (this._container.getNativeElement() != null) { root = this._container.getNativeElement(); } this._wrapper = this._renderer; var icon = this.i; this._icon = icon; icon.provideContainer(this._renderer); this._onChildrenChanged(); //Checkbox.notifySizeChanged(); let mut = new MutationObserver((list) => { for (var mutation of list) { if (mutation.type == 'childList') { this._onChildrenChanged(); } } }); mut.observe(this, { childList: true }); //this._renderer.addSizeWatcher(() => { // this._checkbox.notifySizeChanged(); //}); } _onChildrenChanged() { var children = []; for (var i = 0; i < this.childNodes.length; i++) { var child = this.childNodes[i]; if (child !== this._container.getNativeElement()) { children.push(child); } } this._portalManager.onChildrenChanged(children); } // supports angular themes or custom properties set in CSS updateStyle() { this._styling(this, this); } destroy() { this._icon.destroy(); this._wrapper.destroy(); } createImplementation() { return new XIcon(); } disconnectedCallback() { this._disconnected = true; if (this.i) { this.i.onDetachedFromUI(); } } connectedCallback() { if (this._disconnected) { this._disconnected = false; if (this.i) { this.i.onAttachedToUI(); } return; } this.classList.add("ig-x-icon"); this.classList.add("igc-x-icon"); this.appendChild(this._container.getNativeElement()); this._attached = true; this.style.display = "inline-block"; this.style.verticalAlign = "middle"; //this.style.height = this._height; //this.style.width = this._width; this._flushQueuedAttributes(); // supports themes or custom properties set in CSS this._styling(this, this); this.afterContentInit(); } afterContentInit() { //this.i.notifySizeChanged(); } /** * @hidden */ get i() { return this._implementation; } /** * @hidden */ static _createFromInternal(internal) { if (!internal) { return null; } if (!internal.$type) { return null; } let name = internal.$type.name; let externalName = "Igc" + name + "Component"; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); } _enqueueSetAttribute(attrName, attrValue) { this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue }); } _flushQueuedAttributes() { this._settingAttributes = true; for (let i = 0; i < this._queuedSetAttributes.length; i++) { this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue); } this._settingAttributes = false; this._queuedSetAttributes.length = 0; } _a(attrName, attrValue) { if (this._updatingFromAttribute) { return; } if (attrValue) { attrValue = attrValue.toString(); } this._settingAttributes = true; attrName = toSpinal(attrName); if (this._attached) { this.setAttribute(attrName, attrValue); } else { this._enqueueSetAttribute(attrName, attrValue); } this._settingAttributes = false; } static get observedAttributes() { if (IgcXIconComponent._observedAttributesIgcXIconComponent == null) { let names = getAllPropertyNames(IgcXIconComponent); for (let i = 0; i < names.length; i++) { names[i] = toSpinal(names[i]); } IgcXIconComponent._observedAttributesIgcXIconComponent = names; } return IgcXIconComponent._observedAttributesIgcXIconComponent; } attributeChangedCallback(name, oldValue, newValue) { if (this._settingAttributes) { return; } let setName = fromSpinal(name); this._updatingFromAttribute = true; this[setName] = newValue; this._updatingFromAttribute = false; } static register() { if (!IgcXIconComponent._isElementRegistered) { IgcXIconComponent._isElementRegistered = true; RegisterElementHelper.registerElement(IgcXIconComponent.htmlTagName, IgcXIconComponent); } } /** * Gets or sets the base built in theme to use for the button. */ get baseTheme() { return this.i.m; } set baseTheme(v) { this.i.m = ensureEnum(BaseControlTheme_$type, v); this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.m)); } /** * Gets the fill color currently used by the icon. */ get actualFill() { return brushToString(this.i.c8); } set actualFill(v) { this.i.c8 = stringToBrush(v); this._a("actualFill", brushToString(this.i.c8)); } /** * Gets the stroke color currently used by the icon. */ get actualStroke() { return brushToString(this.i.c9); } set actualStroke(v) { this.i.c9 = stringToBrush(v); this._a("actualStroke", brushToString(this.i.c9)); } /** * Gets the text color currently used by the icon. */ get actualTextColor() { return brushToString(this.i.da); } set actualTextColor(v) { this.i.da = stringToBrush(v); this._a("actualTextColor", brushToString(this.i.da)); } /** * Gets the stroke width currently used by the icon. */ get actualStrokeWidth() { return this.i.ai; } set actualStrokeWidth(v) { this.i.ai = +v; this._a("actualStrokeWidth", this.i.ai); } /** * Gets or sets the fill color to use for the icon. */ get fill() { return brushToString(this.i.fill); } set fill(v) { this.i.fill = stringToBrush(v); this._a("fill", brushToString(this.i.fill)); } /** * Gets or sets the stroke color to use for the icon. */ get stroke() { return brushToString(this.i.dp); } set stroke(v) { this.i.dp = stringToBrush(v); this._a("stroke", brushToString(this.i.dp)); } /** * Gets or sets the stroke thickness to use for the icon. */ get strokeWidth() { return this.i.ao; } set strokeWidth(v) { this.i.ao = +v; this._a("strokeWidth", this.i.ao); } /** * Gets or sets the text color to use for the icon. */ get textColor() { return brushToString(this.i.dq); } set textColor(v) { this.i.dq = stringToBrush(v); this._a("textColor", brushToString(this.i.dq)); } /** * Gets or sets the fill color to use when the icon is hovered. */ get hoverFill() { return brushToString(this.i.dh); } set hoverFill(v) { this.i.dh = stringToBrush(v); this._a("hoverFill", brushToString(this.i.dh)); } /** * Gets or sets the stroke color to use when the icon is hovered. */ get hoverStroke() { return brushToString(this.i.di); } set hoverStroke(v) { this.i.di = stringToBrush(v); this._a("hoverStroke", brushToString(this.i.di)); } /** * Gets or sets the stroke thickness to use when the icon is hovered. */ get hoverStrokeThickness() { return this.i.am; } set hoverStrokeThickness(v) { this.i.am = +v; this._a("hoverStrokeThickness", this.i.am); } /** * Gets or sets the text color to use when the icon is hovered. */ get hoverTextColor() { return brushToString(this.i.dj); } set hoverTextColor(v) { this.i.dj = stringToBrush(v); this._a("hoverTextColor", brushToString(this.i.dj)); } /** * 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 fillColors() { return fromBrushCollection(this.i.e); } set fillColors(v) { this.i.e = toBrushCollection(v); this._a("fillColors", brushCollectionToString(this.i.e)); } /** * 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 strokeColors() { return fromBrushCollection(this.i.f); } set strokeColors(v) { this.i.f = toBrushCollection(v); this._a("strokeColors", brushCollectionToString(this.i.f)); } /** * 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 primaryFillColor() { return brushToString(this.i.dk); } set primaryFillColor(v) { this.i.dk = stringToBrush(v); this._a("primaryFillColor", brushToString(this.i.dk)); } /** * 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 primaryStrokeColor() { return brushToString(this.i.dl); } set primaryStrokeColor(v) { this.i.dl = stringToBrush(v); this._a("primaryStrokeColor", brushToString(this.i.dl)); } /** * 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 secondaryFillColor() { return brushToString(this.i.dm); } set secondaryFillColor(v) { this.i.dm = stringToBrush(v); this._a("secondaryFillColor", brushToString(this.i.dm)); } /** * 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 secondaryStrokeColor() { return brushToString(this.i.dn); } set secondaryStrokeColor(v) { this.i.dn = stringToBrush(v); this._a("secondaryStrokeColor", brushToString(this.i.dn)); } /** * Gets or sets the image source for the icon. Used if none of the other icon types are not used. */ get source() { return this.i.a1; } set source(v) { this.i.a1 = v; } /** * Gets or sets data url for the icon to use. */ get dataURL() { return this.i.bg; } set dataURL(v) { this.i.bg = v; } /** * Gets or sets path data for the icon to use. */ get svgPath() { return this.i.svgPath; } set svgPath(v) { this.i.svgPath = v; } /** * Gets or sets svg text for the icon to use. */ get svg() { return this.i.svg; } set svg(v) { this.i.svg = v; } /** * Gets or sets an array of path data for the icon to use. */ get sVGPaths() { return this.i.b; } set sVGPaths(v) { if (v && !Array.isArray(v) && typeof (v) == "string") { const re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.b = v; } /** * Gets or sets the use for the button. */ get textStyle() { if (this.i.o == null) { return null; } return this.i.o.fontString; } set textStyle(v) { let fi = new FontInfo(); fi.fontString = v; this.i.o = fi; this._a("textStyle", this.i.o != null ? this.i.o.fontString : ""); } /** * Gets or sets the id to use for the checkbox. */ get id() { return this.i.bq; } set id(v) { this.i.bq = v; } /** * Gets or sets TabIndex to use for the checkbox. */ get tabIndex() { return this.i.av; } set tabIndex(v) { this.i.av = +v; this._a("tabIndex", this.i.av); } /** * Gets or sets the value of the aria-label attribute. */ get ariaLabel() { return this.i.bb; } set ariaLabel(v) { this.i.bb = v; } /** * Gets or sets whether the icon is hovered. */ get isHover() { return this.i.v; } set isHover(v) { this.i.v = ensureBool(v); this._a("isHover", this.i.v); } /** * Gets or sets whether the checkbox is disabled. */ get disabled() { return this.i.disabled; } set disabled(v) { this.i.disabled = ensureBool(v); this._a("disabled", this.i.disabled); } get opacity() { return this.i.an; } set opacity(v) { this.i.an = +v; this._a("opacity", this.i.an); } /** * Gets or sets the viewbox left for the svg icon. */ get viewBoxLeft() { return this.i.aq; } set viewBoxLeft(v) { this.i.aq = +v; this._a("viewBoxLeft", this.i.aq); } /** * Gets or sets the viewbox top for the svg icon. */ get viewBoxTop() { return this.i.ar; } set viewBoxTop(v) { this.i.ar = +v; this._a("viewBoxTop", this.i.ar); } /** * Gets or sets the viewbox width for the svg icon. */ get viewBoxWidth() { return this.i.as; } set viewBoxWidth(v) { this.i.as = +v; this._a("viewBoxWidth", this.i.as); } /** * Gets or sets the viewbox height for the svg icon. */ get viewBoxHeight() { return this.i.ap; } set viewBoxHeight(v) { this.i.ap = +v; this._a("viewBoxHeight", this.i.ap); } /** * Gets or sets the width of the icon. */ get width() { return this.i.at; } set width(v) { this.i.at = +v; this._a("width", this.i.at); } /** * Gets or sets the height of the icon. */ get height() { return this.i.al; } set height(v) { this.i.al = +v; this._a("height", this.i.al); } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } return null; } get hasUserValues() { return this._hasUserValues; } __m(propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } } _styling(container, component, parent) { if (this._inStyling) { return; } this._inStyling = true; this._stylingContainer = container; this._stylingParent = component; let genericPrefix = ""; let typeName = this.i.$type.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } genericPrefix = toSpinal("XIconComponent"); let additionalPrefixes = []; let prefix = toSpinal(typeName); additionalPrefixes.push(prefix + "-"); let 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); } let basePrefix = toSpinal(typeName); additionalPrefixes.push(basePrefix + "-"); b = b.baseType; } if (parent) { let parentTypeName = parent.i.$type.name; if (parentTypeName.indexOf("Xam") === 0) { parentTypeName = parentTypeName.substring(3); } let 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; } onDetachedFromUI() { this.i.onDetachedFromUI(); } onAttachedToUI() { this.i.onAttachedToUI(); } /** * Exports visual information about the current state of the grid. */ exportVisualModel() { let iv = this.i.a0(); return (iv); } /** * Returns a serialized copy of the exported visual model */ exportSerializedVisualModel() { let iv = this.i.bi(); return (iv); } } IgcXIconComponent._observedAttributesIgcXIconComponent = null; IgcXIconComponent.htmlTagName = "igc-x-icon"; IgcXIconComponent._isElementRegistered = false; return IgcXIconComponent; })();