Skip to content

Commit 7ee8d3b

Browse files
committed
refactor(types): add missing types to action file
1 parent dcde332 commit 7ee8d3b

File tree

6 files changed

+101
-16
lines changed

6 files changed

+101
-16
lines changed

docs/public/global.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</div>
8484

8585
<div class="example">
86-
This tooltip should appear on the <Tooltip content="<b>Tooltip Top</b><p>This is an example of using HTML and content wrapping.</p>" position="top" animation="slide" arrow={false}><i>top</i></Tooltip> when I hover.
86+
This tooltip should appear on the <Tooltip content="<b>Tooltip Top</b><p>This is an example of using HTML and content wrapping.</p>" position="top" animation="slide" arrow={false}><i>top</i></Tooltip> when you hover.
8787
</div>
8888

8989
<div class="example">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@svelte-plugins/tooltips",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"license": "MIT",
55
"description": "A simple tooltip action and component designed for Svelte.",
66
"author": "Kieran Boyle (https://github.com/dysfunc)",

src/action-tooltip.svelte

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script>
2+
// @ts-check
3+
24
import { onMount, onDestroy } from 'svelte';
35
import { formatVariableKey, getMinWidth, isInViewport } from './helpers';
46
import { inverse } from './constants';
@@ -8,15 +10,27 @@
810
export let align = 'left';
911
export let position = 'top';
1012
export let maxWidth = 200;
11-
export let style = null;
13+
/**
14+
* @type {{ [x: string]: any; } | null}
15+
*/
16+
export let style = null;
1217
export let theme = '';
1318
export let animation = '';
1419
export let arrow = true;
1520
export let autoPosition = false;
1621
22+
/**
23+
* @type {HTMLDivElement | null}
24+
*/
1725
let ref = null;
1826
let minWidth = 0;
27+
/**
28+
* @type {{ $destroy: () => void; } | null}
29+
*/
1930
let component = null;
31+
/**
32+
* @type {string | null}
33+
*/
2034
let animationEffect = null;
2135
let show = false;
2236
@@ -25,6 +39,7 @@
2539
2640
if (ref !== null) {
2741
if (isComponent && !component) {
42+
// @ts-ignore
2843
component = new content.component({ target: ref, props: { action, ...content.props } });
2944
}
3045
@@ -41,6 +56,7 @@
4156
}
4257
4358
if (autoPosition && !isInViewport(ref)) {
59+
// @ts-ignore
4460
position = inverse[position];
4561
}
4662
@@ -61,17 +77,19 @@
6177
$: isComponent = typeof content === 'object';
6278
</script>
6379

64-
<div
65-
bind:this={ref}
66-
class="tooltip animation-{animationEffect} {position} {theme}"
67-
class:show
68-
class:arrowless={!arrow}
69-
style="min-width: {minWidth}px; max-width: {maxWidth}px; text-align: {align};"
70-
>
71-
{#if !isComponent}
72-
{@html content}
73-
{/if}
74-
</div>
80+
{#if content}
81+
<div
82+
bind:this={ref}
83+
class="tooltip animation-{animationEffect} {position} {theme}"
84+
class:show
85+
class:arrowless={!arrow}
86+
style="min-width: {minWidth}px; max-width: {maxWidth}px; text-align: {align};"
87+
>
88+
{#if !isComponent}
89+
{@html content}
90+
{/if}
91+
</div>
92+
{/if}
7593

7694
<style>
7795
/*--------------------------*

src/action-tooltip.svelte.d.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { SvelteComponentTyped } from 'svelte';
2+
3+
export interface ComponentProps {
4+
/**
5+
* The content of the tooltip.
6+
* @default ''
7+
*/
8+
content?: string;
9+
10+
/**
11+
* The position of the tooltip.
12+
* Allowed values are 'top', 'bottom', 'left' or 'right'.
13+
* @default 'top'
14+
*/
15+
position?: string;
16+
17+
/**
18+
* The maximum width of the tooltip.
19+
* @default 200
20+
*/
21+
maxWidth?: number;
22+
23+
/**
24+
* The style of the tooltip.
25+
* @default null
26+
*/
27+
style?: undefined;
28+
29+
/**
30+
* The theme of the tooltip.
31+
* @default ''
32+
*/
33+
theme?: string;
34+
35+
/**
36+
* The animation style of the tooltip.
37+
* @default ''
38+
*/
39+
animation?: string;
40+
41+
/**
42+
* Whether to show the arrow of the tooltip.
43+
* @default true
44+
*/
45+
arrow?: boolean;
46+
47+
/**
48+
* Whether to automatically position the tooltip.
49+
* @default false
50+
*/
51+
autoPosition?: boolean;
52+
}
53+
54+
export default class Component extends SvelteComponentTyped<
55+
ComponentProps,
56+
Record<string, any>,
57+
{ default: {} }
58+
> {}

src/tooltip.svelte.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,51 @@
1-
import type { SvelteComponentTyped } from "svelte";
1+
import type { SvelteComponentTyped } from 'svelte';
22

33
export interface ComponentProps {
44
/**
5+
* The content of the tooltip.
56
* @default ''
67
*/
78
content?: string;
89

910
/**
11+
* The position of the tooltip.
12+
* Allowed values are 'top', 'bottom', 'left' or 'right'.
1013
* @default 'top'
1114
*/
1215
position?: string;
1316

1417
/**
18+
* The maximum width of the tooltip.
1519
* @default 200
1620
*/
1721
maxWidth?: number;
1822

1923
/**
24+
* The style of the tooltip.
2025
* @default null
2126
*/
2227
style?: undefined;
2328

2429
/**
30+
* The theme of the tooltip.
2531
* @default ''
2632
*/
2733
theme?: string;
2834

2935
/**
36+
* The animation style of the tooltip.
3037
* @default ''
3138
*/
3239
animation?: string;
3340

3441
/**
42+
* Whether to show the arrow of the tooltip.
3543
* @default true
3644
*/
3745
arrow?: boolean;
3846

3947
/**
48+
* Whether to automatically position the tooltip.
4049
* @default false
4150
*/
4251
autoPosition?: boolean;

0 commit comments

Comments
 (0)