Skip to content

Instantly share code, notes, and snippets.

@thomasJang
Created January 8, 2019 11:04
Show Gist options
  • Select an option

  • Save thomasJang/03b3292cef28c2522a1ce5e66f3f6420 to your computer and use it in GitHub Desktop.

Select an option

Save thomasJang/03b3292cef28c2522a1ce5e66f3f6420 to your computer and use it in GitHub Desktop.
mouseEventSubscribe
handleRowResizerMove = (e: React.MouseEvent<HTMLDivElement>) => {
const { activePanel } = this.props.appStore.uiStore.queryPanelStore;
const containerTop = this.containerRef.current.getBoundingClientRect().top;
mouseEventSubscribe(
(mpos: IMousePosition) => {
const resizerTop = mpos.clientY - containerTop;
activePanel.setFlexGlow((resizerTop * 2) / this.containerHeight);
},
() => {
// onSubscribeEnd
},
);
};
const mouseEventSubscribe = (
callBack: MouseEventSubscribeCallbackFn,
onEnd: () => void,
) => {
const onMousemoveWindow = (e: MouseEvent) => {
callBack(
{
pageX: e.pageX,
pageY: e.pageY,
clientX: e.clientX,
clientY: e.clientY,
},
() => {
onMouseupWindow();
},
);
};
const onMouseupWindow = (e?: MouseEvent) => {
window.removeEventListener('mousemove', onMousemoveWindow);
window.removeEventListener('mouseup', onMouseupWindow);
window.removeEventListener('mouseleave', onMouseupWindow);
if (onEnd) {
onEnd();
}
};
window.addEventListener('mousemove', onMousemoveWindow, false);
window.addEventListener('mouseup', onMouseupWindow);
window.addEventListener('mouseleave', onMouseupWindow);
};
export default mouseEventSubscribe;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment