vironeer / toastr
一个用于显示toast通知的Laravel包。
v1.0
2024-05-20 15:46 UTC
Requires
- php: >=8.0
- illuminate/session: >=8.0
- illuminate/support: >=8.0
Requires (Dev)
- phpunit/phpunit: ^9.0
README
Vironeer Toastr是一个Laravel包,它为在Laravel应用程序中显示toast通知提供了一个简单的方法。
目录
安装
要开始使用Vironeer Toastr,请按照以下步骤操作
先决条件
- Laravel 8+
- PHP 8.0或更高版本
- Composer
安装包
您可以通过Composer安装此包
composer require vironeer/toastr
发布配置
发布包配置文件以自定义Toast消息设置
php artisan vendor:publish --tag=config --provider="Vironeer\Toastr\ToastrServiceProvider"
设置资产
您可以使用(CDN)资源并渲染Toast消息
@toastrStyles {{-- use the latest styles version --}} @toastrStyles(1.0.0) {{-- use a specific styles version --}} @toastrScripts {{-- use the latest scripts version --}} @toastrScripts(1.0.0) {{-- use a specific scripts version --}} @toastrRender
或者您可以将资源(CSS和JS)发布到您的公共目录
php artisan vendor:publish --tag=toastr-assets --provider="Vironeer\Toastr\ToastrServiceProvider"
并在HTML页面中包含它们
<!DOCTYPE html> <html> <head> <!-- Include Toastr CSS --> <link rel="stylesheet" href="{{ asset('vendor/toastr/css/vironeer-toastr.min.css') }}"> </head> <body> <!-- Your HTML content --> <!-- Include Toastr JavaScript --> <script src="{{ asset('vendor/toastr/js/vironeer-toastr.min.js') }}"></script> @toastrRender </body> </html>
用法
您可以使用提供的辅助函数或外观在任何位置显示Toast消息
使用辅助函数
// Display an info notification toastr()->info('This is an info message', 'Info'); // Display a success notification toastr()->success('This is a success message', 'Success'); // Display a warning notification toastr()->warning('This is a warning message', 'Warning'); // Display an error notification toastr()->error('This is an error message', 'Error');
使用外观
您还可以使用Toast外观来显示通知
use Toastr; // Display an info notification Toastr::info('This is an info message', 'Info'); // Display a success notification Toastr::success('This is a success message', 'Success'); // Display a warning notification Toastr::warning('This is a warning message', 'Warning'); // Display an error notification Toastr::error('This is an error message', 'Error');
配置
您可以通过修改位于config/toastr.php的配置文件来自定义Toast设置。在这里,您可以指定通知选项、持续时间、位置等。
<?php return [ /* |-------------------------------------------------------------------------- | Toastr Configuration |-------------------------------------------------------------------------- | | This configuration file allows you to customize the behavior and appearance | of Toastr notifications. | */ 'options' => [ /* |-------------------------------------------------------------------------- | Default Notification Duration |-------------------------------------------------------------------------- | | The default duration (in milliseconds) for how long a notification will | be displayed on the screen before it automatically disappears. | */ 'duration' => 3000, /* |-------------------------------------------------------------------------- | Show/Hide Animation Duration |-------------------------------------------------------------------------- | | The duration (in milliseconds) for the show and hide animations of the | notification. | */ 'animationDuration' => 400, /* |-------------------------------------------------------------------------- | Progress Bar |-------------------------------------------------------------------------- | | Enable or disable the progress bar that indicates the remaining time | for auto-closing notifications. | */ 'progressBar' => true, /* |-------------------------------------------------------------------------- | Auto-Close Notifications |-------------------------------------------------------------------------- | | Enable or disable auto-closing of notifications after the specified | duration. | */ 'autoClose' => true, /* |-------------------------------------------------------------------------- | Close Button |-------------------------------------------------------------------------- | | Enable or disable the close button on notifications. | */ 'closeButton' => true, /* |-------------------------------------------------------------------------- | Close Button Icon |-------------------------------------------------------------------------- | | Customize the icon for the close button (if enabled). | */ 'closeButtonIcon' => 'vironeer-toast-close-icon', /* |-------------------------------------------------------------------------- | Notification Position Class |-------------------------------------------------------------------------- | | Set the position class for notifications (toast-top-right, toast-top-center, toast-top-left, | toast-bottom-right, toast-bottom-center, toast-bottom-left). | */ 'positionClass' => 'vironeer-toast-top-right', /* |-------------------------------------------------------------------------- | Show Notification Icons |-------------------------------------------------------------------------- | | Enable or disable the display of icons in notifications. | */ 'showIcon' => true, /* |-------------------------------------------------------------------------- | Prevent Duplicates |-------------------------------------------------------------------------- | | Enable or disable duplicating the toasts | */ 'preventDuplicates' => true, /* |-------------------------------------------------------------------------- | Icon Classes |-------------------------------------------------------------------------- | | Define custom icon classes for different notification types. | */ 'icons' => [ 'info' => 'vironeer-toast-info-icon', 'warning' => 'vironeer-toast-warning-icon', 'success' => 'vironeer-toast-success-icon', 'error' => 'vironeer-toast-error-icon', ], /* |-------------------------------------------------------------------------- | Notification Color Classes |-------------------------------------------------------------------------- | | Define custom color classes for different notification types. | */ 'colorsClasses' => [ 'info' => 'vironeer-toast-info', 'warning' => 'vironeer-toast-warning', 'success' => 'vironeer-toast-success', 'error' => 'vironeer-toast-error', ], ], ];
贡献
我们欢迎社区的贡献。如果您发现了一个错误,有一个功能请求或想改进这个包,请打开一个问题或提交一个pull请求。
许可证
此包是开源软件,并使用MIT许可证。
您可以在个人和商业项目中免费使用、修改和分发此包。但是,我们恳请您在使用此包时包含原始许可证说明和归属。
关于MIT许可证的完整文本,请参阅此存储库中包含的LICENSE文件。
联系
对于支持、问题或反馈,请随时联系我们
我们重视您的意见,并随时为您提供帮助。