lapikit 0.4.12 → 0.4.13
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.
- package/dist/labs/compiler/components.js +3 -0
- package/dist/labs/components/dropdown/dropdown.svelte +249 -0
- package/dist/labs/components/dropdown/dropdown.svelte.d.ts +4 -0
- package/dist/labs/components/dropdown/dropdown.svelte.js +148 -0
- package/dist/labs/components/dropdown/dropdown.types.d.ts +28 -0
- package/dist/labs/components/dropdown/dropdown.types.js +1 -0
- package/dist/labs/components/index.d.ts +3 -0
- package/dist/labs/components/index.js +3 -0
- package/dist/labs/components/popover/popover.svelte +188 -0
- package/dist/labs/components/popover/popover.svelte.d.ts +4 -0
- package/dist/labs/components/popover/popover.svelte.js +134 -0
- package/dist/labs/components/popover/popover.types.d.ts +22 -0
- package/dist/labs/components/popover/popover.types.js +1 -0
- package/dist/labs/components/tooltip/tooltip.svelte +372 -0
- package/dist/labs/components/tooltip/tooltip.svelte.d.ts +4 -0
- package/dist/labs/components/tooltip/tooltip.svelte.js +131 -0
- package/dist/labs/components/tooltip/tooltip.types.d.ts +26 -0
- package/dist/labs/components/tooltip/tooltip.types.js +1 -0
- package/dist/labs/utils/index.d.ts +1 -0
- package/dist/labs/utils/index.js +1 -0
- package/dist/labs/utils/outside.d.ts +5 -0
- package/dist/labs/utils/outside.js +34 -0
- package/dist/labs/utils/types/index.d.ts +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { innerWidth, innerHeight } from 'svelte/reactivity/window';
|
|
2
|
+
export function getPositions() {
|
|
3
|
+
// state
|
|
4
|
+
const axis = $state({
|
|
5
|
+
x: 0,
|
|
6
|
+
y: 0,
|
|
7
|
+
location: null
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
get values() {
|
|
11
|
+
return axis;
|
|
12
|
+
},
|
|
13
|
+
update(activator, element, location, centered, avoidCollisions) {
|
|
14
|
+
if (!activator || !element)
|
|
15
|
+
return;
|
|
16
|
+
const elementRect = element.getBoundingClientRect();
|
|
17
|
+
if (activator instanceof HTMLElement) {
|
|
18
|
+
const activatorRect = activator.getBoundingClientRect();
|
|
19
|
+
const spacing = 6;
|
|
20
|
+
const _activator = activatorRect.y + activatorRect.height;
|
|
21
|
+
const _element = elementRect.height + spacing;
|
|
22
|
+
if (location === 'top' || location === 'bottom') {
|
|
23
|
+
if (avoidCollisions) {
|
|
24
|
+
if (location === 'top') {
|
|
25
|
+
if (activatorRect.y - _element < 0) {
|
|
26
|
+
axis.y = activatorRect.bottom + spacing;
|
|
27
|
+
axis.location = 'bottom';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
axis.y = activatorRect.top - _element;
|
|
31
|
+
axis.location = 'top';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (_activator + _element > innerHeight.current) {
|
|
36
|
+
axis.y = activatorRect.top - _element;
|
|
37
|
+
axis.location = 'top';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
axis.y = activatorRect.bottom + spacing;
|
|
41
|
+
axis.location = 'bottom';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (location === 'top') {
|
|
47
|
+
axis.y = activatorRect.top - _element;
|
|
48
|
+
axis.location = 'top';
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
axis.y = activatorRect.bottom + spacing;
|
|
52
|
+
axis.location = 'bottom';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (centered &&
|
|
56
|
+
activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
|
|
57
|
+
activatorRect.left + elementRect.width < innerWidth.current) {
|
|
58
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
|
|
59
|
+
}
|
|
60
|
+
else if (activatorRect.left + elementRect.width > innerWidth.current) {
|
|
61
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
axis.x = activatorRect.left;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (location === 'left' || location === 'right') {
|
|
68
|
+
if (avoidCollisions) {
|
|
69
|
+
if (location === 'left' && !(activatorRect.left - elementRect.width < 0)) {
|
|
70
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
71
|
+
axis.location = 'left';
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (activatorRect.left + activatorRect.width + elementRect.width + spacing >
|
|
75
|
+
innerWidth.current) {
|
|
76
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
77
|
+
axis.location = 'left';
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
axis.x = activatorRect.left + activatorRect.width + spacing;
|
|
81
|
+
axis.location = 'right';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
if (location === 'left') {
|
|
87
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
88
|
+
axis.location = 'left';
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
axis.x = activatorRect.left + activatorRect.width + spacing;
|
|
92
|
+
axis.location = 'right';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (centered &&
|
|
96
|
+
activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
|
|
97
|
+
activatorRect.top + elementRect.height < innerHeight.current) {
|
|
98
|
+
axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
|
|
99
|
+
}
|
|
100
|
+
else if (activatorRect.y + elementRect.height > innerHeight.current) {
|
|
101
|
+
axis.y = activatorRect.y - elementRect.height + activatorRect.height;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
axis.y = activatorRect.y;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (centered &&
|
|
109
|
+
activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
|
|
110
|
+
activatorRect.left + elementRect.width < innerWidth.current) {
|
|
111
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
|
|
112
|
+
}
|
|
113
|
+
else if (activatorRect.left + elementRect.width > innerWidth.current) {
|
|
114
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
axis.x = activatorRect.left;
|
|
118
|
+
}
|
|
119
|
+
if (centered &&
|
|
120
|
+
activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
|
|
121
|
+
activatorRect.top + elementRect.height < innerHeight.current) {
|
|
122
|
+
axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
|
|
123
|
+
}
|
|
124
|
+
else if (activatorRect.bottom + elementRect.height > innerHeight.current) {
|
|
125
|
+
axis.y = activatorRect.top - elementRect.height;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
axis.y = activatorRect.bottom;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Component, PropValue, RoundedType } from '../../utils/types/index.js';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
export type PositionElement = {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
location: 'top' | 'bottom' | 'left' | 'right' | null;
|
|
7
|
+
};
|
|
8
|
+
export type ModelPopoverProps = {
|
|
9
|
+
toggle: (element: HTMLElement | null) => void;
|
|
10
|
+
};
|
|
11
|
+
export interface PopoverProps extends Component {
|
|
12
|
+
ref?: HTMLElement | null;
|
|
13
|
+
open?: boolean;
|
|
14
|
+
dark?: boolean;
|
|
15
|
+
light?: boolean;
|
|
16
|
+
rounded?: RoundedType | string;
|
|
17
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
18
|
+
color?: string;
|
|
19
|
+
background?: string;
|
|
20
|
+
activator?: Snippet<[ModelPopoverProps]>;
|
|
21
|
+
[key: string]: PropValue | Record<string, PropValue> | unknown;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy } from 'svelte';
|
|
3
|
+
import { useClassName, useStyles } from '../../utils/index.js';
|
|
4
|
+
import { makeComponentProps } from '../../compiler/mapped-code.js';
|
|
5
|
+
import { getPositionsTooltip } from './tooltip.svelte.js';
|
|
6
|
+
import type { TooltipProps } from './tooltip.types.js';
|
|
7
|
+
|
|
8
|
+
let {
|
|
9
|
+
ref = $bindable(),
|
|
10
|
+
children,
|
|
11
|
+
tooltip,
|
|
12
|
+
open = $bindable(false),
|
|
13
|
+
forceMount = false,
|
|
14
|
+
label,
|
|
15
|
+
dark = false,
|
|
16
|
+
light = false,
|
|
17
|
+
rounded,
|
|
18
|
+
color,
|
|
19
|
+
background,
|
|
20
|
+
location = 'bottom',
|
|
21
|
+
delayDuration = 850,
|
|
22
|
+
density = 'default',
|
|
23
|
+
variant,
|
|
24
|
+
disabled = false,
|
|
25
|
+
avoidCollisions = true,
|
|
26
|
+
class: className = '',
|
|
27
|
+
style: styleAttr = '',
|
|
28
|
+
's-class': sClass,
|
|
29
|
+
's-style': sStyle,
|
|
30
|
+
...rest
|
|
31
|
+
}: TooltipProps = $props();
|
|
32
|
+
|
|
33
|
+
let safeLocation = $derived(
|
|
34
|
+
location === 'top' || location === 'bottom' || location === 'left' || location === 'right'
|
|
35
|
+
? location
|
|
36
|
+
: 'bottom'
|
|
37
|
+
);
|
|
38
|
+
let safeDensity = $derived(
|
|
39
|
+
density === 'compact' || density === 'comfortable' || density === 'default'
|
|
40
|
+
? density
|
|
41
|
+
: 'default'
|
|
42
|
+
);
|
|
43
|
+
let safeVariant = $derived(variant === 'arrow' ? 'arrow' : undefined);
|
|
44
|
+
|
|
45
|
+
let { classProps, styleProps, restProps } = $derived(
|
|
46
|
+
makeComponentProps(rest as Record<string, unknown>)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
let triggerClass = $derived(
|
|
50
|
+
useClassName({
|
|
51
|
+
baseClass: 'kit-tooltip-trigger',
|
|
52
|
+
className: '',
|
|
53
|
+
sClass,
|
|
54
|
+
classProps
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
let componentClass = $derived(
|
|
59
|
+
useClassName({
|
|
60
|
+
baseClass: 'kit-tooltip__content',
|
|
61
|
+
className: `${className ?? ''}`.trim()
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
let componentStyle = $derived(
|
|
66
|
+
useStyles({
|
|
67
|
+
styleAttr,
|
|
68
|
+
sStyle,
|
|
69
|
+
styleProps
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
let mergedStyle = $derived(
|
|
74
|
+
[
|
|
75
|
+
componentStyle,
|
|
76
|
+
background ? `--kit-tooltip-background:${background}` : '',
|
|
77
|
+
color ? `--kit-tooltip-color:${color}` : '',
|
|
78
|
+
typeof rounded === 'string' && rounded.includes('px') ? `--kit-tooltip-radius:${rounded}` : ''
|
|
79
|
+
]
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.join('; ')
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const positioner = getPositionsTooltip();
|
|
85
|
+
|
|
86
|
+
let triggerRef = $state<HTMLElement | null>(null);
|
|
87
|
+
let tooltipRef = $state<HTMLElement | null>(null);
|
|
88
|
+
let axis = $state(positioner.values);
|
|
89
|
+
let timer = $state<ReturnType<typeof setTimeout> | null>(null);
|
|
90
|
+
let innerHeight = $state(0);
|
|
91
|
+
let innerWidth = $state(0);
|
|
92
|
+
let scrollX = $state(0);
|
|
93
|
+
let scrollY = $state(0);
|
|
94
|
+
const tooltipId = `kit-tooltip-${Math.random().toString(36).slice(2, 10)}`;
|
|
95
|
+
|
|
96
|
+
const clearTimer = () => {
|
|
97
|
+
if (timer) {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
timer = null;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const updatePosition = () => {
|
|
104
|
+
if (!triggerRef || !tooltipRef) return;
|
|
105
|
+
positioner.update(triggerRef, tooltipRef, safeLocation, true, avoidCollisions);
|
|
106
|
+
axis = positioner.values;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const handleHoverOpen = () => {
|
|
110
|
+
if (disabled) {
|
|
111
|
+
open = false;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
clearTimer();
|
|
116
|
+
timer = setTimeout(() => {
|
|
117
|
+
open = true;
|
|
118
|
+
timer = null;
|
|
119
|
+
}, delayDuration);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const handleFocusOpen = () => {
|
|
123
|
+
if (disabled) {
|
|
124
|
+
open = false;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
clearTimer();
|
|
129
|
+
open = true;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const handleClose = () => {
|
|
133
|
+
clearTimer();
|
|
134
|
+
open = false;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const handleKeydown = (event: KeyboardEvent) => {
|
|
138
|
+
if (event.key === 'Escape') handleClose();
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
$effect(() => {
|
|
142
|
+
if (tooltip) forceMount = true;
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
$effect(() => {
|
|
146
|
+
if (disabled) open = false;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
$effect(() => {
|
|
150
|
+
if (open && triggerRef && tooltipRef) {
|
|
151
|
+
updatePosition();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
$effect(() => {
|
|
156
|
+
if (
|
|
157
|
+
open &&
|
|
158
|
+
triggerRef &&
|
|
159
|
+
tooltipRef &&
|
|
160
|
+
(scrollX > 0 || scrollY > 0 || innerHeight > 0 || innerWidth > 0)
|
|
161
|
+
) {
|
|
162
|
+
updatePosition();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
$effect(() => {
|
|
167
|
+
ref = triggerRef;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
onDestroy(() => {
|
|
171
|
+
clearTimer();
|
|
172
|
+
});
|
|
173
|
+
</script>
|
|
174
|
+
|
|
175
|
+
<svelte:window bind:innerHeight bind:innerWidth bind:scrollX bind:scrollY />
|
|
176
|
+
|
|
177
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
178
|
+
<span
|
|
179
|
+
bind:this={triggerRef}
|
|
180
|
+
class={triggerClass}
|
|
181
|
+
style="display:inline-flex"
|
|
182
|
+
aria-describedby={open ? tooltipId : undefined}
|
|
183
|
+
onmouseenter={handleHoverOpen}
|
|
184
|
+
onmouseleave={handleClose}
|
|
185
|
+
onfocusin={handleFocusOpen}
|
|
186
|
+
onfocusout={handleClose}
|
|
187
|
+
onkeydown={handleKeydown}
|
|
188
|
+
>
|
|
189
|
+
{@render children?.()}
|
|
190
|
+
</span>
|
|
191
|
+
|
|
192
|
+
{#if open || forceMount}
|
|
193
|
+
<div
|
|
194
|
+
bind:this={tooltipRef}
|
|
195
|
+
class="kit-tooltip"
|
|
196
|
+
id={tooltipId}
|
|
197
|
+
role="tooltip"
|
|
198
|
+
aria-label={label}
|
|
199
|
+
style={`transform: translate(${axis.x}px, ${axis.y}px); display:${open ? 'block' : 'none'}`}
|
|
200
|
+
>
|
|
201
|
+
<div
|
|
202
|
+
class={componentClass}
|
|
203
|
+
style={mergedStyle}
|
|
204
|
+
data-density={safeDensity}
|
|
205
|
+
data-location={axis.location ?? safeLocation}
|
|
206
|
+
data-variant={safeVariant}
|
|
207
|
+
data-light={light || undefined}
|
|
208
|
+
data-dark={dark || undefined}
|
|
209
|
+
data-rounded={rounded}
|
|
210
|
+
{...restProps}
|
|
211
|
+
>
|
|
212
|
+
{#if tooltip}
|
|
213
|
+
{@render tooltip?.()}
|
|
214
|
+
{:else}
|
|
215
|
+
{label}
|
|
216
|
+
{/if}
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
{/if}
|
|
220
|
+
|
|
221
|
+
<style>
|
|
222
|
+
.kit-tooltip-trigger {
|
|
223
|
+
display: inline-flex;
|
|
224
|
+
width: fit-content;
|
|
225
|
+
max-width: max-content;
|
|
226
|
+
justify-self: start;
|
|
227
|
+
align-self: start;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.kit-tooltip-trigger:focus-visible {
|
|
231
|
+
outline: 2px solid var(--kit-focus);
|
|
232
|
+
outline-offset: 2px;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.kit-tooltip {
|
|
236
|
+
position: fixed;
|
|
237
|
+
inset: 0 auto auto 0;
|
|
238
|
+
z-index: 2000;
|
|
239
|
+
margin: 0;
|
|
240
|
+
pointer-events: none;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.kit-tooltip__content {
|
|
244
|
+
--kit-tooltip-background: var(--kit-surface-3);
|
|
245
|
+
--kit-tooltip-color: var(--kit-fg);
|
|
246
|
+
--kit-tooltip-radius: 8px;
|
|
247
|
+
--kit-tooltip-border: color-mix(in oklab, var(--kit-tooltip-background), black 8%);
|
|
248
|
+
--kit-tooltip-py: 0.15rem;
|
|
249
|
+
--kit-tooltip-px: 0.625rem;
|
|
250
|
+
|
|
251
|
+
position: relative;
|
|
252
|
+
display: inline-block;
|
|
253
|
+
width: max-content;
|
|
254
|
+
max-width: min(20rem, calc(100vw - 1rem));
|
|
255
|
+
padding: var(--kit-tooltip-py) var(--kit-tooltip-px);
|
|
256
|
+
border: 1px solid var(--kit-tooltip-border);
|
|
257
|
+
border-radius: var(--kit-tooltip-radius);
|
|
258
|
+
background: var(--kit-tooltip-background);
|
|
259
|
+
color: var(--kit-tooltip-color);
|
|
260
|
+
font-size: 0.875rem;
|
|
261
|
+
overflow-wrap: break-word;
|
|
262
|
+
box-shadow: 0 16px 29px -10px color-mix(in oklab, black 18%, transparent);
|
|
263
|
+
animation: kit-tooltip-enter 150ms ease;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.kit-tooltip__content[data-density='compact'] {
|
|
267
|
+
--kit-tooltip-py: 0.125rem;
|
|
268
|
+
--kit-tooltip-px: 0.5rem;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.kit-tooltip__content[data-density='comfortable'] {
|
|
272
|
+
--kit-tooltip-py: 0.35rem;
|
|
273
|
+
--kit-tooltip-px: 0.75rem;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.kit-tooltip__content[data-light='true'] {
|
|
277
|
+
--kit-tooltip-background: color-mix(in oklab, white 92%, var(--kit-surface-1));
|
|
278
|
+
--kit-tooltip-color: var(--kit-fg);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.kit-tooltip__content[data-dark='true'] {
|
|
282
|
+
--kit-tooltip-background: color-mix(in oklab, black 76%, var(--kit-surface-3));
|
|
283
|
+
--kit-tooltip-color: white;
|
|
284
|
+
--kit-tooltip-border: color-mix(in oklab, white, transparent 78%);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.kit-tooltip__content[data-rounded='0'] {
|
|
288
|
+
--kit-tooltip-radius: 0;
|
|
289
|
+
}
|
|
290
|
+
.kit-tooltip__content[data-rounded='xs'] {
|
|
291
|
+
--kit-tooltip-radius: 2px;
|
|
292
|
+
}
|
|
293
|
+
.kit-tooltip__content[data-rounded='sm'] {
|
|
294
|
+
--kit-tooltip-radius: 4px;
|
|
295
|
+
}
|
|
296
|
+
.kit-tooltip__content[data-rounded='md'] {
|
|
297
|
+
--kit-tooltip-radius: 8px;
|
|
298
|
+
}
|
|
299
|
+
.kit-tooltip__content[data-rounded='lg'] {
|
|
300
|
+
--kit-tooltip-radius: 16px;
|
|
301
|
+
}
|
|
302
|
+
.kit-tooltip__content[data-rounded='xl'] {
|
|
303
|
+
--kit-tooltip-radius: 99999px;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.kit-tooltip__content[data-variant='arrow']::after {
|
|
307
|
+
content: '';
|
|
308
|
+
position: absolute;
|
|
309
|
+
border-style: solid;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='bottom']::after,
|
|
313
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='top']::after {
|
|
314
|
+
left: 50%;
|
|
315
|
+
margin-left: -0.35rem;
|
|
316
|
+
border-width: 0.35rem;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='bottom']::after {
|
|
320
|
+
bottom: 100%;
|
|
321
|
+
border-color: transparent transparent var(--kit-tooltip-background) transparent;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='top']::after {
|
|
325
|
+
top: 100%;
|
|
326
|
+
border-color: var(--kit-tooltip-background) transparent transparent transparent;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='left']::after,
|
|
330
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='right']::after {
|
|
331
|
+
top: 50%;
|
|
332
|
+
margin-top: -0.35rem;
|
|
333
|
+
border-width: 0.35rem;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='right']::after {
|
|
337
|
+
right: 100%;
|
|
338
|
+
border-color: transparent var(--kit-tooltip-background) transparent transparent;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.kit-tooltip__content[data-variant='arrow'][data-location='left']::after {
|
|
342
|
+
left: 100%;
|
|
343
|
+
border-color: transparent transparent transparent var(--kit-tooltip-background);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
.kit-tooltip__content[data-location='top'] {
|
|
347
|
+
--kit-tooltip-enter-x: 0;
|
|
348
|
+
--kit-tooltip-enter-y: 0.5rem;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
.kit-tooltip__content[data-location='bottom'] {
|
|
352
|
+
--kit-tooltip-enter-x: 0;
|
|
353
|
+
--kit-tooltip-enter-y: -0.5rem;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.kit-tooltip__content[data-location='right'] {
|
|
357
|
+
--kit-tooltip-enter-x: -0.5rem;
|
|
358
|
+
--kit-tooltip-enter-y: 0;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.kit-tooltip__content[data-location='left'] {
|
|
362
|
+
--kit-tooltip-enter-x: 0.5rem;
|
|
363
|
+
--kit-tooltip-enter-y: 0;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
@keyframes kit-tooltip-enter {
|
|
367
|
+
from {
|
|
368
|
+
opacity: 0;
|
|
369
|
+
transform: translate(var(--kit-tooltip-enter-x, 0), var(--kit-tooltip-enter-y, 0)) scale(0.95);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
</style>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { innerWidth, innerHeight } from 'svelte/reactivity/window';
|
|
2
|
+
export function getPositionsTooltip() {
|
|
3
|
+
// state
|
|
4
|
+
const axis = $state({
|
|
5
|
+
x: 0,
|
|
6
|
+
y: 0,
|
|
7
|
+
location: null
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
get values() {
|
|
11
|
+
return axis;
|
|
12
|
+
},
|
|
13
|
+
update(activator, element, location, centered, avoidCollisions) {
|
|
14
|
+
if (!activator || !element)
|
|
15
|
+
return;
|
|
16
|
+
const elementRect = element.getBoundingClientRect();
|
|
17
|
+
const activatorRect = activator.getBoundingClientRect();
|
|
18
|
+
const spacing = 6;
|
|
19
|
+
if (location === 'top' || location === 'bottom') {
|
|
20
|
+
if (avoidCollisions) {
|
|
21
|
+
if (location === 'top') {
|
|
22
|
+
if (activatorRect.y - (elementRect.height + spacing) < 0) {
|
|
23
|
+
axis.y = activatorRect.bottom + spacing;
|
|
24
|
+
axis.location = 'bottom';
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
axis.y = activatorRect.top - (elementRect.height + spacing);
|
|
28
|
+
axis.location = 'top';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
if (activatorRect.y + activatorRect.height + (elementRect.height + spacing) >
|
|
33
|
+
innerHeight.current) {
|
|
34
|
+
axis.y = activatorRect.top - (elementRect.height + spacing);
|
|
35
|
+
axis.location = 'top';
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
axis.y = activatorRect.bottom + spacing;
|
|
39
|
+
axis.location = 'bottom';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (location === 'top') {
|
|
45
|
+
axis.y = activatorRect.top - (elementRect.height + spacing);
|
|
46
|
+
axis.location = 'top';
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
axis.y = activatorRect.bottom + spacing;
|
|
50
|
+
axis.location = 'bottom';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (centered &&
|
|
54
|
+
activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
|
|
55
|
+
activatorRect.left + elementRect.width < innerWidth.current) {
|
|
56
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
|
|
57
|
+
}
|
|
58
|
+
else if (activatorRect.left + elementRect.width > innerWidth.current) {
|
|
59
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
axis.x = activatorRect.left;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (location === 'left' || location === 'right') {
|
|
66
|
+
if (avoidCollisions) {
|
|
67
|
+
if (location === 'left' && !(activatorRect.left - elementRect.width < 0)) {
|
|
68
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
69
|
+
axis.location = 'left';
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
if (activatorRect.left + activatorRect.width + elementRect.width + spacing >
|
|
73
|
+
innerWidth.current) {
|
|
74
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
75
|
+
axis.location = 'left';
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
axis.x = activatorRect.left + activatorRect.width + spacing;
|
|
79
|
+
axis.location = 'right';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (location === 'left') {
|
|
85
|
+
axis.x = activatorRect.left - (elementRect.width + spacing);
|
|
86
|
+
axis.location = 'left';
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
axis.x = activatorRect.left + activatorRect.width + spacing;
|
|
90
|
+
axis.location = 'right';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (centered &&
|
|
94
|
+
activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
|
|
95
|
+
activatorRect.top + elementRect.height < innerHeight.current) {
|
|
96
|
+
axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
|
|
97
|
+
}
|
|
98
|
+
else if (activatorRect.y + elementRect.height > innerHeight.current) {
|
|
99
|
+
axis.y = activatorRect.y - elementRect.height + activatorRect.height;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
axis.y = activatorRect.y;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
if (centered &&
|
|
107
|
+
activatorRect.left - (elementRect.width - activatorRect.width) / 2 > 0 &&
|
|
108
|
+
activatorRect.left + elementRect.width < innerWidth.current) {
|
|
109
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width) / 2;
|
|
110
|
+
}
|
|
111
|
+
else if (activatorRect.left + elementRect.width > innerWidth.current) {
|
|
112
|
+
axis.x = activatorRect.left - (elementRect.width - activatorRect.width);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
axis.x = activatorRect.left;
|
|
116
|
+
}
|
|
117
|
+
if (centered &&
|
|
118
|
+
activatorRect.top - (elementRect.height - activatorRect.height) / 2 > 0 &&
|
|
119
|
+
activatorRect.top + elementRect.height < innerHeight.current) {
|
|
120
|
+
axis.y = activatorRect.top - (elementRect.height - activatorRect.height) / 2;
|
|
121
|
+
}
|
|
122
|
+
else if (activatorRect.bottom + elementRect.height > innerHeight.current) {
|
|
123
|
+
axis.y = activatorRect.top - elementRect.height;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
axis.y = activatorRect.bottom;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Component, PropValue, RoundedType } from '../../utils/types/index.js';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
export interface TooltipProps extends Component {
|
|
4
|
+
ref?: HTMLElement | null;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
forceMount?: boolean;
|
|
7
|
+
dark?: boolean;
|
|
8
|
+
light?: boolean;
|
|
9
|
+
rounded?: RoundedType | string;
|
|
10
|
+
label?: string;
|
|
11
|
+
location?: 'top' | 'bottom' | 'left' | 'right';
|
|
12
|
+
color?: string;
|
|
13
|
+
background?: string;
|
|
14
|
+
delayDuration?: number;
|
|
15
|
+
variant?: 'arrow';
|
|
16
|
+
density?: 'compact' | 'comfortable' | 'default';
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
avoidCollisions?: boolean;
|
|
19
|
+
tooltip?: Snippet;
|
|
20
|
+
[key: string]: PropValue | Record<string, PropValue> | unknown;
|
|
21
|
+
}
|
|
22
|
+
export type PositionElement = {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
location: 'top' | 'bottom' | 'left' | 'right' | null;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|