@viamrobotics/prime-core
Advanced tools
Comparing version 0.0.70 to 0.0.71
@@ -57,2 +57,11 @@ import { describe, it, expect } from 'vitest'; | ||
}); | ||
it('shows the tooltip on mouse enter after a delay', async () => { | ||
const user = userEvent.setup(); | ||
render(Tooltip, { hoverDelayMS: 50 }); | ||
const target = screen.getByTestId('target'); | ||
const tooltip = screen.getByRole('tooltip'); | ||
await user.hover(target); | ||
expect(tooltip).toHaveClass('invisible'); | ||
await waitFor(() => expect(tooltip).not.toHaveClass('invisible')); | ||
}); | ||
it('shows/hides the tooltip on keyboard focus/blur', async () => { | ||
@@ -59,0 +68,0 @@ render(Tooltip); |
@@ -7,2 +7,3 @@ import { SvelteComponent } from "svelte"; | ||
state?: TooltipVisibility | undefined; | ||
hoverDelayMS?: number; | ||
}; | ||
@@ -9,0 +10,0 @@ events: { |
import { SvelteComponent } from "svelte"; | ||
declare const __propDef: { | ||
props: Record<string, never>; | ||
props: { | ||
hoverDelayMS?: number; | ||
}; | ||
events: { | ||
@@ -5,0 +7,0 @@ [evt: string]: CustomEvent<any>; |
@@ -11,2 +11,3 @@ /// <reference types="svelte" /> | ||
setVisibility: (visibility: TooltipVisibility | undefined) => void; | ||
setHoverDelayMS: (hoverDelayMS: number) => void; | ||
setTarget: (target: HTMLElement | undefined) => void; | ||
@@ -13,0 +14,0 @@ setTooltip: (options: { |
@@ -5,2 +5,3 @@ import { setContext, getContext } from 'svelte'; | ||
import { uniqueId } from '../unique-id'; | ||
import noop from 'lodash/noop'; | ||
const CONTEXT_KEY = Symbol('tooltip'); | ||
@@ -34,4 +35,17 @@ /** | ||
const visibility = writable(); | ||
const isVisible = derived([isHovered, visibility], ([$isHovered, $visibility]) => $visibility === 'visible' || | ||
Boolean($visibility === undefined && $isHovered)); | ||
const hoverDelayMS = writable(); | ||
const isVisible = derived([isHovered, visibility, hoverDelayMS], ([$isHovered, $visibility, $hoverDelayMS], set) => { | ||
let cleanup = noop; | ||
if ($visibility === 'visible') { | ||
set(true); | ||
} | ||
else if ($visibility === 'invisible' || !$isHovered) { | ||
set(false); | ||
} | ||
else { | ||
const timeoutID = setTimeout(() => set(true), $hoverDelayMS); | ||
cleanup = () => clearTimeout(timeoutID); | ||
} | ||
return cleanup; | ||
}, false); | ||
const style = floatingStyle({ offset: 7, shift: 5, flip: true, auto: true }); | ||
@@ -44,2 +58,3 @@ return { | ||
setVisibility: visibility.set, | ||
setHoverDelayMS: hoverDelayMS.set, | ||
setTarget: (target) => style.register({ referenceElement: target }), | ||
@@ -46,0 +61,0 @@ setTooltip: ({ tooltip, arrow, placement }) => { |
@@ -15,2 +15,7 @@ import { SvelteComponent } from "svelte"; | ||
*/ state?: TooltipVisibility | undefined; | ||
/** | ||
* If state is `undefined`, the tooltip only renders on mouse enter and focus. | ||
* On mouse enter, this delay is present before the tooltip is shown. | ||
* There is no delay for focus. | ||
*/ hoverDelayMS?: number; | ||
/** Additional CSS classes to pass to the tooltip text element. */ cx?: cx.Argument; | ||
@@ -17,0 +22,0 @@ }; |
{ | ||
"name": "@viamrobotics/prime-core", | ||
"version": "0.0.70", | ||
"version": "0.0.71", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309295
5448