react-composite-events
Version:
A collection of higher-order components (HOCs) to easily create composite events in React components
3 lines (2 loc) • 3.17 kB
JavaScript
!function(e,t){if("function"==typeof define&&define.amd)define(["exports","./compose"],t);else if("undefined"!=typeof exports)t(exports,require("./compose"));else{var o={exports:{}};t(o.exports,e.RCE_compose),e.RCE_mouse=o.exports}}(this,function(e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.withShiftClick=e.withMetaClick=e.withCtrlClick=e.withAltClick=e.withOnlyClick=e.withMouseLeaveBottom=e.withMouseLeaveTop=e.withMouseLeaveRight=e.withMouseLeaveLeft=e.withMouseEnterBottom=e.withMouseEnterTop=e.withMouseEnterRight=e.withMouseEnterLeft=e.withMouseRemainOut=e.withMouseRemainOver=e.withMouseRest=e.composeMouseModifierKey=void 0;var o=babelHelpers.interopRequireDefault(t),n=function(e){var t=e.eventPropName,n=e.direction,i=e.location;return(0,o.default)({eventPropName:t,triggerEvent:"enter"===n?"onMouseEnter":"onMouseLeave",beforeHandle:function(e,t){if(!t)return!1;var o=t,n=o.screenX,r=o.screenY,u=o.currentTarget;if(!(u instanceof HTMLElement))return!1;var a=u.getBoundingClientRect(),s=a.top,l=a.left,v=a.bottom,c=a.right;return"left"===i&&n<=l||"right"===i&&n>=c||"top"===i&&r<=s||"bottom"===i&&r>=v}})},i=e.composeMouseModifierKey=function(e){var t=e.eventPropName,n=e.mouseEvent,i=e.alt,r=void 0!==i&&i,u=e.ctrl,a=void 0!==u&&u,s=e.meta,l=void 0!==s&&s,v=e.shift,c=void 0!==v&&v;return(0,o.default)({eventPropName:t,triggerEvent:n,beforeHandle:function(e,t){var o=t;return o&&o.altKey===r&&o.ctrlKey===a&&o.metaKey===l&&o.shiftKey===c}})};e.withMouseRest=(0,o.default)({eventPropName:"onMouseRest",triggerEvent:["onMouseOver","onMouseMove"],defaultDuration:500,cancelEvent:["onMouseOut","onMouseDown"]}),e.withMouseRemainOver=(0,o.default)({eventPropName:"onMouseRemainOver",triggerEvent:["onMouseOver","onMouseMove"],defaultDuration:500,cancelEvent:["onMouseOut","onMouseDown"],shouldResetTimerOnRetrigger:!1}),e.withMouseRemainOut=(0,o.default)({eventPropName:"onMouseRemainOut",triggerEvent:"onMouseOut",defaultDuration:500,cancelEvent:"onMouseOver"}),e.withMouseEnterLeft=n({eventPropName:"onMouseEnterLeft",direction:"enter",location:"left"}),e.withMouseEnterRight=n({eventPropName:"onMouseEnterRight",direction:"enter",location:"right"}),e.withMouseEnterTop=n({eventPropName:"onMouseEnterTop",direction:"enter",location:"top"}),e.withMouseEnterBottom=n({eventPropName:"onMouseEnterBottom",direction:"enter",location:"bottom"}),e.withMouseLeaveLeft=n({eventPropName:"onMouseLeaveLeft",direction:"leave",location:"left"}),e.withMouseLeaveRight=n({eventPropName:"onMouseLeaveRight",direction:"leave",location:"right"}),e.withMouseLeaveTop=n({eventPropName:"onMouseLeaveTop",direction:"leave",location:"top"}),e.withMouseLeaveBottom=n({eventPropName:"onMouseLeaveBottom",direction:"leave",location:"bottom"}),e.withOnlyClick=i({eventPropName:"onOnlyClick",mouseEvent:"onClick"}),e.withAltClick=i({eventPropName:"onAltClick",mouseEvent:"onClick",alt:!0}),e.withCtrlClick=i({eventPropName:"onCtrlClick",mouseEvent:"onClick",ctrl:!0}),e.withMetaClick=i({eventPropName:"onMetaClick",mouseEvent:"onClick",meta:!0}),e.withShiftClick=i({eventPropName:"onShiftClick",mouseEvent:"onClick",shift:!0})});
//# sourceMappingURL=mouse.min.js.map