INIT
This commit is contained in:
Generated
Vendored
+113
@@ -0,0 +1,113 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { DropdownMenuContentStaticProps } from "../types.js";
|
||||
import { MenuContentState } from "../../menu/menu.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
import { noop } from "../../../internal/noop.js";
|
||||
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
||||
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
||||
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
child,
|
||||
children,
|
||||
ref = $bindable(null),
|
||||
loop = true,
|
||||
onInteractOutside = noop,
|
||||
onEscapeKeydown = noop,
|
||||
onCloseAutoFocus = noop,
|
||||
forceMount = false,
|
||||
style,
|
||||
...restProps
|
||||
}: DropdownMenuContentStaticProps = $props();
|
||||
|
||||
const contentState = MenuContentState.create({
|
||||
id: boxWith(() => id),
|
||||
loop: boxWith(() => loop),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
onCloseAutoFocus: boxWith(() => onCloseAutoFocus),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, contentState.props));
|
||||
|
||||
function handleInteractOutside(e: PointerEvent) {
|
||||
contentState.handleInteractOutside(e);
|
||||
if (e.defaultPrevented) return;
|
||||
onInteractOutside(e);
|
||||
if (e.defaultPrevented) return;
|
||||
contentState.parentMenu.onClose();
|
||||
}
|
||||
function handleEscapeKeydown(e: KeyboardEvent) {
|
||||
onEscapeKeydown(e);
|
||||
if (e.defaultPrevented) return;
|
||||
contentState.parentMenu.onClose();
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if forceMount}
|
||||
<PopperLayerForceMount
|
||||
{...mergedProps}
|
||||
{...contentState.popperProps}
|
||||
ref={contentState.opts.ref}
|
||||
enabled={contentState.parentMenu.opts.open.current}
|
||||
onInteractOutside={handleInteractOutside}
|
||||
onEscapeKeydown={handleEscapeKeydown}
|
||||
trapFocus
|
||||
{loop}
|
||||
forceMount={true}
|
||||
isStatic
|
||||
{id}
|
||||
shouldRender={contentState.shouldRender}
|
||||
>
|
||||
{#snippet popper({ props })}
|
||||
{@const finalProps = mergeProps(
|
||||
props,
|
||||
{ style: getFloatingContentCSSVars("dropdown-menu") },
|
||||
{ style }
|
||||
)}
|
||||
{#if child}
|
||||
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
||||
{:else}
|
||||
<div {...finalProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</PopperLayerForceMount>
|
||||
{:else if !forceMount}
|
||||
<PopperLayer
|
||||
{...mergedProps}
|
||||
{...contentState.popperProps}
|
||||
ref={contentState.opts.ref}
|
||||
open={contentState.parentMenu.opts.open.current}
|
||||
onInteractOutside={handleInteractOutside}
|
||||
onEscapeKeydown={handleEscapeKeydown}
|
||||
trapFocus
|
||||
{loop}
|
||||
forceMount={false}
|
||||
isStatic
|
||||
{id}
|
||||
shouldRender={contentState.shouldRender}
|
||||
>
|
||||
{#snippet popper({ props })}
|
||||
{@const finalProps = mergeProps(
|
||||
props,
|
||||
{ style: getFloatingContentCSSVars("dropdown-menu") },
|
||||
{ style }
|
||||
)}
|
||||
{#if child}
|
||||
{@render child({ props: finalProps, ...contentState.snippetProps })}
|
||||
{:else}
|
||||
<div {...finalProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</PopperLayer>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DropdownMenuContentStaticProps } from "../types.js";
|
||||
declare const DropdownMenuContentStatic: import("svelte").Component<DropdownMenuContentStaticProps, {}, "ref">;
|
||||
type DropdownMenuContentStatic = ReturnType<typeof DropdownMenuContentStatic>;
|
||||
export default DropdownMenuContentStatic;
|
||||
Generated
Vendored
+122
@@ -0,0 +1,122 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { DropdownMenuContentProps } from "../types.js";
|
||||
import { MenuContentState } from "../../menu/menu.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
import { noop } from "../../../internal/noop.js";
|
||||
import PopperLayer from "../../utilities/popper-layer/popper-layer.svelte";
|
||||
import { getFloatingContentCSSVars } from "../../../internal/floating-svelte/floating-utils.svelte.js";
|
||||
import PopperLayerForceMount from "../../utilities/popper-layer/popper-layer-force-mount.svelte";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
child,
|
||||
children,
|
||||
ref = $bindable(null),
|
||||
loop = true,
|
||||
onInteractOutside = noop,
|
||||
onEscapeKeydown = noop,
|
||||
onCloseAutoFocus = noop,
|
||||
forceMount = false,
|
||||
trapFocus = false,
|
||||
style,
|
||||
...restProps
|
||||
}: DropdownMenuContentProps = $props();
|
||||
|
||||
const contentState = MenuContentState.create({
|
||||
id: boxWith(() => id),
|
||||
loop: boxWith(() => loop),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
onCloseAutoFocus: boxWith(() => onCloseAutoFocus),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, contentState.props));
|
||||
|
||||
function handleInteractOutside(e: PointerEvent) {
|
||||
contentState.handleInteractOutside(e);
|
||||
if (e.defaultPrevented) return;
|
||||
onInteractOutside(e);
|
||||
if (e.defaultPrevented) return;
|
||||
|
||||
// don't close if the interaction is with a submenu content or items
|
||||
if (e.target && e.target instanceof Element) {
|
||||
const subContentSelector = `[${contentState.parentMenu.root.getBitsAttr("sub-content")}]`;
|
||||
if (e.target.closest(subContentSelector)) return;
|
||||
}
|
||||
contentState.parentMenu.onClose();
|
||||
}
|
||||
function handleEscapeKeydown(e: KeyboardEvent) {
|
||||
onEscapeKeydown(e);
|
||||
if (e.defaultPrevented) return;
|
||||
contentState.parentMenu.onClose();
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if forceMount}
|
||||
<PopperLayerForceMount
|
||||
{...mergedProps}
|
||||
{...contentState.popperProps}
|
||||
ref={contentState.opts.ref}
|
||||
enabled={contentState.parentMenu.opts.open.current}
|
||||
onInteractOutside={handleInteractOutside}
|
||||
onEscapeKeydown={handleEscapeKeydown}
|
||||
{trapFocus}
|
||||
{loop}
|
||||
forceMount={true}
|
||||
{id}
|
||||
shouldRender={contentState.shouldRender}
|
||||
>
|
||||
{#snippet popper({ props, wrapperProps })}
|
||||
{@const finalProps = mergeProps(
|
||||
props,
|
||||
{ style: getFloatingContentCSSVars("dropdown-menu") },
|
||||
{ style }
|
||||
)}
|
||||
{#if child}
|
||||
{@render child({ props: finalProps, wrapperProps, ...contentState.snippetProps })}
|
||||
{:else}
|
||||
<div {...wrapperProps}>
|
||||
<div {...finalProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</PopperLayerForceMount>
|
||||
{:else if !forceMount}
|
||||
<PopperLayer
|
||||
{...mergedProps}
|
||||
{...contentState.popperProps}
|
||||
ref={contentState.opts.ref}
|
||||
open={contentState.parentMenu.opts.open.current}
|
||||
onInteractOutside={handleInteractOutside}
|
||||
onEscapeKeydown={handleEscapeKeydown}
|
||||
{trapFocus}
|
||||
{loop}
|
||||
forceMount={false}
|
||||
{id}
|
||||
shouldRender={contentState.shouldRender}
|
||||
>
|
||||
{#snippet popper({ props, wrapperProps })}
|
||||
{@const finalProps = mergeProps(
|
||||
props,
|
||||
{ style: getFloatingContentCSSVars("dropdown-menu") },
|
||||
{ style }
|
||||
)}
|
||||
{#if child}
|
||||
{@render child({ props: finalProps, wrapperProps, ...contentState.snippetProps })}
|
||||
{:else}
|
||||
<div {...wrapperProps}>
|
||||
<div {...finalProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</PopperLayer>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DropdownMenuContentProps } from "../types.js";
|
||||
declare const DropdownMenuContent: import("svelte").Component<DropdownMenuContentProps, {}, "ref">;
|
||||
type DropdownMenuContent = ReturnType<typeof DropdownMenuContent>;
|
||||
export default DropdownMenuContent;
|
||||
Reference in New Issue
Block a user