INIT
This commit is contained in:
Generated
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { ContextMenuTriggerProps } from "../types.js";
|
||||
import { ContextMenuTriggerState } from "../../menu/menu.svelte.js";
|
||||
import { useId } from "../../../internal/use-id.js";
|
||||
import { FloatingLayer } from "../../utilities/floating-layer/index.js";
|
||||
|
||||
let {
|
||||
id = useId(),
|
||||
ref = $bindable(null),
|
||||
child,
|
||||
children,
|
||||
disabled = false,
|
||||
...restProps
|
||||
}: ContextMenuTriggerProps = $props();
|
||||
|
||||
const triggerState = ContextMenuTriggerState.create({
|
||||
id: boxWith(() => id),
|
||||
disabled: boxWith(() => disabled),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(
|
||||
mergeProps(
|
||||
restProps,
|
||||
triggerState.props,
|
||||
{ style: { pointerEvents: "auto" } },
|
||||
{
|
||||
style: restProps.style,
|
||||
tabindex: restProps.tabindex,
|
||||
}
|
||||
)
|
||||
);
|
||||
</script>
|
||||
|
||||
<FloatingLayer.Anchor {id} virtualEl={triggerState.virtualElement} ref={triggerState.opts.ref}>
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</FloatingLayer.Anchor>
|
||||
Reference in New Issue
Block a user