Skip to content

Commit 3f9d1dc

Browse files
authored
Merge pull request #22 from joligoms/feat/tooltips/add-delay-prop
feat(tooltips): add delay prop
2 parents d974e01 + 1d4a226 commit 3f9d1dc

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Checkout out my <u use:tooltip={{ content: 'Hello World!' }}>tooltip</u>
4444
| :----------- | :------------------------------------------------------------------ | :---------------------------------------------- |
4545
| action | The action that triggers the tooltip (hover | click | prop) | `string` (default: `hover`) |
4646
| animation | The animation to apply to the tooltip | `string` (default: ``) |
47+
| delay | The animation delay in milliseconds to apply to the tooltip | `number` (default: `200`) |
4748
| arrow | If `false`, the tooltip arrow will not be shown. | `boolean` (default: `true`) |
4849
| autoPosition | Adjust tooltip position if viewport clipping occurs | `string` (default: `false`) |
4950
| content | The string or object containing componentref and props | `string` | `object` component (default: ``) |

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)