-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8871543
commit 675ae05
Showing
4 changed files
with
82 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
export let title; | ||
export let x; | ||
export let y; | ||
</script> | ||
<div style=" | ||
top: {y + 15}px; | ||
left: {x + 15}px;">{title}</div> | ||
|
||
<style> | ||
div { | ||
border: 1px solid #ddd; | ||
box-shadow: 1px 1px 1px #ddd; | ||
background: white; | ||
border-radius: 4px; | ||
padding: 4px; | ||
position: absolute; | ||
z-index: 999; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Tooltip from '../componants/ui/TooltipFromAction.svelte'; | ||
|
||
export function tooltip(element) { | ||
let div; | ||
let title; | ||
let tooltipComponent; | ||
function mouseOver(event) { | ||
// NOTE: remove the `title` attribute, to prevent showing the default browser tooltip | ||
// remember to set it back on `mouseleave` | ||
title = element.getAttribute('title'); | ||
element.removeAttribute('title'); | ||
|
||
tooltipComponent = new Tooltip({ | ||
props: { | ||
title: title, | ||
x: event.pageX, | ||
y: event.pageY, | ||
}, | ||
target: document.body, | ||
}); | ||
} | ||
function mouseMove(event) { | ||
tooltipComponent.$set({ | ||
x: event.pageX, | ||
y: event.pageY, | ||
}) | ||
} | ||
function mouseLeave() { | ||
tooltipComponent.$destroy(); | ||
// NOTE: restore the `title` attribute | ||
element.setAttribute('title', title); | ||
} | ||
|
||
element.addEventListener('mouseover', mouseOver); | ||
element.addEventListener('mouseleave', mouseLeave); | ||
element.addEventListener('mousemove', mouseMove); | ||
|
||
return { | ||
destroy() { | ||
element.removeEventListener('mouseover', mouseOver); | ||
element.removeEventListener('mouseleave', mouseLeave); | ||
element.removeEventListener('mousemove', mouseMove); | ||
} | ||
} | ||
} |