igniteui-react-inputs
Version:
Ignite UI React input components.
522 lines (518 loc) • 14.6 kB
JavaScript
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";
let requiredStyle = `
`;
export class IgrXCheckbox 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-checkbox igr-x-checkbox",
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;
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();
}
}
//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._checkbox.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.onContentReady();
}
createImplementation() {
return new XCheckbox();
}
get i() {
return this._implementation;
}
/**
* Gets or sets the base built in theme to use for the checkbox.
*/
get baseTheme() {
return this.i.n;
}
set baseTheme(v) {
this.i.n = ensureEnum(BaseControlTheme_$type, v);
}
/**
* Gets or sets the color to use for the background when the checkbox is unchecked.
*/
get uncheckedBackgroundColor() {
return brushToString(this.i.dl);
}
set uncheckedBackgroundColor(v) {
this.i.dl = stringToBrush(v);
}
/**
* Gets or sets the color to use for the actual background when the checkbox is unchecked.
*/
get actualUncheckedBackgroundColor() {
return brushToString(this.i.db);
}
set actualUncheckedBackgroundColor(v) {
this.i.db = stringToBrush(v);
}
/**
* Gets or sets the color to use for the background when the checkbox is checked.
*/
get checkedBackgroundColor() {
return brushToString(this.i.dd);
}
set checkedBackgroundColor(v) {
this.i.dd = stringToBrush(v);
}
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get tickColor() {
return brushToString(this.i.dk);
}
set tickColor(v) {
this.i.dk = stringToBrush(v);
}
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get actualTickColor() {
return brushToString(this.i.da);
}
set actualTickColor(v) {
this.i.da = stringToBrush(v);
}
/**
* Gets or sets the color to use for the check mark when the checkbox is unchecked.
*/
get uncheckedBorderColor() {
return brushToString(this.i.dm);
}
set uncheckedBorderColor(v) {
this.i.dm = stringToBrush(v);
}
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get checkedBorderColor() {
return brushToString(this.i.de);
}
set checkedBorderColor(v) {
this.i.de = stringToBrush(v);
}
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get actualUncheckedBorderColor() {
return brushToString(this.i.dc);
}
set actualUncheckedBorderColor(v) {
this.i.dc = stringToBrush(v);
}
/**
* Gets or sets the color to use for the check mark when the checkbox is checked.
*/
get actualCheckedBorderColor() {
return brushToString(this.i.c9);
}
set actualCheckedBorderColor(v) {
this.i.c9 = stringToBrush(v);
}
/**
* Gets or sets the Width to use for the check mark when the checkbox is checked.
*/
get borderWidth() {
return this.i.aq;
}
set borderWidth(v) {
this.i.aq = +v;
}
/**
* Gets or sets the Width to use for the check mark when the checkbox is checked.
*/
get actualBorderWidth() {
return this.i.an;
}
set actualBorderWidth(v) {
this.i.an = +v;
}
/**
* Gets or sets the corner radius to use for the checkbox.
*/
get cornerRadius() {
return this.i.ar;
}
set cornerRadius(v) {
this.i.ar = +v;
}
/**
* Gets or sets the corner radius to use for the checkbox.
*/
get tickStrokeWidth() {
return this.i.av;
}
set tickStrokeWidth(v) {
this.i.av = +v;
}
/**
* Gets or sets the stroke width to use for the check mark.
*/
get actualTickStrokeWidth() {
return this.i.ap;
}
set actualTickStrokeWidth(v) {
this.i.ap = +v;
}
/**
* Gets the actual corner radius to use for the checkbox.
*/
get actualCornerRadius() {
return this.i.ao;
}
set actualCornerRadius(v) {
this.i.ao = +v;
}
/**
* Gets or sets the color to use for the actual background when the checkbox is checked.
*/
get actualCheckedBackgroundColor() {
return brushToString(this.i.c8);
}
set actualCheckedBackgroundColor(v) {
this.i.c8 = stringToBrush(v);
}
/**
* Gets or sets the id to use for the internal native checkbox.
*/
get inputId() {
return this.i.b1;
}
set inputId(v) {
this.i.b1 = v;
}
/**
* Gets or sets the id to use for the checkbox.
*/
get id() {
return this.i.bz;
}
set id(v) {
this.i.bz = v;
}
/**
* Gets or sets id to use for the checkbox label.
*/
get labelId() {
return this.i.labelId;
}
set labelId(v) {
this.i.labelId = v;
}
/**
* Gets or sets name to use for the checkbox.
*/
get name() {
return this.i.ca;
}
set name(v) {
this.i.ca = v;
}
/**
* Gets or sets TabIndex to use for the checkbox.
*/
get tabIndex() {
return this.i.az;
}
set tabIndex(v) {
this.i.az = +v;
}
/**
* Gets or sets if the checkbox is required.
*/
get required() {
return this.i.ay;
}
set required(v) {
this.i.ay = +v;
}
/**
* Gets or sets the value of the aria-labelledby attribute.
*/
get ariaLabelledBy() {
return this.i.bn;
}
set ariaLabelledBy(v) {
this.i.bn = v;
}
/**
* Gets or sets the value of the aria-label attribute.
*/
get ariaLabel() {
return this.i.bm;
}
set ariaLabel(v) {
this.i.bm = v;
}
/**
* Gets or sets value to use for the checkbox.
*/
get value() {
return this.i.a4;
}
set value(v) {
this.i.a4 = v;
}
/**
* Gets or sets if the checkbox is Focused.
*/
get focused() {
return this.i.focused;
}
set focused(v) {
this.i.focused = ensureBool(v);
}
/**
* Gets or sets LabelPosition to use for the checkbox.
*/
get labelPosition() {
return this.i.e;
}
set labelPosition(v) {
this.i.e = ensureEnum(CheckboxLabelPosition_$type, v);
}
/**
* Gets or sets whether to disable the ripple effect for the checkbox.
*/
get disableRipple() {
return this.i.y;
}
set disableRipple(v) {
this.i.y = ensureBool(v);
}
/**
* Gets or sets whether the checkbox is checked.
*/
get checked() {
return this.i.checked;
}
set checked(v) {
this.i.checked = ensureBool(v);
}
/**
* Gets or sets whether the checkbox is indeterminate.
*/
get indeterminate() {
return this.i.indeterminate;
}
set indeterminate(v) {
this.i.indeterminate = ensureBool(v);
}
/**
* Gets or sets whether the checkbox is disabled.
*/
get disabled() {
return this.i.disabled;
}
set disabled(v) {
this.i.disabled = ensureBool(v);
}
/**
* Gets or sets whether the checkbox transitions are disabled.
*/
get disableTransitions() {
return this.i.z;
}
set disableTransitions(v) {
this.i.z = ensureBool(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("XCheckbox");
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.a3();
return (iv);
}
/**
* Returns a serialized copy of the exported visual model
*/
exportSerializedVisualModel() {
let iv = this.i.by();
return (iv);
}
get change() {
return this._change;
}
set change(ev) {
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 = (o, e) => {
let 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);
;
}
}