igniteui-react-inputs
Version:
Ignite UI React input components.
704 lines (701 loc) • 22.4 kB
JavaScript
import { __extends, __values } from "tslib";
import * as React from 'react';
import { XCheckbox } from "./XCheckbox";
import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core";
import { ReactRenderer, PortalManager } from "igniteui-react-core";
import { delegateCombine, delegateRemove } from "igniteui-react-core";
import { IgrCheckboxChangeEventArgs } from './igr-checkbox-change-event-args';
import { CheckboxLabelPosition_$type } from './CheckboxLabelPosition';
import { BaseControlTheme_$type } from "igniteui-react-core";
var requiredStyle = "\n\n";
var IgrXCheckbox = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrXCheckbox, _super);
function IgrXCheckbox(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;
_this._change = null;
_this._change_wrapped = 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("checkboxLabel", _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");
var checkbox = _this.i;
_this._checkbox = checkbox;
checkbox.provideContainer(ren);
if (props) {
_this.initializeProperties();
}
return _this;
}
IgrXCheckbox.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
IgrXCheckbox.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-checkbox igr-x-checkbox",
ref: this._getMainRef,
children: children
});
return div;
};
IgrXCheckbox.prototype.requestRender = function () {
if (this._initialized) {
this.setState({});
}
};
//private _getLabelPortal(element: DomWrapper, portalCallback: (portal: DomPortal) => void): void {
// this._portalManager.getPortal(element, "TemplateContent", portalCallback);
//}
IgrXCheckbox.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;
};
IgrXCheckbox.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
IgrXCheckbox.prototype.updateStyle = function () {
this._styling(this._elRef, this);
};
IgrXCheckbox.prototype.destroy = function () {
this._checkbox.destroy();
this._wrapper.destroy();
};
IgrXCheckbox.prototype.componentWillUnmount = function () {
};
IgrXCheckbox.prototype.componentDidMount = function () {
this._elRef.appendChild(this._container.getNativeElement());
this.initializeContent();
};
IgrXCheckbox.prototype.initializeContent = function () {
this._styling(this._container.getNativeElement(), this);
this.updateStyle();
this.i.onContentReady();
};
IgrXCheckbox.prototype.createImplementation = function () {
return new XCheckbox();
};
Object.defineProperty(IgrXCheckbox.prototype, "i", {
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "baseTheme", {
/**
* Gets or sets the base built in theme to use for the checkbox.
*/
get: function () {
return this.i.n;
},
set: function (v) {
this.i.n = ensureEnum(BaseControlTheme_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "uncheckedBackgroundColor", {
/**
* Gets or sets the color to use for the background when the checkbox is unchecked.
*/
get: function () {
return brushToString(this.i.dl);
},
set: function (v) {
this.i.dl = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualUncheckedBackgroundColor", {
/**
* Gets or sets the color to use for the actual background when the checkbox is unchecked.
*/
get: function () {
return brushToString(this.i.db);
},
set: function (v) {
this.i.db = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "checkedBackgroundColor", {
/**
* Gets or sets the color to use for the background when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.dd);
},
set: function (v) {
this.i.dd = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "tickColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.dk);
},
set: function (v) {
this.i.dk = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualTickColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.da);
},
set: function (v) {
this.i.da = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "uncheckedBorderColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is unchecked.
*/
get: function () {
return brushToString(this.i.dm);
},
set: function (v) {
this.i.dm = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "checkedBorderColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.de);
},
set: function (v) {
this.i.de = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualUncheckedBorderColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.dc);
},
set: function (v) {
this.i.dc = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualCheckedBorderColor", {
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.c9);
},
set: function (v) {
this.i.c9 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "borderWidth", {
/**
* Gets or sets the Width to use for the check mark when the checkbox is checked.
*/
get: function () {
return this.i.aq;
},
set: function (v) {
this.i.aq = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualBorderWidth", {
/**
* Gets or sets the Width to use for the check mark when the checkbox is checked.
*/
get: function () {
return this.i.an;
},
set: function (v) {
this.i.an = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "cornerRadius", {
/**
* Gets or sets the corner radius to use for the checkbox.
*/
get: function () {
return this.i.ar;
},
set: function (v) {
this.i.ar = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "tickStrokeWidth", {
/**
* Gets or sets the corner radius to use for the checkbox.
*/
get: function () {
return this.i.av;
},
set: function (v) {
this.i.av = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualTickStrokeWidth", {
/**
* Gets or sets the stroke width to use for the check mark.
*/
get: function () {
return this.i.ap;
},
set: function (v) {
this.i.ap = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualCornerRadius", {
/**
* Gets the actual corner radius to use for the checkbox.
*/
get: function () {
return this.i.ao;
},
set: function (v) {
this.i.ao = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "actualCheckedBackgroundColor", {
/**
* Gets or sets the color to use for the actual background when the checkbox is checked.
*/
get: function () {
return brushToString(this.i.c8);
},
set: function (v) {
this.i.c8 = stringToBrush(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "inputId", {
/**
* Gets or sets the id to use for the internal native checkbox.
*/
get: function () {
return this.i.b1;
},
set: function (v) {
this.i.b1 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "id", {
/**
* Gets or sets the id to use for the checkbox.
*/
get: function () {
return this.i.bz;
},
set: function (v) {
this.i.bz = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "labelId", {
/**
* Gets or sets id to use for the checkbox label.
*/
get: function () {
return this.i.labelId;
},
set: function (v) {
this.i.labelId = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "name", {
/**
* Gets or sets name to use for the checkbox.
*/
get: function () {
return this.i.ca;
},
set: function (v) {
this.i.ca = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "tabIndex", {
/**
* Gets or sets TabIndex to use for the checkbox.
*/
get: function () {
return this.i.az;
},
set: function (v) {
this.i.az = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "required", {
/**
* Gets or sets if the checkbox is required.
*/
get: function () {
return this.i.ay;
},
set: function (v) {
this.i.ay = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "ariaLabelledBy", {
/**
* Gets or sets the value of the aria-labelledby attribute.
*/
get: function () {
return this.i.bn;
},
set: function (v) {
this.i.bn = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "ariaLabel", {
/**
* Gets or sets the value of the aria-label attribute.
*/
get: function () {
return this.i.bm;
},
set: function (v) {
this.i.bm = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "value", {
/**
* Gets or sets value to use for the checkbox.
*/
get: function () {
return this.i.a4;
},
set: function (v) {
this.i.a4 = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "focused", {
/**
* Gets or sets if the checkbox is Focused.
*/
get: function () {
return this.i.focused;
},
set: function (v) {
this.i.focused = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "labelPosition", {
/**
* Gets or sets LabelPosition to use for the checkbox.
*/
get: function () {
return this.i.e;
},
set: function (v) {
this.i.e = ensureEnum(CheckboxLabelPosition_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "disableRipple", {
/**
* Gets or sets whether to disable the ripple effect for the checkbox.
*/
get: function () {
return this.i.y;
},
set: function (v) {
this.i.y = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "checked", {
/**
* Gets or sets whether the checkbox is checked.
*/
get: function () {
return this.i.checked;
},
set: function (v) {
this.i.checked = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.prototype, "indeterminate", {
/**
* Gets or sets whether the checkbox is indeterminate.
*/
get: function () {
return this.i.indeterminate;
},
set: function (v) {
this.i.indeterminate = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrXCheckbox.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(IgrXCheckbox.prototype, "disableTransitions", {
/**
* Gets or sets whether the checkbox transitions are disabled.
*/
get: function () {
return this.i.z;
},
set: function (v) {
this.i.z = ensureBool(v);
},
enumerable: false,
configurable: true
});
IgrXCheckbox.prototype.findByName = function (name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
return null;
};
Object.defineProperty(IgrXCheckbox.prototype, "hasUserValues", {
get: function () {
return this._hasUserValues;
},
enumerable: false,
configurable: true
});
IgrXCheckbox.prototype.__m = function (propertyName) {
if (!this._inStyling) {
this._hasUserValues.add(propertyName);
}
};
IgrXCheckbox.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("XCheckbox");
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;
};
IgrXCheckbox.prototype.onDetachedFromUI = function () {
this.i.onDetachedFromUI();
};
IgrXCheckbox.prototype.onAttachedToUI = function () {
this.i.onAttachedToUI();
};
/**
* Exports visual information about the current state of the grid.
*/
IgrXCheckbox.prototype.exportVisualModel = function () {
var iv = this.i.a3();
return (iv);
};
/**
* Returns a serialized copy of the exported visual model
*/
IgrXCheckbox.prototype.exportSerializedVisualModel = function () {
var iv = this.i.by();
return (iv);
};
Object.defineProperty(IgrXCheckbox.prototype, "change", {
get: function () {
return this._change;
},
set: function (ev) {
var _this = this;
if (this._change_wrapped !== null) {
this.i.change = delegateRemove(this.i.change, this._change_wrapped);
this._change_wrapped = null;
this._change = null;
}
this._change = ev;
this._change_wrapped = function (o, e) {
var outerArgs = new IgrCheckboxChangeEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeChange) {
_this.beforeChange(_this, outerArgs);
}
if (_this._change) {
_this._change(_this, outerArgs);
}
};
this.i.change = delegateCombine(this.i.change, this._change_wrapped);
;
},
enumerable: false,
configurable: true
});
return IgrXCheckbox;
}(React.Component));
export { IgrXCheckbox };