flowbite-svelte 0.22.29 → 0.22.30
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/tooltips/Tooltip.svelte +46 -40
- package/tooltips/Tooltip.svelte.d.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.22.30](https://github.com/themesberg/flowbite-svelte/compare/v0.22.29...v0.22.30) (2022-08-03)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add Tooltip custom CSS ([1466d16](https://github.com/themesberg/flowbite-svelte/commit/1466d16fff312ccdb22e1c282f49b7b156121d57))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* revert Tooltip component ([9cedc68](https://github.com/themesberg/flowbite-svelte/commit/9cedc68014a7114c0e15691c26081bb9f5af88af))
|
|
16
|
+
|
|
5
17
|
### [0.22.29](https://github.com/themesberg/flowbite-svelte/compare/v0.22.28...v0.22.29) (2022-08-02)
|
|
6
18
|
|
|
7
19
|
|
package/package.json
CHANGED
package/tooltips/Tooltip.svelte
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
<script>import
|
|
2
|
-
import classNames from 'classnames';
|
|
1
|
+
<script>import classNames from 'classnames';
|
|
3
2
|
import { clickOutside } from '../utils/clickOutside';
|
|
4
3
|
import { computePosition, flip, shift, offset, autoPlacement, arrow as arrowFloat } from '@floating-ui/dom';
|
|
4
|
+
import { onDestroy } from 'svelte';
|
|
5
5
|
export let placement = 'top';
|
|
6
6
|
export let trigger = 'hover';
|
|
7
7
|
export let style = 'dark';
|
|
8
8
|
export let content = '';
|
|
9
9
|
export let animation = 'duration-300';
|
|
10
10
|
export let arrow = true;
|
|
11
|
+
export let tipClass = 'absolute inline-block rounded-lg py-2 px-3 text-sm font-medium shadow-sm';
|
|
12
|
+
export let tipColor = '';
|
|
13
|
+
const tipStyleClasses = {
|
|
14
|
+
dark: 'bg-gray-900 text-white dark:bg-gray-700',
|
|
15
|
+
light: 'border border-gray-200 bg-white text-gray-900',
|
|
16
|
+
auto: 'border border-gray-200 bg-white text-gray-900 dark:border-none dark:bg-gray-700 dark:text-white',
|
|
17
|
+
custom: tipColor
|
|
18
|
+
};
|
|
19
|
+
const arrowStyleClasses = {
|
|
20
|
+
dark: 'bg-gray-900 dark:bg-gray-700',
|
|
21
|
+
light: 'bg-white',
|
|
22
|
+
auto: 'bg-white dark:bg-gray-700',
|
|
23
|
+
custom: tipColor
|
|
24
|
+
};
|
|
25
|
+
let toolTipClass;
|
|
26
|
+
$: toolTipClass = classNames(tipClass, animation !== false && `transition-opacity ${animation}`, {
|
|
27
|
+
'invisible opacity-0': !open
|
|
28
|
+
}, tipStyleClasses[style], $$props.class);
|
|
11
29
|
let open = false;
|
|
12
30
|
const floatingPlacement = ({ placement }) => {
|
|
13
31
|
return placement === 'auto' ? undefined : placement;
|
|
@@ -23,26 +41,25 @@ const floatingArrowPlacement = ({ placement }) => {
|
|
|
23
41
|
left: 'right'
|
|
24
42
|
}[placement.split('-')[0]];
|
|
25
43
|
};
|
|
44
|
+
const floatingMiddleware = ({ arrowRef, placement }) => {
|
|
45
|
+
const middleware = [];
|
|
46
|
+
middleware.push(offset(8));
|
|
47
|
+
middleware.push(placement === 'auto' ? autoPlacement() : flip());
|
|
48
|
+
middleware.push(shift({ padding: 8 }));
|
|
49
|
+
if (arrowRef) {
|
|
50
|
+
middleware.push(arrowFloat({ element: arrowRef }));
|
|
51
|
+
}
|
|
52
|
+
return middleware;
|
|
53
|
+
};
|
|
26
54
|
let placementData;
|
|
27
55
|
let tooltipRef, triggerRef, arrowRef;
|
|
56
|
+
const updatePosition = () => computePosition(triggerRef, tooltipRef, {
|
|
57
|
+
middleware: floatingMiddleware({ arrowRef, placement }),
|
|
58
|
+
placement: floatingPlacement({ placement })
|
|
59
|
+
}).then((data) => (placementData = data));
|
|
28
60
|
let attachedScroll = false;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const floatingMiddleware = ({ arrowRef, placement }) => {
|
|
32
|
-
const middleware = [];
|
|
33
|
-
middleware.push(offset(8));
|
|
34
|
-
middleware.push(placement === 'auto' ? autoPlacement() : flip());
|
|
35
|
-
middleware.push(shift({ padding: 8 }));
|
|
36
|
-
if (arrowRef) {
|
|
37
|
-
middleware.push(arrowFloat({ element: arrowRef }));
|
|
38
|
-
}
|
|
39
|
-
return middleware;
|
|
40
|
-
};
|
|
41
|
-
const updatePosition = () => computePosition(triggerRef, tooltipRef, {
|
|
42
|
-
middleware: floatingMiddleware({ arrowRef, placement }),
|
|
43
|
-
placement: floatingPlacement({ placement })
|
|
44
|
-
}).then((data) => (placementData = data));
|
|
45
|
-
tooltipRef && open && updatePosition();
|
|
61
|
+
$: tooltipRef && open && updatePosition();
|
|
62
|
+
$: {
|
|
46
63
|
if (open && !attachedScroll) {
|
|
47
64
|
attachedScroll = true;
|
|
48
65
|
window.addEventListener('scroll', updatePosition, true);
|
|
@@ -51,13 +68,17 @@ onMount(async () => {
|
|
|
51
68
|
attachedScroll = false;
|
|
52
69
|
window.removeEventListener('scroll', updatePosition, true);
|
|
53
70
|
}
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
}
|
|
72
|
+
onDestroy(() => {
|
|
73
|
+
if (attachedScroll) {
|
|
74
|
+
attachedScroll = false;
|
|
75
|
+
window.removeEventListener('scroll', updatePosition, true);
|
|
76
|
+
}
|
|
56
77
|
});
|
|
57
|
-
// console.log('placement', placement);
|
|
58
|
-
// console.log('floatingPlacement', floatingPlacement({ placement }));
|
|
59
78
|
</script>
|
|
60
79
|
|
|
80
|
+
<svelte:window on:resize={() => open && updatePosition()} />
|
|
81
|
+
|
|
61
82
|
<div
|
|
62
83
|
use:clickOutside={() => {
|
|
63
84
|
if (open) {
|
|
@@ -90,18 +111,7 @@ onMount(async () => {
|
|
|
90
111
|
<div
|
|
91
112
|
bind:this={tooltipRef}
|
|
92
113
|
data-testid="tooltip"
|
|
93
|
-
class={
|
|
94
|
-
'absolute inline-block rounded-lg py-2 px-3 text-sm font-medium shadow-sm',
|
|
95
|
-
animation !== false && `transition-opacity ${animation}`,
|
|
96
|
-
{
|
|
97
|
-
'invisible opacity-0': !open,
|
|
98
|
-
'bg-gray-900 text-white dark:bg-gray-700': style === 'dark',
|
|
99
|
-
'border border-gray-200 bg-white text-gray-900': style === 'light',
|
|
100
|
-
'border border-gray-200 bg-white text-gray-900 dark:border-none dark:bg-gray-700 dark:text-white':
|
|
101
|
-
style === 'auto'
|
|
102
|
-
},
|
|
103
|
-
$$props.class
|
|
104
|
-
)}
|
|
114
|
+
class={toolTipClass}
|
|
105
115
|
style={`left:${placementData?.x}px;top:${placementData?.y}px;position:${placementData?.strategy}`}
|
|
106
116
|
>
|
|
107
117
|
<div class="relative z-20">
|
|
@@ -111,11 +121,7 @@ onMount(async () => {
|
|
|
111
121
|
</div>
|
|
112
122
|
{#if arrow}
|
|
113
123
|
<div
|
|
114
|
-
class={classNames('absolute z-10 h-2 w-2 rotate-45',
|
|
115
|
-
'bg-gray-900 dark:bg-gray-700': style === 'dark',
|
|
116
|
-
'bg-white': style === 'light',
|
|
117
|
-
'bg-white dark:bg-gray-700': style === 'auto'
|
|
118
|
-
})}
|
|
124
|
+
class={classNames('absolute z-10 h-2 w-2 rotate-45', arrowStyleClasses[style])}
|
|
119
125
|
data-testid="tooltip-arrow"
|
|
120
126
|
style={`left:${placementData?.middlewareData.arrow?.x}px;top:${
|
|
121
127
|
placementData?.middlewareData.arrow?.y
|
|
@@ -5,10 +5,12 @@ declare const __propDef: {
|
|
|
5
5
|
[x: string]: any;
|
|
6
6
|
placement?: 'auto' | Placement;
|
|
7
7
|
trigger?: 'hover' | 'click';
|
|
8
|
-
style?: 'dark' | 'light' | 'auto';
|
|
8
|
+
style?: 'dark' | 'light' | 'auto' | 'custom';
|
|
9
9
|
content?: string;
|
|
10
10
|
animation?: false | `duration-${number}`;
|
|
11
11
|
arrow?: boolean;
|
|
12
|
+
tipClass?: string;
|
|
13
|
+
tipColor?: string;
|
|
12
14
|
};
|
|
13
15
|
events: {
|
|
14
16
|
[evt: string]: CustomEvent<any>;
|