Skip to content

Issue #1809 has been fixed. #2223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/Webkul/Admin/src/Resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ window.app = createApp({
}

const parentElement = event.currentTarget.parentElement;

if (parentElement.classList.contains('sidebar-collapsed')) {
parentElement.classList.remove('sidebar-collapsed');

parentElement.classList.add('sidebar-not-collapsed');
}

Expand All @@ -67,7 +67,7 @@ window.app = createApp({
}

const parentElement = event.currentTarget.parentElement;

if (parentElement.classList.contains('sidebar-not-collapsed')) {
parentElement.classList.remove('sidebar-not-collapsed');

Expand All @@ -79,7 +79,7 @@ window.app = createApp({
const sidebar = this.$refs.sidebar;

if (
sidebar &&
sidebar &&
!sidebar.contains(event.target)
) {
this.isMenuActive = false;
Expand Down Expand Up @@ -107,6 +107,7 @@ import VeeValidate from "./plugins/vee-validate";
import CreateElement from "./plugins/createElement";
import Draggable from "./plugins/draggable";
import VueCal from "./plugins/vue-cal";

[
Admin,
Axios,
Expand All @@ -123,9 +124,11 @@ import VueCal from "./plugins/vue-cal";
*/
import Debounce from "./directives/debounce";
import DOMPurify from "./directives/dompurify";
import ToolTip from "./directives/tooltip";

app.directive("debounce", Debounce);
app.directive("safe-html", DOMPurify);
app.directive("tooltip", ToolTip);

export default app;

143 changes: 143 additions & 0 deletions packages/Webkul/Admin/src/Resources/assets/js/directives/tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
export default {
mounted(el, binding) {
initTooltip(el, binding);
},
updated(el, binding) {
initTooltip(el, binding);
}
};

const initTooltip = (el, binding) => {
const defaultOptions = {
placement: 'top',
trigger: 'hover',
html: false,
content: '',
delay: { show: 200, hide: 100 }
};

const options = {
...defaultOptions,
...(typeof binding.value === 'object' ? binding.value : { content: binding.value })
};

let tooltip = document.getElementById(`tooltip-${el.tooltipId}`);

if (! tooltip) {
el.tooltipId = Math.random().toString(36).substring(2, 9);
tooltip = document.createElement('div');
tooltip.id = `tooltip-${el.tooltipId}`;
tooltip.className = 'max-w-[250px] break-words rounded-lg bg-gray-800 px-4 py-3 text-sm leading-snug text-white shadow-lg transition-opacity transition-transform duration-200';
tooltip.style.display = 'none';
tooltip.style.position = 'absolute';
tooltip.style.zIndex = '10000';

const inner = document.createElement('div');
inner.className = 'tooltip-inner';

const arrow = document.createElement('div');
arrow.className = 'absolute h-0 w-0 border-solid';

tooltip.appendChild(inner);
tooltip.appendChild(arrow);
document.body.appendChild(tooltip);

if (options.html) {
inner.innerHTML = options.content;
} else {
inner.textContent = options.content;
}

el._tooltip = tooltip;

const showTooltip = () => {
tooltip.style.display = 'block';

const rect = el.getBoundingClientRect();
const tooltipRect = tooltip.getBoundingClientRect();

let top, left;

switch (options.placement) {
case 'top':
top = rect.top - tooltipRect.height - 10;
left = rect.left + (rect.width / 2) - (tooltipRect.width / 2);
arrow.style.top = 'auto';
arrow.style.bottom = '-5px';
arrow.style.left = '50%';
arrow.style.transform = 'translateX(-50%)';
break;
case 'bottom':
top = rect.bottom + 10;
left = rect.left + (rect.width / 2) - (tooltipRect.width / 2);
arrow.style.bottom = 'auto';
arrow.style.top = '-5px';
arrow.style.left = '50%';
arrow.style.transform = 'translateX(-50%) rotate(180deg)';
break;
case 'left':
top = rect.top + (rect.height / 2) - (tooltipRect.height / 2);
left = rect.left - tooltipRect.width - 10;
arrow.style.top = '50%';
arrow.style.left = 'auto';
arrow.style.right = '-5px';
arrow.style.transform = 'translateY(-50%) rotate(-90deg)';
break;
case 'right':
top = rect.top + (rect.height / 2) - (tooltipRect.height / 2);
left = rect.right + 10;
arrow.style.top = '50%';
arrow.style.right = 'auto';
arrow.style.left = '-5px';
arrow.style.transform = 'translateY(-50%) rotate(90deg)';
break;
}

if (top < 0) {
top = 0;
}

if (left < 0) {
left = 0;
}

if (left + tooltipRect.width > window.innerWidth) {
left = window.innerWidth - tooltipRect.width;
}

tooltip.style.top = `${top + window.scrollY}px`;
tooltip.style.left = `${left + window.scrollX}px`;
};

const hideTooltip = () => {
tooltip.style.display = 'none';
};

if (options.trigger === 'hover') {
el.addEventListener('mouseenter', () => {
el._showTimeout = setTimeout(showTooltip, options.delay.show);
});

el.addEventListener('mouseleave', () => {
clearTimeout(el._showTimeout);
el._hideTimeout = setTimeout(hideTooltip, options.delay.hide);
});
} else if (options.trigger === 'click') {
el.addEventListener('click', showTooltip);

document.addEventListener('click', (e) => {
if (e.target !== el && !el.contains(e.target)) {
hideTooltip();
}
});
}
} else {
const inner = tooltip.querySelector('.tooltip-inner');

if (options.html) {
inner.innerHTML = options.content;
} else {
inner.textContent = options.content;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,57 +146,8 @@ class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
type="text"
placeholder="@lang('admin::app.common.start-typing')"
/>

<x-admin::form.control-group.error control-name="comment" />
</x-admin::form.control-group>

<!-- Participants -->
<x-admin::form.control-group>
<x-admin::form.control-group.label>
@lang('admin::app.activities.edit.participants')
</x-admin::form.control-group.label>

<!-- Participants Multi lookup Vue Component -->
<v-multi-lookup-component>
<div
class="relative rounded border border-gray-200 px-2 py-1 hover:border-gray-400 focus:border-gray-400 dark:border-gray-800 dark:hover:border-gray-400 dark:focus:border-gray-400"
role="button"
>
<ul class="flex flex-wrap items-center gap-1">
<li>
<input
type="text"
class="w-full px-1 py-1 dark:bg-gray-900 dark:text-gray-300"
placeholder="@lang('admin::app.activities.edit.participants')"
/>
</li>
</ul>

<span class="icon-down-arrow absolute top-1.5 text-2xl ltr:right-1.5 rtl:left-1.5"></span>
</div>
</v-multi-lookup-component>
</x-admin::form.control-group>

<!-- Lead -->
<x-admin::form.control-group class="!mb-0">
<x-admin::form.control-group.label>
@lang('admin::app.activities.edit.lead')
</x-admin::form.control-group.label>

<x-admin::attributes.edit.lookup/>

<!-- Lead Lookup Vue Component -->
<v-lookup-component
:attribute="{'code': 'lead_id', 'name': 'Lead', 'lookup_type': 'leads'}"
:value='@json($lookUpEntityData)'
can-add-new="true"
>
<x-admin::form.control-group.control
type="text"
placeholder="@lang('admin::app.common.start-typing')"
/>
</v-lookup-component>
</x-admin::form.control-group>
</v-lookup-component>
</x-admin::form.control-group>

{!! view_render_event('admin.activities.edit.form_controls.after') !!}
</div>
Expand Down
Loading
Loading