Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support globally setting max simple page content width #14819

Merged
merged 8 commits into from
Nov 29, 2024
18 changes: 16 additions & 2 deletions packages/panels/docs/09-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ public function panel(Panel $panel): Panel
}
```

If you'd like to set the max content width for pages of the type `SimplePage`, like login and registration pages, you may do so using the `maxSimplePageContentWidth()` method. The default is `Large`:

```php
use Filament\Panel;
use Filament\Support\Enums\MaxWidth;

public function panel(Panel $panel): Panel
{
return $panel
// ...
->maxSimplePageContentWidth(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:
Expand Down Expand Up @@ -230,7 +244,7 @@ use Filament\Resources\Pages\CreateRecord;
class CreatePost extends CreateRecord
{
protected ?bool $hasDatabaseTransactions = false;

// ...
}
```
Expand All @@ -254,7 +268,7 @@ use Filament\Resources\Pages\CreateRecord;
class CreatePost extends CreateRecord
{
protected ?bool $hasDatabaseTransactions = true;

// ...
}
```
Expand Down
35 changes: 23 additions & 12 deletions packages/panels/resources/views/components/layout/simple.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,29 @@ class="fi-simple-main-ctn flex w-full flex-grow items-center justify-center"
<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()->getMaxSimplePageContentWidth() ?? 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,
},
])
>
Expand Down
5 changes: 5 additions & 0 deletions packages/panels/src/FilamentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public function getMaxContentWidth(): MaxWidth | string | null
return $this->getCurrentPanel()->getMaxContentWidth();
}

public function getMaxSimplePageContentWidth(): MaxWidth | string | null
{
return $this->getCurrentPanel()->getMaxSimplePageContentWidth();
}

public function getModelResource(string | Model $model): ?string
{
return $this->getCurrentPanel()->getModelResource($model);
Expand Down
14 changes: 14 additions & 0 deletions packages/panels/src/Panel/Concerns/HasMaxContentWidth.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ trait HasMaxContentWidth
{
protected MaxWidth | string | null $maxContentWidth = null;

protected MaxWidth | string | null $maxSimplePageContentWidth = null;

public function maxContentWidth(MaxWidth | string | null $maxContentWidth): static
{
$this->maxContentWidth = $maxContentWidth;
Expand All @@ -19,4 +21,16 @@ public function getMaxContentWidth(): MaxWidth | string | null
{
return $this->maxContentWidth;
}

public function maxSimplePageContentWidth(MaxWidth | string | null $width): static
{
$this->maxSimplePageContentWidth = $width;

return $this;
}

public function getMaxSimplePageContentWidth(): MaxWidth | string | null
{
return $this->maxSimplePageContentWidth;
}
}
Loading