mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Refactor to extraModalWindowAttributes
This commit is contained in:
@@ -272,13 +272,13 @@ Now, in the view file, you can render the action button by calling `getModalActi
|
||||
</div>
|
||||
```
|
||||
|
||||
## Adding extra attributes to the modal container
|
||||
## Adding extra attributes to the modal window
|
||||
|
||||
You may also pass extra HTML attributes to the modal container using `extraModalAttributes()`:
|
||||
You may also pass extra HTML attributes to the modal window using `extraModalWindowAttributes()`:
|
||||
|
||||
```php
|
||||
Action::make('updateAuthor')
|
||||
->extraModalAttributes(['class' => 'update-author-modal'])
|
||||
->extraModalWindowAttributes(['class' => 'update-author-modal'])
|
||||
```
|
||||
|
||||
## Using a slide-over instead of a modal
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
|
||||
:description="$action?->getModalDescription()"
|
||||
display-classes="block"
|
||||
:extra-modal-window-attributes="$action?->getExtraModalWindowAttributes()"
|
||||
:footer-actions="$action?->getVisibleModalFooterActions()"
|
||||
:footer-actions-alignment="$action?->getModalFooterActionsAlignment()"
|
||||
:heading="$action?->getModalHeading()"
|
||||
@@ -37,11 +38,6 @@
|
||||
$wire.unmountAction(false)
|
||||
"
|
||||
x-on:opened-form-component-action-modal.window="if ($event.detail.id === '{{ $this->getId() }}') close()"
|
||||
:attributes="
|
||||
\Filament\Support\prepare_inherited_attributes(
|
||||
new \Illuminate\View\ComponentAttributeBag($action?->getExtraModalAttributes() ?? [])
|
||||
)
|
||||
"
|
||||
>
|
||||
@if ($action)
|
||||
{{ $action->getModalContent() }}
|
||||
@@ -74,6 +70,7 @@
|
||||
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
|
||||
:description="$action?->getModalDescription()"
|
||||
display-classes="block"
|
||||
:extra-modal-window-attributes="$action?->getExtraModalWindowAttributes()"
|
||||
:footer-actions="$action?->getVisibleModalFooterActions()"
|
||||
:footer-actions-alignment="$action?->getModalFooterActionsAlignment()"
|
||||
:heading="$action?->getModalHeading()"
|
||||
@@ -101,11 +98,6 @@
|
||||
$wire.unmountTableAction(false)
|
||||
"
|
||||
x-on:opened-form-component-action-modal.window="if ($event.detail.id === '{{ $this->getId() }}') close()"
|
||||
:attributes="
|
||||
\Filament\Support\prepare_inherited_attributes(
|
||||
new \Illuminate\View\ComponentAttributeBag($action?->getExtraModalAttributes() ?? [])
|
||||
)
|
||||
"
|
||||
>
|
||||
@if ($action)
|
||||
{{ $action->getModalContent() }}
|
||||
@@ -132,6 +124,7 @@
|
||||
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
|
||||
:description="$action?->getModalDescription()"
|
||||
display-classes="block"
|
||||
:extra-modal-window-attributes="$action?->getExtraModalWindowAttributes()"
|
||||
:footer-actions="$action?->getVisibleModalFooterActions()"
|
||||
:footer-actions-alignment="$action?->getModalFooterActionsAlignment()"
|
||||
:heading="$action?->getModalHeading()"
|
||||
@@ -159,11 +152,6 @@
|
||||
$wire.unmountTableBulkAction(false)
|
||||
"
|
||||
x-on:opened-form-component-action-modal.window="if ($event.detail.id === '{{ $this->getId() }}') close()"
|
||||
:attributes="
|
||||
\Filament\Support\prepare_inherited_attributes(
|
||||
new \Illuminate\View\ComponentAttributeBag($action?->getExtraModalAttributes() ?? [])
|
||||
)
|
||||
"
|
||||
>
|
||||
@if ($action)
|
||||
{{ $action->getModalContent() }}
|
||||
@@ -196,6 +184,7 @@
|
||||
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
|
||||
:description="$action?->getModalDescription()"
|
||||
display-classes="block"
|
||||
:extra-modal-window-attributes="$action?->getExtraModalWindowAttributes()"
|
||||
:footer-actions="$action?->getVisibleModalFooterActions()"
|
||||
:footer-actions-alignment="$action?->getModalFooterActionsAlignment()"
|
||||
:heading="$action?->getModalHeading()"
|
||||
@@ -223,11 +212,6 @@
|
||||
$wire.unmountInfolistAction(false)
|
||||
"
|
||||
x-on:opened-form-component-action-modal.window="if ($event.detail.id === '{{ $this->getId() }}') close()"
|
||||
:attributes="
|
||||
\Filament\Support\prepare_inherited_attributes(
|
||||
new \Illuminate\View\ComponentAttributeBag($action?->getExtraModalAttributes() ?? [])
|
||||
)
|
||||
"
|
||||
>
|
||||
@if ($action)
|
||||
{{ $action->getModalContent() }}
|
||||
@@ -260,6 +244,7 @@
|
||||
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
|
||||
:description="$action?->getModalDescription()"
|
||||
display-classes="block"
|
||||
:extra-modal-window-attributes="$action?->getExtraModalWindowAttributes()"
|
||||
:footer-actions="$action?->getVisibleModalFooterActions()"
|
||||
:footer-actions-alignment="$action?->getModalFooterActionsAlignment()"
|
||||
:heading="$action?->getModalHeading()"
|
||||
@@ -279,11 +264,6 @@
|
||||
$wire.unmountFormComponentAction(false)
|
||||
}
|
||||
"
|
||||
:attributes="
|
||||
\Filament\Support\prepare_inherited_attributes(
|
||||
new \Illuminate\View\ComponentAttributeBag($action?->getExtraModalAttributes() ?? [])
|
||||
)
|
||||
"
|
||||
>
|
||||
@if ($action)
|
||||
{{ $action->getModalContent() }}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Actions\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait HasExtraModalAttributes
|
||||
{
|
||||
/**
|
||||
* @var array<array<mixed> | Closure>
|
||||
*/
|
||||
protected array $extraModalAttributes = [];
|
||||
|
||||
/**
|
||||
* @param array<mixed> | Closure $attributes
|
||||
*/
|
||||
public function extraModalAttributes(array | Closure $attributes, bool $merge = false): static
|
||||
{
|
||||
if ($merge) {
|
||||
$this->extraModalAttributes[] = $attributes;
|
||||
} else {
|
||||
$this->extraModalAttributes = [$attributes];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function getExtraModalAttributes(): array
|
||||
{
|
||||
$temporaryAttributeBag = new ComponentAttributeBag();
|
||||
|
||||
foreach ($this->extraModalAttributes as $extraModalAttributes) {
|
||||
$temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraModalAttributes));
|
||||
}
|
||||
|
||||
return $temporaryAttributeBag->getAttributes();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Actions\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait HasExtraModalWindowAttributes
|
||||
{
|
||||
protected array $extraModalWindowAttributes = [];
|
||||
|
||||
public function extraModalWindowAttributes(array | Closure $attributes): static
|
||||
{
|
||||
$this->extraModalWindowAttributes = $attributes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getExtraModalWindowAttributes(): array
|
||||
{
|
||||
return $this->evaluate($this->extraModalWindowAttributes);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ abstract class MountableAction extends StaticAction implements HasLivewire
|
||||
use Concerns\CanRedirect;
|
||||
use Concerns\CanRequireConfirmation;
|
||||
use Concerns\CanUseDatabaseTransactions;
|
||||
use Concerns\HasExtraModalAttributes;
|
||||
use Concerns\HasExtraModalWindowAttributes;
|
||||
use Concerns\HasForm;
|
||||
use Concerns\HasInfolist;
|
||||
use Concerns\HasLifecycleHooks;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
'closeEventName' => 'close-modal',
|
||||
'description' => null,
|
||||
'displayClasses' => 'inline-block',
|
||||
'extraModalWindowAttributes' => [],
|
||||
'footer' => null,
|
||||
'footerActions' => [],
|
||||
'footerActionsAlignment' => Alignment::Start,
|
||||
@@ -30,6 +31,7 @@
|
||||
])
|
||||
|
||||
@php
|
||||
ray($extraModalWindowAttributes);
|
||||
$hasDescription = filled($description);
|
||||
$hasHeading = filled($heading);
|
||||
$hasIcon = filled($icon);
|
||||
@@ -170,7 +172,7 @@
|
||||
x-transition:leave-start="scale-100 opacity-100"
|
||||
x-transition:leave-end="scale-95 opacity-0"
|
||||
@endif
|
||||
@class([
|
||||
{{ $attributes->class([
|
||||
'fi-modal-window pointer-events-auto relative row-start-2 flex w-full cursor-default flex-col bg-white shadow-xl ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10',
|
||||
'fi-modal-slide-over-window ms-auto overflow-y-auto' => $slideOver,
|
||||
// Using an arbitrary value instead of the h-dvh class that was added in Tailwind CSS v3.4.0
|
||||
@@ -203,7 +205,7 @@
|
||||
MaxWidth::Screen => 'fixed inset-0',
|
||||
default => $width,
|
||||
},
|
||||
])
|
||||
])->merge($extraModalWindowAttributes) }}
|
||||
>
|
||||
@if ($heading || $header)
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user