zero-tooltip 1.0.8 → 1.0.9
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/README.md +15 -12
- package/dist/composables/useHideOnResize.d.ts +4 -0
- package/dist/composables/useHideOnScroll.d.ts +3 -0
- package/dist/index.d.ts +11 -36
- package/dist/style.css +1 -0
- package/dist/tooltip.d.ts +4 -0
- package/dist/types/tooltipConfig.d.ts +18 -0
- package/dist/types/tooltipLocalConfig.d.ts +6 -0
- package/dist/types/tooltipPosition.d.ts +2 -0
- package/dist/types/tooltipPositions.d.ts +8 -0
- package/dist/zero-tooltip.js +30 -25
- package/dist/zero-tooltip.umd.cjs +1 -1
- package/package.json +4 -6
- package/src/composables/useHideOnResize.ts +36 -36
- package/src/composables/useHideOnScroll.ts +49 -49
- package/src/index.ts +20 -13
- package/src/tooltip.ts +533 -533
- package/src/types/tooltipConfig.ts +19 -19
- package/src/types/tooltipLocalConfig.ts +7 -7
- package/src/types/tooltipPosition.ts +4 -4
- package/src/types/tooltipPositions.ts +10 -10
- /package/{dist/styles.css → src/style.css} +0 -0
package/README.md
CHANGED
|
@@ -10,23 +10,26 @@ The component is designed to enhance user interactions by providing informative
|
|
|
10
10
|
```bash
|
|
11
11
|
# npm
|
|
12
12
|
npm install zero-tooltip
|
|
13
|
+
|
|
13
14
|
# yarn
|
|
14
15
|
yarn add zero-tooltip
|
|
16
|
+
|
|
17
|
+
# pnpm
|
|
18
|
+
pnpm install zero-tooltip
|
|
15
19
|
```
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
Register plugin in `main.ts`:
|
|
18
22
|
```ts
|
|
19
23
|
import ZeroTooltip from 'zero-tooltip'
|
|
20
|
-
|
|
21
|
-
import '../node_modules/zero-tooltip/dist/styles.css'
|
|
22
|
-
// register directive
|
|
24
|
+
|
|
23
25
|
const app = createApp(App)
|
|
24
|
-
|
|
26
|
+
|
|
27
|
+
app.use(ZeroTooltip())
|
|
25
28
|
```
|
|
26
29
|
|
|
27
30
|
## Usage
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
Tooltip can be used with directive `v-tooltip` added on elements.
|
|
30
33
|
The given value is displayed as tooltip's text:
|
|
31
34
|
|
|
32
35
|
```html
|
|
@@ -43,17 +46,17 @@ Default position for tooltip is above/on top of the element that is being hovere
|
|
|
43
46
|
<button v-tooltip:right="'Submits this form'">Submit</button>
|
|
44
47
|
```
|
|
45
48
|
|
|
46
|
-
Acceptable arguments are: `left` | `top` | `right` | `bottom`.
|
|
49
|
+
Acceptable arguments are: `left` | `top` | `right` | `bottom`. This will override tooltip default position that was set during plugin registering process.
|
|
47
50
|
|
|
48
|
-
You can also define default position globally when registering
|
|
51
|
+
You can also define default position globally when registering plugin:
|
|
49
52
|
|
|
50
53
|
```ts
|
|
51
|
-
app.
|
|
54
|
+
app.use(ZeroTooltip({
|
|
52
55
|
defaultPosition: 'right'
|
|
53
56
|
}))
|
|
54
57
|
```
|
|
55
58
|
|
|
56
|
-
Tooltip component is fully customizable by giving config object when
|
|
59
|
+
Tooltip component is fully customizable by giving config object as options when registering tooltip plugin:
|
|
57
60
|
```ts
|
|
58
61
|
import ZeroTooltipConfig from 'zero-tooltip'
|
|
59
62
|
|
|
@@ -73,7 +76,7 @@ const tooltipConfig: ZeroTooltipConfig = {
|
|
|
73
76
|
zIndex: ...
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
app.
|
|
79
|
+
app.use(ZeroTooltip(tooltipConfig))
|
|
77
80
|
```
|
|
78
81
|
|
|
79
82
|
All above settings are optional.
|
|
@@ -88,7 +91,7 @@ Tooltip can be customizable also for each usage (locally) using same config as f
|
|
|
88
91
|
import ZeroTooltipLocalConfig from 'zero-tooltip'
|
|
89
92
|
|
|
90
93
|
const tooltipConfig: ZeroTooltipLocalConfig = reactive({
|
|
91
|
-
content: 'This is tooltip'
|
|
94
|
+
content: 'This is tooltip',
|
|
92
95
|
defaultPosition: ... ,
|
|
93
96
|
positions: ... ,
|
|
94
97
|
offsetFromSource: ... ,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
maxWidth?: number;
|
|
13
|
-
tooltipBorderWidth?: number;
|
|
14
|
-
tooltipClasses?: string;
|
|
15
|
-
textClasses?: string;
|
|
16
|
-
arrowSize?: number;
|
|
17
|
-
arrowClasses?: string;
|
|
18
|
-
arrowMinOffsetFromTooltipCorner?: number;
|
|
19
|
-
zIndex?: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export declare type ZeroTooltipLocalConfig = {
|
|
23
|
-
content: string;
|
|
24
|
-
show?: boolean;
|
|
25
|
-
} & ZeroTooltipConfig;
|
|
26
|
-
|
|
27
|
-
export declare type ZeroTooltipPosition = 'left' | 'top' | 'right' | 'bottom';
|
|
28
|
-
|
|
29
|
-
export declare type ZeroTooltipPositions = {
|
|
30
|
-
left: [ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition];
|
|
31
|
-
top: [ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition];
|
|
32
|
-
right: [ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition];
|
|
33
|
-
bottom: [ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition, ZeroTooltipPosition];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export { }
|
|
1
|
+
import './style.css';
|
|
2
|
+
import { App } from 'vue';
|
|
3
|
+
import TooltipConfig from "./types/tooltipConfig";
|
|
4
|
+
import TooltipLocalConfig from "./types/tooltipLocalConfig";
|
|
5
|
+
import TooltipPosition from "./types/tooltipPosition";
|
|
6
|
+
import TooltipPositions from "./types/tooltipPositions";
|
|
7
|
+
declare const _default: {
|
|
8
|
+
install: (app: App, options?: TooltipConfig) => void;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
11
|
+
export type { TooltipConfig as ZeroTooltipConfig, TooltipPosition as ZeroTooltipPosition, TooltipPositions as ZeroTooltipPositions, TooltipLocalConfig as ZeroTooltipLocalConfig };
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.zt-fixed{position:fixed}.zt-absolute{position:absolute}.zt-box-border{box-sizing:border-box}.zt-inline-block{display:inline-block}.zt-h-\[2000px\]{height:2000px}.zt-w-fit{width:-moz-fit-content;width:fit-content}.zt-w-full{width:100%}.zt-whitespace-pre-wrap{white-space:pre-wrap}.zt-break-words{overflow-wrap:break-word}.zt-rounded-md{border-radius:.375rem}.zt-border-solid{border-style:solid}.zt-border-\[\#495057\]{--tw-border-opacity:1;border-color:rgb(73 80 87/var(--tw-border-opacity))}.\!zt-border-x-transparent{border-left-color:#0000!important;border-right-color:#0000!important}.\!zt-border-y-transparent{border-top-color:#0000!important}.\!zt-border-b-transparent,.\!zt-border-y-transparent{border-bottom-color:#0000!important}.\!zt-border-l-transparent{border-left-color:#0000!important}.\!zt-border-r-transparent{border-right-color:#0000!important}.\!zt-border-t-transparent{border-top-color:#0000!important}.zt-bg-\[\#495057\]{--tw-bg-opacity:1;background-color:rgb(73 80 87/var(--tw-bg-opacity))}.zt-bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}.zt-px-2{padding-left:.5rem;padding-right:.5rem}.zt-px-2\.5{padding-left:.625rem;padding-right:.625rem}.zt-py-1{padding-top:.25rem;padding-bottom:.25rem}.zt-py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.zt-text-sm{font-size:.875rem;line-height:1.25rem}.zt-text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.zt-opacity-0{opacity:0}.zt-shadow-\[0_2px_12px_0_rgba\(0\,0\,0\,0\.1\)\]{--tw-shadow:0 2px 12px 0 #0000001a;--tw-shadow-colored:0 2px 12px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import TooltipPosition from "./tooltipPosition";
|
|
2
|
+
import TooltipPositions from "./tooltipPositions";
|
|
3
|
+
type TooltipConfig = {
|
|
4
|
+
defaultPosition?: TooltipPosition;
|
|
5
|
+
positions?: Partial<TooltipPositions>;
|
|
6
|
+
offsetFromSource?: number;
|
|
7
|
+
offsetFromViewport?: number;
|
|
8
|
+
minWidth?: number;
|
|
9
|
+
maxWidth?: number;
|
|
10
|
+
tooltipBorderWidth?: number;
|
|
11
|
+
tooltipClasses?: string;
|
|
12
|
+
textClasses?: string;
|
|
13
|
+
arrowSize?: number;
|
|
14
|
+
arrowClasses?: string;
|
|
15
|
+
arrowMinOffsetFromTooltipCorner?: number;
|
|
16
|
+
zIndex?: number;
|
|
17
|
+
};
|
|
18
|
+
export default TooltipConfig;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import TooltipPosition from "./tooltipPosition";
|
|
2
|
+
type TooltipPositions = {
|
|
3
|
+
left: [TooltipPosition, TooltipPosition, TooltipPosition, TooltipPosition];
|
|
4
|
+
top: [TooltipPosition, TooltipPosition, TooltipPosition, TooltipPosition];
|
|
5
|
+
right: [TooltipPosition, TooltipPosition, TooltipPosition, TooltipPosition];
|
|
6
|
+
bottom: [TooltipPosition, TooltipPosition, TooltipPosition, TooltipPosition];
|
|
7
|
+
};
|
|
8
|
+
export default TooltipPositions;
|
package/dist/zero-tooltip.js
CHANGED
|
@@ -77,7 +77,7 @@ const { handleHideOnScroll: ut } = ht(), { handleHideOnResize: mt, resetResizeRe
|
|
|
77
77
|
top: ["top", "bottom", "right", "left"],
|
|
78
78
|
right: ["right", "left", "top", "bottom"],
|
|
79
79
|
bottom: ["bottom", "top", "right", "left"]
|
|
80
|
-
}, R = "top", N = 10, Z = 20, G = 100, J = 250, K = 0, Q = "zt-fixed zt-opacity-0 zt-inline-block zt-w-fit zt-py-1.5 zt-px-2.5 zt-rounded-md zt-bg-[#495057] zt-shadow-[0_2px_12px_0_rgba(0,0,0,0.1)] zt-box-border", X = "zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words", Y = 5, ct = "zt-absolute zt-border-solid zt-border-[#495057]", E = 6, l = 1, b = !0, n = {},
|
|
80
|
+
}, R = "top", N = 10, Z = 20, G = 100, J = 250, K = 0, Q = "zt-fixed zt-opacity-0 zt-inline-block zt-w-fit zt-py-1.5 zt-px-2.5 zt-rounded-md zt-bg-[#495057] zt-shadow-[0_2px_12px_0_rgba(0,0,0,0.1)] zt-box-border", X = "zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words", Y = 5, ct = "zt-absolute zt-border-solid zt-border-[#495057]", E = 6, l = 1, b = !0, n = {}, Ot = (e) => ({
|
|
81
81
|
created: (t, r, s) => {
|
|
82
82
|
const d = pt();
|
|
83
83
|
s.el.$_tooltip = { uuid: d }, V(r.value, e, r.arg, t, d), typeof r.value != "string" && et(r.value) && rt(r.value, (i) => {
|
|
@@ -94,24 +94,24 @@ const { handleHideOnScroll: ut } = ht(), { handleHideOnResize: mt, resetResizeRe
|
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
function V(e, t, r, s, d) {
|
|
97
|
-
let i =
|
|
98
|
-
const o =
|
|
97
|
+
let i = xt(e, t, r);
|
|
98
|
+
const o = Tt(s, i, d);
|
|
99
99
|
n[d] = o, s.matches(":hover") && s.dispatchEvent(new Event("mouseenter"));
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function xt(e, t, r) {
|
|
102
102
|
var a, L, H, $, A, _, I, U, f, k, D, P;
|
|
103
|
-
let s, d, i, o, p, h, u, m, x, O, F, T, W,
|
|
104
|
-
return s =
|
|
103
|
+
let s, d, i, o, p, h, u, m, x, O, F, T, W, v, z;
|
|
104
|
+
return s = Ft(e), typeof e != "string" && (d = r ?? e.defaultPosition ?? (t == null ? void 0 : t.defaultPosition) ?? R, i = {
|
|
105
105
|
left: ((a = e.positions) == null ? void 0 : a.left) ?? ((L = t == null ? void 0 : t.positions) == null ? void 0 : L.left) ?? c.left,
|
|
106
106
|
top: ((H = e.positions) == null ? void 0 : H.top) ?? (($ = t == null ? void 0 : t.positions) == null ? void 0 : $.top) ?? c.top,
|
|
107
107
|
right: ((A = e.positions) == null ? void 0 : A.right) ?? ((_ = t == null ? void 0 : t.positions) == null ? void 0 : _.right) ?? c.right,
|
|
108
108
|
bottom: ((I = e.positions) == null ? void 0 : I.bottom) ?? ((U = t == null ? void 0 : t.positions) == null ? void 0 : U.bottom) ?? c.bottom
|
|
109
|
-
}, o = e.offsetFromSource ?? (t == null ? void 0 : t.offsetFromSource) ?? N, p = e.offsetFromViewport ?? (t == null ? void 0 : t.offsetFromViewport) ?? Z, h = e.minWidth ?? (t == null ? void 0 : t.minWidth) ?? G, u = e.maxWidth ?? (t == null ? void 0 : t.maxWidth) ?? J, m = e.tooltipBorderWidth ?? (t == null ? void 0 : t.tooltipBorderWidth) ?? K, x = y + " " + Q + " " + (e.tooltipClasses ?? (t == null ? void 0 : t.tooltipClasses) ?? ""), O = j + " " + X + " " + (e.textClasses ?? (t == null ? void 0 : t.textClasses) ?? ""), F = e.arrowSize ?? (t == null ? void 0 : t.arrowSize) ?? Y, T = e.arrowClasses ?? (t == null ? void 0 : t.arrowClasses) ?? "", W = e.arrowMinOffsetFromTooltipCorner ?? (t == null ? void 0 : t.arrowMinOffsetFromTooltipCorner) ?? E,
|
|
109
|
+
}, o = e.offsetFromSource ?? (t == null ? void 0 : t.offsetFromSource) ?? N, p = e.offsetFromViewport ?? (t == null ? void 0 : t.offsetFromViewport) ?? Z, h = e.minWidth ?? (t == null ? void 0 : t.minWidth) ?? G, u = e.maxWidth ?? (t == null ? void 0 : t.maxWidth) ?? J, m = e.tooltipBorderWidth ?? (t == null ? void 0 : t.tooltipBorderWidth) ?? K, x = y + " " + Q + " " + (e.tooltipClasses ?? (t == null ? void 0 : t.tooltipClasses) ?? ""), O = j + " " + X + " " + (e.textClasses ?? (t == null ? void 0 : t.textClasses) ?? ""), F = e.arrowSize ?? (t == null ? void 0 : t.arrowSize) ?? Y, T = e.arrowClasses ?? (t == null ? void 0 : t.arrowClasses) ?? "", W = e.arrowMinOffsetFromTooltipCorner ?? (t == null ? void 0 : t.arrowMinOffsetFromTooltipCorner) ?? E, v = e.zIndex ?? (t == null ? void 0 : t.zIndex) ?? l, z = e.show ?? b), d === void 0 && (d = r ?? (t == null ? void 0 : t.defaultPosition) ?? R), i === void 0 && (i = {
|
|
110
110
|
left: ((f = t == null ? void 0 : t.positions) == null ? void 0 : f.left) ?? c.left,
|
|
111
111
|
top: ((k = t == null ? void 0 : t.positions) == null ? void 0 : k.top) ?? c.top,
|
|
112
112
|
right: ((D = t == null ? void 0 : t.positions) == null ? void 0 : D.right) ?? c.right,
|
|
113
113
|
bottom: ((P = t == null ? void 0 : t.positions) == null ? void 0 : P.bottom) ?? c.bottom
|
|
114
|
-
}), o === void 0 && (o = (t == null ? void 0 : t.offsetFromSource) ?? N), p === void 0 && (p = (t == null ? void 0 : t.offsetFromViewport) ?? Z), h === void 0 && (h = (t == null ? void 0 : t.minWidth) ?? G), u === void 0 && (u = (t == null ? void 0 : t.maxWidth) ?? J), m === void 0 && (m = (t == null ? void 0 : t.tooltipBorderWidth) ?? K), x === void 0 && (x = y + " " + Q + " " + ((t == null ? void 0 : t.tooltipClasses) ?? "")), O === void 0 && (O = j + " " + X + " " + ((t == null ? void 0 : t.textClasses) ?? "")), F === void 0 && (F = (t == null ? void 0 : t.arrowSize) ?? Y), T === void 0 && (T = (t == null ? void 0 : t.arrowClasses) ?? ""), W === void 0 && (W = (t == null ? void 0 : t.arrowMinOffsetFromTooltipCorner) ?? E),
|
|
114
|
+
}), o === void 0 && (o = (t == null ? void 0 : t.offsetFromSource) ?? N), p === void 0 && (p = (t == null ? void 0 : t.offsetFromViewport) ?? Z), h === void 0 && (h = (t == null ? void 0 : t.minWidth) ?? G), u === void 0 && (u = (t == null ? void 0 : t.maxWidth) ?? J), m === void 0 && (m = (t == null ? void 0 : t.tooltipBorderWidth) ?? K), x === void 0 && (x = y + " " + Q + " " + ((t == null ? void 0 : t.tooltipClasses) ?? "")), O === void 0 && (O = j + " " + X + " " + ((t == null ? void 0 : t.textClasses) ?? "")), F === void 0 && (F = (t == null ? void 0 : t.arrowSize) ?? Y), T === void 0 && (T = (t == null ? void 0 : t.arrowClasses) ?? ""), W === void 0 && (W = (t == null ? void 0 : t.arrowMinOffsetFromTooltipCorner) ?? E), v === void 0 && (v = (t == null ? void 0 : t.zIndex) ?? l), z === void 0 && (z = b), {
|
|
115
115
|
tooltipText: s,
|
|
116
116
|
tooltipPosition: d,
|
|
117
117
|
tooltipPositions: i,
|
|
@@ -125,21 +125,21 @@ function Ot(e, t, r) {
|
|
|
125
125
|
arrowSize: F,
|
|
126
126
|
arrowClasses: T,
|
|
127
127
|
arrowMinOffsetFromTooltipCorner: W,
|
|
128
|
-
zIndex:
|
|
129
|
-
shouldShow:
|
|
128
|
+
zIndex: v,
|
|
129
|
+
shouldShow: z
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function Ft(e) {
|
|
133
133
|
const t = typeof e == "string" ? e : e.content;
|
|
134
134
|
if (!t)
|
|
135
135
|
throw new Error("Please enter valid tooltip value");
|
|
136
136
|
return t;
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
let s = e, d =
|
|
138
|
+
function Tt(e, t, r) {
|
|
139
|
+
let s = e, d = Wt(t.textClasses, t.tooltipText), i = vt(t.tooltipClasses, t.tooltipBorderWidth);
|
|
140
140
|
i.append(d), i.dataset.uuid = r;
|
|
141
141
|
const o = new AbortController(), p = new AbortController();
|
|
142
|
-
return s.addEventListener("mouseenter", () => zt(s, t, i, r), { signal: o.signal }), s.addEventListener("mouseleave", () =>
|
|
142
|
+
return s.addEventListener("mouseenter", () => zt(s, t, i, r), { signal: o.signal }), s.addEventListener("mouseleave", () => Mt(r), { signal: p.signal }), {
|
|
143
143
|
anchorElement: s,
|
|
144
144
|
tooltipConfig: t,
|
|
145
145
|
tooltipElement: i,
|
|
@@ -147,11 +147,11 @@ function Ft(e, t, r) {
|
|
|
147
147
|
mouseLeaveEventController: p
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function Wt(e, t) {
|
|
151
151
|
let r = document.createElement("p");
|
|
152
152
|
return r.classList.add(...e.trim().split(" ")), r.innerHTML = t, r;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function vt(e, t) {
|
|
155
155
|
let r = document.createElement("div");
|
|
156
156
|
return r.classList.add(...e.trim().split(" ")), r.style.borderWidth = `${t}px`, r;
|
|
157
157
|
}
|
|
@@ -161,14 +161,14 @@ function zt(e, t, r, s) {
|
|
|
161
161
|
const d = e.getBoundingClientRect(), i = document.querySelector("body");
|
|
162
162
|
i == null || i.appendChild(r);
|
|
163
163
|
let o = !1, p = t.tooltipPosition;
|
|
164
|
-
for (let h = 0; h < 4 && (p = t.tooltipPositions[t.tooltipPosition][h], p === "left" ? o =
|
|
164
|
+
for (let h = 0; h < 4 && (p = t.tooltipPositions[t.tooltipPosition][h], p === "left" ? o = yt(d, t, r) : p === "top" ? o = Vt(d, t, r) : p === "right" ? o = St(d, t, r) : p === "bottom" && (o = Bt(d, t, r)), !o); h++)
|
|
165
165
|
;
|
|
166
|
-
o && (
|
|
166
|
+
o && (at(d, p, t, r), r.style.opacity = "1", r.style.zIndex = t.zIndex.toString(), ut(e, () => S(s)), mt(e, () => S(s)));
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function Mt(e) {
|
|
169
169
|
S(e);
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function yt(e, t, r) {
|
|
172
172
|
const s = Math.min(e.left - t.tooltipOffsetFromSource - t.tooltipOffsetFromViewport, t.tooltipMaxWidth), d = e.top >= t.tooltipOffsetFromViewport, i = window.innerHeight - e.bottom >= t.tooltipOffsetFromViewport;
|
|
173
173
|
if (s < t.tooltipMinWidth || !d || !i)
|
|
174
174
|
return !1;
|
|
@@ -179,7 +179,7 @@ function Mt(e, t, r) {
|
|
|
179
179
|
const h = e.left - t.tooltipOffsetFromSource - o.width;
|
|
180
180
|
return e.bottom < p + t.arrowMinOffsetFromTooltipCorner * 2 || e.top > p + o.height - t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${p}px`, r.style.left = `${h}px`, !0);
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function St(e, t, r) {
|
|
183
183
|
const s = Math.min(window.innerWidth - (e.right + t.tooltipOffsetFromSource) - t.tooltipOffsetFromViewport, t.tooltipMaxWidth), d = e.top >= t.tooltipOffsetFromViewport, i = window.innerHeight - e.bottom >= t.tooltipOffsetFromViewport;
|
|
184
184
|
if (s < t.tooltipMinWidth || !d || !i)
|
|
185
185
|
return !1;
|
|
@@ -190,7 +190,7 @@ function yt(e, t, r) {
|
|
|
190
190
|
const h = e.right + t.tooltipOffsetFromSource;
|
|
191
191
|
return e.bottom < p + t.arrowMinOffsetFromTooltipCorner * 2 || e.top > p + o.height - t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${p}px`, r.style.left = `${h}px`, !0);
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function Vt(e, t, r) {
|
|
194
194
|
const s = Math.min(window.innerWidth - t.tooltipOffsetFromViewport * 2, t.tooltipMaxWidth);
|
|
195
195
|
r.style.maxWidth = `${s}px`;
|
|
196
196
|
const d = r.getBoundingClientRect();
|
|
@@ -200,7 +200,7 @@ function St(e, t, r) {
|
|
|
200
200
|
let o = e.left + e.width / 2 - d.width / 2;
|
|
201
201
|
return o < t.tooltipOffsetFromViewport ? o = t.tooltipOffsetFromViewport : o + d.width > window.innerWidth - t.tooltipOffsetFromViewport && (o = window.innerWidth - t.tooltipOffsetFromViewport - d.width), e.left > o + d.width - t.arrowMinOffsetFromTooltipCorner * 2 || e.right < o + t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${i}px`, r.style.left = `${o}px`, !0);
|
|
202
202
|
}
|
|
203
|
-
function
|
|
203
|
+
function Bt(e, t, r) {
|
|
204
204
|
const s = Math.min(window.innerWidth - t.tooltipOffsetFromViewport * 2, t.tooltipMaxWidth);
|
|
205
205
|
r.style.maxWidth = `${s}px`;
|
|
206
206
|
const d = r.getBoundingClientRect();
|
|
@@ -210,7 +210,7 @@ function Vt(e, t, r) {
|
|
|
210
210
|
let o = e.left + e.width / 2 - d.width / 2;
|
|
211
211
|
return o < t.tooltipOffsetFromViewport ? o = t.tooltipOffsetFromViewport : o + d.width > window.innerWidth - t.tooltipOffsetFromViewport && (o = window.innerWidth - t.tooltipOffsetFromViewport - d.width), e.left > o + d.width - t.arrowMinOffsetFromTooltipCorner * 2 || e.right < o + t.arrowMinOffsetFromTooltipCorner * 2 ? !1 : (r.style.top = `${i}px`, r.style.left = `${o}px`, !0);
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function at(e, t, r, s) {
|
|
214
214
|
var O;
|
|
215
215
|
const d = document.createElement("div"), i = s.getBoundingClientRect(), o = Math.sin(45 * (180 / Math.PI)) * r.arrowSize, p = 1;
|
|
216
216
|
let h = 0, u = 0, m = "";
|
|
@@ -261,6 +261,11 @@ function B(e) {
|
|
|
261
261
|
const t = e.tooltipElement.dataset.uuid;
|
|
262
262
|
t && (S(t), delete n[t]), e.mouseEnterEventController.abort(), e.mouseLeaveEventController.abort();
|
|
263
263
|
}
|
|
264
|
+
const Ht = {
|
|
265
|
+
install: (e, t = {}) => {
|
|
266
|
+
e.directive("tooltip", Ot(t));
|
|
267
|
+
}
|
|
268
|
+
};
|
|
264
269
|
export {
|
|
265
|
-
|
|
270
|
+
Ht as default
|
|
266
271
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(x,c){typeof exports=="object"&&typeof module<"u"?module.exports=c(require("vue")):typeof define=="function"&&define.amd?define(["vue"],c):(x=typeof globalThis<"u"?globalThis:x||self,x.ZeroTooltip=c(x.Vue))})(this,function(x){"use strict";let c;const rt=new Uint8Array(16);function st(){if(!c&&(c=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!c))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return c(rt)}const h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function dt(e,t=0){return h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]}const L={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function it(e,t,r){if(L.randomUUID&&!t&&!e)return L.randomUUID();e=e||{};const s=e.random||(e.rng||st)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,t){r=r||0;for(let d=0;d<16;++d)t[r+d]=s[d];return t}return dt(s)}function ot(){let e=[];const t=(d,i)=>{if(r(d),e.length>0)for(const o of e)o.addEventListener("scroll",i);window.addEventListener("scroll",()=>{i(),s(i)})},r=d=>{let i=d;for(;i!==null&&i.tagName!=="HTML";){if(i.scrollHeight!==i.clientHeight){const o=window.getComputedStyle(i);(o.overflow==="auto"||o.overflow==="scroll")&&e.push(i)}i=i.parentElement}},s=d=>{if(e.length>0){for(const i of e)i.removeEventListener("scroll",d);e=[]}window.removeEventListener("scroll",d)};return{handleHideOnScroll:t}}function pt(){let e=null,t=null;return{handleHideOnResize:(d,i)=>{e=new ResizeObserver(o=>{const p=o[0].target;if(t===null)t=d.getBoundingClientRect();else{const u=p.getBoundingClientRect();(u.left!==t.left||u.top!==t.top||u.width!==t.width||u.height!==t.height)&&i()}}),e.observe(d)},resetResizeReferences:()=>{e!==null&&e.disconnect(),e=null,t=null}}}const{handleHideOnScroll:ut}=ot(),{handleHideOnResize:ht,resetResizeReferences:wt}=pt(),W="zero-tooltip__container",H="zero-tooltip__text",$="zero-tooltip__arrow",O={left:["left","right","top","bottom"],top:["top","bottom","right","left"],right:["right","left","top","bottom"],bottom:["bottom","top","right","left"]},A="top",f=10,_=20,I=100,U=250,k=0,D="zt-fixed zt-opacity-0 zt-inline-block zt-w-fit zt-py-1.5 zt-px-2.5 zt-rounded-md zt-bg-[#495057] zt-shadow-[0_2px_12px_0_rgba(0,0,0,0.1)] zt-box-border",P="zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words",q=5,nt="zt-absolute zt-border-solid zt-border-[#495057]",j=6,R=1,Z=!0,m={},mt=e=>({created:(t,r,s)=>{const d=it();s.el.$_tooltip={uuid:d},B(r.value,e,r.arg,t,d),typeof r.value!="string"&&x.isReactive(r.value)&&x.watch(r.value,i=>{m[d]&&a(m[d]),B(i,e,r.arg,t,d)})},updated:(t,r,s)=>{const d=s.el.$_tooltip.uuid;m[d]&&a(m[d]),B(r.value,e,r.arg,t,d)},beforeUnmount:(t,r,s)=>{const d=s.el.$_tooltip.uuid;m[d]&&a(m[d])}});function B(e,t,r,s,d){let i=ct(e,t,r);const o=xt(s,i,d);m[d]=o,s.matches(":hover")&&s.dispatchEvent(new Event("mouseenter"))}function ct(e,t,r){var J,K,Q,X,Y,E,l,b,C,g,tt,et;let s,d,i,o,p,u,w,n,T,F,z,y,M,S,V;return s=Ot(e),typeof e!="string"&&(d=r??e.defaultPosition??(t==null?void 0:t.defaultPosition)??A,i={left:((J=e.positions)==null?void 0:J.left)??((K=t==null?void 0:t.positions)==null?void 0:K.left)??O.left,top:((Q=e.positions)==null?void 0:Q.top)??((X=t==null?void 0:t.positions)==null?void 0:X.top)??O.top,right:((Y=e.positions)==null?void 0:Y.right)??((E=t==null?void 0:t.positions)==null?void 0:E.right)??O.right,bottom:((l=e.positions)==null?void 0:l.bottom)??((b=t==null?void 0:t.positions)==null?void 0:b.bottom)??O.bottom},o=e.offsetFromSource??(t==null?void 0:t.offsetFromSource)??f,p=e.offsetFromViewport??(t==null?void 0:t.offsetFromViewport)??_,u=e.minWidth??(t==null?void 0:t.minWidth)??I,w=e.maxWidth??(t==null?void 0:t.maxWidth)??U,n=e.tooltipBorderWidth??(t==null?void 0:t.tooltipBorderWidth)??k,T=W+" "+D+" "+(e.tooltipClasses??(t==null?void 0:t.tooltipClasses)??""),F=H+" "+P+" "+(e.textClasses??(t==null?void 0:t.textClasses)??""),z=e.arrowSize??(t==null?void 0:t.arrowSize)??q,y=e.arrowClasses??(t==null?void 0:t.arrowClasses)??"",M=e.arrowMinOffsetFromTooltipCorner??(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??j,S=e.zIndex??(t==null?void 0:t.zIndex)??R,V=e.show??Z),d===void 0&&(d=r??(t==null?void 0:t.defaultPosition)??A),i===void 0&&(i={left:((C=t==null?void 0:t.positions)==null?void 0:C.left)??O.left,top:((g=t==null?void 0:t.positions)==null?void 0:g.top)??O.top,right:((tt=t==null?void 0:t.positions)==null?void 0:tt.right)??O.right,bottom:((et=t==null?void 0:t.positions)==null?void 0:et.bottom)??O.bottom}),o===void 0&&(o=(t==null?void 0:t.offsetFromSource)??f),p===void 0&&(p=(t==null?void 0:t.offsetFromViewport)??_),u===void 0&&(u=(t==null?void 0:t.minWidth)??I),w===void 0&&(w=(t==null?void 0:t.maxWidth)??U),n===void 0&&(n=(t==null?void 0:t.tooltipBorderWidth)??k),T===void 0&&(T=W+" "+D+" "+((t==null?void 0:t.tooltipClasses)??"")),F===void 0&&(F=H+" "+P+" "+((t==null?void 0:t.textClasses)??"")),z===void 0&&(z=(t==null?void 0:t.arrowSize)??q),y===void 0&&(y=(t==null?void 0:t.arrowClasses)??""),M===void 0&&(M=(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??j),S===void 0&&(S=(t==null?void 0:t.zIndex)??R),V===void 0&&(V=Z),{tooltipText:s,tooltipPosition:d,tooltipPositions:i,tooltipOffsetFromSource:o,tooltipOffsetFromViewport:p,tooltipMinWidth:u,tooltipMaxWidth:w,tooltipBorderWidth:n,tooltipClasses:T,textClasses:F,arrowSize:z,arrowClasses:y,arrowMinOffsetFromTooltipCorner:M,zIndex:S,shouldShow:V}}function Ot(e){const t=typeof e=="string"?e:e.content;if(!t)throw new Error("Please enter valid tooltip value");return t}function xt(e,t,r){let s=e,d=Ft(t.textClasses,t.tooltipText),i=Tt(t.tooltipClasses,t.tooltipBorderWidth);i.append(d),i.dataset.uuid=r;const o=new AbortController,p=new AbortController;return s.addEventListener("mouseenter",()=>Wt(s,t,i,r),{signal:o.signal}),s.addEventListener("mouseleave",()=>vt(r),{signal:p.signal}),{anchorElement:s,tooltipConfig:t,tooltipElement:i,mouseEnterEventController:o,mouseLeaveEventController:p}}function Ft(e,t){let r=document.createElement("p");return r.classList.add(...e.trim().split(" ")),r.innerHTML=t,r}function Tt(e,t){let r=document.createElement("div");return r.classList.add(...e.trim().split(" ")),r.style.borderWidth=`${t}px`,r}function Wt(e,t,r,s){if(!t.shouldShow)return;const d=e.getBoundingClientRect(),i=document.querySelector("body");i==null||i.appendChild(r);let o=!1,p=t.tooltipPosition;for(let u=0;u<4&&(p=t.tooltipPositions[t.tooltipPosition][u],p==="left"?o=zt(d,t,r):p==="top"?o=Mt(d,t,r):p==="right"?o=yt(d,t,r):p==="bottom"&&(o=St(d,t,r)),!o);u++);o&&(Vt(d,p,t,r),r.style.opacity="1",r.style.zIndex=t.zIndex.toString(),ut(e,()=>v(s)),ht(e,()=>v(s)))}function vt(e){v(e)}function zt(e,t,r){const s=Math.min(e.left-t.tooltipOffsetFromSource-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.left-t.tooltipOffsetFromSource-o.width;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function yt(e,t,r){const s=Math.min(window.innerWidth-(e.right+t.tooltipOffsetFromSource)-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.right+t.tooltipOffsetFromSource;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function Mt(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.top-t.tooltipOffsetFromSource-d.height;if(i<t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function St(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.bottom+t.tooltipOffsetFromSource;if(i+d.height>window.innerHeight-t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function Vt(e,t,r,s){var F;const d=document.createElement("div"),i=s.getBoundingClientRect(),o=Math.sin(45*(180/Math.PI))*r.arrowSize,p=1;let u=0,w=0,n="";switch(t){case"left":n="!zt-border-y-transparent !zt-border-r-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=i.width-r.tooltipBorderWidth-p;break;case"top":n="!zt-border-x-transparent !zt-border-b-transparent",u=i.height-r.tooltipBorderWidth-p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break;case"right":n="!zt-border-y-transparent !zt-border-l-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=-r.arrowSize*2-r.tooltipBorderWidth+p;break;case"bottom":n="!zt-border-x-transparent !zt-border-t-transparent",u=-r.arrowSize*2-r.tooltipBorderWidth+p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break}t==="left"||t==="right"?N(t,i,u,r)||(u=G(t,i,u,r)):N(t,i,w,r)||(w=G(t,i,w,r));const T=$+" "+nt+" "+n+" "+r.arrowClasses;d.classList.add(...T.trim().split(" ")),d.style.top=`${u}px`,d.style.left=`${w}px`,d.style.borderWidth=`${r.arrowSize}px`,(F=document.querySelector(`.${W}`))==null||F.appendChild(d)}function N(e,t,r,s){switch(e){case"left":case"right":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.height+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.width+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function G(e,t,r,s){switch(e){case"left":case"right":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.height-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.width-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function v(e){var s,d;const t=document.querySelector(`.${W}`),r=(s=m[e])==null?void 0:s.tooltipElement;r&&t&&t instanceof HTMLElement&&t===r&&(wt(),(d=t.querySelector(`.${$}`))==null||d.remove(),t.style.left="0",t.style.top="0",t.remove())}function a(e){const t=e.tooltipElement.dataset.uuid;t&&(v(t),delete m[t]),e.mouseEnterEventController.abort(),e.mouseLeaveEventController.abort()}return mt});
|
|
1
|
+
(function(O,T){typeof exports=="object"&&typeof module<"u"?module.exports=T(require("vue")):typeof define=="function"&&define.amd?define(["vue"],T):(O=typeof globalThis<"u"?globalThis:O||self,O.ZeroTooltip=T(O.Vue))})(this,function(O){"use strict";const T="";let W;const st=new Uint8Array(16);function dt(){if(!W&&(W=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!W))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return W(st)}const h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function it(e,t=0){return h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]}const H={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ot(e,t,r){if(H.randomUUID&&!t&&!e)return H.randomUUID();e=e||{};const s=e.random||(e.rng||dt)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,t){r=r||0;for(let d=0;d<16;++d)t[r+d]=s[d];return t}return it(s)}function pt(){let e=[];const t=(d,i)=>{if(r(d),e.length>0)for(const o of e)o.addEventListener("scroll",i);window.addEventListener("scroll",()=>{i(),s(i)})},r=d=>{let i=d;for(;i!==null&&i.tagName!=="HTML";){if(i.scrollHeight!==i.clientHeight){const o=window.getComputedStyle(i);(o.overflow==="auto"||o.overflow==="scroll")&&e.push(i)}i=i.parentElement}},s=d=>{if(e.length>0){for(const i of e)i.removeEventListener("scroll",d);e=[]}window.removeEventListener("scroll",d)};return{handleHideOnScroll:t}}function ut(){let e=null,t=null;return{handleHideOnResize:(d,i)=>{e=new ResizeObserver(o=>{const p=o[0].target;if(t===null)t=d.getBoundingClientRect();else{const u=p.getBoundingClientRect();(u.left!==t.left||u.top!==t.top||u.width!==t.width||u.height!==t.height)&&i()}}),e.observe(d)},resetResizeReferences:()=>{e!==null&&e.disconnect(),e=null,t=null}}}const{handleHideOnScroll:ht}=pt(),{handleHideOnResize:wt,resetResizeReferences:nt}=ut(),v="zero-tooltip__container",$="zero-tooltip__text",A="zero-tooltip__arrow",c={left:["left","right","top","bottom"],top:["top","bottom","right","left"],right:["right","left","top","bottom"],bottom:["bottom","top","right","left"]},f="top",_=10,I=20,U=100,k=250,D=0,P="zt-fixed zt-opacity-0 zt-inline-block zt-w-fit zt-py-1.5 zt-px-2.5 zt-rounded-md zt-bg-[#495057] zt-shadow-[0_2px_12px_0_rgba(0,0,0,0.1)] zt-box-border",q="zt-text-sm zt-text-white zt-whitespace-pre-wrap zt-break-words",j=5,mt="zt-absolute zt-border-solid zt-border-[#495057]",R=6,Z=1,N=!0,m={},ct=e=>({created:(t,r,s)=>{const d=ot();s.el.$_tooltip={uuid:d},a(r.value,e,r.arg,t,d),typeof r.value!="string"&&O.isReactive(r.value)&&O.watch(r.value,i=>{m[d]&&L(m[d]),a(i,e,r.arg,t,d)})},updated:(t,r,s)=>{const d=s.el.$_tooltip.uuid;m[d]&&L(m[d]),a(r.value,e,r.arg,t,d)},beforeUnmount:(t,r,s)=>{const d=s.el.$_tooltip.uuid;m[d]&&L(m[d])}});function a(e,t,r,s,d){let i=Ot(e,t,r);const o=Ft(s,i,d);m[d]=o,s.matches(":hover")&&s.dispatchEvent(new Event("mouseenter"))}function Ot(e,t,r){var K,Q,X,Y,E,l,b,C,g,tt,et,rt;let s,d,i,o,p,u,w,n,F,x,y,M,S,V,B;return s=xt(e),typeof e!="string"&&(d=r??e.defaultPosition??(t==null?void 0:t.defaultPosition)??f,i={left:((K=e.positions)==null?void 0:K.left)??((Q=t==null?void 0:t.positions)==null?void 0:Q.left)??c.left,top:((X=e.positions)==null?void 0:X.top)??((Y=t==null?void 0:t.positions)==null?void 0:Y.top)??c.top,right:((E=e.positions)==null?void 0:E.right)??((l=t==null?void 0:t.positions)==null?void 0:l.right)??c.right,bottom:((b=e.positions)==null?void 0:b.bottom)??((C=t==null?void 0:t.positions)==null?void 0:C.bottom)??c.bottom},o=e.offsetFromSource??(t==null?void 0:t.offsetFromSource)??_,p=e.offsetFromViewport??(t==null?void 0:t.offsetFromViewport)??I,u=e.minWidth??(t==null?void 0:t.minWidth)??U,w=e.maxWidth??(t==null?void 0:t.maxWidth)??k,n=e.tooltipBorderWidth??(t==null?void 0:t.tooltipBorderWidth)??D,F=v+" "+P+" "+(e.tooltipClasses??(t==null?void 0:t.tooltipClasses)??""),x=$+" "+q+" "+(e.textClasses??(t==null?void 0:t.textClasses)??""),y=e.arrowSize??(t==null?void 0:t.arrowSize)??j,M=e.arrowClasses??(t==null?void 0:t.arrowClasses)??"",S=e.arrowMinOffsetFromTooltipCorner??(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??R,V=e.zIndex??(t==null?void 0:t.zIndex)??Z,B=e.show??N),d===void 0&&(d=r??(t==null?void 0:t.defaultPosition)??f),i===void 0&&(i={left:((g=t==null?void 0:t.positions)==null?void 0:g.left)??c.left,top:((tt=t==null?void 0:t.positions)==null?void 0:tt.top)??c.top,right:((et=t==null?void 0:t.positions)==null?void 0:et.right)??c.right,bottom:((rt=t==null?void 0:t.positions)==null?void 0:rt.bottom)??c.bottom}),o===void 0&&(o=(t==null?void 0:t.offsetFromSource)??_),p===void 0&&(p=(t==null?void 0:t.offsetFromViewport)??I),u===void 0&&(u=(t==null?void 0:t.minWidth)??U),w===void 0&&(w=(t==null?void 0:t.maxWidth)??k),n===void 0&&(n=(t==null?void 0:t.tooltipBorderWidth)??D),F===void 0&&(F=v+" "+P+" "+((t==null?void 0:t.tooltipClasses)??"")),x===void 0&&(x=$+" "+q+" "+((t==null?void 0:t.textClasses)??"")),y===void 0&&(y=(t==null?void 0:t.arrowSize)??j),M===void 0&&(M=(t==null?void 0:t.arrowClasses)??""),S===void 0&&(S=(t==null?void 0:t.arrowMinOffsetFromTooltipCorner)??R),V===void 0&&(V=(t==null?void 0:t.zIndex)??Z),B===void 0&&(B=N),{tooltipText:s,tooltipPosition:d,tooltipPositions:i,tooltipOffsetFromSource:o,tooltipOffsetFromViewport:p,tooltipMinWidth:u,tooltipMaxWidth:w,tooltipBorderWidth:n,tooltipClasses:F,textClasses:x,arrowSize:y,arrowClasses:M,arrowMinOffsetFromTooltipCorner:S,zIndex:V,shouldShow:B}}function xt(e){const t=typeof e=="string"?e:e.content;if(!t)throw new Error("Please enter valid tooltip value");return t}function Ft(e,t,r){let s=e,d=Tt(t.textClasses,t.tooltipText),i=Wt(t.tooltipClasses,t.tooltipBorderWidth);i.append(d),i.dataset.uuid=r;const o=new AbortController,p=new AbortController;return s.addEventListener("mouseenter",()=>vt(s,t,i,r),{signal:o.signal}),s.addEventListener("mouseleave",()=>zt(r),{signal:p.signal}),{anchorElement:s,tooltipConfig:t,tooltipElement:i,mouseEnterEventController:o,mouseLeaveEventController:p}}function Tt(e,t){let r=document.createElement("p");return r.classList.add(...e.trim().split(" ")),r.innerHTML=t,r}function Wt(e,t){let r=document.createElement("div");return r.classList.add(...e.trim().split(" ")),r.style.borderWidth=`${t}px`,r}function vt(e,t,r,s){if(!t.shouldShow)return;const d=e.getBoundingClientRect(),i=document.querySelector("body");i==null||i.appendChild(r);let o=!1,p=t.tooltipPosition;for(let u=0;u<4&&(p=t.tooltipPositions[t.tooltipPosition][u],p==="left"?o=yt(d,t,r):p==="top"?o=St(d,t,r):p==="right"?o=Mt(d,t,r):p==="bottom"&&(o=Vt(d,t,r)),!o);u++);o&&(Bt(d,p,t,r),r.style.opacity="1",r.style.zIndex=t.zIndex.toString(),ht(e,()=>z(s)),wt(e,()=>z(s)))}function zt(e){z(e)}function yt(e,t,r){const s=Math.min(e.left-t.tooltipOffsetFromSource-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.left-t.tooltipOffsetFromSource-o.width;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function Mt(e,t,r){const s=Math.min(window.innerWidth-(e.right+t.tooltipOffsetFromSource)-t.tooltipOffsetFromViewport,t.tooltipMaxWidth),d=e.top>=t.tooltipOffsetFromViewport,i=window.innerHeight-e.bottom>=t.tooltipOffsetFromViewport;if(s<t.tooltipMinWidth||!d||!i)return!1;r.style.maxWidth=`${s}px`;const o=r.getBoundingClientRect();let p=e.top+e.height/2-o.height/2;p<t.tooltipOffsetFromViewport?p=t.tooltipOffsetFromViewport:p+o.height>window.innerHeight-t.tooltipOffsetFromViewport&&(p=window.innerHeight-t.tooltipOffsetFromViewport-o.height);const u=e.right+t.tooltipOffsetFromSource;return e.bottom<p+t.arrowMinOffsetFromTooltipCorner*2||e.top>p+o.height-t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${p}px`,r.style.left=`${u}px`,!0)}function St(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.top-t.tooltipOffsetFromSource-d.height;if(i<t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function Vt(e,t,r){const s=Math.min(window.innerWidth-t.tooltipOffsetFromViewport*2,t.tooltipMaxWidth);r.style.maxWidth=`${s}px`;const d=r.getBoundingClientRect();let i=e.bottom+t.tooltipOffsetFromSource;if(i+d.height>window.innerHeight-t.tooltipOffsetFromViewport)return!1;let o=e.left+e.width/2-d.width/2;return o<t.tooltipOffsetFromViewport?o=t.tooltipOffsetFromViewport:o+d.width>window.innerWidth-t.tooltipOffsetFromViewport&&(o=window.innerWidth-t.tooltipOffsetFromViewport-d.width),e.left>o+d.width-t.arrowMinOffsetFromTooltipCorner*2||e.right<o+t.arrowMinOffsetFromTooltipCorner*2?!1:(r.style.top=`${i}px`,r.style.left=`${o}px`,!0)}function Bt(e,t,r,s){var x;const d=document.createElement("div"),i=s.getBoundingClientRect(),o=Math.sin(45*(180/Math.PI))*r.arrowSize,p=1;let u=0,w=0,n="";switch(t){case"left":n="!zt-border-y-transparent !zt-border-r-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=i.width-r.tooltipBorderWidth-p;break;case"top":n="!zt-border-x-transparent !zt-border-b-transparent",u=i.height-r.tooltipBorderWidth-p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break;case"right":n="!zt-border-y-transparent !zt-border-l-transparent",u=e.top-i.top+e.height/2-o-r.tooltipBorderWidth,w=-r.arrowSize*2-r.tooltipBorderWidth+p;break;case"bottom":n="!zt-border-x-transparent !zt-border-t-transparent",u=-r.arrowSize*2-r.tooltipBorderWidth+p,w=e.left-i.left+e.width/2-o-r.tooltipBorderWidth;break}t==="left"||t==="right"?G(t,i,u,r)||(u=J(t,i,u,r)):G(t,i,w,r)||(w=J(t,i,w,r));const F=A+" "+mt+" "+n+" "+r.arrowClasses;d.classList.add(...F.trim().split(" ")),d.style.top=`${u}px`,d.style.left=`${w}px`,d.style.borderWidth=`${r.arrowSize}px`,(x=document.querySelector(`.${v}`))==null||x.appendChild(d)}function G(e,t,r,s){switch(e){case"left":case"right":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.height+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r>s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth&&r<t.width+s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function J(e,t,r,s){switch(e){case"left":case"right":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.height-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2;case"top":case"bottom":return r<s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth?s.arrowMinOffsetFromTooltipCorner-s.tooltipBorderWidth:t.width-s.tooltipBorderWidth-s.arrowMinOffsetFromTooltipCorner-s.arrowSize*2}}function z(e){var s,d;const t=document.querySelector(`.${v}`),r=(s=m[e])==null?void 0:s.tooltipElement;r&&t&&t instanceof HTMLElement&&t===r&&(nt(),(d=t.querySelector(`.${A}`))==null||d.remove(),t.style.left="0",t.style.top="0",t.remove())}function L(e){const t=e.tooltipElement.dataset.uuid;t&&(z(t),delete m[t]),e.mouseEnterEventController.abort(),e.mouseLeaveEventController.abort()}return{install:(e,t={})=>{e.directive("tooltip",ct(t))}}});
|
package/package.json
CHANGED
|
@@ -10,21 +10,19 @@
|
|
|
10
10
|
"require": "./dist/zero-tooltip.umd.cjs",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
},
|
|
13
|
-
"./dist/
|
|
14
|
-
|
|
15
|
-
"require": "./dist/styles.css"
|
|
16
|
-
}
|
|
13
|
+
"./dist/style.css": "./dist/style.css",
|
|
14
|
+
"./style.css": "./dist/style.css"
|
|
17
15
|
},
|
|
18
16
|
"./package.json": "./package.json",
|
|
19
17
|
"files": [
|
|
20
18
|
"dist",
|
|
21
19
|
"src"
|
|
22
20
|
],
|
|
23
|
-
"version": "1.0.
|
|
21
|
+
"version": "1.0.9",
|
|
24
22
|
"type": "module",
|
|
25
23
|
"scripts": {
|
|
26
24
|
"dev": "vite",
|
|
27
|
-
"build": "
|
|
25
|
+
"build": "npx tailwindcss -o ./src/style.css --minify && vite build && vue-tsc -d --emitDeclarationOnly",
|
|
28
26
|
"preview": "vite preview"
|
|
29
27
|
},
|
|
30
28
|
"peerDependencies": {
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export default function useHideOnResize() {
|
|
2
|
-
let anchorElementResizeObserver: ResizeObserver | null = null
|
|
3
|
-
let anchorElementRect: DOMRect | null = null
|
|
4
|
-
|
|
5
|
-
const handleHideOnResize = (anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
-
anchorElementResizeObserver = new ResizeObserver((entries) => {
|
|
7
|
-
const targetElement = entries[0].target
|
|
8
|
-
|
|
9
|
-
if (anchorElementRect === null) {
|
|
10
|
-
// On initial trigger set initial values
|
|
11
|
-
anchorElementRect = anchorElement.getBoundingClientRect()
|
|
12
|
-
} else {
|
|
13
|
-
const targetElementRect = targetElement.getBoundingClientRect()
|
|
14
|
-
|
|
15
|
-
// Check if anchor element has moved or resized
|
|
16
|
-
if (targetElementRect.left !== anchorElementRect.left
|
|
17
|
-
|| targetElementRect.top !== anchorElementRect.top
|
|
18
|
-
|| targetElementRect.width !== anchorElementRect.width
|
|
19
|
-
|| targetElementRect.height !== anchorElementRect.height) {
|
|
20
|
-
hideOverlay()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
anchorElementResizeObserver.observe(anchorElement)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const resetResizeReferences = () => {
|
|
29
|
-
if (anchorElementResizeObserver !== null) anchorElementResizeObserver.disconnect()
|
|
30
|
-
|
|
31
|
-
anchorElementResizeObserver = null
|
|
32
|
-
anchorElementRect = null
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return { handleHideOnResize, resetResizeReferences }
|
|
36
|
-
}
|
|
1
|
+
export default function useHideOnResize() {
|
|
2
|
+
let anchorElementResizeObserver: ResizeObserver | null = null
|
|
3
|
+
let anchorElementRect: DOMRect | null = null
|
|
4
|
+
|
|
5
|
+
const handleHideOnResize = (anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
+
anchorElementResizeObserver = new ResizeObserver((entries) => {
|
|
7
|
+
const targetElement = entries[0].target
|
|
8
|
+
|
|
9
|
+
if (anchorElementRect === null) {
|
|
10
|
+
// On initial trigger set initial values
|
|
11
|
+
anchorElementRect = anchorElement.getBoundingClientRect()
|
|
12
|
+
} else {
|
|
13
|
+
const targetElementRect = targetElement.getBoundingClientRect()
|
|
14
|
+
|
|
15
|
+
// Check if anchor element has moved or resized
|
|
16
|
+
if (targetElementRect.left !== anchorElementRect.left
|
|
17
|
+
|| targetElementRect.top !== anchorElementRect.top
|
|
18
|
+
|| targetElementRect.width !== anchorElementRect.width
|
|
19
|
+
|| targetElementRect.height !== anchorElementRect.height) {
|
|
20
|
+
hideOverlay()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
anchorElementResizeObserver.observe(anchorElement)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const resetResizeReferences = () => {
|
|
29
|
+
if (anchorElementResizeObserver !== null) anchorElementResizeObserver.disconnect()
|
|
30
|
+
|
|
31
|
+
anchorElementResizeObserver = null
|
|
32
|
+
anchorElementRect = null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { handleHideOnResize, resetResizeReferences }
|
|
36
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
export default function useHideOnScroll() {
|
|
3
|
-
let scrollContainers: Array<HTMLElement> = []
|
|
4
|
-
|
|
5
|
-
const handleHideOnScroll = (anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
-
getScrollContainers(anchorElement)
|
|
7
|
-
|
|
8
|
-
if (scrollContainers.length > 0) {
|
|
9
|
-
for (const scrollContainer of scrollContainers) {
|
|
10
|
-
scrollContainer.addEventListener('scroll', hideOverlay)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
window.addEventListener('scroll', () => {
|
|
15
|
-
hideOverlay()
|
|
16
|
-
removeHideOnScrollListeners(hideOverlay)
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const getScrollContainers = (anchorElement: HTMLElement) => {
|
|
21
|
-
let currentElement: HTMLElement | null = anchorElement
|
|
22
|
-
|
|
23
|
-
while (currentElement !== null && currentElement.tagName !== 'HTML') {
|
|
24
|
-
if (currentElement.scrollHeight !== currentElement.clientHeight) {
|
|
25
|
-
const computedStyle = window.getComputedStyle(currentElement)
|
|
26
|
-
|
|
27
|
-
if (computedStyle.overflow === 'auto' || computedStyle.overflow === 'scroll') {
|
|
28
|
-
scrollContainers.push(currentElement)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
currentElement = currentElement.parentElement
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const removeHideOnScrollListeners = (hideOverlay: () => void) => {
|
|
37
|
-
if (scrollContainers.length > 0) {
|
|
38
|
-
for (const scrollContainer of scrollContainers) {
|
|
39
|
-
scrollContainer.removeEventListener('scroll', hideOverlay)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
scrollContainers = []
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
window.removeEventListener('scroll', hideOverlay)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return { handleHideOnScroll }
|
|
49
|
-
}
|
|
1
|
+
|
|
2
|
+
export default function useHideOnScroll() {
|
|
3
|
+
let scrollContainers: Array<HTMLElement> = []
|
|
4
|
+
|
|
5
|
+
const handleHideOnScroll = (anchorElement: HTMLElement, hideOverlay: () => void) => {
|
|
6
|
+
getScrollContainers(anchorElement)
|
|
7
|
+
|
|
8
|
+
if (scrollContainers.length > 0) {
|
|
9
|
+
for (const scrollContainer of scrollContainers) {
|
|
10
|
+
scrollContainer.addEventListener('scroll', hideOverlay)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
window.addEventListener('scroll', () => {
|
|
15
|
+
hideOverlay()
|
|
16
|
+
removeHideOnScrollListeners(hideOverlay)
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getScrollContainers = (anchorElement: HTMLElement) => {
|
|
21
|
+
let currentElement: HTMLElement | null = anchorElement
|
|
22
|
+
|
|
23
|
+
while (currentElement !== null && currentElement.tagName !== 'HTML') {
|
|
24
|
+
if (currentElement.scrollHeight !== currentElement.clientHeight) {
|
|
25
|
+
const computedStyle = window.getComputedStyle(currentElement)
|
|
26
|
+
|
|
27
|
+
if (computedStyle.overflow === 'auto' || computedStyle.overflow === 'scroll') {
|
|
28
|
+
scrollContainers.push(currentElement)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
currentElement = currentElement.parentElement
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const removeHideOnScrollListeners = (hideOverlay: () => void) => {
|
|
37
|
+
if (scrollContainers.length > 0) {
|
|
38
|
+
for (const scrollContainer of scrollContainers) {
|
|
39
|
+
scrollContainer.removeEventListener('scroll', hideOverlay)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
scrollContainers = []
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
window.removeEventListener('scroll', hideOverlay)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return { handleHideOnScroll }
|
|
49
|
+
}
|