Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FloatingArrow component #35

Merged
merged 32 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
572c04f
Initial component structure
endigo9740 May 1, 2024
f0337dd
Refinement
endigo9740 May 1, 2024
c6ca518
Move styleParser to utils
endigo9740 May 1, 2024
cd57771
Merge latest
endigo9740 May 2, 2024
7833175
Merge
endigo9740 May 2, 2024
8a39c7e
Add component to index
endigo9740 May 2, 2024
010b127
Merge again
endigo9740 May 2, 2024
b2b82b7
Progress
endigo9740 May 2, 2024
285a2f5
Merge branch 'dev' into feature/floating-arrow-component
endigo9740 May 2, 2024
684092a
Merge plus Platform import
endigo9740 May 2, 2024
ea93ac0
Updated FloatingContext type. Updated ref type. Import `platform` fro…
Hugos68 May 2, 2024
56f1a20
Updated type for style parser.
Hugos68 May 2, 2024
5a12035
Refinement
endigo9740 May 3, 2024
5a2f4a0
Minor adjustments
endigo9740 May 3, 2024
fc959b8
Styles, comments, temp pre output
endigo9740 May 3, 2024
1239e1d
Merge branch 'dev' into feature/floating-arrow-component
endigo9740 May 3, 2024
9ae294f
Add offset middlware
endigo9740 May 3, 2024
ad6d2c4
Added changeset
endigo9740 May 3, 2024
05d4bcb
Runified FloatingArrow
Hugos68 May 3, 2024
95fbf1d
Preview styles, readme updates
endigo9740 May 3, 2024
77e8d4d
Readme props added
endigo9740 May 3, 2024
7e7bfd5
Cleanup
endigo9740 May 3, 2024
2860d65
Unify styles parser, type defaults added
endigo9740 May 3, 2024
8325398
Merge branch 'dev' into feature/floating-arrow-component
endigo9740 May 3, 2024
002ba60
Linting pass
endigo9740 May 3, 2024
00b0e37
Remove SSR setting
endigo9740 May 3, 2024
637394b
Cleaned up reactivity with derived destructure
Hugos68 May 4, 2024
f988dce
Reactivity cleanup
Hugos68 May 4, 2024
d99fd73
Moved to switch case statement. Makes it more clear
Hugos68 May 4, 2024
2b4da0a
Review feedback implemented
endigo9740 May 6, 2024
e8f524b
Merge branch 'dev' into feature/floating-arrow-component
endigo9740 May 6, 2024
fe734ce
Basic test case, fix rest spread
endigo9740 May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-hounds-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skeletonlabs/floating-ui-svelte": minor
---

feature: added the FloatingArrow component
78 changes: 75 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ npm install @skeletonlabs/floating-ui-svelte

## Usage

### Making elements "float"
endigo9740 marked this conversation as resolved.
Show resolved Hide resolved

We want it to float on top of the UI though, so it doesn’t disrupt the flow of the document. Add this class to all floating elements. Note that Floating UI does not have opinions about how your elements stack on the z-axis.

```css
.floating {
width: max-content;
position: absolute;
top: 0;
left: 0;
}

```

### The Basics

Import the desired hook or component from floating-ui-svelte. [View each example](https://floating-ui-svelte.vercel.app/) for additional guidance.

```js
Expand All @@ -38,8 +54,8 @@ The `useFloating` Svelte hook acts as a controller for all other Floating UI Sve
const floating = useFloating({ elements });
</script>

<div bind:this="{elements.reference}">Reference</div>
<div bind:this="{elements.floating}" style="{floating.floatingStyles}">Floating</div>
<button bind:this="{elements.reference}">Reference</button>
<div bind:this="{elements.floating}" style="{floating.floatingStyles}" class="floating">Floating</div>
```

> [!WARNING]
Expand Down Expand Up @@ -135,7 +151,63 @@ This will ensure all event handlers will be registered rather being overruled by

### FloatingArrow

(tbd)
Renders a customizable `<svg>` pointing arrow triangle inside the floating element that gets automatically positioned.

```html
<script lang="ts">
import { arrow, useFloating, FloatingArrow, autoUpdate, offset } from '$lib/index.js';

let arrowRef: HTMLElement | null = $state(null);

const elements: { reference: HTMLElement | null; floating: HTMLElement | null } = $state({
reference: null,
floating: null
});

const floating = useFloating({
elements,
get middleware() {
return [
offset(10),
arrowRef && arrow({ element: arrowRef })
];
}
});
</script>

<button bind:this={elements.reference}>Reference</button>
<div bind:this={elements.floating} style={floating.floatingStyles} class="floating">
<div>Floating</div>
<FloatingArrow
bind:ref={arrowRef}
context={floating.context}
classes="fill-surface-500"
/>
</div>
```

#### Props

| Prop | Description | Default | Type |
| -------- | ----------- | ---- | ---- |
| ref* | Binded element reference. | - | HTMLElement, null |
| context* | The context object returned from useFloating(). | - | FloatingContext |
| width | The width of the arrow. | `14` | number |
| height | The height of the arrow. | `7` | number |
| tipRadius | The radius (rounding) of the arrow tip. | `0` (sharp) | number |
| staticOffset | A static offset override of the arrow from the floating element edge. Often desirable if the floating element is smaller than the reference element along the relevant axis and has an edge alignment (`start`/`end`). | `undefined` (use dynamic path) | string, number, null |
| d | A custom path for the arrow. Useful if you want fancy rounding. The path should be inside a square SVG and placed at the `bottom` of it. The path is designed for the 'bottom' placement, which will be rotated for other placements. | `"black"` (browser default) | string |
| fill | The color of the arrow. | xxx | string |
| stroke | The stroke (border) color of the arrow. This must match (or be less than) the floating element’s border width. | `"none"` | string |
| strokeWidth | The stroke (border) width of the arrow. | `0` | number |

#### Utility Classes and Styles
endigo9740 marked this conversation as resolved.
Show resolved Hide resolved

Provide artibrary utility classes using the standard attribute.

```html
<FloatingArrow class="fill-white" />
```

### FloatingOverlay

Expand Down
Loading