miladkermanji/livewire-tooltip 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

miladkermanji/livewire-tooltip

Composer 安装命令:

composer require miladkermanji/livewire-tooltip

包简介

A Livewire component for displaying tooltips with Popper.js, supporting static and dynamic content.

README 文档

README

A lightweight Laravel package that provides a Livewire component for displaying tooltips using Popper.js. It supports both static tooltips via data-tooltip and dynamic content via tooltip-method, with smooth fade-in/fade-out animations.

Features

  • Static Tooltips: Display simple text tooltips using data-tooltip.
  • Dynamic Tooltips: Fetch content from Livewire methods using tooltip-method.
  • Smooth Animations: 300ms fade-in/fade-out transitions.
  • Livewire Compatible: Works seamlessly with Livewire updates.
  • Prevent Empty Tooltips: Ensures only valid tooltips are shown.
  • Customizable: Configure placement and animation duration.
  • Lightweight: Minimal footprint with no unnecessary dependencies.

Requirements

  • PHP 8.1 or higher
  • Laravel 10.0, 11.0, or 12.0
  • Livewire 3.0 or higher
  • Popper.js (via CDN or npm)

Installation

  1. Install the Package

    Install the package via Composer:

    composer require miladkermanji/livewire-tooltip
  2. Add Popper.js

    Include Popper.js in your Laravel layout (e.g., resources/views/layouts/app.blade.php) before the closing </body> tag:

    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2/dist/umd/popper.min.js"></script>

    Alternatively, if using npm:

    npm install @popperjs/core

    Then import it in your JavaScript file (e.g., resources/js/app.js):

    import Popper from '@popperjs/core';
    window.Popper = Popper;
  3. Register the Tooltip Component

    Add the Livewire component to your layout or specific view (e.g., resources/views/layouts/app.blade.php or resources/views/livewire/dr/panel/turn/schedule/appointments-list.blade.php):

    <livewire:miladkermanji-tooltip wire:key="tooltip-component" />
  4. Clear Cache (Optional)

    Clear Laravel caches to ensure smooth integration:

    php artisan cache:clear
    php artisan config:clear
    php artisan view:clear
    composer dump-autoload

Usage

Static Tooltips

Add the tooltip-link class and data-tooltip attribute to any HTML element:

<button class="tooltip-link" data-tooltip="Cancel appointment" data-placement="top">
    Hover me
</button>

Dynamic Tooltips

Use the tooltip-method attribute to call a Livewire method for dynamic content:

<button class="tooltip-link" tooltip-method="\App\Livewire\MyComponent@getTooltipContent" data-param1="value">
    Dynamic Tooltip
</button>

In your Livewire component (e.g., app/Livewire/MyComponent.php):

namespace App\Livewire;

use Livewire\Component;

class MyComponent extends Component
{
    public function getTooltipContent($param1)
    {
        return "Dynamic content: $param1";
    }

    public function render()
    {
        return view('livewire.my-component');
    }
}

Example in a Real Project

In resources/views/livewire/dr/panel/turn/schedule/appointments-list.blade.php, you can use the tooltip for action buttons:

<button class="btn btn-light rounded-circle shadow-sm tooltip-link"
        data-tooltip="جابجایی نوبت"
        data-placement="top"
        wire:click="$dispatch('showModal', {data: {'alias': 'reschedule-modal', 'params': {'appointmentId': {{ $appointment->id }}}}})"
        {{ $appointment->status === 'cancelled' || $appointment->status === 'attended' ? 'disabled' : '' }}>
    <img src="{{ asset('dr-assets/icons/rescheule-appointment.svg') }}" alt="جابجایی">
</button>

<button class="btn btn-light rounded-circle shadow-sm tooltip-link"
        data-tooltip="لغو نوبت"
        data-placement="top"
        wire:click="cancelSingleAppointment({{ $appointment->id }})"
        {{ $appointment->status === 'cancelled' || $appointment->status === 'attended' ? 'disabled' : '' }}>
    <img src="{{ asset('dr-assets/icons/cancle-appointment.svg') }}" alt="لغو">
</button>

Configuration

You can publish the configuration file to customize default settings:

php artisan vendor:publish --tag=livewire-tooltip-config

This will create a config/livewire-tooltip.php file with the following defaults:

<?php

return [
    'default_placement' => 'top', // Options: top, right, bottom, left
    'animation_duration' => 300,  // Duration in milliseconds
];

Debugging

If tooltips don't appear or show empty content:

  1. Check Popper.js: Ensure Popper.js is loaded:

    console.log('Popper:', typeof Popper !== 'undefined');
  2. Inspect Tooltip Links: Verify that elements have the tooltip-link class and valid data-tooltip or tooltip-method attributes:

    console.log('Tooltip links:', document.querySelectorAll('.tooltip-link').length);
  3. Check Console Logs: Look for warnings or errors:

    console.warn('Invalid tooltip link:', ...);
    console.debug('Tooltip shown:', ...);
  4. Review Laravel Logs: Check storage/logs/laravel.log for any errors related to the tooltip component.

Contributing

Contributions are welcome! Please submit a pull request or open an issue on the GitHub repository.

License

This package is open-sourced under the MIT License.

About

Created by Miladkermanji. Built with ❤️ for the Laravel community.

miladkermanji/livewire-tooltip 适用场景与选型建议

miladkermanji/livewire-tooltip 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 miladkermanji/livewire-tooltip 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 miladkermanji/livewire-tooltip 我们能提供哪些服务?
定制开发 / 二次开发

基于 miladkermanji/livewire-tooltip 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-26