Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
f5fb681802
|
|||
|
39acbac0f1
|
|||
|
70991f6769
|
|||
|
49fe8cb238
|
|||
|
04e29c7987
|
|||
|
f1e8f86ce9
|
940
.yarn/releases/yarn-4.14.1.cjs
vendored
Executable file
940
.yarn/releases/yarn-4.14.1.cjs
vendored
Executable file
File diff suppressed because one or more lines are too long
942
.yarn/releases/yarn-4.9.4.cjs
vendored
942
.yarn/releases/yarn-4.9.4.cjs
vendored
File diff suppressed because one or more lines are too long
@@ -1,5 +1,3 @@
|
||||
compressionLevel: mixed
|
||||
|
||||
enableGlobalCache: false
|
||||
|
||||
yarnPath: .yarn/releases/yarn-4.9.4.cjs
|
||||
yarnPath: .yarn/releases/yarn-4.14.1.cjs
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
## v7.0.1
|
||||
|
||||
- Исправление работы анимации
|
||||
|
||||
## v7.0.0
|
||||
|
||||
- Изменено значение по умолчанию для параметра `trigger`
|
||||
- Рефакторинг кода и устранение ошибок
|
||||
|
||||
## v6.0.0
|
||||
|
||||
- Корректная работа сообытий mouseenter/mouseleave на тач-устройствах
|
||||
|
||||
@@ -43,7 +43,7 @@ createTooltip(document.querySelector('button'), 'Подсказка', {
|
||||
placement: 'top',
|
||||
shiftPadding: [8, 0],
|
||||
theme: 'light',
|
||||
trigger: 'mouseenter',
|
||||
trigger: 'mouseenter click',
|
||||
virtualReference: undefined,
|
||||
zIndex: '',
|
||||
// Callback-функции, по умолчанию не заданы
|
||||
|
||||
75
index.js
75
index.js
@@ -25,6 +25,15 @@ const handleVisibilityChange = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const templates = {
|
||||
arrow: () => `
|
||||
<div class="tooltip__arrow" style="pointer-events: none; position: absolute; transform: rotate(45deg);"></div>
|
||||
`,
|
||||
interactiveHelper: () => `
|
||||
<div class="tooltip__interactive-helper" style="position: absolute; z-index: -1;"></div>
|
||||
`,
|
||||
};
|
||||
|
||||
export const createTooltip = ($el, content, options) => {
|
||||
options = {
|
||||
animation: [
|
||||
@@ -42,7 +51,7 @@ export const createTooltip = ($el, content, options) => {
|
||||
placement: 'top',
|
||||
shiftPadding: [8, 0],
|
||||
theme: 'light',
|
||||
trigger: 'mouseenter',
|
||||
trigger: 'mouseenter click',
|
||||
virtualReference: undefined,
|
||||
zIndex: '',
|
||||
...options,
|
||||
@@ -70,7 +79,9 @@ export const createTooltip = ($el, content, options) => {
|
||||
$interactive: undefined,
|
||||
_showTimeout: undefined,
|
||||
_hideTimeout: undefined,
|
||||
_currentAnimation: undefined,
|
||||
autoUpdateCleanup: () => {},
|
||||
updatePosition: async () => {},
|
||||
|
||||
setContent(updatedContent) {
|
||||
if (updatedContent !== undefined) {
|
||||
@@ -94,15 +105,7 @@ export const createTooltip = ($el, content, options) => {
|
||||
if (updatedOptions.arrow !== undefined && $el._tooltip.$tooltip) {
|
||||
if (options.arrow) {
|
||||
if (!$el._tooltip.$arrow) {
|
||||
$el._tooltip.$tooltip.insertAdjacentHTML(
|
||||
'afterbegin',
|
||||
`
|
||||
<div
|
||||
class="tooltip__arrow"
|
||||
style="pointer-events: none; position: absolute; transform: rotate(45deg);">
|
||||
</div>
|
||||
`,
|
||||
);
|
||||
$el._tooltip.$tooltip.querySelector('.tooltip__root').insertAdjacentHTML('afterbegin', templates.arrow());
|
||||
$el._tooltip.$arrow = $el._tooltip.$tooltip.querySelector('.tooltip__arrow');
|
||||
}
|
||||
} else {
|
||||
@@ -120,15 +123,7 @@ export const createTooltip = ($el, content, options) => {
|
||||
if ($el._tooltip.$tooltip) {
|
||||
if (options.interactive) {
|
||||
if (!$el._tooltip.$interactive) {
|
||||
$el._tooltip.$tooltip.insertAdjacentHTML(
|
||||
'afterbegin',
|
||||
`
|
||||
<div
|
||||
class="tooltip__interactive-helper"
|
||||
style="position: absolute; z-index: -1;">
|
||||
</div>
|
||||
`,
|
||||
);
|
||||
$el._tooltip.$tooltip.querySelector('.tooltip__root').insertAdjacentHTML('afterbegin', templates.interactiveHelper());
|
||||
$el._tooltip.$interactive =
|
||||
$el._tooltip.$tooltip.querySelector('.tooltip__interactive-helper');
|
||||
}
|
||||
@@ -169,6 +164,7 @@ export const createTooltip = ($el, content, options) => {
|
||||
|
||||
clearTimeout($el._tooltip._showTimeout);
|
||||
clearTimeout($el._tooltip._hideTimeout);
|
||||
$el._tooltip._currentAnimation?.cancel();
|
||||
cancelAnimationFrame(rafId);
|
||||
|
||||
$el._tooltip.$tooltip?.remove();
|
||||
@@ -183,6 +179,8 @@ export const createTooltip = ($el, content, options) => {
|
||||
}
|
||||
listeners.length = 0;
|
||||
|
||||
document.body.removeEventListener('click', $el._tooltip.hideOnClickListener);
|
||||
|
||||
delete $el._tooltip;
|
||||
},
|
||||
};
|
||||
@@ -204,26 +202,8 @@ export const createTooltip = ($el, content, options) => {
|
||||
|
||||
$el._tooltip.$tooltip.innerHTML = `
|
||||
<div class="tooltip__root">
|
||||
${
|
||||
options.interactive
|
||||
? `
|
||||
<div
|
||||
class="tooltip__interactive-helper"
|
||||
style="position: absolute; z-index: -1;">
|
||||
</div>
|
||||
`
|
||||
: ''
|
||||
}
|
||||
${
|
||||
options.arrow
|
||||
? `
|
||||
<div
|
||||
class="tooltip__arrow"
|
||||
style="pointer-events: none; position: absolute; transform: rotate(45deg);">
|
||||
</div>
|
||||
`
|
||||
: ''
|
||||
}
|
||||
${options.interactive ? templates.interactiveHelper() : ''}
|
||||
${options.arrow ? templates.arrow() : ''}
|
||||
<div class="tooltip__container"></div>
|
||||
</div>
|
||||
`;
|
||||
@@ -332,10 +312,12 @@ export const createTooltip = ($el, content, options) => {
|
||||
}
|
||||
|
||||
try {
|
||||
await $el._tooltip.$tooltip.querySelector('.tooltip__root').animate(options.animation[0], {
|
||||
const animation = $el._tooltip.$tooltip.querySelector('.tooltip__root').animate(options.animation[0], {
|
||||
duration: immediately ? 0 : options.duration[0],
|
||||
easing: options.easing[0],
|
||||
}).finished;
|
||||
});
|
||||
$el._tooltip._currentAnimation = animation;
|
||||
await animation.finished;
|
||||
} catch {} // eslint-disable-line no-empty
|
||||
|
||||
if (options.onShown) {
|
||||
@@ -359,11 +341,15 @@ export const createTooltip = ($el, content, options) => {
|
||||
options.onHide($el._tooltip);
|
||||
}
|
||||
|
||||
document.body.removeEventListener('click', $el._tooltip.hideOnClickListener);
|
||||
|
||||
try {
|
||||
await $el._tooltip.$tooltip.querySelector('.tooltip__root').animate(options.animation[1], {
|
||||
const animation = $el._tooltip.$tooltip.querySelector('.tooltip__root').animate(options.animation[1], {
|
||||
duration: immediately ? 0 : options.duration[1],
|
||||
easing: options.easing[1],
|
||||
}).finished;
|
||||
});
|
||||
$el._tooltip._currentAnimation = animation;
|
||||
await animation.finished;
|
||||
} catch {} // eslint-disable-line no-empty
|
||||
|
||||
// Ещё одна проверка на сущестование $el._tooltip после await
|
||||
@@ -392,17 +378,14 @@ export const createTooltip = ($el, content, options) => {
|
||||
|
||||
if (options.hideOnClick === 'all') {
|
||||
$el._tooltip.hide();
|
||||
document.body.removeEventListener('click', $el._tooltip.hideOnClickListener);
|
||||
} else if (options.hideOnClick === 'toggle') {
|
||||
if ($el.contains(target)) {
|
||||
$el._tooltip.hide();
|
||||
document.body.removeEventListener('click', $el._tooltip.hideOnClickListener);
|
||||
}
|
||||
} else {
|
||||
// options.hideOnClick === true
|
||||
if ($el.contains(target) || !$el._tooltip.$tooltip.contains(target)) {
|
||||
$el._tooltip.hide();
|
||||
document.body.removeEventListener('click', $el._tooltip.hideOnClickListener);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@advdominion/tooltip",
|
||||
"version": "6.0.0",
|
||||
"version": "7.0.1",
|
||||
"type": "module",
|
||||
"packageManager": "yarn@4.9.4",
|
||||
"packageManager": "yarn@4.14.1",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user