summaryrefslogtreecommitdiff
path: root/src/Columns
diff options
context:
space:
mode:
Diffstat (limited to 'src/Columns')
-rw-r--r--src/Columns/ButtonColumn.php3
-rw-r--r--src/Columns/Column.php41
-rw-r--r--src/Columns/ElementColumn.php8
-rw-r--r--src/Columns/LinkColumn.php9
4 files changed, 34 insertions, 27 deletions
diff --git a/src/Columns/ButtonColumn.php b/src/Columns/ButtonColumn.php
index 2124a37..0c76557 100644
--- a/src/Columns/ButtonColumn.php
+++ b/src/Columns/ButtonColumn.php
@@ -11,8 +11,7 @@ class ButtonColumn extends ElementColumn
protected function getElemAttributes(Model $row): array
{
return parent::getElemAttributes($row) + [
- 'type' => 'button'
+ 'type' => 'button',
];
}
-
}
diff --git a/src/Columns/Column.php b/src/Columns/Column.php
index e260472..0638490 100644
--- a/src/Columns/Column.php
+++ b/src/Columns/Column.php
@@ -2,30 +2,32 @@
namespace Lightscale\LaralightTables\Columns;
-use Lightscale\LaralightTables\TableComponent;
-use Lightscale\LaralightTables\Concerns\Makable;
-
-use Illuminate\Database\Eloquent\Model;
+use Closure;
use Illuminate\Database\Eloquent\Builder;
-use Illuminate\View\ComponentAttributeBag;
+use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\HtmlString;
+use Illuminate\View\ComponentAttributeBag;
+use Lightscale\LaralightTables\Concerns\Makable;
+use Lightscale\LaralightTables\TableComponent;
-use Closure;
-
-class Column {
+class Column
+{
use Makable;
/**
* @var TableComponent<Model>
*/
private TableComponent $table;
+
private bool $showInSelect;
+
private bool $shouldEscape = true;
/**
* @var ?Closure(Model, Column): string
*/
private ?Closure $slotFn = null;
+
private ?Closure $sortFn = null;
/**
@@ -44,7 +46,8 @@ class Column {
/**
* @template TModel of Model
- * @param TableComponent<TModel> $table
+ *
+ * @param TableComponent<TModel> $table
*/
public function setTable(TableComponent $table): void
{
@@ -61,9 +64,10 @@ class Column {
return (string) $row->{$this->name};
}
- public function slot(callable $fn) : static
+ public function slot(callable $fn): static
{
$this->slotFn = Closure::fromCallable($fn);
+
return $this;
}
@@ -72,6 +76,7 @@ class Column {
if ($fn !== null) {
$this->sortFn = Closure::fromCallable($fn);
}
+
return $this;
}
@@ -82,7 +87,8 @@ class Column {
/**
* @template TModel of Model
- * @param Builder<TModel> $query
+ *
+ * @param Builder<TModel> $query
*/
public function applySort(Builder $query, ?string $dir): void
{
@@ -91,26 +97,29 @@ class Column {
}
}
- public function colClass(string $v) : static
+ public function colClass(string $v): static
{
$this->colClass = $v;
+
return $this;
}
- public function getColClass() : ?string
+ public function getColClass(): ?string
{
return $this->colClass;
}
- public function tdAttributes(callable $fn) : static
+ public function tdAttributes(callable $fn): static
{
$this->tdAttributesFn = Closure::fromCallable($fn);
+
return $this;
}
public function showInSelect(bool $show = true): static
{
$this->showInSelect = $show;
+
return $this;
}
@@ -122,6 +131,7 @@ class Column {
public function shouldEscape(bool $v): static
{
$this->shouldEscape = $v;
+
return $this;
}
@@ -133,6 +143,7 @@ class Column {
protected function getContent(Model $row): string
{
$content = $this->slotFn === null ? $this->defaultSlot($row) : ($this->slotFn)($row, $this);
+
return $this->escape($content);
}
@@ -149,7 +160,7 @@ class Column {
$attributes = $this->tdAttributesFn?->call($this, $row) ?? [];
$attributes = (new ComponentAttributeBag($attributes))->toHtml();
$content = $this->getContent($row);
+
return new HtmlString("<td {$attributes}>{$content}</td>");
}
-
}
diff --git a/src/Columns/ElementColumn.php b/src/Columns/ElementColumn.php
index aaac071..a6024e3 100644
--- a/src/Columns/ElementColumn.php
+++ b/src/Columns/ElementColumn.php
@@ -2,15 +2,13 @@
namespace Lightscale\LaralightTables\Columns;
+use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\HtmlString;
use Illuminate\View\ComponentAttributeBag;
-use Closure;
-
abstract class ElementColumn extends Column
{
-
protected string $element;
/**
@@ -18,9 +16,10 @@ abstract class ElementColumn extends Column
*/
private ?Closure $elemAttributesFn = null;
- public function attributes(callable $fn) : static
+ public function attributes(callable $fn): static
{
$this->elemAttributesFn = Closure::fromCallable($fn);
+
return $this;
}
@@ -42,5 +41,4 @@ abstract class ElementColumn extends Column
"<{$this->element} {$attributes}>{$content}</{$this->element}>"
);
}
-
}
diff --git a/src/Columns/LinkColumn.php b/src/Columns/LinkColumn.php
index 35cedcf..ee974df 100644
--- a/src/Columns/LinkColumn.php
+++ b/src/Columns/LinkColumn.php
@@ -2,9 +2,8 @@
namespace Lightscale\LaralightTables\Columns;
-use Illuminate\Database\Eloquent\Model;
-
use Closure;
+use Illuminate\Database\Eloquent\Model;
class LinkColumn extends ElementColumn
{
@@ -15,17 +14,17 @@ class LinkColumn extends ElementColumn
*/
private Closure $urlFn;
- public function url(callable $fn) : static
+ public function url(callable $fn): static
{
$this->urlFn = Closure::fromCallable($fn);
+
return $this;
}
- public function getElemAttributes(Model $row) : array
+ public function getElemAttributes(Model $row): array
{
return parent::getElemAttributes($row) + [
'href' => ($this->urlFn)($row),
];
}
-
}