-
-
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.
- Loading branch information
Showing
81 changed files
with
9,361 additions
and
6,239 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
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
27 changes: 7 additions & 20 deletions
27
packages/bits-ui/src/lib/bits/select/components/select-arrow.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,27 +1,14 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import { setArrow } from "../ctx.js"; | ||
import type { ArrowProps } from "../index.js"; | ||
import { useSelectArrow } from "../select.svelte.js"; | ||
import { FloatingLayer } from "$lib/bits/utilities/floating-layer/index.js"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
type $$Props = ArrowProps; | ||
let { el = $bindable(), ...restProps }: ArrowProps = $props(); | ||
export let asChild: $$Props["asChild"] = false; | ||
export let el: $$Props["el"] = undefined; | ||
export let size = 8; | ||
const state = useSelectArrow(); | ||
const { | ||
elements: { arrow }, | ||
getAttrs, | ||
} = setArrow(size); | ||
const attrs = getAttrs("arrow"); | ||
$: builder = $arrow; | ||
$: Object.assign(builder, attrs); | ||
const mergedProps = $derived(mergeProps(restProps, state.props as any)); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} /> | ||
{:else} | ||
<div bind:this={el} use:melt={builder} {...$$restProps} /> | ||
{/if} | ||
<FloatingLayer.Arrow bind:el {...mergedProps} /> |
37 changes: 37 additions & 0 deletions
37
packages/bits-ui/src/lib/bits/select/components/select-content-floating.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script lang="ts"> | ||
import { CONTENT_MARGIN, useSelectFloatingPosition } from "../select.svelte.js"; | ||
import type { ContentProps } from "../index.js"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
import type { WithoutChildren } from "$lib/shared/index.js"; | ||
import type { WithAsChild } from "$lib/internal/types.js"; | ||
import type { PopperLayerImplProps } from "$lib/bits/utilities/popper-layer/types.js"; | ||
import { FloatingLayer } from "$lib/bits/utilities/floating-layer/index.js"; | ||
let { | ||
children, | ||
asChild, | ||
child, | ||
align = "start", | ||
collisionPadding = CONTENT_MARGIN, | ||
el = $bindable(), | ||
enabled = false, | ||
...restProps | ||
}: WithoutChildren<PopperLayerImplProps> & WithAsChild<ContentProps> = $props(); | ||
const state = useSelectFloatingPosition(); | ||
const mergedProps = $derived(mergeProps(restProps, state.content.props, state.props)); | ||
</script> | ||
|
||
<FloatingLayer.Content {...restProps} {enabled} {align} {collisionPadding}> | ||
{#snippet content({ props })} | ||
{@const finalProps = mergeProps(props, mergedProps)} | ||
{#if asChild} | ||
{@render child?.({ props: finalProps })} | ||
{:else} | ||
<div {...finalProps} bind:this={el}> | ||
{@render children?.()} | ||
</div> | ||
{/if} | ||
{/snippet} | ||
</FloatingLayer.Content> |
93 changes: 93 additions & 0 deletions
93
packages/bits-ui/src/lib/bits/select/components/select-content-impl.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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<script lang="ts"> | ||
import type { ContentImplProps } from "../index.js"; | ||
import { SelectContentState } from "../select.svelte.js"; | ||
import SelectContentFloating from "./select-content-floating.svelte"; | ||
import SelectContentItemAligned from "./select-content-item-aligned.svelte"; | ||
import FocusScope from "$lib/bits/utilities/focus-scope/focus-scope.svelte"; | ||
import { noop } from "$lib/internal/callbacks.js"; | ||
import { useId } from "$lib/internal/useId.svelte.js"; | ||
import EscapeLayer from "$lib/bits/utilities/escape-layer/escape-layer.svelte"; | ||
import DismissableLayer from "$lib/bits/utilities/dismissable-layer/dismissable-layer.svelte"; | ||
import TextSelectionLayer from "$lib/bits/utilities/text-selection-layer/text-selection-layer.svelte"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
let { | ||
el = $bindable(), | ||
id = useId(), | ||
onMountAutoFocus = noop, | ||
onDestroyAutoFocus = noop, | ||
present, | ||
position = "floating", | ||
context, | ||
onEscapeKeydown = noop, | ||
onInteractOutside = noop, | ||
...restProps | ||
}: ContentImplProps & { present: boolean; context: SelectContentState } = $props(); | ||
const state = context; | ||
// eslint-disable-next-line unused-imports/no-unused-vars, ts/no-unused-vars | ||
const { children, child, asChild, ...restWithoutChildren } = restProps; | ||
</script> | ||
|
||
<FocusScope | ||
{id} | ||
trapped={present} | ||
onMountAutoFocus={(e) => { | ||
onMountAutoFocus(e); | ||
e.preventDefault(); | ||
}} | ||
onDestroyAutoFocus={(e) => { | ||
onDestroyAutoFocus(e); | ||
}} | ||
> | ||
{#snippet focusScope({ props: focusScopeProps })} | ||
<EscapeLayer | ||
{...restWithoutChildren} | ||
enabled={present} | ||
onEscapeKeydown={(e) => { | ||
// TODO: users should be able to cancel this | ||
onEscapeKeydown(e); | ||
state.root.handleClose(); | ||
}} | ||
> | ||
<DismissableLayer | ||
{...restWithoutChildren} | ||
{id} | ||
enabled={present} | ||
onInteractOutside={(e) => { | ||
onInteractOutside(e); | ||
if (e.defaultPrevented) return; | ||
state.root.handleClose(); | ||
}} | ||
> | ||
{#snippet children({ props: dismissableProps })} | ||
<TextSelectionLayer {...restWithoutChildren} {id} enabled={present}> | ||
{@const mergedProps = mergeProps( | ||
restWithoutChildren, | ||
dismissableProps, | ||
focusScopeProps, | ||
state.props, | ||
{ style: { pointerEvents: "auto" } } | ||
) as any} | ||
{#if position === "floating"} | ||
<SelectContentFloating | ||
{...restProps} | ||
{...mergedProps} | ||
bind:el | ||
onPlaced={() => (state.isPositioned.value = true)} | ||
/> | ||
{:else} | ||
<SelectContentItemAligned | ||
{...restProps} | ||
{...mergedProps} | ||
bind:el | ||
onPlaced={() => (state.isPositioned.value = true)} | ||
/> | ||
{/if} | ||
</TextSelectionLayer> | ||
{/snippet} | ||
</DismissableLayer> | ||
</EscapeLayer> | ||
{/snippet} | ||
</FocusScope> |
39 changes: 39 additions & 0 deletions
39
packages/bits-ui/src/lib/bits/select/components/select-content-item-aligned.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script lang="ts"> | ||
import { box } from "svelte-toolbelt"; | ||
import { useSelectItemAlignedPosition } from "../select.svelte.js"; | ||
import type { PrimitiveDivAttributes, WithAsChild } from "$lib/internal/types.js"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
import { useBodyScrollLock } from "$lib/internal/useBodyScrollLock.svelte.js"; | ||
let { | ||
child, | ||
children, | ||
asChild, | ||
el = $bindable(), | ||
preventScroll = true, | ||
onPlaced, | ||
...restProps | ||
}: WithAsChild<PrimitiveDivAttributes> & { | ||
preventScroll?: boolean; | ||
onPlaced: () => void; | ||
} = $props(); | ||
const state = useSelectItemAlignedPosition({ | ||
onPlaced: box.with(() => onPlaced), | ||
}); | ||
const mergedProps = $derived(mergeProps(restProps, state.props)); | ||
const mergedWrapperProps = $derived(mergeProps(state.wrapperProps, {})); | ||
useBodyScrollLock(preventScroll); | ||
</script> | ||
|
||
<div {...mergedWrapperProps}> | ||
{#if asChild} | ||
{@render child?.({ props: mergedProps })} | ||
{:else} | ||
<div bind:this={el} {...mergedProps}> | ||
{@render children?.()} | ||
</div> | ||
{/if} | ||
</div> |
Oops, something went wrong.