import {
Dialog as Kobalte,
DialogRootProps,
DialogTitleProps,
DialogCloseButtonProps,
DialogDescriptionProps,
} from "@kobalte/core/dialog"
import { ComponentProps, type JSX, onCleanup, Show, splitProps } from "solid-js"
import { IconButton } from "./icon-button"
export interface DialogProps extends DialogRootProps {
trigger?: JSX.Element
class?: ComponentProps<"div">["class"]
classList?: ComponentProps<"div">["classList"]
}
export function DialogRoot(props: DialogProps) {
let trigger!: HTMLElement
const [local, others] = splitProps(props, ["trigger", "class", "classList", "children"])
const resetTabIndex = () => {
trigger.tabIndex = 0
}
const handleTriggerFocus = (e: FocusEvent & { currentTarget: HTMLElement | null }) => {
const firstChild = e.currentTarget?.firstElementChild as HTMLElement
if (!firstChild) return
firstChild.focus()
trigger.tabIndex = -1
firstChild.addEventListener("focusout", resetTabIndex)
onCleanup(() => {
firstChild.removeEventListener("focusout", resetTabIndex)
})
}
return (