-
-
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
12 changed files
with
180 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script lang="ts"> | ||
import type { ArrowProps } from "../index.js"; | ||
import { FloatingLayer } from "$lib/bits/utilities/index.js"; | ||
let { el = $bindable(), ...restProps }: ArrowProps = $props(); | ||
</script> | ||
|
||
<FloatingLayer.Arrow bind:el {...restProps} /> |
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
37 changes: 37 additions & 0 deletions
37
packages/bits-ui/src/lib/bits/utilities/arrow/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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script lang="ts"> | ||
import type { ArrowProps } from "./types.js"; | ||
import { generateId } from "$lib/internal/id.js"; | ||
import { styleToString } from "$lib/internal/style.js"; | ||
let { | ||
id = generateId(), | ||
el = $bindable(), | ||
children, | ||
asChild, | ||
child, | ||
style = {}, | ||
height = 5, | ||
width = 10, | ||
...restProps | ||
}: ArrowProps = $props(); | ||
const mergedProps = $derived({ | ||
...restProps, | ||
style: styleToString(style), | ||
id, | ||
}); | ||
</script> | ||
|
||
{#if asChild} | ||
{@render child?.({ props: mergedProps })} | ||
{:else} | ||
<span {...mergedProps} bind:this={el}> | ||
{#if children} | ||
{@render children?.()} | ||
{:else} | ||
<svg {width} {height} viewBox="0 0 30 10" preserveAspectRatio="none"> | ||
<polygon points="0,0 30,0 15,10" fill="currentColor" /> | ||
</svg> | ||
{/if} | ||
</span> | ||
{/if} |
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,2 @@ | ||
export { default as Arrow } from "./arrow.svelte"; | ||
export type { ArrowProps } from "./types.js"; |
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,19 @@ | ||
import type { PrimitiveSpanAttributes, WithAsChild } from "$lib/internal/types.js"; | ||
|
||
export type ArrowPropsWithoutHTML = WithAsChild<{ | ||
/** | ||
* The width of the arrow in pixels. | ||
* | ||
* @defaultValue 10 | ||
*/ | ||
width?: number; | ||
|
||
/** | ||
* The height of the arrow in pixels. | ||
* | ||
* @defaultValue 5 | ||
*/ | ||
height?: number; | ||
}>; | ||
|
||
export type ArrowProps = ArrowPropsWithoutHTML & PrimitiveSpanAttributes; |
17 changes: 13 additions & 4 deletions
17
...ages/bits-ui/src/lib/bits/utilities/floating-layer/components/floating-layer-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,11 +1,20 @@ | ||
<script lang="ts"> | ||
import type { ArrowProps } from "../index.js"; | ||
import { setFloatingArrowState } from "../floating-layer.svelte.js"; | ||
import { Arrow, type ArrowProps } from "$lib/bits/utilities/arrow/index.js"; | ||
import { readonlyBox } from "$lib/internal/box.svelte.js"; | ||
import { generateId } from "$lib/internal/id.js"; | ||
let { id, children, style = {} }: ArrowProps = $props(); | ||
let { id = generateId(), el = $bindable(), style = {}, ...restProps }: ArrowProps = $props(); | ||
setFloatingArrowState({ id: readonlyBox(() => id), style: readonlyBox(() => style) }); | ||
const state = setFloatingArrowState({ | ||
id: readonlyBox(() => id), | ||
style: readonlyBox(() => style), | ||
}); | ||
const mergedProps = $derived({ | ||
...restProps, | ||
...state.props, | ||
}); | ||
</script> | ||
|
||
{@render children?.()} | ||
<Arrow {...mergedProps} bind:el /> |
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
Oops, something went wrong.