Support globally setting simple page max width

This commit is contained in:
Zep Fietje
2024-11-16 15:23:03 +01:00
parent 47d5173caf
commit 3039a14e3c
4 changed files with 58 additions and 14 deletions
+16 -2
View File
@@ -115,6 +115,20 @@ public function panel(Panel $panel): Panel
}
```
If you'd like to set the max width for pages of the type `SimplePage`, like login and registration pages, you may do so by using the `simplePageMaxWidth()` method. The default is `Large`:
```php
use Filament\Panel;
use Filament\Support\Enums\MaxWidth;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->simplePageMaxWidth(MaxWidth::Small);
}
```
## Lifecycle hooks
Hooks may be used to execute code during a panel's lifecycle. `bootUsing()` is a hook that gets run on every request that takes place within that panel. If you have multiple panels, only the current panel's `bootUsing()` will be run. The function gets run from middleware, after all service providers have been booted:
@@ -230,7 +244,7 @@ use Filament\Resources\Pages\CreateRecord;
class CreatePost extends CreateRecord
{
protected ?bool $hasDatabaseTransactions = false;
// ...
}
```
@@ -254,7 +268,7 @@ use Filament\Resources\Pages\CreateRecord;
class CreatePost extends CreateRecord
{
protected ?bool $hasDatabaseTransactions = true;
// ...
}
```
@@ -30,18 +30,29 @@
<main
@class([
'fi-simple-main my-16 w-full bg-white px-6 py-12 shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10 sm:rounded-xl sm:px-12',
match ($maxWidth ?? null) {
MaxWidth::ExtraSmall, 'xs' => 'sm:max-w-xs',
MaxWidth::Small, 'sm' => 'sm:max-w-sm',
MaxWidth::Medium, 'md' => 'sm:max-w-md',
MaxWidth::ExtraLarge, 'xl' => 'sm:max-w-xl',
MaxWidth::TwoExtraLarge, '2xl' => 'sm:max-w-2xl',
MaxWidth::ThreeExtraLarge, '3xl' => 'sm:max-w-3xl',
MaxWidth::FourExtraLarge, '4xl' => 'sm:max-w-4xl',
MaxWidth::FiveExtraLarge, '5xl' => 'sm:max-w-5xl',
MaxWidth::SixExtraLarge, '6xl' => 'sm:max-w-6xl',
MaxWidth::SevenExtraLarge, '7xl' => 'sm:max-w-7xl',
default => 'sm:max-w-lg',
match ($maxWidth ??= (filament()->getSimplePageMaxWidth() ?? MaxWidth::Large)) {
MaxWidth::ExtraSmall, 'xs' => 'max-w-xs',
MaxWidth::Small, 'sm' => 'max-w-sm',
MaxWidth::Medium, 'md' => 'max-w-md',
MaxWidth::Large, 'lg' => 'max-w-lg',
MaxWidth::ExtraLarge, 'xl' => 'max-w-xl',
MaxWidth::TwoExtraLarge, '2xl' => 'max-w-2xl',
MaxWidth::ThreeExtraLarge, '3xl' => 'max-w-3xl',
MaxWidth::FourExtraLarge, '4xl' => 'max-w-4xl',
MaxWidth::FiveExtraLarge, '5xl' => 'max-w-5xl',
MaxWidth::SixExtraLarge, '6xl' => 'max-w-6xl',
MaxWidth::SevenExtraLarge, '7xl' => 'max-w-7xl',
MaxWidth::Full, 'full' => 'max-w-full',
MaxWidth::MinContent, 'min' => 'max-w-min',
MaxWidth::MaxContent, 'max' => 'max-w-max',
MaxWidth::FitContent, 'fit' => 'max-w-fit',
MaxWidth::Prose, 'prose' => 'max-w-prose',
MaxWidth::ScreenSmall, 'screen-sm' => 'max-w-screen-sm',
MaxWidth::ScreenMedium, 'screen-md' => 'max-w-screen-md',
MaxWidth::ScreenLarge, 'screen-lg' => 'max-w-screen-lg',
MaxWidth::ScreenExtraLarge, 'screen-xl' => 'max-w-screen-xl',
MaxWidth::ScreenTwoExtraLarge, 'screen-2xl' => 'max-w-screen-2xl',
default => $maxWidth,
},
])
>
+5
View File
@@ -225,6 +225,11 @@ class FilamentManager
return $this->getCurrentPanel()->getMaxContentWidth();
}
public function getSimplePageMaxWidth(): MaxWidth | string | null
{
return $this->getCurrentPanel()->getSimplePageMaxWidth();
}
public function getModelResource(string | Model $model): ?string
{
return $this->getCurrentPanel()->getModelResource($model);
@@ -8,6 +8,8 @@ trait HasMaxContentWidth
{
protected MaxWidth | string | null $maxContentWidth = null;
protected MaxWidth | string | null $simplePageMaxWidth = null;
public function maxContentWidth(MaxWidth | string | null $maxContentWidth): static
{
$this->maxContentWidth = $maxContentWidth;
@@ -19,4 +21,16 @@ trait HasMaxContentWidth
{
return $this->maxContentWidth;
}
public function simplePageMaxWidth(MaxWidth | string | null $width): static
{
$this->simplePageMaxWidth = $width;
return $this;
}
public function getSimplePageMaxWidth(): MaxWidth | string | null
{
return $this->simplePageMaxWidth;
}
}