igniteui-webcomponents-inputs
Version:
Ignite UI Web Components inputs components.
793 lines (790 loc) • 27.6 kB
JavaScript
import { __extends, __values } from "tslib";
import { XCheckbox } from "./XCheckbox";
import { ensureEnum, brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, toSpinal, enumToString, getAllPropertyNames, fromSpinal } from "igniteui-webcomponents-core";
import { WebComponentRenderer, PortalManager } from "igniteui-webcomponents-core";
import { delegateCombine, delegateRemove } from "igniteui-webcomponents-core";
import { TypeRegistrar } from "igniteui-webcomponents-core";
import { RegisterElementHelper } from "igniteui-webcomponents-core";
import { IgcCheckboxChangeEventArgs } from './igc-checkbox-change-event-args';
import { CheckboxLabelPosition_$type } from './CheckboxLabelPosition';
import { BaseControlTheme_$type } from "igniteui-webcomponents-core";
import { IgcHTMLElement } from "igniteui-webcomponents-core";
var pending = [];
var checked = /*@__PURE__*/ new WeakMap(); // TODO why not WeakSet?
export var IgcXCheckboxComponent = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgcXCheckboxComponent, _super);
function IgcXCheckboxComponent() {
var _this = _super.call(this) || this;
_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;
_this._change = null;
_this._change_wrapped = null;
if (_this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
}
_this._portalManager = new PortalManager("checkboxLabel");
_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 checkbox = _this.i;
_this._checkbox = checkbox;
checkbox.provideContainer(_this._renderer);
_this._onChildrenChanged();
//Checkbox.notifySizeChanged();
var mut = new MutationObserver(function (list) {
var e_1, _b;
try {
for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) {
var mutation = list_1_1.value;
if (mutation.type == 'childList') {
_this._onChildrenChanged();
}
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (list_1_1 && !list_1_1.done && (_b = list_1.return))
_b.call(list_1);
}
finally {
if (e_1)
throw e_1.error;
}
}
});
mut.observe(_this, {
childList: true
});
return _this;
//this._renderer.addSizeWatcher(() => {
// this._checkbox.notifySizeChanged();
//});
}
IgcXCheckboxComponent.prototype._onChildrenChanged = function () {
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
IgcXCheckboxComponent.prototype.updateStyle = function () {
this._styling(this, this);
};
IgcXCheckboxComponent.prototype.destroy = function () {
this._checkbox.destroy();
this._wrapper.destroy();
};
IgcXCheckboxComponent.prototype.createImplementation = function () {
return new XCheckbox();
};
IgcXCheckboxComponent.prototype.disconnectedCallback = function () {
this._disconnected = true;
if (this.i) {
this.i.onDetachedFromUI();
}
};
IgcXCheckboxComponent.prototype.connectedCallback = function () {
if (this._disconnected) {
this._disconnected = false;
if (this.i) {
this.i.onAttachedToUI();
}
return;
}
this.classList.add("ig-x-checkbox");
this.classList.add("igc-x-checkbox");
this.appendChild(this._container.getNativeElement());
this._attached = true;
this.style.display = "inline-block";
//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();
};
IgcXCheckboxComponent.prototype.afterContentInit = function () {
this.i.onContentReady();
//this.i.notifySizeChanged();
};
Object.defineProperty(IgcXCheckboxComponent.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
} /**
* @hidden
*/,
enumerable: false,
configurable: true
});
IgcXCheckboxComponent._createFromInternal = function (internal) {
if (!internal) {
return null;
}
if (!internal.$type) {
return null;
}
var name = internal.$type.name;
var externalName = "Igc" + name + "Component";
if (!TypeRegistrar.isRegistered(externalName)) {
return null;
}
return TypeRegistrar.create(externalName);
};
IgcXCheckboxComponent.prototype._enqueueSetAttribute = function (attrName, attrValue) {
this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue });
};
IgcXCheckboxComponent.prototype._flushQueuedAttributes = function () {
this._settingAttributes = true;
for (var i = 0; i < this._queuedSetAttributes.length; i++) {
this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue);
}
this._settingAttributes = false;
this._queuedSetAttributes.length = 0;
};
IgcXCheckboxComponent.prototype._a = function (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;
};
Object.defineProperty(IgcXCheckboxComponent, "observedAttributes", {
get: function () {
if (IgcXCheckboxComponent._observedAttributesIgcXCheckboxComponent == null) {
var names = getAllPropertyNames(IgcXCheckboxComponent);
for (var i = 0; i < names.length; i++) {
names[i] = toSpinal(names[i]);
}
IgcXCheckboxComponent._observedAttributesIgcXCheckboxComponent = names;
}
return IgcXCheckboxComponent._observedAttributesIgcXCheckboxComponent;
},
enumerable: false,
configurable: true
});
IgcXCheckboxComponent.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
if (this._settingAttributes) {
return;
}
var setName = fromSpinal(name);
this._updatingFromAttribute = true;
this[setName] = newValue;
this._updatingFromAttribute = false;
};
IgcXCheckboxComponent.register = function () {
if (!IgcXCheckboxComponent._isElementRegistered) {
IgcXCheckboxComponent._isElementRegistered = true;
RegisterElementHelper.registerElement(IgcXCheckboxComponent.htmlTagName, IgcXCheckboxComponent);
}
};
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("baseTheme", enumToString(BaseControlTheme_$type, this.i.n));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("uncheckedBackgroundColor", brushToString(this.i.dl));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("actualUncheckedBackgroundColor", brushToString(this.i.db));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("checkedBackgroundColor", brushToString(this.i.dd));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("tickColor", brushToString(this.i.dk));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("actualTickColor", brushToString(this.i.da));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("uncheckedBorderColor", brushToString(this.i.dm));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("checkedBorderColor", brushToString(this.i.de));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("actualUncheckedBorderColor", brushToString(this.i.dc));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("actualCheckedBorderColor", brushToString(this.i.c9));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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;
this._a("borderWidth", this.i.aq);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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;
this._a("actualBorderWidth", this.i.an);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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;
this._a("cornerRadius", this.i.ar);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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;
this._a("tickStrokeWidth", this.i.av);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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;
this._a("actualTickStrokeWidth", this.i.ap);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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;
this._a("actualCornerRadius", this.i.ao);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("actualCheckedBackgroundColor", brushToString(this.i.c8));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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(IgcXCheckboxComponent.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(IgcXCheckboxComponent.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(IgcXCheckboxComponent.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(IgcXCheckboxComponent.prototype, "tabIndex", {
/**
* Gets or sets TabIndex to use for the checkbox.
*/
get: function () {
return this.i.az;
},
set: function (v) {
this.i.az = +v;
this._a("tabIndex", this.i.az);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.prototype, "required", {
/**
* Gets or sets if the checkbox is required.
*/
get: function () {
return this.i.ay;
},
set: function (v) {
this.i.ay = +v;
this._a("required", this.i.ay);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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(IgcXCheckboxComponent.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(IgcXCheckboxComponent.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(IgcXCheckboxComponent.prototype, "focused", {
/**
* Gets or sets if the checkbox is Focused.
*/
get: function () {
return this.i.focused;
},
set: function (v) {
this.i.focused = ensureBool(v);
this._a("focused", this.i.focused);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("labelPosition", enumToString(CheckboxLabelPosition_$type, this.i.e));
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("disableRipple", this.i.y);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.prototype, "checked", {
/**
* Gets or sets whether the checkbox is checked.
*/
get: function () {
return this.i.checked;
},
set: function (v) {
this.i.checked = ensureBool(v);
this._a("checked", this.i.checked);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.prototype, "indeterminate", {
/**
* Gets or sets whether the checkbox is indeterminate.
*/
get: function () {
return this.i.indeterminate;
},
set: function (v) {
this.i.indeterminate = ensureBool(v);
this._a("indeterminate", this.i.indeterminate);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.prototype, "disabled", {
/**
* Gets or sets whether the checkbox is disabled.
*/
get: function () {
return this.i.disabled;
},
set: function (v) {
this.i.disabled = ensureBool(v);
this._a("disabled", this.i.disabled);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgcXCheckboxComponent.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);
this._a("disableTransitions", this.i.z);
},
enumerable: false,
configurable: true
});
IgcXCheckboxComponent.prototype.findByName = function (name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
return null;
};
Object.defineProperty(IgcXCheckboxComponent.prototype, "hasUserValues", {
get: function () {
return this._hasUserValues;
},
enumerable: false,
configurable: true
});
IgcXCheckboxComponent.prototype.__m = function (propertyName) {
if (!this._inStyling) {
this._hasUserValues.add(propertyName);
}
};
IgcXCheckboxComponent.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("XCheckboxComponent");
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;
};
IgcXCheckboxComponent.prototype.onDetachedFromUI = function () {
this.i.onDetachedFromUI();
};
IgcXCheckboxComponent.prototype.onAttachedToUI = function () {
this.i.onAttachedToUI();
};
/**
* Exports visual information about the current state of the grid.
*/
IgcXCheckboxComponent.prototype.exportVisualModel = function () {
var iv = this.i.a3();
return (iv);
};
/**
* Returns a serialized copy of the exported visual model
*/
IgcXCheckboxComponent.prototype.exportSerializedVisualModel = function () {
var iv = this.i.by();
return (iv);
};
Object.defineProperty(IgcXCheckboxComponent.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 IgcCheckboxChangeEventArgs();
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
});
IgcXCheckboxComponent._observedAttributesIgcXCheckboxComponent = null;
IgcXCheckboxComponent.htmlTagName = "igc-x-checkbox";
IgcXCheckboxComponent._isElementRegistered = false;
return IgcXCheckboxComponent;
}(IgcHTMLElement));