igniteui-react-inputs
Version:
Ignite UI React input components.
556 lines (553 loc) • 14.8 kB
JavaScript
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.c8);
}
set actualFill(v) {
this.i.c8 = stringToBrush(v);
}
/**
* Gets the stroke color currently used by the icon.
*/
get actualStroke() {
return brushToString(this.i.c9);
}
set actualStroke(v) {
this.i.c9 = stringToBrush(v);
}
/**
* Gets the text color currently used by the icon.
*/
get actualTextColor() {
return brushToString(this.i.da);
}
set actualTextColor(v) {
this.i.da = stringToBrush(v);
}
/**
* Gets the stroke width currently used by the icon.
*/
get actualStrokeWidth() {
return this.i.ai;
}
set actualStrokeWidth(v) {
this.i.ai = +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.dp);
}
set stroke(v) {
this.i.dp = stringToBrush(v);
}
/**
* Gets or sets the stroke thickness to use for the icon.
*/
get strokeWidth() {
return this.i.ao;
}
set strokeWidth(v) {
this.i.ao = +v;
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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;
}
/**
* 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);
}
/**
* 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.dk);
}
set primaryFillColor(v) {
this.i.dk = 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.dl);
}
set primaryStrokeColor(v) {
this.i.dl = 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.dm);
}
set secondaryFillColor(v) {
this.i.dm = 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.dn);
}
set secondaryStrokeColor(v) {
this.i.dn = 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.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;
}
/**
* 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;
}
/**
* 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);
}
/**
* 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.an;
}
set opacity(v) {
this.i.an = +v;
}
/**
* Gets or sets the viewbox left for the svg icon.
*/
get viewBoxLeft() {
return this.i.aq;
}
set viewBoxLeft(v) {
this.i.aq = +v;
}
/**
* Gets or sets the viewbox top for the svg icon.
*/
get viewBoxTop() {
return this.i.ar;
}
set viewBoxTop(v) {
this.i.ar = +v;
}
/**
* Gets or sets the viewbox width for the svg icon.
*/
get viewBoxWidth() {
return this.i.as;
}
set viewBoxWidth(v) {
this.i.as = +v;
}
/**
* Gets or sets the viewbox height for the svg icon.
*/
get viewBoxHeight() {
return this.i.ap;
}
set viewBoxHeight(v) {
this.i.ap = +v;
}
/**
* Gets or sets the width of the icon.
*/
get width() {
return this.i.at;
}
set width(v) {
this.i.at = +v;
}
/**
* Gets or sets the height of the icon.
*/
get height() {
return this.i.al;
}
set height(v) {
this.i.al = +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.a0();
return (iv);
}
/**
* Returns a serialized copy of the exported visual model
*/
exportSerializedVisualModel() {
let iv = this.i.bi();
return (iv);
}
}