-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anatol Zakrividoroga <53095479+anatolzak@users.noreply.github.com> fix: tooltip & grace area (#521)
- Loading branch information
Showing
137 changed files
with
3,948 additions
and
2,913 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/accordion/components/accordion-content.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/accordion/components/accordion-header.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/accordion/components/accordion-item.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/accordion/components/accordion-trigger.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/accordion/components/accordion.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/avatar/components/avatar-image.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/checkbox/components/checkbox.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/collapsible/collapsible.svelte.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/collapsible/components/collapsible-content.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bits-ui/src/lib/bits/collapsible/components/collapsible.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 80 additions & 97 deletions
177
packages/bits-ui/src/lib/bits/context-menu/components/context-menu-content.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,88 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import { getCtx, updatePositioning } from "../ctx.js"; | ||
import type { ContentEvents, ContentProps } from "../index.js"; | ||
import type { Transition } from "$lib/internal/types.js"; | ||
import { createDispatcher } from "$lib/internal/events.js"; | ||
import { box } from "svelte-toolbelt"; | ||
import type { ContentProps } from "../index.js"; | ||
import { useMenuContent } from "$lib/bits/menu/menu.svelte.js"; | ||
import { useId } from "$lib/internal/useId.svelte.js"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
import { noop } from "$lib/internal/callbacks.js"; | ||
import PopperLayer from "$lib/bits/utilities/popper-layer/popper-layer.svelte"; | ||
import { isElement } from "$lib/internal/is.js"; | ||
import type { InteractOutsideEvent } from "$lib/bits/utilities/dismissable-layer/types.js"; | ||
type T = $$Generic<Transition>; | ||
type In = $$Generic<Transition>; | ||
type Out = $$Generic<Transition>; | ||
type $$Props = ContentProps<T, In, Out>; | ||
type $$Events = ContentEvents; | ||
let { | ||
id = useId(), | ||
asChild, | ||
child, | ||
children, | ||
el = $bindable(), | ||
loop = true, | ||
onInteractOutside = noop, | ||
onEscapeKeydown = noop, | ||
forceMount = false, | ||
...restProps | ||
}: ContentProps = $props(); | ||
export let transition: $$Props["transition"] = undefined; | ||
export let transitionConfig: $$Props["transitionConfig"] = undefined; | ||
export let inTransition: $$Props["inTransition"] = undefined; | ||
export let inTransitionConfig: $$Props["inTransitionConfig"] = undefined; | ||
export let outTransition: $$Props["outTransition"] = undefined; | ||
export let outTransitionConfig: $$Props["outTransitionConfig"] = undefined; | ||
export let asChild: $$Props["asChild"] = false; | ||
export let id: $$Props["id"] = undefined; | ||
export let alignOffset: $$Props["alignOffset"] = 0; | ||
export let collisionPadding: $$Props["collisionPadding"] = 8; | ||
export let avoidCollisions: $$Props["avoidCollisions"] = true; | ||
export let collisionBoundary: $$Props["collisionBoundary"] = undefined; | ||
export let fitViewport: $$Props["fitViewport"] = false; | ||
export let strategy: $$Props["strategy"] = "absolute"; | ||
export let overlap: $$Props["overlap"] = false; | ||
export let el: $$Props["el"] = undefined; | ||
const { | ||
elements: { menu }, | ||
states: { open }, | ||
ids, | ||
getAttrs, | ||
} = getCtx(); | ||
const dispatch = createDispatcher(); | ||
const attrs = getAttrs("content"); | ||
const state = useMenuContent({ | ||
id: box.with(() => id), | ||
loop: box.with(() => loop), | ||
}); | ||
$: if (id) { | ||
ids.menu.set(id); | ||
function handleInteractOutsideStart(e: InteractOutsideEvent) { | ||
if (!isElement(e.target)) return; | ||
if (e.target.id === state.parentMenu.triggerId.value) { | ||
e.preventDefault(); | ||
return; | ||
} | ||
if (e.target.closest(`#${state.parentMenu.triggerId.value}`)) { | ||
e.preventDefault(); | ||
} | ||
} | ||
$: builder = $menu; | ||
$: Object.assign(builder, attrs); | ||
$: updatePositioning({ | ||
alignOffset, | ||
collisionPadding, | ||
avoidCollisions, | ||
collisionBoundary, | ||
fitViewport, | ||
strategy, | ||
overlap, | ||
}); | ||
const mergedProps = $derived( | ||
mergeProps(restProps, state.props, { | ||
onInteractOutsideStart: handleInteractOutsideStart, | ||
style: { | ||
outline: "none", | ||
"--bits-context-menu-content-transform-origin": | ||
"var(--bits-floating-transform-origin)", | ||
"--bits-context-menu-content-available-width": | ||
"var(--bits-floating-available-width)", | ||
"--bits-context-menu-content-available-height": | ||
"var(--bits-floating-available-height)", | ||
"--bits-context-menu-trigger-width": "var(--bits-floating-anchor-width)", | ||
"--bits-context-menu-trigger-height": "var(--bits-floating-anchor-height)", | ||
}, | ||
}) | ||
); | ||
</script> | ||
|
||
{#if asChild && $open} | ||
<slot {builder} /> | ||
{:else if transition && $open} | ||
<div | ||
bind:this={el} | ||
transition:transition={transitionConfig} | ||
use:melt={builder} | ||
{...$$restProps} | ||
on:m-keydown={dispatch} | ||
> | ||
<slot {builder} /> | ||
</div> | ||
{:else if inTransition && outTransition && $open} | ||
<div | ||
bind:this={el} | ||
in:inTransition={inTransitionConfig} | ||
out:outTransition={outTransitionConfig} | ||
use:melt={builder} | ||
{...$$restProps} | ||
on:m-keydown={dispatch} | ||
> | ||
<slot {builder} /> | ||
</div> | ||
{:else if inTransition && $open} | ||
<div | ||
bind:this={el} | ||
in:inTransition={inTransitionConfig} | ||
use:melt={builder} | ||
{...$$restProps} | ||
on:m-keydown={dispatch} | ||
> | ||
<slot {builder} /> | ||
</div> | ||
{:else if outTransition && $open} | ||
<div | ||
bind:this={el} | ||
out:outTransition={outTransitionConfig} | ||
use:melt={builder} | ||
{...$$restProps} | ||
on:m-keydown={dispatch} | ||
> | ||
<slot {builder} /> | ||
</div> | ||
{:else if $open} | ||
<div bind:this={el} use:melt={builder} {...$$restProps} on:m-keydown={dispatch}> | ||
<slot {builder} /> | ||
</div> | ||
{/if} | ||
<PopperLayer | ||
{...mergedProps} | ||
side="right" | ||
sideOffset={2} | ||
align="start" | ||
present={state.parentMenu.open.value || forceMount} | ||
onInteractOutside={(e) => { | ||
onInteractOutside(e); | ||
if (e.defaultPrevented) return; | ||
state.parentMenu.onClose(); | ||
}} | ||
onEscapeKeydown={(e) => { | ||
// TODO: users should be able to cancel this | ||
onEscapeKeydown(e); | ||
state.parentMenu.onClose(); | ||
}} | ||
trapped | ||
{loop} | ||
> | ||
{#snippet popper({ props })} | ||
{@const finalProps = mergeProps(props, mergedProps)} | ||
{#if asChild} | ||
{@render child?.({ props: finalProps })} | ||
{:else} | ||
<div {...finalProps} bind:this={el}> | ||
{@render children?.()} | ||
</div> | ||
{/if} | ||
{/snippet} | ||
</PopperLayer> |
Oops, something went wrong.