Skip to content

Commit

Permalink
Merge pull request #238 from bezhanSalleh/feature/column-grid-customi…
Browse files Browse the repository at this point in the history
…zations

Feature/column grid customizations
  • Loading branch information
bezhanSalleh committed Oct 2, 2023
2 parents 7653c02 + 2ad22ec commit 0da8b24
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 32 deletions.
115 changes: 115 additions & 0 deletions src/Concerns/CanCustomizeColumns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

declare(strict_types=1);

namespace BezhanSalleh\FilamentShield\Concerns;

trait CanCustomizeColumns
{
protected int | string | array $checkboxListColumnSpan = 'full';

protected int | string | array $checkboxListColumns = [
'sm' => 2,
'lg' => 4,
];

protected int | string | array $gridColumns = 1;

protected int | string | array $resourceCheckboxListColumnSpan = 'full';

protected int | string | array $resourceCheckboxListColumns = [
'sm' => 2,
'lg' => 4,
];

protected int | string | array $sectionColumnSpan = 'full';

protected int | string | array $sectionColumns = [
'sm' => 2,
'lg' => 4,
];

public function checkboxListColumns(int | string | array $columns): static
{
$this->checkboxListColumns = $columns;

return $this;
}

public function checkboxListColumnSpan(int | string | array $columnSpan): static
{
$this->checkboxListColumnSpan = $columnSpan;

return $this;
}

public function gridColumns(int | string | array $columns): static
{
$this->gridColumns = $columns;

return $this;
}

public function resourceCheckboxListColumns(int | string | array $columns): static
{
$this->resourceCheckboxListColumns = $columns;

return $this;
}

public function resourceCheckboxListColumnSpan(int | string | array $columnSpan): static
{
$this->resourceCheckboxListColumnSpan = $columnSpan;

return $this;
}

public function sectionColumns(int | string | array $columns): static
{
$this->sectionColumns = $columns;

return $this;
}

public function sectionColumnSpan(int | string | array $columnSpan): static
{
$this->sectionColumnSpan = $columnSpan;

return $this;
}

public function getCheckboxListColumns(): int | string | array
{
return $this->checkboxListColumns;
}

public function getCheckboxListColumnSpan(): int | string | array
{
return $this->checkboxListColumnSpan;
}

public function getGridColumns(): int | string | array
{
return $this->gridColumns;
}

public function getResourceCheckboxListColumns(): int | string | array
{
return $this->resourceCheckboxListColumns;
}

public function getResourceCheckboxListColumnSpan(): int | string | array
{
return $this->resourceCheckboxListColumnSpan;
}

public function getSectionColumns(): int | string | array
{
return $this->sectionColumns;
}

public function getSectionColumnSpan(): int | string | array
{
return $this->sectionColumnSpan;
}
}
14 changes: 7 additions & 7 deletions src/FilamentShieldPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

use BezhanSalleh\FilamentShield\Support\Utils;
use Filament\Contracts\Plugin;
use Filament\FilamentManager;
use Filament\Panel;

class FilamentShieldPlugin implements Plugin
{
use Concerns\CanCustomizeColumns;

public static function make(): static
{
return app(static::class);
Expand All @@ -35,12 +36,11 @@ public function boot(Panel $panel): void
//
}

/**
* Class MyClass overrides inline block form.
*
* @phpstan-ignore-next-line */
public static function get(): Plugin | FilamentManager
public static function get(): static
{
return filament(app(static::class)->getId());
/** @var static $plugin */
$plugin = filament(app(static::class)->getId());

return $plugin;
}
}
35 changes: 10 additions & 25 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions;
use BezhanSalleh\FilamentShield\Facades\FilamentShield;
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
use BezhanSalleh\FilamentShield\Resources\RoleResource\Pages;
use BezhanSalleh\FilamentShield\Support\Utils;
use Filament\Forms;
Expand Down Expand Up @@ -78,10 +79,7 @@ public static function form(Form $form): Form
->schema([
Forms\Components\Grid::make()
->schema(static::getResourceEntitiesSchema())
->columns([
'sm' => 1,
'lg' => 1,
]),
->columns(FilamentShieldPlugin::get()->getGridColumns()),
]),
Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.pages'))
->visible(fn (): bool => (bool) Utils::isPageEntityEnabled() && (count(FilamentShield::getPages()) > 0 ? true : false))
Expand Down Expand Up @@ -118,11 +116,8 @@ public static function form(Form $form): Form
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'sm' => 2,
'lg' => 4,
])
->columnSpanFull(),
->columns(FilamentShieldPlugin::get()->getCheckboxListColumns())
->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()),
]),
Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.widgets'))
->visible(fn (): bool => (bool) Utils::isWidgetEntityEnabled() && (count(FilamentShield::getWidgets()) > 0 ? true : false))
Expand Down Expand Up @@ -160,11 +155,8 @@ public static function form(Form $form): Form
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'sm' => 2,
'lg' => 4,
])
->columnSpanFull(),
->columns(FilamentShieldPlugin::get()->getCheckboxListColumns())
->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()),
]),
Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.custom'))
->visible(fn (): bool => (bool) Utils::isCustomPermissionEntityEnabled() && (count(static::getCustomEntities()) > 0 ? true : false))
Expand Down Expand Up @@ -201,11 +193,8 @@ public static function form(Form $form): Form
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'sm' => 2,
'lg' => 4,
])
->columnSpanFull(),
->columns(FilamentShieldPlugin::get()->getCheckboxListColumns())
->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()),
]),
])
->columnSpan('full'),
Expand Down Expand Up @@ -365,13 +354,9 @@ public static function getResourceEntitiesSchema(): ?array
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'default' => 2,
'sm' => 3,
'lg' => 4,
]),
->columns(FilamentShieldPlugin::get()->getResourceCheckboxListColumns()),
])
->columnSpanFull()
->columnSpan(FilamentShieldPlugin::get()->getSectionColumnSpan())
->collapsible();

return $entities;
Expand Down

0 comments on commit 0da8b24

Please sign in to comment.