Skip to content

Feat: useHover hook #34

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

Merged
merged 44 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
87745ad
Renamed mouse to hover
Hugos68 Apr 29, 2024
41d5999
Tooltip ish working
Hugos68 Apr 29, 2024
1a1be3f
Started with restTimeout
Hugos68 Apr 29, 2024
fe6626b
Added tooltip!
Hugos68 Apr 29, 2024
29bbac2
svelte transition :D
Hugos68 Apr 29, 2024
b785ebf
Implemented `restMs`
Hugos68 Apr 30, 2024
5cf8907
Removed unused import
Hugos68 Apr 30, 2024
2e482a2
cleanup
Hugos68 Apr 30, 2024
f913cb7
Implemented `move`
Hugos68 Apr 30, 2024
8af5d56
Renamed props
Hugos68 Apr 30, 2024
b929c74
Better tooltip defaults
Hugos68 Apr 30, 2024
3a7a68c
Init timeout class field
Hugos68 Apr 30, 2024
6ca9f67
Properly cleanup timeouts
Hugos68 Apr 30, 2024
3bb6980
Added interaction interface
Hugos68 Apr 30, 2024
1dfed1c
Removed example page
Hugos68 Apr 30, 2024
f801c70
format
Hugos68 Apr 30, 2024
e046a56
interactions stuff
Hugos68 Apr 30, 2024
c856775
Started conversion to react
Hugos68 May 1, 2024
a072575
Implemented 2 effects
Hugos68 May 1, 2024
52d8b2e
Progress
Hugos68 May 1, 2024
bd312e9
progress
Hugos68 May 1, 2024
2de2254
Merge branch 'dev' into feat/use-hover
Hugos68 May 2, 2024
bc64410
Fixed some conflicts
Hugos68 May 2, 2024
58243a7
Merge branch 'dev' into feat/use-hover
Hugos68 May 2, 2024
f35c8c6
Remove useInteractions hook (handled by Add: useInteractions hook #3)
Hugos68 May 3, 2024
fe8ddc2
Merge branch 'dev' into feat/use-hover
Hugos68 May 4, 2024
a3602dc
Added `useHover` hook
Hugos68 May 4, 2024
8d377ab
Simplified with $derived
Hugos68 May 4, 2024
b2ae64d
formatting
Hugos68 May 4, 2024
b881f3d
more tests
Hugos68 May 4, 2024
16f8924
Added docs
Hugos68 May 5, 2024
b81976f
Merge branch 'dev' into feat/use-hoverpnpm
Hugos68 May 5, 2024
200bc85
Resolve pnpm-lock
Hugos68 May 5, 2024
3fc6ba8
Moved everything to attributes
Hugos68 May 5, 2024
a3fd70e
Renamed to `elementProps`
Hugos68 May 5, 2024
af09963
Started testing
Hugos68 May 6, 2024
dd461f5
Started porting tests!
Hugos68 May 6, 2024
aace1de
Added more tests
Hugos68 May 6, 2024
94c096b
Added more tests
Hugos68 May 6, 2024
f931b1d
Removed redundant import
Hugos68 May 6, 2024
a6ade8c
Remove space
Hugos68 May 6, 2024
d1f3051
Feedback
Hugos68 May 6, 2024
dcb62e5
Merge branch 'dev' into feat/use-hover
Hugos68 May 6, 2024
4cf00d6
Added changeset
Hugos68 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/curvy-snakes-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skeletonlabs/floating-ui-svelte": minor
---

Added the `useHover` hook
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,37 @@ This will ensure all event handlers will be registered rather being overruled by

| Property | Description | Type |
| -------- | ----------- | ---- |
| getReferenceProps | The merged attributes for the `reference` element | (userProps?: HTMLAttributes<Element>) => Record<string, unknown> |
| getFloatingProps | The merged attributes for the `floating` element | (userProps?: HTMLAttributes<Element>) => Record<string, unknown> |
| getItemProps | The merged attributes for when dealing with a list inside the `floating` element. | (userProps?: HTMLAttributes<Element> & ExtendedUserProps) => Record<string, unknown> |
| getReferenceProps | The merged attributes for the `reference` element. | (userProps?: HTMLAttributes<Element>) => Record<string, unknown> |
| getFloatingProps | The merged attributes for the `floating` element. | (userProps?: HTMLAttributes<Element>) => Record<string, unknown> |
| getItemProps | The merged attributes for when dealing with a list inside the `floating` element. | (userProps?: HTMLAttributes<Element> & ExtendedUserProps) => Record<string, unknown> |

### useHover

(tbd)
#### Usage

```html
<script>
import { useFloating, useInteractions, useHover } from '@skeletonlabs/floating-ui-svelte';

const floating = useFloating();
const hover = useHover(floating.context);
const interactions = useInteractions([hover]);
</script>

<button {...interactions.getReferenceProps()}>Reference</button>
<div {...interactions.getFloatingProps()}>Tooltip</div>
```

#### Options

| Property | Description | Type | Default Value |
| -------- | ----------- | ---- | ------------- |
| enabled | Enables the hook. | boolean | true |
| mouseOnly | Only allow pointers of type mouse to trigger the hover (thus excluding pens and touchscreens). | boolean | false |
| delay | Time in ms that will delay the change of the open state. Also accepts an object with open and close properties for finer grained control. | number | 0 |
| restMs | Time in ms that the pointer must rest on the reference element before the open state is set to true. | number | 0 |
| move | Whether moving the pointer over the floating element will open it, without a regular hover event required. | boolean | true |
| handleClose | Callback to handle the closing of the floating element. | HandleCloseFn | null |

### useFocus

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"!dist/**/*.spec.*"
],
"dependencies": {
"@floating-ui/dom": "^1.6.3"
"@floating-ui/dom": "^1.6.3",
"@floating-ui/utils": "^0.2.2"
},
"peerDependencies": {
"svelte": "^5.0.0-next.1"
Expand Down
Loading