Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added outline to hovered elements #123

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/liveEditor/components/visualEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ function VisualEditorComponent(props: VisualEditorProps): JSX.Element {
className="visual-editor__overlay--outline"
></div>
</div>


<div
className="visual-editor__hover-outline"
data-testid="visual-editor__hover-outline">
</div>
<div
className="visual-editor__focused-toolbar"
data-testid="visual-editor__focused-toolbar"
Expand Down
21 changes: 21 additions & 0 deletions src/liveEditor/generators/generateHoverOutline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

/**
* Adds a hover outline to the target element.
* @param targetElement - The element to add the hover outline to.
* @returns void
*/
export function addHoverOutline(
targetElement: Element
): void {

const targetElementDimension = targetElement.getBoundingClientRect();

const hoverOutline = document.querySelector<HTMLDivElement>(".visual-editor__hover-outline");

if (hoverOutline) {
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`;
}
}
25 changes: 19 additions & 6 deletions src/liveEditor/listeners/mouseHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import { getFieldType } from "../utils/getFieldType";

import EventListenerHandlerParams from "./types";
import { VisualEditor } from "..";
import { addHoverOutline } from "../generators/generateHoverOutline";

export interface HandleMouseHoverParams
extends Pick<
EventListenerHandlerParams,
"event" | "overlayWrapper" | "visualEditorContainer"
> {
customCursor: HTMLDivElement | null;
}


function resetCustomCursor(customCursor: HTMLDivElement | null): void {
if (customCursor) {
Expand All @@ -34,12 +44,10 @@ function handleCursorPosition(
}
}

export interface HandleMouseHoverParams
extends Pick<
EventListenerHandlerParams,
"event" | "overlayWrapper" | "visualEditorContainer"
> {
customCursor: HTMLDivElement | null;
function addOutline(params: any): void {
if(!params.event || !params.event.target) return;

addHoverOutline(params.event.target);
}

async function handleMouseHover(params: HandleMouseHoverParams): Promise<void> {
Expand Down Expand Up @@ -105,6 +113,11 @@ async function handleMouseHover(params: HandleMouseHoverParams): Promise<void> {
handleCursorPosition(params.event, params.customCursor);
}

if(!editableElement.classList.contains('visual-editor__empty-block-parent')
&& !editableElement.classList.contains('visual-editor__empty-block')){
addOutline(params);
}

if (
VisualEditor.VisualEditorGlobalState.value
.previousHoveredTargetDOM === editableElement
Expand Down
7 changes: 7 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,10 @@ div.multiple div.cslp-tooltip-child:hover:before {
padding-block: 0px;
letter-spacing: 0.01rem;
}

.visual-editor__hover-outline {
position: absolute;
pointer-events: none;
outline: 2px dashed #6C5CE7;
transition: all 0.2s ease-in;
}