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 ( {props.trigger}
{local.children}
) } function DialogHeader(props: ComponentProps<"div">) { return
} function DialogBody(props: ComponentProps<"div">) { return
} function DialogTitle(props: DialogTitleProps & ComponentProps<"h2">) { return } function DialogDescription(props: DialogDescriptionProps & ComponentProps<"p">) { return } function DialogCloseButton(props: DialogCloseButtonProps & ComponentProps<"button">) { return } export const Dialog = Object.assign(DialogRoot, { Header: DialogHeader, Title: DialogTitle, Description: DialogDescription, CloseButton: DialogCloseButton, Body: DialogBody, })