Add <Render> to Dialog
This commit is contained in:
@@ -1,20 +1,42 @@
|
||||
<script lang="ts">
|
||||
import { DialogStates, useDialogContext } from "./Dialog.svelte";
|
||||
import { useId } from "$lib/hooks/use-id";
|
||||
import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
|
||||
import { get_current_component } from "svelte/internal";
|
||||
import type { SupportedAs } from "$lib/internal/elements";
|
||||
import type { HTMLActionArray } from "$lib/hooks/use-actions";
|
||||
import Render from "$lib/utils/Render.svelte";
|
||||
const forwardEvents = forwardEventsBuilder(get_current_component());
|
||||
|
||||
export let as: SupportedAs = "div";
|
||||
export let use: HTMLActionArray = [];
|
||||
|
||||
let api = useDialogContext("DialogOverlay");
|
||||
let id = `headlessui-dialog-overlay-${useId()}`;
|
||||
function handleClick(event: MouseEvent) {
|
||||
|
||||
function handleClick(e: CustomEvent) {
|
||||
let event = e as any as MouseEvent;
|
||||
if (event.target !== event.currentTarget) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
$api.close();
|
||||
}
|
||||
|
||||
$: propsWeControl = {
|
||||
id,
|
||||
"aria-hidden": true,
|
||||
};
|
||||
|
||||
$: slotProps = { open: $api.dialogState === DialogStates.Open };
|
||||
</script>
|
||||
|
||||
<div {...{ ...$$restProps, ...propsWeControl }} on:click={handleClick}>
|
||||
<slot open={$api.dialogState === DialogStates.Open} />
|
||||
</div>
|
||||
<Render
|
||||
{...{ ...$$restProps, ...propsWeControl }}
|
||||
{as}
|
||||
{slotProps}
|
||||
use={[...use, forwardEvents]}
|
||||
name={"DialogOverlay"}
|
||||
on:click={handleClick}
|
||||
>
|
||||
<slot {...slotProps} />
|
||||
</Render>
|
||||
|
||||
Reference in New Issue
Block a user