I'm trying to implement dynamic column resizing on a table (like in Excel or Google Sheets).
In my render function I use the handle
callback when the user clicks mouse down on my resize control:
<div
className="resizer"
onMouseDown={self.handle(handleColumnResizeStart)}
/>
In the handler I want to add a new event listener for mousemove so that when the user is "dragging" we can draw something to indicate where the new column edge would end up.
Within the mousemove handler I was thinking I could send a reducer action that contained the mouse clientX coordinate to update the component state so that the render function could draw something while they are dragging.
let handleColumnResizeStart = (evt, self) => {
/* this handler gets invoked when the mouse is moved */
let handleMouseMove = evt => {
Js.log(evt); /* in js land I can see that clientX is in that evt object */
Js.log(ReactEvent.Mouse.clientX(evt)); /* but this creates type errors */
};
/* adds an event handler using the bs-webapi module */
Webapi.Dom.EventTarget.addEventListener(
"mousemove",
handleMouseMove,
document,
);
};
When I try to use ReactEvent.Mouse.clientX(evt)
to get the specific int value of clientX, I get this error:
25 Webapi.Dom.EventTarget.removeEventListener(
26 ┆ "mousemove",
27 ┆ handleMouseMove,
28 ┆ document,
29 ┆ );
This has type:
ReactEvent.Mouse.t => unit
But somewhere wanted:
Dom.event => unit
The incompatible parts:
ReactEvent.Mouse.t (defined as
ReactEvent.synthetic(ReactEvent.Mouse.tag))
vs
Dom.event (defined as Dom.event_like(Dom._baseClass))
>>>> Finish compiling(exit: 1)
My understanding of the type system is limited here and I'm not sure how to get the value of the mouse clientX coordinate into variable.