-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
9 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,21 @@ | ||
[role="tooltip"] { | ||
@apply py-1 px-2; | ||
@apply text-xs; | ||
@apply font-bold; | ||
@apply text-white; | ||
@apply bg-gray-800; | ||
@apply rounded; | ||
@apply whitespace-nowrap; | ||
@apply invisible; | ||
@apply opacity-0; | ||
@apply transition-opacity; | ||
@apply duration-200; | ||
@apply delay-300; | ||
@apply ease-in; | ||
|
||
&[data-show] { | ||
@apply visible; | ||
@apply opacity-100; | ||
z-index: var(--z-index-tooltip); | ||
} | ||
} |
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 @@ | ||
export * from "./tooltip"; |
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,35 @@ | ||
import { createPopper, type Instance } from "@popperjs/core"; | ||
|
||
const showEvents = ["mouseenter", "focus"]; | ||
const hideEvents = ["mouseleave", "blur"]; | ||
|
||
export class Tooltip extends HTMLDivElement { | ||
private popperInstance: Instance; | ||
|
||
constructor() { | ||
super(); | ||
this.setAttribute("role", "tooltip"); | ||
} | ||
|
||
connectedCallback() { | ||
// don't know yet if this is cool or not using `this.parentElement` as popper reference element | ||
const parent = this.parentElement; | ||
|
||
this.popperInstance = createPopper(parent, this); | ||
|
||
for (const event of showEvents) { | ||
parent.addEventListener(event, () => { | ||
this.dataset.show = ""; | ||
this.popperInstance.update(); | ||
}); | ||
} | ||
|
||
for (const event of hideEvents) { | ||
parent.addEventListener(event, () => { | ||
delete this.dataset.show; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
customElements.define("z-tooltip", Tooltip, { extends: "div" }); |
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