diff --git a/CHANGELOG.md b/CHANGELOG.md index d5ebe7647..5e5520c15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to `laravel-livewire-tables` will be documented in this file +## UNRELEASED +- Add Full Page Component capability by @amshehzad in https://github.com/rappasoft/laravel-livewire-tables/pull/1430 + ## [v3.1.3] - 2023-11-03 - Add additional Lifecycle Hook by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534 - SettingColumns/ColumnsSet diff --git a/src/DataTableComponent.php b/src/DataTableComponent.php index 6200ba35b..36f5e8b13 100644 --- a/src/DataTableComponent.php +++ b/src/DataTableComponent.php @@ -109,12 +109,29 @@ public function customView(): string public function render(): \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View { - return view('livewire-tables::datatable') - ->with([ - 'filterGenericData' => $this->getFilterGenericData(), - 'columns' => $this->getColumns(), - 'rows' => $this->getRows(), - 'customView' => $this->customView(), - ]); + $view = view('livewire-tables::datatable'); + + if ($this->hasLayout()) { + $view->layout($this->layout); + } + + if ($this->hasExtends()) { + $view->extends($this->extends); + } + + if ($this->hasSection()) { + $view->section($this->section); + } + + if ($this->hasSlot()) { + $view->slot($this->slot); + } + + return $view->with([ + 'filterGenericData' => $this->getFilterGenericData(), + 'columns' => $this->getColumns(), + 'rows' => $this->getRows(), + 'customView' => $this->customView(), + ]); } } diff --git a/src/Traits/Configuration/FullPageComponentConfiguration.php b/src/Traits/Configuration/FullPageComponentConfiguration.php new file mode 100644 index 000000000..0648b1491 --- /dev/null +++ b/src/Traits/Configuration/FullPageComponentConfiguration.php @@ -0,0 +1,34 @@ +layout = $layout; + + return $this; + } + + public function setSlot(string $slot): self + { + $this->slot = $slot; + + return $this; + } + + public function setExtends(string $layout): self + { + $this->extends = $layout; + + return $this; + } + + public function setSection(string $section): self + { + $this->section = $section; + + return $this; + } +} diff --git a/src/Traits/HasAllTraits.php b/src/Traits/HasAllTraits.php index 6ffd5eba8..0c0366c42 100644 --- a/src/Traits/HasAllTraits.php +++ b/src/Traits/HasAllTraits.php @@ -15,6 +15,7 @@ trait HasAllTraits WithEvents, WithFilters, WithFooter, + WithFullPageComponent, WithLoadingPlaceholder, WithPagination, WithQueryString, diff --git a/src/Traits/Helpers/FullPageComponentHelpers.php b/src/Traits/Helpers/FullPageComponentHelpers.php new file mode 100644 index 000000000..917a715de --- /dev/null +++ b/src/Traits/Helpers/FullPageComponentHelpers.php @@ -0,0 +1,46 @@ +extends !== null; + } + + public function getExtends() + { + return $this->extends; + } + + public function hasSection() + { + return $this->section !== null; + } + + public function getSection() + { + return $this->section; + } + + public function hasSlot() + { + return $this->slot !== null; + } + + public function getSlot() + { + return $this->slot; + } + + public function hasLayout() + { + return $this->layout !== null; + } + + public function getLayout() + { + return $this->layout; + } +} diff --git a/src/Traits/WithFullPageComponent.php b/src/Traits/WithFullPageComponent.php new file mode 100644 index 000000000..611667b9a --- /dev/null +++ b/src/Traits/WithFullPageComponent.php @@ -0,0 +1,20 @@ +basicTable->setExtends('app.layout'); + $this->assertEquals('app.layout', $this->basicTable->getExtends()); + } + + /** @test */ + public function can_set_layout(): void + { + $this->basicTable->setLayout('app.layout'); + $this->assertEquals('app.layout', $this->basicTable->getLayout()); + } + + /** @test */ + public function can_set_section(): void + { + $this->basicTable->setSection('content'); + $this->assertEquals('content', $this->basicTable->getSection()); + } + + /** @test */ + public function can_set_slot(): void + { + $this->basicTable->setSlot('my_slot'); + $this->assertEquals('my_slot', $this->basicTable->getSlot()); + } +}