jss-react-material
Version:
Google Material Components for React
70 lines (58 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function calculateTouchPoint(node, touche) {
var rect = node.getBoundingClientRect();
var touchPageX = touche.pageX;
var touchPageY = touche.pageY;
return {
left: touchPageX - rect.left - 28,
top: touchPageY - rect.top - 28
};
}
function setTouchReference(component) {
this._touchReference = component;
}
function setTouchTapReference(component) {
this._touchTapReference = component;
}
function addAnimatedTouchPoint(touch) {
var elementTouch = this._touchReference;
var elementTouchTap = this._touchTapReference;
var touchPoint = calculateTouchPoint(elementTouch, touch);
elementTouchTap.style.left = touchPoint.left + 'px';
elementTouchTap.style.top = touchPoint.top + 'px';
elementTouchTap.style.width = '2px';
elementTouchTap.style.height = '2px';
elementTouchTap.classList.add('tap-active');
}
/* eslint no-console: 0 */
function removeAnimatedTouchPoint() {
var elementTouchTap = this._touchTapReference;
if (elementTouchTap) {
elementTouchTap.style.left = null;
elementTouchTap.style.top = null;
elementTouchTap.style.width = null;
elementTouchTap.style.height = null;
elementTouchTap.classList.remove('tap-active');
}
}
function _handleAnimation(event) {
var nativeEvent = event.nativeEvent.targetTouches ? event.nativeEvent.targetTouches[0] : event.nativeEvent;
this.addAnimatedTouchPoint(nativeEvent);
setTimeout(this.removeAnimatedTouchPoint.bind(this), 250);
}
/**
* Makes the given component "calculateTouchPoint".
*
* @param object component Component.
*/
function getClassesDecorator(component) {
component.prototype.addAnimatedTouchPoint = addAnimatedTouchPoint;
component.prototype.removeAnimatedTouchPoint = removeAnimatedTouchPoint;
component.prototype.setTouchReference = setTouchReference;
component.prototype.setTouchTapReference = setTouchTapReference;
component.prototype._handleAnmation = _handleAnimation;
}
exports.default = getClassesDecorator;