Skip to content

Commit

Permalink
Merge branch 'filamentphp:3.x' into fix/select-current-page-only-sele…
Browse files Browse the repository at this point in the history
…ct-all-link-behavior
  • Loading branch information
dev-idkwhoami authored May 20, 2024
2 parents ee982b5 + 03b8b60 commit 221ea5b
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 41 deletions.
23 changes: 23 additions & 0 deletions packages/actions/docs/04-modals.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,29 @@ use Filament\Support\View\Components\Modal;
Modal::closedByClickingAway(false);
```

## Closing the modal by escaping

By default, when you press escape on a modal, it will close itself. If you wish to disable this behavior for a specific action, you can use the `closedByEscaping(false)` method:

```php
Action::make('updateAuthor')
->form([
// ...
])
->action(function (array $data): void {
// ...
})
->closedByEscaping(false)
```

If you'd like to change the behaviour for all modals in the application, you can do so by calling `Modal::closedByEscaping()` inside a service provider or middleware:

```php
use Filament\Support\View\Components\Modal;

Modal::closedByEscaping(false);
```

## Hiding the modal close button

By default, modals have a close button in the top right corner. If you wish to hide the close button, you can use the `modalCloseButton(false)` method:
Expand Down
5 changes: 5 additions & 0 deletions packages/actions/resources/views/components/modals.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:alignment="$action?->getModalAlignment()"
:close-button="$action?->hasModalCloseButton()"
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
:close-by-escaping="$action?->isModalClosedByEscaping()"
:description="$action?->getModalDescription()"
display-classes="block"
:extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()"
Expand Down Expand Up @@ -68,6 +69,7 @@
:alignment="$action?->getModalAlignment()"
:close-button="$action?->hasModalCloseButton()"
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
:close-by-escaping="$action?->isModalClosedByEscaping()"
:description="$action?->getModalDescription()"
display-classes="block"
:extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()"
Expand Down Expand Up @@ -122,6 +124,7 @@
:alignment="$action?->getModalAlignment()"
:close-button="$action?->hasModalCloseButton()"
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
:close-by-escaping="$action?->isModalClosedByEscaping()"
:description="$action?->getModalDescription()"
display-classes="block"
:extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()"
Expand Down Expand Up @@ -182,6 +185,7 @@
:alignment="$action?->getModalAlignment()"
:close-button="$action?->hasModalCloseButton()"
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
:close-by-escaping="$action?->isModalClosedByEscaping()"
:description="$action?->getModalDescription()"
display-classes="block"
:extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()"
Expand Down Expand Up @@ -242,6 +246,7 @@
:alignment="$action?->getModalAlignment()"
:close-button="$action?->hasModalCloseButton()"
:close-by-clicking-away="$action?->isModalClosedByClickingAway()"
:close-by-escaping="$action?->isModalClosedByEscaping()"
:description="$action?->getModalDescription()"
display-classes="block"
:extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()"
Expand Down
14 changes: 14 additions & 0 deletions packages/actions/src/Concerns/CanOpenModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ trait CanOpenModal

protected bool | Closure | null $isModalClosedByClickingAway = null;

protected bool | Closure | null $isModalClosedByEscaping = null;

protected string | Closure | null $modalIcon = null;

/**
Expand All @@ -94,6 +96,13 @@ public function closeModalByClickingAway(bool | Closure | null $condition = true
return $this;
}

public function closeModalByEscaping(bool | Closure | null $condition = true): static
{
$this->isModalClosedByEscaping = $condition;

return $this;
}

/**
* @deprecated Use `modalAlignment(Alignment::Center)` instead.
*/
Expand Down Expand Up @@ -600,6 +609,11 @@ public function isModalClosedByClickingAway(): bool
return (bool) ($this->evaluate($this->isModalClosedByClickingAway) ?? Modal::$isClosedByClickingAway);
}

public function isModalClosedByEscaping(): bool
{
return (bool) ($this->evaluate($this->isModalClosedByEscaping) ?? Modal::$isClosedByEscaping);
}

/**
* @deprecated Use `makeModalSubmitAction()` instead.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ class="mb-2"
<span
x-show="! areAllCheckboxesChecked"
x-on:click="toggleAllCheckboxes()"
wire:key="{{ $this->getId() }}.{{ $statePath }}.{{ $field::class }}.actions.select_all"
wire:key="{{ $this->getId() }}.{{ $statePath }}.{{ $field::class }}.actions.select-all"
>
{{ $getAction('selectAll') }}
</span>

<span
x-show="areAllCheckboxesChecked"
x-on:click="toggleAllCheckboxes()"
wire:key="{{ $this->getId() }}.{{ $statePath }}.{{ $field::class }}.actions.deselect_all"
wire:key="{{ $this->getId() }}.{{ $statePath }}.{{ $field::class }}.actions.deselect-all"
>
{{ $getAction('deselectAll') }}
</span>
Expand Down
7 changes: 7 additions & 0 deletions packages/panels/resources/lang/id/unsaved-changes-alert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [

'body' => 'Anda memiliki perubahan yang belum disimpan. Apakah Anda yakin ingin meninggalkan halaman ini?',

];
12 changes: 12 additions & 0 deletions packages/panels/src/Panel/Concerns/HasComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,22 @@ protected function registerLivewireComponents(): void
}
}

if ($this->hasProfile() && is_subclass_of($profilePageComponent = $this->getProfilePage(), Component::class)) {
$this->queueLivewireComponentForRegistration($profilePageComponent);
}

if ($this->hasRegistration() && is_subclass_of($registrationRouteAction = $this->getRegistrationRouteAction(), Component::class)) {
$this->queueLivewireComponentForRegistration($registrationRouteAction);
}

if ($this->hasTenantRegistration() && is_subclass_of($tenantRegistrationComponent = $this->getTenantRegistrationPage(), Component::class)) {
$this->queueLivewireComponentForRegistration($tenantRegistrationComponent);
}

if ($this->hasTenantProfile() && is_subclass_of($tenantProfileComponent = $this->getTenantProfilePage(), Component::class)) {
$this->queueLivewireComponentForRegistration($tenantProfileComponent);
}

foreach ($this->getResources() as $resource) {
foreach ($resource::getPages() as $pageRegistration) {
$this->queueLivewireComponentForRegistration($pageRegistration->getPage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
'ring-1 ring-gray-950/10 dark:ring-white/20' => (($color === 'gray') || ($tag === 'label')) && (! $grouped),
'bg-custom-600 text-white hover:bg-custom-500 focus-visible:ring-custom-500/50 dark:bg-custom-500 dark:hover:bg-custom-400 dark:focus-visible:ring-custom-400/50' => ($color !== 'gray') && ($tag !== 'label'),
'[input:checked+&]:bg-custom-600 [input:checked+&]:text-white [input:checked+&]:ring-0 [input:checked+&]:hover:bg-custom-500 dark:[input:checked+&]:bg-custom-500 dark:[input:checked+&]:hover:bg-custom-400 [input:checked:focus-visible+&]:ring-custom-500/50 dark:[input:checked:focus-visible+&]:ring-custom-400/50 [input:focus-visible+&]:z-10 [input:focus-visible+&]:ring-2 [input:focus-visible+&]:ring-gray-950/10 dark:[input:focus-visible+&]:ring-white/20' => ($color !== 'gray') && ($tag === 'label'),
]
]
),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'ariaLabelledby' => null,
'closeButton' => \Filament\Support\View\Components\Modal::$hasCloseButton,
'closeByClickingAway' => \Filament\Support\View\Components\Modal::$isClosedByClickingAway,
'closeByEscaping' => \Filament\Support\View\Components\Modal::$isClosedByEscaping,
'closeEventName' => 'close-modal',
'description' => null,
'displayClasses' => 'inline-block',
Expand Down Expand Up @@ -155,7 +156,9 @@
$watch('isOpen', () => (isShown = isOpen))
})
"
x-on:keydown.window.escape="{{ $closeEventHandler }}"
@if ($closeByEscaping)
x-on:keydown.window.escape="{{ $closeEventHandler }}"
@endif
x-show="isShown"
x-transition:enter="duration-300"
x-transition:leave="duration-300"
Expand Down
7 changes: 7 additions & 0 deletions packages/support/src/View/Components/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Modal

public static bool $isClosedByClickingAway = true;

public static bool $isClosedByEscaping = true;

public static function closeButton(bool $condition = true): void
{
static::$hasCloseButton = $condition;
Expand All @@ -17,4 +19,9 @@ public static function closedByClickingAway(bool $condition = true): void
{
static::$isClosedByClickingAway = $condition;
}

public static function closedByEscaping(bool $condition = true): void
{
static::$isClosedByEscaping = $condition;
}
}
15 changes: 15 additions & 0 deletions packages/tables/docs/08-grouping.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,18 @@ public function table(Table $table): Table
->groupingSettingsHidden();
}
```

