summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Light <samlight1994@gmail.com>2025-09-24 00:12:43 +0100
committerSam Light <samlight1994@gmail.com>2025-09-24 00:12:43 +0100
commit94fd2a9a3cff8c926ce12046e01f481f15c02d76 (patch)
treeed9425d35a713ecee5de009fbb83b0012a0881d4
parent2aca9a441ef48fb66ace8a5bfb9d8b730bc4e925 (diff)
Changed the wrapper component to use a method
-rw-r--r--resources/views/components/dynamic-wrapper.blade.php9
-rw-r--r--resources/views/table.blade.php12
-rw-r--r--src/TableComponent.php17
3 files changed, 23 insertions, 15 deletions
diff --git a/resources/views/components/dynamic-wrapper.blade.php b/resources/views/components/dynamic-wrapper.blade.php
new file mode 100644
index 0000000..8593f3a
--- /dev/null
+++ b/resources/views/components/dynamic-wrapper.blade.php
@@ -0,0 +1,9 @@
+@use('Illuminate\View\ComponentAttributeBag')
+@props(['component'])
+@php
+$componentName = $component[0];
+$attributes = new ComponentAttributeBag($component[1] ?? []);
+@endphp
+<x-dynamic-component :component="$componentName" :$attributes>
+ {{ $slot }}
+</x-dynamic-component>
diff --git a/resources/views/table.blade.php b/resources/views/table.blade.php
index 741a27f..d4290a9 100644
--- a/resources/views/table.blade.php
+++ b/resources/views/table.blade.php
@@ -1,12 +1,12 @@
<div @class($rootClass)>
- <x-dynamic-component :component="$toolbarsWrapperComponent">
+ <x-laralight-tables::dynamic-wrapper :component="$this->wrapperComponent('toolbars')">
@foreach($toolbars as $toolbar)
{{ $toolbar?->render() }}
@endforeach
- </x-dynamic-component>
+ </x-laralight-tables::dynamic-wrapper>
- <x-dynamic-component :component="$tableWrapperComponent">
+ <x-laralight-tables::dynamic-wrapper :component="$this->wrapperComponent('table')">
<table @class($tableClass)>
<colgroup>
@foreach($columns as $column)
@@ -45,9 +45,9 @@
@endforeach
</tbody>
</table>
- </x-dynamic-component>
+ </x-laralight-tables::dynamic-wrapper>
- <x-dynamic-component :component="$paginationWrapperComponent">
+ <x-laralight-tables::dynamic-wrapper :component="$this->wrapperComponent('pagination')">
<div class="table-pagination d-flex justify-content-between align-items-center">
{{ $data->links() }}
<div>
@@ -56,6 +56,6 @@
</div>
</div>
- </x-dynamic-component>
+ </x-laralight-tables::dynamic-wrapper>
</div>
diff --git a/src/TableComponent.php b/src/TableComponent.php
index 180d7c4..34d56c8 100644
--- a/src/TableComponent.php
+++ b/src/TableComponent.php
@@ -41,12 +41,6 @@ abstract class TableComponent extends Component
protected string $tableClass = 'table';
- protected string $tableWrapperComponent = 'laralight-tables::wrapper';
-
- protected string $paginationWrapperComponent = 'laralight-tables::wrapper';
-
- protected string $toolbarsWrapperComponent = 'laralight-tables::wrapper';
-
// Properties
#[Url]
public string $search = '';
@@ -247,6 +241,14 @@ abstract class TableComponent extends Component
return $this->columnsCache;
}
+ /**
+ * @return array{0: string, 1?: array<string,mixed>}
+ */
+ public function wrapperComponent(string $location): array
+ {
+ return ['laralight-tables::wrapper'];
+ }
+
public function render(): View
{
$data = $this->buildQuery()->paginate($this->pageSize);
@@ -259,9 +261,6 @@ abstract class TableComponent extends Component
return view('laralight-tables::table', [
'rootClass' => $this->rootClass,
'tableClass' => $this->tableClass,
- 'tableWrapperComponent' => $this->tableWrapperComponent,
- 'paginationWrapperComponent' => $this->paginationWrapperComponent,
- 'toolbarsWrapperComponent' => $this->toolbarsWrapperComponent,
] + compact(
'data', 'allColumns', 'columns', 'toolbars',
));