Skip to content

Commit

Permalink
no luck
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Apr 19, 2024
1 parent c3204f2 commit 62d841d
Show file tree
Hide file tree
Showing 25 changed files with 702 additions and 416 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
<script lang="ts">
import { melt } from "@melt-ui/svelte";
let { asChild, children, child } = $props();
</script>

{#if asChild}
<slot {builder} />
{:else}
<div bind:this={el} use:melt={builder} {...$$restProps} />
{/if}
Original file line number Diff line number Diff line change
@@ -1,38 +0,0 @@
<script lang="ts">
import { melt } from "@melt-ui/svelte";
import { getCtx } from "../ctx.js";
import type { CloseEvents, CloseProps } from "../index.js";
import { createDispatcher } from "$lib/internal/events.js";
type $$Props = CloseProps;
type $$Events = CloseEvents;
export let asChild: $$Props["asChild"] = false;
export let el: $$Props["el"] = undefined;
const {
elements: { close },
getAttrs,
} = getCtx();
const dispatch = createDispatcher();
const attrs = getAttrs("close");
$: builder = $close;
$: Object.assign(builder, attrs);
</script>

{#if asChild}
<slot {builder} />
{:else}
<button
bind:this={el}
use:melt={builder}
type="button"
{...$$restProps}
on:m-click={dispatch}
on:m-keydown={dispatch}
>
<slot {builder} />
</button>
{/if}
Original file line number Diff line number Diff line change
@@ -1,99 +1,44 @@
<script lang="ts">
import { melt } from "@melt-ui/svelte";
import { getCtx, updatePositioning } from "../ctx.js";
import type { ContentProps } from "../index.js";
import type { Transition } from "$lib/internal/index.js";
type T = $$Generic<Transition>;
type In = $$Generic<Transition>;
type Out = $$Generic<Transition>;
type $$Props = ContentProps<T, In, Out>;
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 side: $$Props["side"] = "bottom";
export let align: $$Props["align"] = "center";
export let sideOffset: $$Props["sideOffset"] = 0;
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 sameWidth: $$Props["sameWidth"] = false;
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: { content },
states: { open },
ids,
getAttrs,
} = getCtx();
const attrs = getAttrs("content");
$: if (id) {
ids.content.set(id);
}
$: builder = $content;
$: Object.assign(builder, attrs);
$: if ($open) {
updatePositioning({
side,
align,
sideOffset,
alignOffset,
collisionPadding,
avoidCollisions,
collisionBoundary,
sameWidth,
fitViewport,
strategy,
overlap,
});
}
import { setPopoverContentState } from "../popover.svelte.js";
import { FloatingLayer } from "$lib/bits/utilities/index.js";
import { readonlyBox } from "$lib/internal/box.svelte.js";
import { generateId } from "$lib/internal/id.js";
import Presence from "$lib/bits/utilities/presence.svelte";
let {
asChild,
child,
children,
el = $bindable(),
style = {},
id = generateId(),
forceMount = false,
...restProps
}: ContentProps = $props();
const state = setPopoverContentState({
id: readonlyBox(() => id),
});
</script>

{#if asChild && $open}
<slot {builder} />
{:else if transition && $open}
<div
bind:this={el}
transition:transition={transitionConfig}
use:melt={builder}
{...$$restProps}
>
<slot {builder} />
</div>
{:else if inTransition && outTransition && $open}
<div
bind:this={el}
in:inTransition={inTransitionConfig}
out:outTransition={outTransitionConfig}
use:melt={builder}
{...$$restProps}
>
<slot {builder} />
</div>
{:else if inTransition && $open}
<div bind:this={el} in:inTransition={inTransitionConfig} use:melt={builder} {...$$restProps}>
<slot {builder} />
</div>
{:else if outTransition && $open}
<div bind:this={el} out:outTransition={outTransitionConfig} use:melt={builder} {...$$restProps}>
<slot {builder} />
</div>
{:else if $open}
<div bind:this={el} use:melt={builder} {...$$restProps}>
<slot {builder} />
</div>
{/if}
<FloatingLayer.Content {id} {style} {...restProps}>
{#snippet content({ props })}
<Presence forceMount={true} present={state.root.open.value || forceMount} node={state.node}>
{#snippet presence({ present })}
{@const mergedProps = {
...state.props,
...props,
hidden: present.value ? undefined : true,
}}
{#if asChild}
{@render child?.({ props: mergedProps })}
{:else}
<div {...mergedProps} bind:this={el}>
{@render children?.()}
</div>
{/if}
{/snippet}
</Presence>
{/snippet}
</FloatingLayer.Content>
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
<script lang="ts">
import { melt } from "@melt-ui/svelte";
import { getCtx } from "../ctx.js";
import type { TriggerEvents, TriggerProps } from "../index.js";
import { createDispatcher } from "$lib/internal/events.js";
type $$Props = TriggerProps;
type $$Events = TriggerEvents;
export let asChild: $$Props["asChild"] = false;
export let id: $$Props["id"] = undefined;
export let el: $$Props["el"] = undefined;
const {
elements: { trigger },
states: { open },
ids,
getAttrs,
} = getCtx();
const dispatch = createDispatcher();
const bitsAttrs = getAttrs("trigger");
$: if (id) {
ids.trigger.set(id);
}
$: attrs = {
...bitsAttrs,
"aria-controls": $open ? ids.content : undefined,
};
$: builder = $trigger;
$: Object.assign(builder, attrs);
import type { TriggerProps } from "../index.js";
import { setPopoverTriggerState } from "../popover.svelte.js";
import { generateId, noop, readonlyBox, styleToString } from "$lib/internal/index.js";
import { FloatingLayer } from "$lib/bits/utilities/index.js";
let {
asChild,
children,
child,
id = generateId(),
el = $bindable(),
onclick = noop,
onkeydown = noop,
style = {},
...restProps
}: TriggerProps = $props();
const popoverTriggerState = setPopoverTriggerState({
id: readonlyBox(() => id),
onclick: readonlyBox(() => onclick),
onkeydown: readonlyBox(() => onkeydown),
});
const mergedProps = $derived({
...restProps,
...popoverTriggerState.props,
style: styleToString(style),
});
</script>

{#if asChild}
<slot {builder} />
{:else}
<button
bind:this={el}
use:melt={builder}
type="button"
{...$$restProps}
on:m-click={dispatch}
on:m-keydown={dispatch}
>
<slot {builder} />
</button>
{/if}
<FloatingLayer.Anchor {id}>
{#if asChild}
{@render child?.({ props: mergedProps })}
{:else}
<button {...mergedProps} bind:this={el}>
{@render children?.()}
</button>
{/if}
</FloatingLayer.Anchor>
19 changes: 17 additions & 2 deletions packages/bits-ui/src/lib/bits/popover/components/popover.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<script lang="ts">
import type { RootProps } from "../index.js";
import { setPopoverRootState } from "../popover.svelte.js";
import { box } from "$lib/internal/box.svelte.js";
import { FloatingLayer } from "$lib/bits/utilities/index.js";
let { open, children, onOpenChange }: RootProps = $props();
let { open = $bindable(false), children, onOpenChange }: RootProps = $props();
setPopoverRootState({
open: box(
() => open,
(v) => {
open = v;
onOpenChange?.(v);
}
),
});
</script>

{@render children?.()}
<FloatingLayer.Root>
{@render children?.()}
</FloatingLayer.Root>
66 changes: 0 additions & 66 deletions packages/bits-ui/src/lib/bits/popover/ctx.ts

This file was deleted.

Loading

0 comments on commit 62d841d

Please sign in to comment.