jsketcher/web/app/cad/actions/actionButtonBehavior.js
2018-06-22 00:31:33 -07:00

36 lines
848 B
JavaScript

export function mapActionBehavior(actionIdGetter) {
return ({services}, props) => {
const actionId = actionIdGetter(props);
let request = {actionId, x:0, y:0};
let canceled = true;
let shown = false;
function updateCoords({pageX, pageY}) {
request.x = pageX + 10;
request.y = pageY + 10;
}
return {
onClick: e => services.action.run(actionId, e),
onMouseEnter: e => {
updateCoords(e);
canceled = false;
shown = false;
setTimeout(() => {
if (!canceled) {
shown = true;
services.action.showHintFor(request)
}
}, 500);
},
onMouseMove: updateCoords,
onMouseLeave: () => {
canceled = true;
if (shown) {
services.action.showHintFor(null)
}
}
}};
}