### Hiding the grouping direction setting only

You can hide the grouping direction select interface using the `groupingDirectionSettingHidden()` method:

```php
use Filament\Tables\Table;

public function table(Table $table): Table
{
return $table
->defaultGroup('status');
->groupingDirectionSettingHidden();
}
```
71 changes: 37 additions & 34 deletions packages/tables/resources/views/components/groups.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@props([
'directionSetting' => false,
'dropdownOnDesktop' => false,
'groups',
'triggerAction',
Expand Down Expand Up @@ -71,23 +72,24 @@
</x-filament::input.wrapper>
</label>

<label x-cloak x-show="group" class="grid gap-y-2">
<span class="{{ $labelClasses }}">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>

<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@if (! $directionSetting)
<label x-cloak x-show="group" class="grid gap-y-2">
<span class="{{ $labelClasses }}">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>
<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@endif
</div>
</x-filament::dropdown>

Expand Down Expand Up @@ -116,23 +118,24 @@
</x-filament::input.wrapper>
</label>

<label x-cloak x-show="group">
<span class="sr-only">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>

<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@if (! $directionSetting)
<label x-cloak x-show="group">
<span class="sr-only">
{{ __('filament-tables::table.grouping.fields.direction.label') }}
</span>
<x-filament::input.wrapper>
<x-filament::input.select x-model="direction">
<option value="asc">
{{ __('filament-tables::table.grouping.fields.direction.options.asc') }}
</option>

<option value="desc">
{{ __('filament-tables::table.grouping.fields.direction.options.desc') }}
</option>
</x-filament::input.select>
</x-filament::input.wrapper>
</label>
@endif
</div>
@endif
</div>
8 changes: 5 additions & 3 deletions packages/tables/resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$isReorderable = $isReorderable();
$isReordering = $isReordering();
$areGroupingSettingsVisible = (! $isReordering) && count($groups) && (! $areGroupingSettingsHidden());
$isGroupingDirectionSettingHidden = $isGroupingDirectionSettingHidden();
$isColumnSearchVisible = $isSearchableByColumn();
$isGlobalSearchVisible = $isSearchable();
$isSearchOnBlur = $isSearchOnBlur();
Expand Down Expand Up @@ -196,6 +197,7 @@ class="fi-ta-header-toolbar flex items-center justify-between gap-x-4 px-4 py-3

@if ($areGroupingSettingsVisible)
<x-filament-tables::groups
:direction-setting="$isGroupingDirectionSettingHidden"
:dropdown-on-desktop="$areGroupingSettingsInDropdownOnDesktop()"
:groups="$groups"
:trigger-action="$getGroupRecordsTriggerAction()"
Expand Down Expand Up @@ -296,7 +298,7 @@ class="flex items-center gap-4 gap-x-6 bg-gray-50 px-4 dark:bg-white/5 sm:px-6"
@if ($isSelectionEnabled && (! $isReordering))
<x-filament-tables::selection.checkbox
{{-- Make sure the "checked" state gets re-evaluated after a Livewire request: --}}
:wire:key="$this->getId() . '.table.bulk_select_page.checkbox.' . Str::random()"
:wire:key="$this->getId() . '.table.bulk-select-page.checkbox.' . Str::random()"
:label="__('filament-tables::table.fields.bulk_select_page.label')"
x-bind:checked="
const recordsOnPage = getRecordsOnPage()
Expand Down Expand Up @@ -783,7 +785,7 @@ class="text-sm font-semibold text-gray-950 dark:text-white"
<x-filament-tables::selection.cell tag="th">
<x-filament-tables::selection.checkbox
{{-- Make sure the "checked" state gets re-evaluated after a Livewire request: --}}
:wire:key="$this->getId() . '.table.bulk_select_page.checkbox.' . Str::random()"
:wire:key="$this->getId() . '.table.bulk-select-page.checkbox.' . Str::random()"
:label="__('filament-tables::table.fields.bulk_select_page.label')"
x-bind:checked="
const recordsOnPage = getRecordsOnPage()
Expand Down Expand Up @@ -860,7 +862,7 @@ class="text-sm font-semibold text-gray-950 dark:text-white"
<x-filament-tables::selection.cell tag="th">
<x-filament-tables::selection.checkbox
{{-- Make sure the "checked" state gets re-evaluated after a Livewire request: --}}
:wire:key="$this->getId() . '.table.bulk_select_page.checkbox.' . Str::random()"
:wire:key="$this->getId() . '.table.bulk-select-page.checkbox.' . Str::random()"
:label="__('filament-tables::table.fields.bulk_select_page.label')"
x-bind:checked="
const recordsOnPage = getRecordsOnPage()
Expand Down
14 changes: 14 additions & 0 deletions packages/tables/src/Table/Concerns/CanGroupRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ trait CanGroupRecords

protected bool | Closure $areGroupingSettingsHidden = false;

protected bool | Closure $isGroupingDirectionSettingHidden = false;

protected ?Closure $modifyGroupRecordsTriggerActionUsing = null;

public function groupRecordsTriggerAction(?Closure $callback): static
Expand Down Expand Up @@ -56,6 +58,13 @@ public function groupingSettingsHidden(bool | Closure $condition = true): static
return $this;
}

public function groupingDirectionSettingHidden(bool | Closure $condition = true): static
{
$this->isGroupingDirectionSettingHidden = $condition;

return $this;
}

public function defaultGroup(string | Group | null $group): static
{
$this->defaultGroup = $group;
Expand Down Expand Up @@ -130,6 +139,11 @@ public function areGroupingSettingsHidden(): bool
return (bool) $this->evaluate($this->areGroupingSettingsHidden);
}

public function isGroupingDirectionSettingHidden(): bool
{
return (bool) $this->evaluate($this->isGroupingDirectionSettingHidden);
}

public function getDefaultGroup(): ?Group
{
if ($this->defaultGroup === null) {
Expand Down

0 comments on commit 221ea5b

Please sign in to comment.