summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Light <samlight1994@gmail.com>2025-09-23 22:54:57 +0100
committerSam Light <samlight1994@gmail.com>2025-09-23 22:54:57 +0100
commit2aca9a441ef48fb66ace8a5bfb9d8b730bc4e925 (patch)
treea3798b6aca1882347e7e55bb1db9249196e0ee73 /src
parent94caf14491860e35eaf07d76e1aea7ee90e1246a (diff)
Initial pint code formatting
Diffstat (limited to 'src')
-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
-rw-r--r--src/Concerns/WithAttributes.php4
-rw-r--r--src/ServiceProvider.php21
-rw-r--r--src/TableComponent.php64
-rw-r--r--src/Toolbar.php33
-rw-r--r--src/Toolbar/ColumnSelect.php2
-rw-r--r--src/Toolbar/Filter.php15
-rw-r--r--src/Toolbar/Item.php10
-rw-r--r--src/Toolbar/PageSize.php2
-rw-r--r--src/Toolbar/SelectFilter.php9
13 files changed, 110 insertions, 111 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),
];
}
-
}
diff --git a/src/Concerns/WithAttributes.php b/src/Concerns/WithAttributes.php
index 9072145..d97f84a 100644
--- a/src/Concerns/WithAttributes.php
+++ b/src/Concerns/WithAttributes.php
@@ -12,11 +12,12 @@ trait WithAttributes
protected ?array $attributes = null;
/**
- * @param array<string, string> $attributes
+ * @param array<string, string> $attributes
*/
public function attributes(array $attributes): static
{
$this->attributes = $attributes;
+
return $this;
}
@@ -24,5 +25,4 @@ trait WithAttributes
{
return new ComponentAttributeBag($this->attributes ?? []);
}
-
}
diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php
index a509fff..1128218 100644
--- a/src/ServiceProvider.php
+++ b/src/ServiceProvider.php
@@ -2,26 +2,22 @@
namespace Lightscale\LaralightTables;
-use Lightscale\LaralightAssets\Facades\Assets;
-
-use Illuminate\Support\ServiceProvider as ServiceProviderBase;
use Illuminate\Foundation\Console\AboutCommand;
+use Illuminate\Support\ServiceProvider as ServiceProviderBase;
+use Lightscale\LaralightAssets\Facades\Assets;
class ServiceProvider extends ServiceProviderBase
{
- public function register() : void
- {
-
- }
+ public function register(): void {}
- public function boot() : void
+ public function boot(): void
{
- AboutCommand::add('Laralight Tables', fn() => [
- 'Version' => 'dev'
+ AboutCommand::add('Laralight Tables', fn () => [
+ 'Version' => 'dev',
]);
$ns = Service::NAMESPACE;
- $root = __DIR__ . '/..';
+ $root = __DIR__.'/..';
$viewsPath = "{$root}/resources/views";
$assetsUri = "vendor/{$ns}";
$assetsPath = public_path($assetsUri);
@@ -30,7 +26,7 @@ class ServiceProvider extends ServiceProviderBase
$this->publishes([
$viewsPath => resource_path("views/vendor/{$ns}"),
- ], Service::NAMESPACE . '-views');
+ ], Service::NAMESPACE.'-views');
$this->publishes([
"{$root}/public" => $assetsPath,
@@ -38,5 +34,4 @@ class ServiceProvider extends ServiceProviderBase
Assets::registerManifest($ns, "{$assetsPath}/assets-manifest.json", $assetsUri);
}
-
}
diff --git a/src/TableComponent.php b/src/TableComponent.php
index 8e84d50..180d7c4 100644
--- a/src/TableComponent.php
+++ b/src/TableComponent.php
@@ -2,23 +2,19 @@
namespace Lightscale\LaralightTables;
-use Lightscale\LaralightTables\Columns\Column;
-use Lightscale\LaralightTables\Toolbar\Filter;
-use Lightscale\LaralightAssets\Facades\Assets;
-
-use Livewire\Component;
-use Livewire\WithPagination;
-use Livewire\Attributes\Url;
-
-use Illuminate\Pagination\Paginator;
+use Exception;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Support\Str;
+use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
+use Illuminate\Support\Str;
use Illuminate\View\View;
-
-use Exception;
-
+use Lightscale\LaralightAssets\Facades\Assets;
+use Lightscale\LaralightTables\Columns\Column;
+use Lightscale\LaralightTables\Toolbar\Filter;
+use Livewire\Attributes\Url;
+use Livewire\Component;
+use Livewire\WithPagination;
/**
* @template TModel of Model
@@ -34,7 +30,6 @@ abstract class TableComponent extends Component
*/
protected $paginationTheme = 'bootstrap';
-
/**
* @var ?class-string<TModel>
*/
@@ -43,10 +38,13 @@ abstract class TableComponent extends Component
protected int $defaultPageSize = 10;
protected ?string $rootClass = null;
+
protected string $tableClass = 'table';
protected string $tableWrapperComponent = 'laralight-tables::wrapper';
+
protected string $paginationWrapperComponent = 'laralight-tables::wrapper';
+
protected string $toolbarsWrapperComponent = 'laralight-tables::wrapper';
// Properties
@@ -83,14 +81,14 @@ abstract class TableComponent extends Component
protected function setDefaultPageSize(): void
{
- if (!isset($this->pageSize)) {
+ if (! isset($this->pageSize)) {
$this->pageSize = $this->defaultPageSize;
}
}
protected function setDefaultActiveColumns(): void
{
- foreach($this->getColumns() as $column) {
+ foreach ($this->getColumns() as $column) {
$this->activeColumns[] = $column->name;
}
}
@@ -99,8 +97,9 @@ abstract class TableComponent extends Component
{
$search = $this
->getToolbars()
- ->first(fn(Toolbar $tb) => $tb->getSearch() !== null)
+ ->first(fn (Toolbar $tb) => $tb->getSearch() !== null)
?->getSearch();
+
return $search !== null && Str::length($this->search) >= $search->getMinLength();
}
@@ -122,12 +121,10 @@ abstract class TableComponent extends Component
if ($this->orderDirection === 'desc') {
$this->order = null;
$this->orderDirection = null;
- }
- else {
+ } else {
$this->orderDirection = 'desc';
}
- }
- else {
+ } else {
$this->order = $column;
$this->orderDirection = 'asc';
}
@@ -151,24 +148,27 @@ abstract class TableComponent extends Component
*/
protected function getToolbars(): Collection
{
- if (!isset($this->toolbarsCache)) {
+ if (! isset($this->toolbarsCache)) {
$this->toolbarsCache = collect($this->toolbars());
}
+
return $this->toolbarsCache;
}
/**
* @return Builder<TModel>
+ *
* @phpstan-return Builder<TModel>
*/
protected function query(): Builder
{
- if($this->model === null) {
+ if ($this->model === null) {
throw new Exception('Requires $model to be set or query() method to be overridden');
}
/** @var Builder<TModel> */
$query = $this->model::query();
+
return $query;
}
@@ -178,10 +178,9 @@ abstract class TableComponent extends Component
abstract protected function columns(): array;
/**
- * @param Builder<TModel> $builder
- * @param string $search
+ * @param Builder<TModel> $builder
*/
- protected function search(Builder $builder, string $search) : void {}
+ protected function search(Builder $builder, string $search): void {}
/**
* @return Collection<int, Filter>
@@ -189,18 +188,17 @@ abstract class TableComponent extends Component
protected function getFilters(): Collection
{
return $this->getToolbars()
- ->map(fn(Toolbar $toolbar): Collection => $toolbar->getFilters())
+ ->map(fn (Toolbar $toolbar): Collection => $toolbar->getFilters())
->flatten();
}
-
protected function getOrderColumn(): ?Column
{
return ($name = $this->order) === null ? null : $this->getColumns()[$name] ?? null;
}
/**
- * @param Builder<TModel> $query
+ * @param Builder<TModel> $query
*/
protected function applyOrder(Builder $query): void
{
@@ -213,7 +211,7 @@ abstract class TableComponent extends Component
/**
* @return Builder<TModel>
*/
- protected function buildQuery() : Builder
+ protected function buildQuery(): Builder
{
$query = $this->query();
@@ -240,9 +238,9 @@ abstract class TableComponent extends Component
*/
public function getColumns(): Collection
{
- if($this->columnsCache === null) {
+ if ($this->columnsCache === null) {
$this->columnsCache = collect($this->columns())->each(
- fn($c) => $c->setTable($this)
+ fn ($c) => $c->setTable($this)
)->keyBy('name');
}
@@ -253,7 +251,7 @@ abstract class TableComponent extends Component
{
$data = $this->buildQuery()->paginate($this->pageSize);
$allColumns = $this->getColumns();
- $columns = $allColumns->filter(fn($c) => in_array($c->name,$this->activeColumns));
+ $columns = $allColumns->filter(fn ($c) => in_array($c->name, $this->activeColumns));
$toolbars = $this->getToolbars();
Paginator::defaultView('laralight-tables::pagination');
diff --git a/src/Toolbar.php b/src/Toolbar.php
index 80f093b..0a8aaad 100644
--- a/src/Toolbar.php
+++ b/src/Toolbar.php
@@ -2,21 +2,21 @@
namespace Lightscale\LaralightTables;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Collection;
+use Illuminate\View\View;
+use Lightscale\LaralightTables\Concerns\Makable;
+use Lightscale\LaralightTables\Toolbar\Filter as FilterItem;
use Lightscale\LaralightTables\Toolbar\Item as ToolbarItem;
-use Lightscale\LaralightTables\Toolbar\Search as SearchItem;
use Lightscale\LaralightTables\Toolbar\PageSize as PageSizeItem;
-use Lightscale\LaralightTables\Toolbar\Filter as FilterItem;
-use Lightscale\LaralightTables\Concerns\Makable;
-
-use Illuminate\View\View;
-use Illuminate\Support\Collection;
-use Illuminate\Database\Eloquent\Model;
+use Lightscale\LaralightTables\Toolbar\Search as SearchItem;
class Toolbar
{
use Makable;
protected ?SearchItem $searchItem = null;
+
protected ?PageSizeItem $pageSizeItem = null;
/**
@@ -41,12 +41,12 @@ class Toolbar
/**
* @template TModel of Model
- * @param TableComponent<TModel> $table
+ *
+ * @param TableComponent<TModel> $table
*/
public function __construct(
private TableComponent $table
- )
- {
+ ) {
$this->startItems = collect();
$this->midItems = collect();
$this->endItems = collect();
@@ -59,32 +59,32 @@ class Toolbar
if ($item instanceof FilterItem) {
$this->filterItems->push($item);
- }
- else if ($item instanceof PageSizeItem) {
+ } elseif ($item instanceof PageSizeItem) {
$this->pageSizeItem = $item;
- }
- else if ($item instanceof SearchItem) {
+ } elseif ($item instanceof SearchItem) {
$this->searchItem = $item;
}
}
/**
- * @param Collection<int, ToolbarItem> $list
+ * @param Collection<int, ToolbarItem> $list
*/
private function prependItem(Collection $list, ToolbarItem $item): static
{
$this->processItem($item);
$list->prepend($item);
+
return $this;
}
/**
- * @param Collection<int, ToolbarItem> $list
+ * @param Collection<int, ToolbarItem> $list
*/
private function appendItem(Collection $list, ToolbarItem $item): static
{
$this->processItem($item);
$list->push($item);
+
return $this;
}
@@ -152,5 +152,4 @@ class Toolbar
'endItems' => $this->endItems,
]);
}
-
}
diff --git a/src/Toolbar/ColumnSelect.php b/src/Toolbar/ColumnSelect.php
index 9380650..8e173cd 100644
--- a/src/Toolbar/ColumnSelect.php
+++ b/src/Toolbar/ColumnSelect.php
@@ -13,7 +13,7 @@ class ColumnSelect extends Item
return view('laralight-tables::toolbar.column-select', [
'allColumns' => $this->getTable()
->getColumns()
- ->filter(fn($c) => $c->getShowInSelect())
+ ->filter(fn ($c) => $c->getShowInSelect()),
]);
}
}
diff --git a/src/Toolbar/Filter.php b/src/Toolbar/Filter.php
index f6777ce..d444dcf 100644
--- a/src/Toolbar/Filter.php
+++ b/src/Toolbar/Filter.php
@@ -2,10 +2,9 @@
namespace Lightscale\LaralightTables\Toolbar;
-use Illuminate\Database\Eloquent\Model;
-use Illuminate\Database\Eloquent\Builder;
-
use Closure;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Model;
abstract class Filter extends Item
{
@@ -19,6 +18,7 @@ abstract class Filter extends Item
public function label(string $v): static
{
$this->label = $v;
+
return $this;
}
@@ -29,23 +29,24 @@ abstract class Filter extends Item
public function filter(callable $fn): static
{
- $this->filterCallback = Closure::fromCallable($fn);;
+ $this->filterCallback = Closure::fromCallable($fn);
+
return $this;
}
/**
* @template TModel of Model
- * @param Builder<TModel> $query
+ *
+ * @param Builder<TModel> $query
*/
public function applyFilter(Builder $query): void
{
if ($this->filterCallback !== null) {
$value = $this->getTable()->filters[$this->key] ?? null;
- if (!empty($value)) {
+ if (! empty($value)) {
($this->filterCallback)($query, $value);
}
}
}
-
}
diff --git a/src/Toolbar/Item.php b/src/Toolbar/Item.php
index e161fb9..1b4d1fb 100644
--- a/src/Toolbar/Item.php
+++ b/src/Toolbar/Item.php
@@ -2,13 +2,12 @@
namespace Lightscale\LaralightTables\Toolbar;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\HtmlString;
+use Illuminate\View\View;
+use Lightscale\LaralightTables\Concerns\Makable;
use Lightscale\LaralightTables\TableComponent;
use Lightscale\LaralightTables\Toolbar;
-use Lightscale\LaralightTables\Concerns\Makable;
-
-use Illuminate\View\View;
-use Illuminate\Support\HtmlString;
-use Illuminate\Database\Eloquent\Model;
abstract class Item
{
@@ -35,5 +34,4 @@ abstract class Item
}
abstract public function render(): View|HtmlString|string|null;
-
}
diff --git a/src/Toolbar/PageSize.php b/src/Toolbar/PageSize.php
index 79234a8..71049ba 100644
--- a/src/Toolbar/PageSize.php
+++ b/src/Toolbar/PageSize.php
@@ -7,7 +7,7 @@ use Illuminate\View\View;
class PageSize extends Item
{
/**
- * @param array<int> $pageSizes
+ * @param array<int> $pageSizes
*/
public function __construct(
private array $pageSizes = [10, 25, 50],
diff --git a/src/Toolbar/SelectFilter.php b/src/Toolbar/SelectFilter.php
index 7adc47a..d9c6118 100644
--- a/src/Toolbar/SelectFilter.php
+++ b/src/Toolbar/SelectFilter.php
@@ -2,9 +2,8 @@
namespace Lightscale\LaralightTables\Toolbar;
-use Lightscale\LaralightTables\Concerns\WithAttributes;
-
use Illuminate\View\View;
+use Lightscale\LaralightTables\Concerns\WithAttributes;
class SelectFilter extends Filter
{
@@ -14,20 +13,23 @@ class SelectFilter extends Filter
* @var iterable<string, string>
*/
protected iterable $options;
+
protected ?string $placeholder = null;
public function placeholder(?string $v): static
{
$this->placeholder = $v;
+
return $this;
}
/**
- * @param iterable<string, string> $options
+ * @param iterable<string, string> $options
*/
public function options(iterable $options): static
{
$this->options = $options;
+
return $this;
}
@@ -42,5 +44,4 @@ class SelectFilter extends Filter
'attributes' => $this->getAttributes(),
]);
}
-
}