diff --git a/packages/actions/docs/04-modals.md b/packages/actions/docs/04-modals.md index 2222ebc220..fb609242df 100644 --- a/packages/actions/docs/04-modals.md +++ b/packages/actions/docs/04-modals.md @@ -272,13 +272,13 @@ Now, in the view file, you can render the action button by calling `getModalActi ``` -## 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 diff --git a/packages/actions/resources/views/components/modals.blade.php b/packages/actions/resources/views/components/modals.blade.php index 630e3edefb..394308247e 100644 --- a/packages/actions/resources/views/components/modals.blade.php +++ b/packages/actions/resources/views/components/modals.blade.php @@ -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() }} diff --git a/packages/actions/src/Concerns/HasExtraModalAttributes.php b/packages/actions/src/Concerns/HasExtraModalAttributes.php deleted file mode 100644 index f1365bfd03..0000000000 --- a/packages/actions/src/Concerns/HasExtraModalAttributes.php +++ /dev/null @@ -1,42 +0,0 @@ - | Closure> - */ - protected array $extraModalAttributes = []; - - /** - * @param array | 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 - */ - public function getExtraModalAttributes(): array - { - $temporaryAttributeBag = new ComponentAttributeBag(); - - foreach ($this->extraModalAttributes as $extraModalAttributes) { - $temporaryAttributeBag = $temporaryAttributeBag->merge($this->evaluate($extraModalAttributes)); - } - - return $temporaryAttributeBag->getAttributes(); - } -} diff --git a/packages/actions/src/Concerns/HasExtraModalWindowAttributes.php b/packages/actions/src/Concerns/HasExtraModalWindowAttributes.php new file mode 100644 index 0000000000..4063d4502f --- /dev/null +++ b/packages/actions/src/Concerns/HasExtraModalWindowAttributes.php @@ -0,0 +1,23 @@ +extraModalWindowAttributes = $attributes; + + return $this; + } + + public function getExtraModalWindowAttributes(): array + { + return $this->evaluate($this->extraModalWindowAttributes); + } +} diff --git a/packages/actions/src/MountableAction.php b/packages/actions/src/MountableAction.php index 6c5b1bfb14..f484ca2cbb 100644 --- a/packages/actions/src/MountableAction.php +++ b/packages/actions/src/MountableAction.php @@ -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; diff --git a/packages/support/resources/views/components/modal/index.blade.php b/packages/support/resources/views/components/modal/index.blade.php index 678a467ea4..5ac79d2abd 100644 --- a/packages/support/resources/views/components/modal/index.blade.php +++ b/packages/support/resources/views/components/modal/index.blade.php @@ -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)