Skip to content

Commit 9800591

Browse files
authored
refactor(web): remove cursor styling from interaction engine (#1886)
* chore(web): cleanup unused cursor styles * refactor: extract cursor prop from adapter and overlay * fix(tests): remove cursor props
1 parent a0b5799 commit 9800591

9 files changed

Lines changed: 9 additions & 107 deletions

File tree

packages/web/src/common/calendar-grid/components/CalendarTimedEventCard.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
} from "@web/components/Flex/Flex";
4242
import { Text } from "@web/components/Text/Text";
4343

44-
export interface CalendarTimedEventCardProps {
44+
interface CalendarTimedEventCardProps {
4545
boxShadow?: CSSProperties["boxShadow"];
4646
displayMode: "draft" | "placeholder" | "saved";
4747
event: Schema_GridEvent;
@@ -121,14 +121,9 @@ const CalendarTimedEventCardBase = (
121121
: hoverColor
122122
: bgColor;
123123

124-
const hoverCursorClass =
125-
!isPlaceholder && !isResizing
126-
? isDragging
127-
? "hover:cursor-move"
128-
: isPending
129-
? "hover:cursor-wait"
130-
: "hover:cursor-pointer"
131-
: "";
124+
const hoverCursorClass = isPending
125+
? "hover:cursor-wait"
126+
: "hover:cursor-pointer";
132127

133128
const eventStyle = {
134129
"--event-bg": bgColor,
@@ -168,6 +163,7 @@ const CalendarTimedEventCardBase = (
168163

169164
const showResizeCursor =
170165
!isPlaceholder && !isResizing && !isDragging && !isPending;
166+
171167
const scalerStyle = (
172168
placement: Pick<CSSProperties, "top" | "bottom">,
173169
): CSSProperties => ({
@@ -200,7 +196,7 @@ const CalendarTimedEventCardBase = (
200196
role="button"
201197
tabIndex={0}
202198
className={cn(
203-
"absolute min-h-2.5 select-none overflow-hidden rounded-xs pr-0.75 pl-1.25 transition-[background-color,filter] duration-[260ms] ease-[cubic-bezier(0.16,1,0.3,1)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary",
199+
"absolute min-h-2.5 select-none overflow-hidden rounded-xs pr-0.75 pl-1.25 transition-[background-color,filter] duration-260 ease-[cubic-bezier(0.16,1,0.3,1)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary",
204200
isSelected
205201
? "bg-event-selected shadow-[0_4px_10px_-4px_#00000080]"
206202
: "bg-(--event-bg) hover:bg-(--event-hover-bg)",

packages/web/src/common/calendar-grid/interaction/calendarInteractionDom.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type CSSProperties } from "react";
21
import { type FloatingInteractionOverlayMount } from "@web/common/calendar-interaction/CalendarInteractionAdapter";
32
import { createInteractionClone } from "@web/common/calendar-interaction/dom/clone/createInteractionClone";
43
import { type Schema_GridEvent } from "@web/common/types/web.event.types";
@@ -41,10 +40,8 @@ export const updateCalendarOverlayTimeLabel = (
4140
};
4241

4342
export const createCalendarInteractionEventOverlayMount = ({
44-
cursor,
4543
source,
4644
}: {
47-
cursor?: CSSProperties["cursor"];
4845
source: HTMLElement;
4946
}): FloatingInteractionOverlayMount => {
5047
const rect = source.getBoundingClientRect();
@@ -61,7 +58,6 @@ export const createCalendarInteractionEventOverlayMount = ({
6158

6259
return {
6360
clone,
64-
cursor,
6561
rect: {
6662
height: rect.height,
6763
left: rect.left,

packages/web/src/common/calendar-interaction/CalendarInteractionEngine.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ const createHarness = ({
5151
sourceOverlayMode?: SourceElementOverlayMode;
5252
} = {}) => {
5353
document.body.innerHTML = "";
54-
document.body.style.cursor = "";
55-
document.documentElement.style.cursor = "";
5654

5755
let now = 100;
5856
let nextFrameId = 1;
@@ -93,7 +91,6 @@ const createHarness = ({
9391

9492
return {
9593
clone,
96-
cursor: "grabbing",
9794
rect: {
9895
height: 40,
9996
left: 10,
@@ -183,8 +180,6 @@ const createHarness = ({
183180

184181
afterEach(() => {
185182
document.body.innerHTML = "";
186-
document.body.style.cursor = "";
187-
document.documentElement.style.cursor = "";
188183
});
189184

190185
describe("CalendarInteractionEngine", () => {
@@ -321,7 +316,6 @@ describe("CalendarInteractionEngine", () => {
321316
expect(
322317
document.body.querySelector("[data-calendar-interaction-overlay]"),
323318
).toBeNull();
324-
expect(document.body.style.cursor).toBe("");
325319
expect(engine.getMetrics()).toMatchObject({
326320
active: false,
327321
phase: "commit",
@@ -394,7 +388,6 @@ describe("FloatingInteractionOverlay", () => {
394388

395389
overlay.mount({
396390
clone,
397-
cursor: "grabbing",
398391
rect: {
399392
height: 20,
400393
left: 10,
@@ -419,12 +412,10 @@ describe("FloatingInteractionOverlay", () => {
419412
expect(clone.style.height).toBe("24px");
420413
expect(clone.style.width).toBe("70px");
421414
expect(clone.style.zIndex).toBe(`${ZIndex.MAX}`);
422-
expect(document.body.style.cursor).toBe("grabbing");
423415

424416
overlay.unmount();
425417

426418
expect(clone.parentElement).toBeNull();
427-
expect(document.body.style.cursor).toBe("");
428419
});
429420
});
430421

packages/web/src/common/calendar-interaction/dom/overlay/FloatingInteractionOverlay.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ import { type CalendarInteractionPoint } from "../../CalendarInteractionSession"
33

44
export class FloatingInteractionOverlay {
55
#node: HTMLElement | null = null;
6-
#previousCursor: {
7-
body: string;
8-
documentElement: string;
9-
} | null = null;
106

117
mount({
128
clone,
13-
cursor,
149
rect,
1510
}: {
1611
clone: HTMLElement;
17-
cursor?: string;
1812
rect: {
1913
height: number;
2014
left: number;
@@ -30,7 +24,6 @@ export class FloatingInteractionOverlay {
3024
clone.style.position = "fixed";
3125
clone.style.pointerEvents = "none";
3226
clone.style.top = `${rect.top}px`;
33-
clone.style.cursor = cursor ?? "";
3427
clone.style.transition = "none";
3528
clone.style.transform = "translate3d(0px, 0px, 0)";
3629
clone.style.willChange = "transform";
@@ -39,15 +32,6 @@ export class FloatingInteractionOverlay {
3932

4033
document.body.append(clone);
4134
this.#node = clone;
42-
43-
if (cursor) {
44-
this.#previousCursor = {
45-
body: document.body.style.cursor,
46-
documentElement: document.documentElement.style.cursor,
47-
};
48-
document.body.style.cursor = cursor;
49-
document.documentElement.style.cursor = cursor;
50-
}
5135
}
5236

5337
update({
@@ -82,13 +66,6 @@ export class FloatingInteractionOverlay {
8266
}
8367

8468
unmount() {
85-
if (this.#previousCursor) {
86-
document.body.style.cursor = this.#previousCursor.body;
87-
document.documentElement.style.cursor =
88-
this.#previousCursor.documentElement;
89-
this.#previousCursor = null;
90-
}
91-
9269
this.#node?.remove();
9370
this.#node = null;
9471
}

packages/web/src/common/utils/event/event.util.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,6 @@ export const isEventInRange = (
217217
return isStartDateInRange || isEndDateInRange;
218218
};
219219

220-
export const getEventCursorStyle = (
221-
isDragging: boolean,
222-
isPending = false,
223-
): string => {
224-
if (isDragging) return "move";
225-
if (isPending) return "wait";
226-
return "pointer";
227-
};
228-
229-
export const getEventCursorClass = (
230-
isDragging: boolean,
231-
isPending = false,
232-
): string => {
233-
if (isDragging) return "cursor-move";
234-
if (isPending) return "cursor-wait";
235-
return "cursor-pointer";
236-
};
237-
238220
const _assembleBaseEvent = (
239221
userId: string,
240222
event: Partial<Schema_Event>,

packages/web/src/views/Day/interaction/adapter/DayInteractionAdapter.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,8 @@ export const createDayInteractionAdapter = ({
310310
startMinutes: getLocalMinutes(target.event.startDate),
311311
});
312312
},
313-
getOverlayMount: ({ sourceElement, target }) =>
313+
getOverlayMount: ({ sourceElement }) =>
314314
createCalendarInteractionEventOverlayMount({
315-
cursor: getInteractionCursor(target),
316315
source: sourceElement,
317316
}),
318317
getSourceElement: (target) => target.registered.element,
@@ -798,18 +797,6 @@ const getOwnershipReason = (target: DayInteractionTarget) => {
798797
}
799798
};
800799

801-
const getInteractionCursor = (target: DayInteractionTarget) => {
802-
switch (target.type) {
803-
case "allDayResize":
804-
return "col-resize";
805-
case "timedResize":
806-
return "row-resize";
807-
case "allDayDrag":
808-
case "timedDrag":
809-
return "move";
810-
}
811-
};
812-
813800
const readElementRect = (element: HTMLElement) => {
814801
const rect = element.getBoundingClientRect();
815802

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect } from "react";
1+
import { useCallback } from "react";
22
import { selectIsDrafting } from "@web/ducks/events/selectors/draft.selectors";
33
import { useAppSelector } from "@web/store/store.hooks";
44
import { useEventListener } from "@web/views/Week/hooks/mouse/useEventListener";
@@ -19,24 +19,11 @@ export const useGridMouseMove = () => {
1919
resize(e);
2020
} else if (isDragging) {
2121
e.preventDefault();
22-
document.body.style.cursor = "move";
2322
drag(e);
2423
}
2524
},
2625
[drag, isDrafting, isDragging, isResizing, resize],
2726
);
2827

29-
const _onMouseUp = useCallback(() => {
30-
document.body.style.cursor = "";
31-
}, []);
32-
3328
useEventListener("mousemove", _onMouseMove);
34-
useEventListener("mouseup", _onMouseUp);
35-
36-
// Ensure cursor resets when the component unmounts
37-
useEffect(() => {
38-
return () => {
39-
document.body.style.cursor = "";
40-
};
41-
}, []);
4229
};

packages/web/src/views/Week/interaction/adapter/WeekInteractionAdapter.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,8 @@ export const createWeekInteractionAdapter = ({
316316
target,
317317
});
318318
},
319-
getOverlayMount: ({ sourceElement, target }) =>
319+
getOverlayMount: ({ sourceElement }) =>
320320
createCalendarInteractionEventOverlayMount({
321-
cursor: getInteractionCursor(target),
322321
source: sourceElement,
323322
}),
324323
getSourceElement: (target) => target.registered.element,
@@ -732,18 +731,6 @@ const getOwnershipReason = (target: WeekInteractionTarget) => {
732731
}
733732
};
734733

735-
const getInteractionCursor = (target: WeekInteractionTarget) => {
736-
switch (target.type) {
737-
case "allDayResize":
738-
return "col-resize";
739-
case "timedResize":
740-
return "row-resize";
741-
case "allDayDrag":
742-
case "timedDrag":
743-
return "move";
744-
}
745-
};
746-
747734
const buildWeekLayoutCacheForTarget = (
748735
target: WeekInteractionTarget,
749736
sources: WeekLayoutCacheSources,

packages/web/src/views/Week/interaction/registry/weekEventRegistry.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ describe("createCalendarInteractionEventOverlayMount", () => {
522522
source.append(child);
523523

524524
const mount = createCalendarInteractionEventOverlayMount({
525-
cursor: "grabbing",
526525
source,
527526
});
528527
const clonedChild = mount.clone.querySelector("button");

0 commit comments

Comments
 (0)