UNPKG

igniteui-react-inputs

Version:

Ignite UI React input components.

592 lines (589 loc) 15.6 kB
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"; export class IgrXIcon extends React.Component { _getMainRef(ref) { this._elRef = ref; } render() { let propChildren = this.props.children; let children = []; React.Children.forEach(propChildren, (ch) => { children.push(React.cloneElement(ch)); }); this._portalManager.onRender(children); let div = React.createElement("div", { className: "ig-x-icon igr-x-icon", ref: this._getMainRef, children: children }); return div; } requestRender() { if (this._initialized) { this.setState({}); } } constructor(props) { super(props); 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(); } } //private _getLabelPortal(element: DomWrapper, portalCallback: (portal: DomPortal) => void): void { // this._portalManager.getPortal(element, "TemplateContent", portalCallback); //} shouldComponentUpdate(nextProps, nextState) { const mod = getModifiedProps(this.props, nextProps); for (const p of Object.keys(mod)) { if (isValidProp(this, p)) { this[p] = mod[p]; } } return true; } initializeProperties() { for (const p of Object.keys(this.props)) { if (isValidProp(this, p)) { this[p] = this.props[p]; } } } // supports angular themes or custom properties set in CSS updateStyle() { this._styling(this._elRef, this); } destroy() { this._icon.destroy(); this._wrapper.destroy(); } componentWillUnmount() { } componentDidMount() { this._elRef.appendChild(this._container.getNativeElement()); this.initializeContent(); } initializeContent() { this._styling(this._container.getNativeElement(), this); this.updateStyle(); } createImplementation() { return new XIcon(); } get i() { return this._implementation; } /** * 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); } /** * Gets the fill color currently used by the icon. */ get actualFill() { return brushToString(this.i.du); } set actualFill(v) { this.i.du = stringToBrush(v); } /** * Gets the stroke color currently used by the icon. */ get actualStroke() { return brushToString(this.i.dv); } set actualStroke(v) { this.i.dv = stringToBrush(v); } /** * Gets the text color currently used by the icon. */ get actualTextColor() { return brushToString(this.i.dw); } set actualTextColor(v) { this.i.dw = stringToBrush(v); } /** * Gets the stroke width currently used by the icon. */ get actualStrokeWidth() { return this.i.aq; } set actualStrokeWidth(v) { this.i.aq = +v; } /** * 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); } /** * Gets or sets the stroke color to use for the icon. */ get stroke() { return brushToString(this.i.ea); } set stroke(v) { this.i.ea = stringToBrush(v); } /** * Gets or sets the stroke thickness to use for the icon. */ get strokeWidth() { return this.i.a4; } set strokeWidth(v) { this.i.a4 = +v; } /** * Gets or sets the text color to use for the icon. */ get textColor() { return brushToString(this.i.eb); } set textColor(v) { this.i.eb = stringToBrush(v); } /** * Gets or sets the fill color to use when the icon is hovered. */ get hoverFill() { return brushToString(this.i.d3); } set hoverFill(v) { this.i.d3 = stringToBrush(v); } /** * Gets or sets the stroke color to use when the icon is hovered. */ get hoverStroke() { return brushToString(this.i.d4); } set hoverStroke(v) { this.i.d4 = stringToBrush(v); } /** * Gets or sets the stroke thickness to use when the icon is hovered. */ get hoverStrokeThickness() { return this.i.a2; } set hoverStrokeThickness(v) { this.i.a2 = +v; } /** * Gets or sets the text color to use when the icon is hovered. */ get hoverTextColor() { return brushToString(this.i.d5); } set hoverTextColor(v) { this.i.d5 = stringToBrush(v); } /** * 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); } /** * 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); } /** * 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.d6); } set primaryFillColor(v) { this.i.d6 = stringToBrush(v); } /** * 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.d7); } set primaryStrokeColor(v) { this.i.d7 = stringToBrush(v); } /** * 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.d8); } set secondaryFillColor(v) { this.i.d8 = stringToBrush(v); } /** * 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.d9); } set secondaryStrokeColor(v) { this.i.d9 = stringToBrush(v); } /** * 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.bj; } set source(v) { this.i.bj = v; } /** * Gets or sets data url for the icon to use. */ get dataURL() { return this.i.b2; } set dataURL(v) { this.i.b2 = 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; } /** * Gets or sets the id to use for the checkbox. */ get id() { return this.i.cc; } set id(v) { this.i.cc = v; } /** * Gets or sets TabIndex to use for the checkbox. */ get tabIndex() { return this.i.bb; } set tabIndex(v) { this.i.bb = +v; } /** * Gets or sets the value of the aria-label attribute. */ get ariaLabel() { return this.i.bx; } set ariaLabel(v) { this.i.bx = v; } /** * Gets or sets whether the icon is hovered. */ get isHover() { return this.i.v; } set isHover(v) { this.i.v = ensureBool(v); } /** * Gets or sets whether the checkbox is disabled. */ get disabled() { return this.i.disabled; } set disabled(v) { this.i.disabled = ensureBool(v); } get opacity() { return this.i.a3; } set opacity(v) { this.i.a3 = +v; } /** * Gets the actual viewbox left for the svg icon. */ get actualViewBoxLeft() { return this.i.as; } set actualViewBoxLeft(v) { this.i.as = +v; } /** * Gets or sets the viewbox left for the svg icon. */ get viewBoxLeft() { return this.i.a6; } set viewBoxLeft(v) { this.i.a6 = +v; } /** * Gets the actual viewbox top for the svg icon. */ get actualViewBoxTop() { return this.i.at; } set actualViewBoxTop(v) { this.i.at = +v; } /** * Gets or sets the viewbox top for the svg icon. */ get viewBoxTop() { return this.i.a7; } set viewBoxTop(v) { this.i.a7 = +v; } /** * Gets the actual viewbox width for the svg icon. */ get actualViewBoxWidth() { return this.i.au; } set actualViewBoxWidth(v) { this.i.au = +v; } /** * Gets or sets the viewbox width for the svg icon. */ get viewBoxWidth() { return this.i.a8; } set viewBoxWidth(v) { this.i.a8 = +v; } /** * Gets the actual viewbox height for the svg icon. */ get actualViewBoxHeight() { return this.i.ar; } set actualViewBoxHeight(v) { this.i.ar = +v; } /** * Gets or sets the viewbox height for the svg icon. */ get viewBoxHeight() { return this.i.a5; } set viewBoxHeight(v) { this.i.a5 = +v; } /** * Gets or sets the width of the icon. */ get width() { return this.i.a9; } set width(v) { this.i.a9 = +v; } /** * Gets or sets the height of the icon. */ get height() { return this.i.a1; } set height(v) { this.i.a1 = +v; } 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("XIcon"); 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.bi(); return (iv); } /** * Returns a serialized copy of the exported visual model */ exportSerializedVisualModel() { let iv = this.i.b4(); return (iv); } }