Skip to content

Commit 3449b90

Browse files
committed
add import button component
1 parent cd155d4 commit 3449b90

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<button
2+
{{ $attributes }}
3+
x-data
4+
x-on:click="window.livewire.emitTo('csv-importer', 'toogle')">
5+
{{ $slot }}
6+
</button>

src/LaravelCsvServiceProvider.php

+33-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Coderflex\LaravelCsv\Commands\LaravelCsvCommand;
66
use Coderflex\LaravelCsv\Http\Livewire\CsvImporter;
77
use Coderflex\LaravelCsv\Http\Livewire\HandleImports;
8+
use Illuminate\Support\Facades\Blade;
9+
use Illuminate\View\Compilers\BladeCompiler;
810
use Livewire\Livewire;
911
use Spatie\LaravelPackageTools\Package;
1012
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -29,11 +31,41 @@ public function configurePackage(Package $package): void
2931
public function bootingPackage()
3032
{
3133
$this->registerLivewireComponents();
34+
35+
$this->configureComponents();
36+
}
37+
38+
/**
39+
* Configure Laravel CSV Blade components
40+
*
41+
* @return void
42+
*/
43+
protected function configureComponents(): void
44+
{
45+
$this->callAfterResolving(BladeCompiler::class, function () {
46+
$this->registerComponent('button');
47+
});
3248
}
3349

34-
private function registerLivewireComponents()
50+
/**
51+
* Register livewire components
52+
*
53+
* @return void
54+
*/
55+
protected function registerLivewireComponents(): void
3556
{
3657
Livewire::component('csv-importer', CsvImporter::class);
3758
Livewire::component('handle-imports', HandleImports::class);
3859
}
60+
61+
/**
62+
* Register given component.
63+
*
64+
* @param string $component
65+
* @return void
66+
*/
67+
protected function registerComponent(string $component): void
68+
{
69+
Blade::component('laravel-csv::components.'.$component, 'csv-'.$component);
70+
}
3971
}

0 commit comments

Comments
 (0)