Skip to content

Commit 7dab070

Browse files
authored
Merge pull request #16 from slimani-dev/main
Fix Layout with Filament Grid Style and HasColumns Trait
2 parents fef21e3 + b0a349d commit 7dab070

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,33 @@ FilamentDeveloperLoginsPlugin::make()
5151
->enabled(app()->environment('local'))
5252
```
5353

54+
### columns()
55+
56+
To customize the grid layout, you can use the columns() method. This method allows you to configure the grid layout based on your needs.
57+
58+
By default, the columns() method sets the grid to 2 columns. You can adjust the default column count or specify different column counts for different screen sizes by passing an array.
59+
60+
Example:
61+
62+
```php
63+
// ...
64+
FilamentDeveloperLoginsPlugin::make()
65+
->columns() // default 2
66+
```
67+
68+
or you can use an array like this
69+
70+
```php
71+
// ...
72+
FilamentDeveloperLoginsPlugin::make()
73+
->columns([
74+
'sm' => 3,
75+
'xl' => 6,
76+
'2xl' => 8,
77+
])
78+
```
79+
80+
5481
### switchable()
5582

5683
By default, a "Switch to" button is shown in the top right corner of the screen, so you can easily switch between the provided users.
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
@if (! empty($users))
1+
@if(count($users) > 0)
22
<div class="flex flex-col gap-y-6">
3-
<div class="relative flex items-center justify-center text-center">
4-
<div class="absolute border-t border-gray-200 w-full h-px"></div>
5-
<p class="inline-block relative bg-white text-sm p-2 rounded-full font-medium text-gray-500 dark:bg-gray-800 dark:text-gray-100">
3+
4+
<div class="flex items-center justify-center text-center gap-x-4">
5+
<div class="border-t border-gray-200 grow h-px"></div>
6+
<p class="font-medium text-gray-500 dark:text-gray-100 shrink">
67
{{ __('filament-developer-logins::auth.login-as') }}
78
</p>
9+
<div class="border-t border-gray-200 grow h-px"></div>
810
</div>
911

1012
@if ($errors->has('developer-logins-failed'))
1113
<div class="justify-center text-center">
12-
<p class="fi-fo-field-wrp-error-message text-sm text-danger-600 dark:text-danger-400">
14+
<p class="fi-fo-field-wrp-error-message text-danger-600 dark:text-danger-400">
1315
{{ $errors->first('developer-logins-failed') }}
1416
</p>
1517
</div>
1618
@endif
17-
<div class="grid grid-cols-2 gap-4">
19+
20+
<x-filament::grid
21+
:default="$columns['default'] ?? 1"
22+
:sm="$columns['sm'] ?? null"
23+
:md="$columns['md'] ?? null"
24+
:lg="$columns['lg'] ?? ($columns ? (is_array($columns) ? null : $columns) : 2)"
25+
:xl="$columns['xl'] ?? null"
26+
:two-xl="$columns['2xl'] ?? null"
27+
:attributes="\Filament\Support\prepare_inherited_attributes($attributes)->class('fi-wi gap-4')"
28+
>
1829
@foreach ($users as $label => $credentials)
1930
<form action="{{ route('filament-developer-logins.login-as') }}" method="POST">
2031
@csrf
@@ -27,7 +38,6 @@
2738
</x-filament::button>
2839
</form>
2940
@endforeach
30-
</div>
41+
</x-filament::grid>
3142
</div>
32-
@endif
33-
43+
@endif

src/FilamentDeveloperLoginsPlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
use DutchCodingCompany\FilamentDeveloperLogins\Exceptions\ImplementationException;
88
use Filament\Contracts\Plugin;
99
use Filament\Facades\Filament;
10+
use Filament\Forms\Concerns\HasColumns;
1011
use Filament\Panel;
1112
use Filament\Support\Concerns\EvaluatesClosures;
1213
use Illuminate\Contracts\Auth\Authenticatable;
1314

1415
class FilamentDeveloperLoginsPlugin implements Plugin
1516
{
16-
use EvaluatesClosures;
17+
use EvaluatesClosures, HasColumns;
1718

1819
public Closure | bool $enabled = false;
1920

src/View/Components/DeveloperLogins.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace DutchCodingCompany\FilamentDeveloperLogins\View\Components;
44

5+
use DutchCodingCompany\FilamentDeveloperLogins\Exceptions\ImplementationException;
56
use DutchCodingCompany\FilamentDeveloperLogins\FilamentDeveloperLoginsPlugin;
67
use Illuminate\View\Component;
78
use Illuminate\View\View;
@@ -10,6 +11,9 @@ class DeveloperLogins extends Component
1011
{
1112
protected FilamentDeveloperLoginsPlugin $plugin;
1213

14+
/**
15+
* @throws ImplementationException
16+
*/
1317
public function __construct()
1418
{
1519
$this->plugin = FilamentDeveloperLoginsPlugin::current();
@@ -19,6 +23,7 @@ public function render(): View
1923
{
2024
return view('filament-developer-logins::components.developer-logins', [
2125
'users' => $this->plugin->getUsers(),
26+
'columns' => $this->plugin->getColumns()
2227
]);
2328
}
2429
}

0 commit comments

Comments
 (0)