-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateHoverOutline.tsx
More file actions
51 lines (46 loc) · 1.7 KB
/
generateHoverOutline.tsx
File metadata and controls
51 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { visualBuilderStyles } from "../visualBuilder.style";
/**
* Adds a hover outline to the target element.
* @param targetElement - The element to add the hover outline to.
* @param isAnchorElement - Boolean to check for anchor elements.
* @returns void
*/
export function addHoverOutline(
targetElement: Element,
disabled?: boolean,
isVariant?: boolean
): void {
const targetElementDimension = targetElement.getBoundingClientRect();
const hoverOutline = document.querySelector<HTMLDivElement>(
".visual-builder__hover-outline"
);
if (hoverOutline) {
hoverOutline.classList.remove(
visualBuilderStyles()["visual-builder__hover-outline--hidden"]
);
if (disabled) {
hoverOutline.classList.add(
visualBuilderStyles()["visual-builder__hover-outline--disabled"]
);
} else {
hoverOutline.classList.remove(
visualBuilderStyles()["visual-builder__hover-outline--disabled"]
);
if (isVariant) {
hoverOutline.classList.add(
visualBuilderStyles()["visual-builder__hover-outline--variant"]
);
} else {
hoverOutline.classList.remove(
visualBuilderStyles()["visual-builder__hover-outline--variant"]
);
}
}
hoverOutline.style.top = `${
targetElementDimension.top + window.scrollY
}px`;
hoverOutline.style.left = `${targetElementDimension.left}px`;
hoverOutline.style.width = `${targetElementDimension.width}px`;
hoverOutline.style.height = `${targetElementDimension.height}px`;
}
}