coolify/resources/views/components/helper.blade.php

63 lines
2.3 KiB
PHP
Raw Permalink Normal View History

<div x-data="{
open: false,
pinned: false,
style: '',
show(pinned = false) {
this.pinned = pinned;
this.open = true;
this.$nextTick(() => this.position());
},
hide() {
if (!this.pinned) {
this.open = false;
}
},
close() {
this.pinned = false;
this.open = false;
},
position() {
const trigger = this.$refs.trigger;
const popup = this.$refs.popup;
if (!trigger || !popup) {
return;
}
const triggerRect = trigger.getBoundingClientRect();
const popupRect = popup.getBoundingClientRect();
const padding = 8;
let top = triggerRect.bottom + padding;
let left = triggerRect.right - popupRect.width;
if (top + popupRect.height > window.innerHeight - padding) {
top = triggerRect.top - popupRect.height - padding;
}
left = Math.min(Math.max(padding, left), window.innerWidth - popupRect.width - padding);
top = Math.max(padding, top);
this.style = `top: ${top}px; left: ${left}px;`;
}
}" @click.outside="close" @keydown.window.escape="close" @resize.window="open && position()" @scroll.window="open && position()"
{{ $attributes->merge(['class' => 'inline-block align-middle']) }}>
<div x-ref="trigger" class="info-helper" @mouseenter="show(false)" @mouseleave="hide" @click.stop="open && pinned ? close() : show(true)">
2024-04-12 11:15:24 +00:00
@isset($icon)
{{ $icon }}
@else
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-4 h-4 stroke-current">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
@endisset
2023-06-15 07:15:41 +00:00
</div>
<template x-teleport="body">
<div x-ref="popup" x-show="open" x-cloak :style="style"
class="fixed z-[9999] w-max max-w-[min(20rem,calc(100vw-2rem))] rounded-sm border border-neutral-300 bg-neutral-200 text-xs text-neutral-700 shadow-lg whitespace-normal break-words dark:border-coolgray-500 dark:bg-coolgray-400 dark:text-neutral-300">
<div class="p-4">
{!! $helper !!}
</div>
2023-06-15 07:15:41 +00:00
</div>
</template>
2023-06-15 07:15:41 +00:00
</div>