Skip to content

Commit 72c7274

Browse files
committed
feat(tooltips): add delay prop
1 parent d974e01 commit 72c7274

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/action-tooltip.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
/** @type {string} */
3333
export let animation = '';
3434
35+
/** @type {number} */
36+
export let delay = 200;
37+
3538
/** @type {boolean} */
3639
export let arrow = true;
3740
@@ -64,7 +67,7 @@
6467
left: 0
6568
};
6669
67-
const delay = animation ? 200 : 0;
70+
const animationDelay = animation ? delay : 0;
6871
6972
onMount(() => {
7073
if (tooltipRef !== null) {
@@ -97,7 +100,7 @@
97100
animationEffect = animation;
98101
}
99102
100-
setTimeout(() => (visible = true), delay);
103+
setTimeout(() => (visible = true), animationDelay);
101104
});
102105
103106
onDestroy(() => {
@@ -108,7 +111,7 @@
108111
});
109112
110113
$: isComponent = typeof content === 'object';
111-
$: tooltipRef && show ? setTimeout(() => (visible = true), delay) : (visible = false);
114+
$: tooltipRef && show ? setTimeout(() => (visible = true), animationDelay) : (visible = false);
112115
</script>
113116

114117
{#if content}

src/action-tooltip.svelte.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export interface ComponentProps {
1919
*/
2020
animation?: string;
2121

22+
/**
23+
* The animation's delay of the tooltip.
24+
* @default 200
25+
*/
26+
delay?: number;
27+
2228
/**
2329
* Whether to show the arrow of the tooltip.
2430
* @default true

src/tooltip.svelte

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
/** @type {string} */
3030
export let animation = '';
3131
32+
/** @type {number} */
33+
export let delay = 200;
34+
3235
/** @type {boolean} */
3336
export let arrow = true;
3437
@@ -79,7 +82,7 @@
7982
};
8083
8184
const onShow = () => {
82-
const delay = animation ? 200 : 0;
85+
const animationDelay = animation ? delay : 0;
8386
8487
// @ts-ignore
8588
if (autoPosition && !isElementInViewport(containerRef, tooltipRef, position)) {
@@ -93,7 +96,7 @@
9396
animationEffect = animation;
9497
}
9598
96-
timer = setTimeout(() => (visible = true), delay);
99+
timer = setTimeout(() => (visible = true), animationDelay);
97100
};
98101
99102
const onHide = () => {

src/tooltip.svelte.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export interface ComponentProps {
1919
*/
2020
animation?: string;
2121

22+
/**
23+
* The animation's delay of the tooltip.
24+
* @default 200
25+
*/
26+
delay?: number;
27+
2228
/**
2329
* Whether to show the arrow of the tooltip.
2430
* @default true

0 commit comments

Comments
 (0)