Skip to content
Merged
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
14 changes: 4 additions & 10 deletions src/Views/Columns/ComponentColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
use Illuminate\View\ComponentAttributeBag;
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Traits\Columns\{HasComponentView, HasSlot};
use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\ComponentColumnConfiguration;
use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\ComponentColumnHelpers;

class ComponentColumn extends Column
{
use ComponentColumnConfiguration,
ComponentColumnHelpers;

protected string $componentView;

protected mixed $slotCallback = null;
use HasComponentView,
HasSlot;

public function __construct(string $title, ?string $from = null)
{
Expand Down Expand Up @@ -46,10 +43,7 @@
}
}
if ($this->hasSlotCallback()) {
$slotContent = call_user_func($this->getSlotCallback(), $value, $row, $this);
if (is_string($slotContent)) {
$slotContent = new HtmlString($slotContent);
}
$slotContent = $this->getSlotContent($row, $value);

Check warning on line 46 in src/Views/Columns/ComponentColumn.php

View check run for this annotation

Codecov / codecov/patch

src/Views/Columns/ComponentColumn.php#L46

Added line #L46 was not covered by tests
}

return view($this->getComponentView(), [
Expand Down
6 changes: 3 additions & 3 deletions src/Views/Columns/ViewComponentColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
use Illuminate\Support\HtmlString;
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Traits\Columns\HasComponentView;
use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\ViewComponentColumnConfiguration;
use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\ViewComponentColumnHelpers;
use ReflectionClass;

class ViewComponentColumn extends Column
{
use ViewComponentColumnConfiguration,
ViewComponentColumnHelpers;

protected ?string $componentView;
ViewComponentColumnHelpers,
HasComponentView;

protected ?string $customComponentView;

Expand Down
25 changes: 25 additions & 0 deletions src/Views/Traits/Columns/HasComponentView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Views\Traits\Columns;

trait HasComponentView
{
protected string $componentView;

public function component(string $component): self
{
$this->componentView = 'components.'.$component;

return $this;
}

public function getComponentView(): string
{
return $this->componentView;
}

public function hasComponentView(): bool
{
return isset($this->componentView);
}
}
39 changes: 39 additions & 0 deletions src/Views/Traits/Columns/HasSlot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Rappasoft\LaravelLivewireTables\Views\Traits\Columns;

use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\HtmlString;

trait HasSlot
{
protected ?Closure $slotCallback = null;

public function getSlotContent(Model $row, mixed $value): string|HtmlString

Check warning on line 13 in src/Views/Traits/Columns/HasSlot.php

View check run for this annotation

Codecov / codecov/patch

src/Views/Traits/Columns/HasSlot.php#L13

Added line #L13 was not covered by tests
{
$slotContent = call_user_func($this->getSlotCallback(), $value, $row, $this);
if (is_string($slotContent)) {
$slotContent = new HtmlString($slotContent);

Check warning on line 17 in src/Views/Traits/Columns/HasSlot.php

View check run for this annotation

Codecov / codecov/patch

src/Views/Traits/Columns/HasSlot.php#L15-L17

Added lines #L15 - L17 were not covered by tests
}

return $slotContent;

Check warning on line 20 in src/Views/Traits/Columns/HasSlot.php

View check run for this annotation

Codecov / codecov/patch

src/Views/Traits/Columns/HasSlot.php#L20

Added line #L20 was not covered by tests
}

public function getSlotCallback(): ?callable
{
return $this->slotCallback;
}

public function hasSlotCallback(): bool
{
return isset($this->slotCallback) && $this->slotCallback !== null;
}

public function slot(callable $callback): self
{
$this->slotCallback = $callback;

return $this;
}
}
20 changes: 0 additions & 20 deletions src/Views/Traits/Configuration/ComponentColumnConfiguration.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@

trait ViewComponentColumnConfiguration
{
/**
* Defines the View Component to be used for the Column
*/
public function component(string $component): self
{
$this->componentView = $component;

return $this;
}

public function customComponent(string $customComponentView): self
{
$this->customComponentView = $customComponentView;
Expand Down
26 changes: 0 additions & 26 deletions src/Views/Traits/Helpers/ComponentColumnHelpers.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Views/Traits/Helpers/ViewComponentColumnHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@

trait ViewComponentColumnHelpers
{
/**
* Retrieves the defined Component View
*/
public function getComponentView(): string
{
return $this->componentView;
}

/**
* Determines whether a Component View has been set
*/
public function hasComponentView(): bool
{
return isset($this->componentView);
}

public function hasCustomComponent(): bool
{
return isset($this->customComponentView);
Expand Down
Loading