الطبقات العائمة
tooltip
تلميح يظهر عند المرور أو التركيز مع تحديد الجهة.
أضف إلى المكتبة
<x-ui.tooltip text="أضف إلى المكتبة">
<x-ui.button variant="outline">مرّر المؤشر هنا</x-ui.button>
</x-ui.tooltip>
التثبيت
php artisan ui:add tooltip
1. ثبّت الاعتماديات
- composer:
gehrisandro/tailwind-merge-laravel
2.
انسخ الكود إلى
resources/views/components/ui/
resources/views/components/ui/tooltip.blade.php
@props([
'text' => '',
'side' => 'top',
])
@php
$position = match ($side) {
'bottom' => 'top-full mt-2 left-1/2 -translate-x-1/2',
'left' => 'right-full mr-2 top-1/2 -translate-y-1/2',
'right' => 'left-full ml-2 top-1/2 -translate-y-1/2',
// start and end follow the document direction; left and right don't.
'start' => 'end-full me-2 top-1/2 -translate-y-1/2',
'end' => 'start-full ms-2 top-1/2 -translate-y-1/2',
default => 'bottom-full mb-2 left-1/2 -translate-x-1/2',
};
// Shown while the wrapper is hovered or anything inside it holds focus, so
// pointer and keyboard both work. No JavaScript needed.
$tipClasses = \TailwindMerge\Laravel\Facades\TailwindMerge::merge(
'pointer-events-none invisible absolute z-50 w-fit max-w-xs text-balance rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground opacity-0 transition-opacity duration-150 group-hover:visible group-hover:opacity-100 group-focus-within:visible group-focus-within:opacity-100',
$position,
$attributes->get('class'),
);
@endphp
<span class="group relative inline-flex" {{ $attributes->except('class') }}>
{{ $slot }}
<span role="tooltip" class="{{ $tipClasses }}">
{{ $text }}
</span>
</span>
الاستخدام
<x-ui.tooltip text="Add to library">
<x-ui.button variant="outline">Hover me</x-ui.button>
</x-ui.tooltip>
{{-- side: top (default), bottom, start or end. start and end follow
dir="rtl"; left and right stay physical. --}}
<x-ui.tooltip text="Deletes the project for everyone" side="end">
<x-ui.button variant="destructive">Delete</x-ui.button>
</x-ui.tooltip>
CSS خالص (المرور مع focus-within)، بلا JavaScript إطلاقًا. غلّف المشغّل في الخانة؛ ومرّر text وside الاختيارية (top|bottom|start|end، أو left|right الفعليتين). start وend تتبعان dir="rtl".
الخصائص
كل خاصية مع قيمتها الافتراضية. مرّر أيًّا منها كسمة، واستخدم : لربط قيمة PHP.
@props([
'text' => '',
'side' => 'top',
])