@hyvor/design 2.1.6-beta.1 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,22 +1,43 @@
|
|
|
1
|
-
<!-- @migration-task Error while migrating Svelte code: This migration would change the name of a slot making the component unusable -->
|
|
2
1
|
<script lang="ts">
|
|
3
|
-
import { tick, onMount
|
|
2
|
+
import { tick, onMount } from 'svelte';
|
|
4
3
|
import { fade } from 'svelte/transition';
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
text?: string;
|
|
9
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
10
|
+
color?: 'black' | 'accent' | 'soft' | 'danger';
|
|
11
|
+
show?: boolean;
|
|
12
|
+
maxWidth?: number;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
delay?: number;
|
|
15
|
+
children?: Snippet;
|
|
16
|
+
tooltip?: Snippet;
|
|
17
|
+
wrapperProps?: HTMLAttributes<HTMLDivElement>;
|
|
18
|
+
}
|
|
5
19
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
let {
|
|
21
|
+
text = '',
|
|
22
|
+
position = 'top',
|
|
23
|
+
color = 'black',
|
|
24
|
+
show = $bindable(false),
|
|
25
|
+
maxWidth = 300,
|
|
26
|
+
disabled = false,
|
|
27
|
+
delay = 100,
|
|
28
|
+
children,
|
|
29
|
+
tooltip,
|
|
30
|
+
wrapperProps = {}
|
|
31
|
+
}: Props = $props();
|
|
32
|
+
|
|
33
|
+
let wrap: HTMLDivElement | undefined = $state();
|
|
34
|
+
let tooltipEl: HTMLDivElement | undefined = $state();
|
|
35
|
+
let showTimeout: ReturnType<typeof setTimeout>;
|
|
15
36
|
|
|
16
37
|
function positionTooltip() {
|
|
17
|
-
if (wrap &&
|
|
38
|
+
if (wrap && tooltipEl && show) {
|
|
18
39
|
const wrapRect = wrap.getBoundingClientRect();
|
|
19
|
-
const tooltipRect =
|
|
40
|
+
const tooltipRect = tooltipEl.getBoundingClientRect();
|
|
20
41
|
|
|
21
42
|
let top, left;
|
|
22
43
|
|
|
@@ -36,36 +57,41 @@
|
|
|
36
57
|
left = position === 'left' ? leftVal : wrapRect.right + 10;
|
|
37
58
|
}
|
|
38
59
|
|
|
39
|
-
|
|
40
|
-
|
|
60
|
+
tooltipEl.style.top = top + 'px';
|
|
61
|
+
tooltipEl.style.left = left + 'px';
|
|
41
62
|
}
|
|
42
63
|
}
|
|
43
64
|
|
|
44
|
-
|
|
65
|
+
function handleMouseEnter() {
|
|
45
66
|
if (!disabled) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
clearTimeout(showTimeout);
|
|
68
|
+
showTimeout = setTimeout(async () => {
|
|
69
|
+
show = true;
|
|
70
|
+
await tick();
|
|
71
|
+
positionTooltip();
|
|
72
|
+
}, delay);
|
|
49
73
|
}
|
|
50
74
|
}
|
|
51
75
|
|
|
52
76
|
function handleMouseLeave() {
|
|
77
|
+
clearTimeout(showTimeout);
|
|
53
78
|
show = false;
|
|
54
79
|
}
|
|
55
80
|
|
|
56
|
-
|
|
81
|
+
$effect(() => {
|
|
57
82
|
if (text) {
|
|
58
83
|
tick().then(() => {
|
|
59
84
|
positionTooltip();
|
|
60
85
|
});
|
|
61
86
|
}
|
|
62
|
-
}
|
|
87
|
+
});
|
|
63
88
|
|
|
64
89
|
onMount(() => {
|
|
65
90
|
positionTooltip();
|
|
66
91
|
document.addEventListener('scroll', positionTooltip);
|
|
67
92
|
|
|
68
93
|
return () => {
|
|
94
|
+
clearTimeout(showTimeout);
|
|
69
95
|
document.removeEventListener('scroll', positionTooltip);
|
|
70
96
|
};
|
|
71
97
|
});
|
|
@@ -73,23 +99,23 @@
|
|
|
73
99
|
|
|
74
100
|
<div
|
|
75
101
|
class="tooltip-wrap {color}"
|
|
76
|
-
|
|
77
|
-
|
|
102
|
+
onmouseenter={handleMouseEnter}
|
|
103
|
+
onmouseleave={handleMouseLeave}
|
|
78
104
|
role="tooltip"
|
|
79
105
|
bind:this={wrap}
|
|
80
|
-
{
|
|
106
|
+
{...wrapperProps}
|
|
81
107
|
>
|
|
82
|
-
|
|
108
|
+
{@render children?.()}
|
|
83
109
|
|
|
84
110
|
{#if !disabled && show}
|
|
85
111
|
<div
|
|
86
112
|
class="tooltip {position}"
|
|
87
113
|
style:max-width={maxWidth + 'px'}
|
|
88
|
-
bind:this={
|
|
114
|
+
bind:this={tooltipEl}
|
|
89
115
|
transition:fade={{ duration: 100 }}
|
|
90
116
|
>
|
|
91
|
-
{#if
|
|
92
|
-
|
|
117
|
+
{#if tooltip}
|
|
118
|
+
{@render tooltip()}
|
|
93
119
|
{:else}
|
|
94
120
|
{text}
|
|
95
121
|
{/if}
|
|
@@ -1,37 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
interface Props {
|
|
4
|
+
text?: string;
|
|
5
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
6
|
+
color?: 'black' | 'accent' | 'soft' | 'danger';
|
|
7
|
+
show?: boolean;
|
|
8
|
+
maxWidth?: number;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
delay?: number;
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
tooltip?: Snippet;
|
|
13
|
+
wrapperProps?: HTMLAttributes<HTMLDivElement>;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} ? Props extends Record<string, never> ? any : {
|
|
17
|
-
children?: any;
|
|
18
|
-
} : {});
|
|
19
|
-
declare const Tooltip: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
20
|
-
[x: string]: any;
|
|
21
|
-
text?: string | undefined;
|
|
22
|
-
position?: "top" | "bottom" | "left" | "right" | undefined;
|
|
23
|
-
color?: "black" | "accent" | "soft" | "danger" | undefined;
|
|
24
|
-
show?: boolean | undefined;
|
|
25
|
-
maxWidth?: number | undefined;
|
|
26
|
-
disabled?: boolean | undefined;
|
|
27
|
-
}, {
|
|
28
|
-
default: {};
|
|
29
|
-
tooltip: {};
|
|
30
|
-
}>, {
|
|
31
|
-
[evt: string]: CustomEvent<any>;
|
|
32
|
-
}, {
|
|
33
|
-
default: {};
|
|
34
|
-
tooltip: {};
|
|
35
|
-
}, {}, string>;
|
|
36
|
-
type Tooltip = InstanceType<typeof Tooltip>;
|
|
15
|
+
declare const Tooltip: import("svelte").Component<Props, {}, "show">;
|
|
16
|
+
type Tooltip = ReturnType<typeof Tooltip>;
|
|
37
17
|
export default Tooltip;
|