UNPKG

igniteui-react-inputs

Version:

Ignite UI React input components.

300 lines (297 loc) 8.32 kB
import * as React from 'react'; import { XRipple } from "./XRipple"; import { brushToString, stringToBrush, ensureBool, initializePropertiesFromCss, NamePatcher, isValidProp, toSpinal, getModifiedProps } from "igniteui-react-core"; import { ReactRenderer } from "igniteui-react-core"; export class IgrXRipple extends React.Component { set height(value) { this._height = value; if (this._elRef) { this._elRef.style.height = value; } } get height() { return this._height; } set width(value) { this._width = value; if (this._elRef) { this._elRef.style.width = value; } } get width() { return this._width; } set top(value) { this._top = value; if (this._elRef) { this._elRef.style.top = value; } } get top() { return this._top; } set left(value) { this._left = value; if (this._elRef) { this._elRef.style.left = value; } } get left() { return this._left; } set position(value) { this._position = value; if (this._elRef) { this._elRef.style.position = value; } } get position() { return this._position; } _getMainRef(ref) { this._elRef = ref; } render() { let div = React.createElement("div", { className: "ig-x-ripple igr-x-ripple", ref: this._getMainRef }); //} return div; } 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); if (document) { this._container = document.createElement("div"); this._container.style.display = "block"; } var root; root = this._container; if (this._container != null) { root = this._container; } var ren = new ReactRenderer(root, document, true, {}); this._wrapper = ren; var ripple = this.i; this._ripple = ripple; ripple.provideContainer(ren); if (props) { this.initializeProperties(); } } 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._ripple.destroy(); this._wrapper.destroy(); } componentWillUnmount() { } componentDidMount() { this._elRef.appendChild(this._container); this.initializeContent(); } initializeContent() { this._styling(this._container, this); this.updateStyle(); } createImplementation() { return new XRipple(); } get i() { return this._implementation; } /** * Gets or sets the target element to inject ripples into. */ get eventSource() { return this.i.q; } set eventSource(v) { this.i.q = v; } /** * Gets or sets the color to use for the background when the checkbox is unchecked. */ get rippleColor() { return brushToString(this.i.ax); } set rippleColor(v) { this.i.ax = stringToBrush(v); } /** * Gets or sets the color to use for the background when the ripple is hovered. */ get hoverColor() { return brushToString(this.i.aw); } set hoverColor(v) { this.i.aw = stringToBrush(v); } /** * Gets or sets the actual color to use for the background when the ripple is hovered. */ get actualHoverColor() { return brushToString(this.i.as); } set actualHoverColor(v) { this.i.as = stringToBrush(v); } /** * Gets or sets the color to use for the actual background when the checkbox is unchecked. */ get actualRippleColor() { return brushToString(this.i.at); } set actualRippleColor(v) { this.i.at = stringToBrush(v); } /** * Gets or sets the duration to use for the ripple animation. */ get rippleDuration() { return this.i.o; } set rippleDuration(v) { this.i.o = +v; } /** * Gets or sets if the ripple is disabled. */ get isDisabled() { return this.i.i; } set isDisabled(v) { this.i.i = ensureBool(v); } /** * Gets or sets if the ripple is centered. */ get isCentered() { return this.i.h; } set isCentered(v) { this.i.h = ensureBool(v); } /** * Gets or sets if the ripple is centered. */ get isHoverEnabled() { return this.i.k; } set isHoverEnabled(v) { this.i.k = 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("XRipple"); 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.r(); return (iv); } /** * Returns a serialized copy of the exported visual model */ exportSerializedVisualModel() { let iv = this.i.v(); return (iv); } }