Skip to content

Commit dd8cb84

Browse files
committed
refactor(types): update typescript config and add/updare typescript defs
1 parent 6ad8907 commit dd8cb84

File tree

8 files changed

+115
-42
lines changed

8 files changed

+115
-42
lines changed

.lintstagedrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"./src/**/*.{test.js,js,json,svelte}": [
2+
"./src/**/*.{test.js,ts,json,svelte}": [
3+
"svelte-check --tsconfig ./tsconfig.json",
34
"eslint -c ./.eslintrc.json --fix",
45
"prettier --write"
56
]

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 120,
2+
"printWidth": 80,
33
"trailingComma": "none",
44
"tabWidth": 2,
55
"semi": true,

src/tooltip.svelte.d.ts renamed to src/action-tooltip.d.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { SvelteComponentTyped } from 'svelte';
1+
import { SvelteComponent } from 'svelte';
22

3-
export interface ComponentProps {
3+
export interface TooltipActionProps {
44
/**
55
* The action to trigger the tooltip
66
* @default 'hover'
@@ -19,12 +19,6 @@ 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-
2822
/**
2923
* Whether to show the arrow of the tooltip.
3024
* @default true
@@ -43,6 +37,19 @@ export interface ComponentProps {
4337
*/
4438
content?: string;
4539

40+
/**
41+
* The animation's delay of the tooltip.
42+
* @default 200
43+
*/
44+
delay?: number;
45+
46+
/**
47+
* Whether to hide the tooltip when clicking outside.
48+
* Only works when action is set to 'click'.
49+
* @default false
50+
*/
51+
hideOnClickOutside?: boolean;
52+
4653
/**
4754
* The maximum width of the tooltip.
4855
* @default 200
@@ -67,15 +74,27 @@ export interface ComponentProps {
6774
*/
6875
style?: undefined;
6976

77+
/**
78+
* The target element to bind the tooltip to.
79+
* @default null
80+
*/
81+
targetElement?: HTMLElement | null;
82+
7083
/**
7184
* The theme of the tooltip.
7285
* @default ''
7386
*/
7487
theme?: string;
7588
}
7689

77-
export default class Component extends SvelteComponentTyped<
78-
ComponentProps,
79-
Record<string, any>,
80-
{ default: {} }
90+
export interface TooltipActionEvents {}
91+
92+
export interface TooltipActionSlots {
93+
default: {};
94+
}
95+
96+
export default class TooltipAction extends SvelteComponent<
97+
TooltipActionProps,
98+
TooltipActionEvents,
99+
TooltipActionSlots
81100
> {}

src/action.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Tooltip from './action/action-tooltip.svelte';
2+
3+
interface TooltipProps {
4+
[key: string]: any;
5+
}
6+
7+
interface TooltipActions {
8+
destroy(): void;
9+
}
10+
11+
export function tooltip(
12+
element: HTMLElement,
13+
props: TooltipProps
14+
): TooltipActions;

src/helpers.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export declare function formatVariableKey(str: string): string;
2+
3+
export declare function getMinWidth(
4+
element: HTMLElement,
5+
maxWidth: number
6+
): number;
7+
8+
export declare function isElementInViewport(
9+
element: HTMLElement,
10+
container?: HTMLElement | null,
11+
position?: string
12+
): boolean;
13+
14+
interface TooltipCoords {
15+
top: number;
16+
left: number;
17+
}
18+
19+
export declare function computeTooltipPosition(
20+
containerRef: HTMLElement | null,
21+
tooltipRef: HTMLElement | null,
22+
position: string,
23+
coords: TooltipCoords
24+
): TooltipCoords;
25+
26+
export declare function onClickOutside(
27+
node: HTMLElement,
28+
callback: () => void
29+
): { destroy: () => void };

src/action-tooltip.svelte.d.ts renamed to src/tooltip.d.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { SvelteComponentTyped } from 'svelte';
1+
import { SvelteComponent } from 'svelte';
22

3-
export interface ComponentProps {
3+
export interface TooltipProps {
44
/**
55
* The action to trigger the tooltip
66
* @default 'hover'
@@ -19,12 +19,6 @@ 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-
2822
/**
2923
* Whether to show the arrow of the tooltip.
3024
* @default true
@@ -43,6 +37,19 @@ export interface ComponentProps {
4337
*/
4438
content?: string;
4539

40+
/**
41+
* The animation's delay of the tooltip.
42+
* @default 200
43+
*/
44+
delay?: number;
45+
46+
/**
47+
* Whether to hide the tooltip when clicking outside.
48+
* Only works when action is set to 'click'.
49+
* @default false
50+
*/
51+
hideOnClickOutside?: boolean;
52+
4653
/**
4754
* The maximum width of the tooltip.
4855
* @default 200
@@ -67,21 +74,21 @@ export interface ComponentProps {
6774
*/
6875
style?: undefined;
6976

70-
/**
71-
* The target element to bind the tooltip to.
72-
* @default null
73-
*/
74-
targetElement?: HTMLElement | null,
75-
7677
/**
7778
* The theme of the tooltip.
7879
* @default ''
7980
*/
8081
theme?: string;
8182
}
8283

83-
export default class Component extends SvelteComponentTyped<
84-
ComponentProps,
85-
Record<string, any>,
86-
{ default: {} }
84+
export interface TooltipEvents {}
85+
86+
export interface TooltipSlots {
87+
default: {};
88+
}
89+
90+
export default class Tooltip extends SvelteComponent<
91+
TooltipProps,
92+
TooltipEvents,
93+
TooltipSlots
8794
> {}

svelte.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
2+
3+
export default {
4+
preprocess: vitePreprocess()
5+
};

tsconfig.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
2+
"extends": "@tsconfig/svelte/tsconfig.json",
3+
"include": ["src/**/*.d.ts"],
4+
"exclude": ["node_modules/*", "src/**/*.js", "src/**/*.test.js"],
25
"compilerOptions": {
6+
"baseUrl": ".",
7+
"moduleResolution": "node",
38
"esModuleInterop": true,
49
"forceConsistentCasingInFileNames": true,
5-
"ignoreDeprecations": "5.0",
610
"importsNotUsedAsValues": "error",
711
"resolveJsonModule": true,
8-
"isolatedModules": true,
9-
"moduleResolution": "node",
12+
"sourceMap": true,
1013
"strict": true,
11-
"types": ["svelte"],
12-
"paths": {
13-
"@svelte-plugins/tooltips": ["./src"],
14-
"@svelte-plugins/tooltips/*": ["./src/*"]
15-
}
16-
},
17-
"include": ["src"]
14+
"types": ["svelte"]
15+
}
1816
}

0 commit comments

Comments
 (0)