igniteui-react-inputs
Version:
Ignite UI React input components.
389 lines (386 loc) • 10 kB
JavaScript
import * as React from 'react';
import { XLabel } from "./XLabel";
import { ensureEnum, brushToString, stringToBrush, ensureBool, NamePatcher, isValidProp, getModifiedProps } from "igniteui-react-core";
import { FontInfo } from "igniteui-react-core";
import { ReactRenderer, PortalManager } from "igniteui-react-core";
import { IgrXInputGroupItem } from './igr-x-input-group-item';
import { ControlDisplayDensity_$type } from "igniteui-react-core";
import { BaseControlTheme_$type } from "igniteui-react-core";
export class IgrXLabel extends IgrXInputGroupItem {
_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-label igr-x-label",
ref: this._getMainRef,
children: children
});
return div;
}
requestRender() {
if (this._initialized) {
this.setState({});
}
}
constructor(props) {
super(props);
this._wrapper = 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("labelContent", 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 label = this.i;
this._label = label;
label.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._label.destroy();
this._wrapper.destroy();
}
componentWillUnmount() {
}
componentDidMount() {
this._elRef.appendChild(this._container.getNativeElement());
this.initializeContent();
}
initializeContent() {
this._styling(this._container.getNativeElement(), this);
this.updateStyle();
this.i.onSizeReady();
}
createImplementation() {
return new XLabel();
}
_onDisplayChanged() {
if (this._elRef) {
this._elRef.style.display = this.display;
}
}
_onFlexDirectionChanged() {
if (this._elRef) {
this._elRef.style.flexDirection = this.flexDirection;
}
}
_onFlexGrowChanged() {
if (this._elRef) {
this._elRef.style.flexGrow = this.flexGrow;
}
}
_onAlignItemsChanged() {
if (this._elRef) {
this._elRef.style.alignItems = this.alignItems;
}
}
_onAlignSelfChanged() {
if (this._elRef) {
this._elRef.style.alignSelf = this.alignSelf;
}
}
/**
* @hidden
*/
get i() {
return this._implementation;
}
/**
* Gets or sets the base built in theme to use for the label.
*/
get baseTheme() {
return this.i.p;
}
set baseTheme(v) {
this.i.p = ensureEnum(BaseControlTheme_$type, v);
}
/**
* Gets or sets the display density to use for the label.
*/
get density() {
return this.i.t;
}
set density(v) {
this.i.t = ensureEnum(ControlDisplayDensity_$type, v);
}
/**
* Gets the actual display density to use for the label.
*/
get actualDensity() {
return this.i.s;
}
set actualDensity(v) {
this.i.s = ensureEnum(ControlDisplayDensity_$type, v);
}
/**
* Gets the actual color to use for the text color.
*/
get actualTextColor() {
return brushToString(this.i.c3);
}
set actualTextColor(v) {
this.i.c3 = stringToBrush(v);
}
/**
* Gets the actual color to use for the text color.
*/
get actualHighlightTextColor() {
return brushToString(this.i.c0);
}
set actualHighlightTextColor(v) {
this.i.c0 = stringToBrush(v);
}
/**
* Gets the actual color to use for the text color when highlighted and hovered.
*/
get actualHoverHighlightTextColor() {
return brushToString(this.i.c1);
}
set actualHoverHighlightTextColor(v) {
this.i.c1 = stringToBrush(v);
}
/**
* Gets the actual hover color to use for the text.
*/
get actualHoverTextColor() {
return brushToString(this.i.c2);
}
set actualHoverTextColor(v) {
this.i.c2 = stringToBrush(v);
}
/**
* Gets or sets the color to use for the text.
*/
get textColor() {
return brushToString(this.i.dj);
}
set textColor(v) {
this.i.dj = stringToBrush(v);
}
/**
* Gets or sets the color to use for the text.
*/
get highlightTextColor() {
return brushToString(this.i.dg);
}
set highlightTextColor(v) {
this.i.dg = stringToBrush(v);
}
/**
* Gets or sets the color to use for the text.
*/
get hoverHighlightTextColor() {
return brushToString(this.i.dh);
}
set hoverHighlightTextColor(v) {
this.i.dh = stringToBrush(v);
}
/**
* Gets or sets the use for the button.
*/
get textStyle() {
if (this.i.y == null) {
return null;
}
return this.i.y.fontString;
}
set textStyle(v) {
let fi = new FontInfo();
fi.fontString = v;
this.i.y = fi;
}
/**
* Gets or sets the color to use for the hovered text of the button regardless of type.
*/
get hoverTextColor() {
return brushToString(this.i.di);
}
set hoverTextColor(v) {
this.i.di = stringToBrush(v);
}
/**
* Gets or sets the id to use for the checkbox.
*/
get id() {
return this.i.bw;
}
set id(v) {
this.i.bw = v;
}
/**
* Gets or sets the id to use for the checkbox.
*/
get display() {
return this.i.bk;
}
set display(v) {
this.i.bk = v;
}
/**
* Gets or sets the id to use for the checkbox.
*/
get flexDirection() {
return this.i.bn;
}
set flexDirection(v) {
this.i.bn = v;
}
/**
* Gets or sets the flex-grow setting for the button.
*/
get flexGrow() {
return this.i.bp;
}
set flexGrow(v) {
this.i.bp = v;
}
/**
* Gets or sets the id to use for the checkbox.
*/
get alignItems() {
return this.i.bc;
}
set alignItems(v) {
this.i.bc = v;
}
/**
* Gets or sets the id to use for the checkbox.
*/
get alignSelf() {
return this.i.be;
}
set alignSelf(v) {
this.i.be = v;
}
/**
* Gets or sets TabIndex to use for the checkbox.
*/
get tabIndex() {
return this.i.au;
}
set tabIndex(v) {
this.i.au = +v;
}
/**
* Gets or sets the for attribute to use for the label.
*/
get for() {
return this.i.br;
}
set for(v) {
this.i.br = v;
}
/**
* Gets or sets the value of the aria-label attribute.
*/
get ariaLabel() {
return this.i.bg;
}
set ariaLabel(v) {
this.i.bg = v;
}
/**
* Gets or sets the text for the label.
*/
get text() {
return this.i.text;
}
set text(v) {
this.i.text = v;
}
/**
* Gets or sets whether the label is hovered.
*/
get isHover() {
return this.i.ao;
}
set isHover(v) {
this.i.ao = ensureBool(v);
}
/**
* Gets or sets the value for the label.
*/
get value() {
return this.i.as;
}
set value(v) {
this.i.as = ensureBool(v);
}
/**
* Gets or sets whether the checkbox is disabled.
*/
get disabled() {
return this.i.disabled;
}
set disabled(v) {
this.i.disabled = ensureBool(v);
}
onDetachedFromUI() {
this.i.onDetachedFromUI();
}
onAttachedToUI() {
this.i.onAttachedToUI();
}
/**
* Exports visual information about the current state of the grid.
*/
exportVisualModel() {
let iv = this.i.aw();
return (iv);
}
/**
* Returns a serialized copy of the exported visual model
*/
exportSerializedVisualModel() {
let iv = this.i.bm();
return (iv);
}
}