refac: model item tag styling

This commit is contained in:
Timothy Jaeryang Baek
2025-07-22 11:19:40 +04:00
parent d8b80caff3
commit 496ea40d1d
4 changed files with 86 additions and 15 deletions
+27 -13
View File
@@ -5,6 +5,8 @@
import tippy from 'tippy.js';
export let elementId = '';
export let placement = 'top';
export let content = `I'm a tooltip!`;
export let touch = true;
@@ -17,20 +19,30 @@
let tooltipElement;
let tooltipInstance;
$: if (tooltipElement && content) {
if (tooltipInstance) {
tooltipInstance.setContent(DOMPurify.sanitize(content));
$: if (tooltipElement && (content || elementId)) {
let tooltipContent = null;
if (elementId) {
tooltipContent = document.getElementById(`${elementId}`);
} else {
tooltipInstance = tippy(tooltipElement, {
content: DOMPurify.sanitize(content),
placement: placement,
allowHTML: allowHTML,
touch: touch,
...(theme !== '' ? { theme } : { theme: 'dark' }),
arrow: false,
offset: offset,
...tippyOptions
});
tooltipContent = DOMPurify.sanitize(content);
}
if (tooltipInstance) {
tooltipInstance.setContent(tooltipContent);
} else {
if (content) {
tooltipInstance = tippy(tooltipElement, {
content: tooltipContent,
placement: placement,
allowHTML: allowHTML,
touch: touch,
...(theme !== '' ? { theme } : { theme: 'dark' }),
arrow: false,
offset: offset,
...tippyOptions
});
}
}
} else if (tooltipInstance && content === '') {
if (tooltipInstance) {
@@ -48,3 +60,5 @@
<div bind:this={tooltipElement} class={className}>
<slot />
</div>
<slot name="tooltip"></slot>