Skip to content

Commit 9c214f9

Browse files
committed
Fix Layout with Filament Grid Style and HasColumns Trait
- Corrected layout issues by applying Filament's grid system for consistent display across screen sizes. - Integrated HasColumns trait to manage column layout more effectively and improve responsiveness. - Updated README with documentation on customizing the grid layout using the columns() method.
1 parent ffd5659 commit 9c214f9

File tree

4 files changed

+77
-33
lines changed

4 files changed

+77
-33
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,46 @@ In the `users` method you can define the users (note: the users must exist), the
3939

4040
### enabled()
4141

42+
To customize the grid layout, you can use the columns() method. This method allows you to configure the grid layout based on your needs.
43+
44+
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.
45+
46+
Example:
47+
48+
```php
49+
// ...
50+
FilamentDeveloperLoginsPlugin::make()
51+
->enabled(app()->environment('local'))
52+
```
53+
54+
### columns()
55+
56+
You may use the columns() method to easily create a grid within the section
4257
By default, the plugin is disabled. You can enable it by calling the enabled() method. I strongly suggest enabling
43-
this plugin only in the local environment. You can achieve this by using the app()->environment() method. Additionally,
58+
this plugin only in the local environment. You can achieve this by using the app()->environment() method. Additionally,
4459
the enabled() method also accepts a closure if you wish to enable the plugin based on a custom condition.
4560

4661
Example:
4762

4863
```php
4964
// ...
5065
FilamentDeveloperLoginsPlugin::make()
51-
->enabled(app()->environment('local'))
66+
->columns() // default 2
5267
```
5368

69+
or you can use an array like this
70+
71+
```php
72+
// ...
73+
FilamentDeveloperLoginsPlugin::make()
74+
->columns([
75+
'sm' => 3,
76+
'xl' => 6,
77+
'2xl' => 8,
78+
])
79+
```
80+
81+
5482
### switchable()
5583

5684
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: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
1-
@foreach ($users as $label => $credentials)
2-
@if ($loop->first)
3-
<div class="flex flex-col gap-y-6">
4-
<div class="relative flex items-center justify-center text-center">
5-
<div class="absolute border-t border-gray-200 w-full h-px"></div>
6-
<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">
7-
{{ __('filament-developer-logins::auth.login-as') }}
1+
@if(count($users) > 0)
2+
<div class="flex flex-col gap-y-6">
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">
7+
{{ __('filament-developer-logins::auth.login-as') }}
8+
</p>
9+
<div class="border-t border-gray-200 grow h-px"></div>
10+
</div>
11+
12+
@if ($errors->has('developer-logins-failed'))
13+
<div class="justify-center text-center">
14+
<p class="fi-fo-field-wrp-error-message text-danger-600 dark:text-danger-400">
15+
{{ $errors->first('developer-logins-failed') }}
816
</p>
917
</div>
18+
@endif
1019

11-
@if ($errors->has('developer-logins-failed'))
12-
<div class="justify-center text-center">
13-
<p class="fi-fo-field-wrp-error-message text-danger-600 dark:text-danger-400">
14-
{{ $errors->first('developer-logins-failed') }}
15-
</p>
16-
</div>
17-
@endif
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+
>
29+
@foreach ($users as $label => $credentials)
30+
@if ($loop->first)
31+
@endif
32+
<form action="{{ route('filament-developer-logins.login-as') }}" method="POST">
33+
@csrf
1834

19-
<div class="grid grid-cols-2 gap-4">
20-
@endif
21-
<form action="{{ route('filament-developer-logins.login-as') }}" method="POST">
22-
@csrf
35+
<input type="hidden" name="panel_id" value="{{ \Filament\Facades\Filament::getId() }}">
36+
<input type="hidden" name="credentials" value="{{ $credentials }}">
2337

24-
<input type="hidden" name="panel_id" value="{{ \Filament\Facades\Filament::getId() }}">
25-
<input type="hidden" name="credentials" value="{{ $credentials }}">
26-
27-
<x-filament::button class="w-full" color="gray" outlined="true" type="submit">
28-
{{ "$label ($credentials)" }}
29-
</x-filament::button>
30-
</form>
31-
@if ($loop->first)
32-
</div>
33-
</div>
34-
@endif
35-
@endforeach
38+
<x-filament::button class="w-full" color="gray" outlined="true" type="submit">
39+
{{ "$label ($credentials)" }}
40+
</x-filament::button>
41+
</form>
42+
@endforeach
43+
</x-filament::grid>
44+
</div>
45+
@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)