cngmc / dialogboxbslw
对话框 Bootstrap Livewire
dev-master
2024-08-07 15:03 UTC
Requires
- php: ^8.2
Requires (Dev)
- livewire/livewire: ^3.5
- orchestra/testbench: ^9.1
- phpunit/phpunit: ^11.0.1
This package is not auto-updated.
Last update: 2024-09-25 18:46:37 UTC
README
-
版本:1.0 测试版
bla bla..
安装、要求和使用说明
安装
composer require cngmc/dialogboxbslw
要求
- Livewire
- Bootstrap 5
- jQuery
基本使用说明
示例 Livewire 组件(livewire/sample.php)
public function boot(): void { $dialogBox = [ "box" => [ 'name' => 'sample', 'id' => 'dialogbox-sample', // Bootstrap modal ID "contents" => [ 'title' => 'Sample Title', 'body' => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", 'cancelButtonText' => "Cancel", 'actionButtonText' => "Accept" ], ], 'acceptFn' => function () { return $this->accept($this->dialogBoxes['sample']['box']['params'][0], $this->dialogBoxes['sample']['box']['params'][1]); }, 'cancelFn' => function () { return $this->cancel($this->dialogBoxes['sample']['box']['params'][0], $this->dialogBoxes['sample']['box']['params'][1]); } ]; $this->setDialogBox('sample', $dialogBox); } private function accept($param1, $param2) { return 'accepted'; } private function cancel($param1, $param2) { return 'canceled'; }
示例 Livewire 组件 blade 文件(livewire/sample.blade.php)
<button wire:click="dialogBox('sample', 'openFn', '1', 'Test')" class="btn btn-primary">Open Dialog</button>
<x-dialogboxbslw::dialog modal="dialogbox-sample" />
高级使用
自定义视图
php artisan vendor:publish --tag=dialogboxbslw --force
您可以在 resources/views/vendor/dialogboxbslw/components/dialog.blade.php 中对自定义组件设计进行必要的调整
在对话框中使用动态数据
示例 Livewire 组件(sample.php)
use DialogBox {
DialogBox::dialogBoxOpenFn as private parentDialogBoxOpenFn;
}
private function dialogBoxOpenFn($name, $params): bool
{
$this->dialogBoxes[$name]['box']['contents']['title'] = 'Custom Title Params 0: ' . $params[0]. ' Params 1: ' . $params[1]; $this->dialogBoxes[$name]['box']['contents']['title'] = 'Custom Title Params 0: ' . $params[0]. ' Params 1: ' . $params[1];
$this->parentDialogBoxOpenFn($name);
}
测试
vendor/bin/phpunit
许可证
DialogBoxBsLw 包是开源软件,许可协议为 MIT 许可证。