Repository URL to install this package:
|
Version:
1.0.1 ▾
|
"use strict";
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
/* eslint-disable brace-style */
const react_1 = __importDefault(require("react"));
const exotic_1 = require("exotic"); // import { computed } from 'xmobx'
const deps_1 = require("./deps");
const isActiveAndAnimated = props => props.isActive === true && deps_1.isAnimated(props);
class BaseButtonAtomStateful extends react_1.default.Component {
constructor() {
super(...arguments);
/**
* @description handles keydown enter - auto works with isFocused
*/
this.handleKeyDown = event => {
if (event.key === 'Enter') {
this.handleClick(event);
this.state.activate();
} else if (event.key === 'Space' || event.key === ' ') {
// ada
if (deps_1.isLink(this.props) === true) {
this.handleClick(event);
this.state.activate();
}
} else {
console.log(event.key); // @Note this causes errors on Tabbing through modals
// this.state.deactivate()
}
};
this.debounceClick = () => this.justClicked = false;
this.handleActiveTimeout = () => {
this.state.handleInactive();
this.forceUpdate();
};
this.internalClickHandler = event => {
console.log('BUTTON_CLICK'); // not on state, don't trigger update
this.justClicked = true;
clearTimeout(this.doubleClickTimeout);
this.doubleClickTimeout = setTimeout(this.debounceClick, 10);
const baseButtonOnClick = this.props.handleClick || this.props.onClick;
if (exotic_1.isFunction(baseButtonOnClick)) {
baseButtonOnClick(event);
}
if (deps_1.hasSnackbar(this.props) === true) {
this.state.setActive(true);
this.activeTimeout = setTimeout(this.handleActiveTimeout, 2000);
}
if (this.isAnimated === true) {
this.state.setActive(true); // clearTimeout(this.activeTimeout)
this.activeTimeout = setTimeout(this.state.handleInactive, this.props.timeout);
}
};
this.handleClick = event => {
if (isActiveAndAnimated(this.props) === true) {
clearTimeout(this.clickTimeout);
this.clickTimeout = setTimeout(this.handleClick, this.props.timeout);
return;
}
if (this.justClicked === true) {
// console.log('DBL_CLICK')
return;
}
if (this.isTouching === true) {
return;
}
this.internalClickHandler(event);
};
}
}
exports.BaseButtonAtomStateful = BaseButtonAtomStateful;
exports.default = BaseButtonAtomStateful; //# sourceMappingURL=BaseButtonAtomStateful.js.map