Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 - Full Page Component Option #1537

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 24 additions & 7 deletions src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
]);
}
}
34 changes: 34 additions & 0 deletions src/Traits/Configuration/FullPageComponentConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Configuration;

trait FullPageComponentConfiguration
{
public function setLayout(string $layout): self
{
$this->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;
}
}
1 change: 1 addition & 0 deletions src/Traits/HasAllTraits.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trait HasAllTraits
WithEvents,
WithFilters,
WithFooter,
WithFullPageComponent,
WithLoadingPlaceholder,
WithPagination,
WithQueryString,
Expand Down
46 changes: 46 additions & 0 deletions src/Traits/Helpers/FullPageComponentHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits\Helpers;

trait FullPageComponentHelpers
{
public function hasExtends()
{
return $this->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;
}
}
20 changes: 20 additions & 0 deletions src/Traits/WithFullPageComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Traits;

use Rappasoft\LaravelLivewireTables\Traits\Configuration\FullPageComponentConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Helpers\FullPageComponentHelpers;

trait WithFullPageComponent
{
use FullPageComponentConfiguration,
FullPageComponentHelpers;

protected ?string $layout = null;

protected ?string $slot = null;

protected ?string $extends = null;

protected ?string $section = null;
}
36 changes: 36 additions & 0 deletions tests/Traits/Configuration/FullPageComponentConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Configuration;

use Rappasoft\LaravelLivewireTables\Tests\TestCase;

class FullPageComponentConfigurationTest extends TestCase
{
/** @test */
public function can_set_extends(): void
{
$this->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());
}
}