import { Tooltip as KobalteTooltip } from "@kobalte/core/tooltip" import { children, createEffect, createSignal, splitProps } from "solid-js" import type { ComponentProps } from "solid-js" export interface TooltipProps extends ComponentProps { value: string | (() => string) class?: string } export function Tooltip(props: TooltipProps) { const [open, setOpen] = createSignal(false) const [local, others] = splitProps(props, ["class", "children"]) const c = children(() => local.children) createEffect(() => { const childElements = c() if (childElements instanceof HTMLElement) { childElements.addEventListener("focus", () => setOpen(true)) childElements.addEventListener("blur", () => setOpen(false)) } else if (Array.isArray(childElements)) { for (const child of childElements) { if (child instanceof HTMLElement) { child.addEventListener("focus", () => setOpen(true)) child.addEventListener("blur", () => setOpen(false)) } } } }) return ( {c()} {typeof others.value === "function" ? others.value() : others.value} ) }