From 3ba14e7793e9161285a8fb740a612b0cfa2a1ba3 Mon Sep 17 00:00:00 2001 From: Simeon Benson Date: Mon, 22 Apr 2024 02:02:18 +0700 Subject: [PATCH 01/17] feat: adding the possibility to hide the group direction visible --- .../views/components/groups.blade.php | 23 +++++++++++-------- .../tables/resources/views/index.blade.php | 2 ++ .../src/Table/Concerns/CanGroupRecords.php | 14 +++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/tables/resources/views/components/groups.blade.php b/packages/tables/resources/views/components/groups.blade.php index f875fd43e4d..d6e287893bc 100644 --- a/packages/tables/resources/views/components/groups.blade.php +++ b/packages/tables/resources/views/components/groups.blade.php @@ -2,6 +2,7 @@ 'dropdownOnDesktop' => false, 'groups', 'triggerAction', + 'groupingDirectionVisible' => true, ]) @php @@ -121,17 +122,19 @@ {{ __('filament-tables::table.grouping.fields.direction.label') }} - - - + @if ($groupingDirectionVisible) + + + - - - + + + + @endif @endif diff --git a/packages/tables/resources/views/index.blade.php b/packages/tables/resources/views/index.blade.php index e1e04951887..4580f0db70f 100644 --- a/packages/tables/resources/views/index.blade.php +++ b/packages/tables/resources/views/index.blade.php @@ -42,6 +42,7 @@ $isReorderable = $isReorderable(); $isReordering = $isReordering(); $areGroupingSettingsVisible = (! $isReordering) && count($groups) && (! $areGroupingSettingsHidden()); + $isGroupingDirectionVisible = (! $isGroupingDirectionHidden()); $isColumnSearchVisible = $isSearchableByColumn(); $isGlobalSearchVisible = $isSearchable(); $isSearchOnBlur = $isSearchOnBlur(); @@ -198,6 +199,7 @@ class="fi-ta-header-toolbar flex items-center justify-between gap-x-4 px-4 py-3 :dropdown-on-desktop="$areGroupingSettingsInDropdownOnDesktop()" :groups="$groups" :trigger-action="$getGroupRecordsTriggerAction()" + :grouping-direction-visible="$isGroupingDirectionVisible" /> @endif diff --git a/packages/tables/src/Table/Concerns/CanGroupRecords.php b/packages/tables/src/Table/Concerns/CanGroupRecords.php index cd4b93b6d83..0719e655ccb 100644 --- a/packages/tables/src/Table/Concerns/CanGroupRecords.php +++ b/packages/tables/src/Table/Concerns/CanGroupRecords.php @@ -23,6 +23,8 @@ trait CanGroupRecords protected bool | Closure $areGroupingSettingsHidden = false; + protected bool | Closure $isGroupingDirectionHidden = false; + protected ?Closure $modifyGroupRecordsTriggerActionUsing = null; public function groupRecordsTriggerAction(?Closure $callback): static @@ -56,6 +58,13 @@ public function groupingSettingsHidden(bool | Closure $condition = true): static return $this; } + public function groupingSortDirectionHidden(bool | Closure $condition = true): static + { + $this->isGroupingDirectionHidden = $condition; + + return $this; + } + public function defaultGroup(string | Group | null $group): static { $this->defaultGroup = $group; @@ -130,6 +139,11 @@ public function areGroupingSettingsHidden(): bool return (bool) $this->evaluate($this->areGroupingSettingsHidden); } + public function isGroupingDirectionHidden(): bool + { + return (bool) $this->evaluate($this->isGroupingDirectionHidden); + } + public function getDefaultGroup(): ?Group { if ($this->defaultGroup === null) { From e22b2c3ff6831dd101a3fbc0fa9fc40997d0f747 Mon Sep 17 00:00:00 2001 From: Simeon Benson Date: Thu, 16 May 2024 19:49:09 +0700 Subject: [PATCH 02/17] feat: grouping sort direction hiding --- .../views/components/groups.blade.php | 74 +++++++++---------- .../tables/resources/views/index.blade.php | 4 +- .../src/Table/Concerns/CanGroupRecords.php | 2 +- .../Tables/Concerns/CanGroupRecordsTest.php | 14 ++++ 4 files changed, 54 insertions(+), 40 deletions(-) create mode 100644 tests/src/Tables/Concerns/CanGroupRecordsTest.php diff --git a/packages/tables/resources/views/components/groups.blade.php b/packages/tables/resources/views/components/groups.blade.php index d6e287893bc..4320780aaae 100644 --- a/packages/tables/resources/views/components/groups.blade.php +++ b/packages/tables/resources/views/components/groups.blade.php @@ -2,7 +2,7 @@ 'dropdownOnDesktop' => false, 'groups', 'triggerAction', - 'groupingDirectionVisible' => true, + 'groupingDirectionHidden' => false, ]) @php @@ -72,23 +72,24 @@ - + @if ($groupingDirectionHidden) + + @endif @@ -117,25 +118,24 @@ - + @if ($groupingDirectionHidden) + + @endif @endif diff --git a/packages/tables/resources/views/index.blade.php b/packages/tables/resources/views/index.blade.php index 4580f0db70f..3ed0bb33a0f 100644 --- a/packages/tables/resources/views/index.blade.php +++ b/packages/tables/resources/views/index.blade.php @@ -42,7 +42,7 @@ $isReorderable = $isReorderable(); $isReordering = $isReordering(); $areGroupingSettingsVisible = (! $isReordering) && count($groups) && (! $areGroupingSettingsHidden()); - $isGroupingDirectionVisible = (! $isGroupingDirectionHidden()); + $isGroupingDirectionHidden = (! $isGroupingDirectionHidden()); $isColumnSearchVisible = $isSearchableByColumn(); $isGlobalSearchVisible = $isSearchable(); $isSearchOnBlur = $isSearchOnBlur(); @@ -199,7 +199,7 @@ class="fi-ta-header-toolbar flex items-center justify-between gap-x-4 px-4 py-3 :dropdown-on-desktop="$areGroupingSettingsInDropdownOnDesktop()" :groups="$groups" :trigger-action="$getGroupRecordsTriggerAction()" - :grouping-direction-visible="$isGroupingDirectionVisible" + :grouping-direction-hidden="$isGroupingDirectionHidden" /> @endif diff --git a/packages/tables/src/Table/Concerns/CanGroupRecords.php b/packages/tables/src/Table/Concerns/CanGroupRecords.php index 0719e655ccb..87eff19b358 100644 --- a/packages/tables/src/Table/Concerns/CanGroupRecords.php +++ b/packages/tables/src/Table/Concerns/CanGroupRecords.php @@ -58,7 +58,7 @@ public function groupingSettingsHidden(bool | Closure $condition = true): static return $this; } - public function groupingSortDirectionHidden(bool | Closure $condition = true): static + public function groupingDirectionHidden(bool | Closure $condition = true): static { $this->isGroupingDirectionHidden = $condition; diff --git a/tests/src/Tables/Concerns/CanGroupRecordsTest.php b/tests/src/Tables/Concerns/CanGroupRecordsTest.php new file mode 100644 index 00000000000..daf2e83ff11 --- /dev/null +++ b/tests/src/Tables/Concerns/CanGroupRecordsTest.php @@ -0,0 +1,14 @@ +assertHasNoErrors() + ->assertDontSee('') + ->assertDontSee(__('filament-tables::table.grouping.fields.direction.options.asc')) + ->assertDontSee(__('filament-tables::table.grouping.fields.direction.options.desc')); +}); From 11e9ceba90ff3e3622596dc07569f167dc5db487 Mon Sep 17 00:00:00 2001 From: Simeon Benson Date: Thu, 16 May 2024 20:22:50 +0700 Subject: [PATCH 03/17] docs: adding functionality to hide the grouping direction --- packages/tables/docs/08-grouping.md | 15 +++++++++++++++ tests/src/Tables/Concerns/CanGroupRecordsTest.php | 14 -------------- 2 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 tests/src/Tables/Concerns/CanGroupRecordsTest.php diff --git a/packages/tables/docs/08-grouping.md b/packages/tables/docs/08-grouping.md index 1fc5000c2a5..743d1d8f44a 100644 --- a/packages/tables/docs/08-grouping.md +++ b/packages/tables/docs/08-grouping.md @@ -323,6 +323,21 @@ public function table(Table $table): Table } ``` +## Hiding the grouping direction settings + +You can hide the grouping direction drop-down select interface using the `groupingDirectionHidden()` method: + +```php +use Filament\Tables\Table; + +public function table(Table $table): Table +{ + return $table + ->defaultGroup('status'); + ->groupingDirectionHidden(); +} +``` + ## Hiding the grouping settings You can hide the grouping settings interface using the `groupingSettingsHidden()` method: diff --git a/tests/src/Tables/Concerns/CanGroupRecordsTest.php b/tests/src/Tables/Concerns/CanGroupRecordsTest.php deleted file mode 100644 index daf2e83ff11..00000000000 --- a/tests/src/Tables/Concerns/CanGroupRecordsTest.php +++ /dev/null @@ -1,14 +0,0 @@ -assertHasNoErrors() - ->assertDontSee('') - ->assertDontSee(__('filament-tables::table.grouping.fields.direction.options.asc')) - ->assertDontSee(__('filament-tables::table.grouping.fields.direction.options.desc')); -}); From 866d66b7b920ae696b948587ef5810410bc47fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borja=20Jim=C3=A9nez?= Date: Fri, 17 May 2024 00:27:23 +0200 Subject: [PATCH 04/17] add option to prevent modal closing by hitting escape --- packages/actions/docs/04-modals.md | 23 +++++++++++++++++++ .../views/components/modals.blade.php | 5 ++++ .../actions/src/Concerns/CanOpenModal.php | 13 +++++++++++ .../views/components/modal/index.blade.php | 10 ++++++-- .../support/src/View/Components/Modal.php | 6 +++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/packages/actions/docs/04-modals.md b/packages/actions/docs/04-modals.md index 312bf083260..c8a1187381e 100644 --- a/packages/actions/docs/04-modals.md +++ b/packages/actions/docs/04-modals.md @@ -506,6 +506,29 @@ use Filament\Support\View\Components\Modal; Modal::closedByClickingAway(false); ``` +## Closing the modal by hitting escape + +By default, when you hit escape on a modal, it will close itself. If you wish to disable this behavior for a specific action, you can use the `closedByHittingEscape(false)` method: + +```php +Action::make('updateAuthor') + ->form([ + // ... + ]) + ->action(function (array $data): void { + // ... + }) + ->closedByHittingEscape(false) +``` + +If you'd like to change the behaviour for all modals in the application, you can do so by calling `Modal::closedByHittingEscape()` inside a service provider or middleware: + +```php +use Filament\Support\View\Components\Modal; + +Modal::closedByHittingEscape(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: diff --git a/packages/actions/resources/views/components/modals.blade.php b/packages/actions/resources/views/components/modals.blade.php index d4e91b82172..eb38292739f 100644 --- a/packages/actions/resources/views/components/modals.blade.php +++ b/packages/actions/resources/views/components/modals.blade.php @@ -8,6 +8,7 @@ :alignment="$action?->getModalAlignment()" :close-button="$action?->hasModalCloseButton()" :close-by-clicking-away="$action?->isModalClosedByClickingAway()" + :close-by-hitting-escape="$action?->isModalClosedByHittingEscape()" :description="$action?->getModalDescription()" display-classes="block" :extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()" @@ -68,6 +69,7 @@ :alignment="$action?->getModalAlignment()" :close-button="$action?->hasModalCloseButton()" :close-by-clicking-away="$action?->isModalClosedByClickingAway()" + :close-by-hitting-escape="$action?->isModalClosedByHittingEscape()" :description="$action?->getModalDescription()" display-classes="block" :extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()" @@ -122,6 +124,7 @@ :alignment="$action?->getModalAlignment()" :close-button="$action?->hasModalCloseButton()" :close-by-clicking-away="$action?->isModalClosedByClickingAway()" + :close-by-hitting-escape="$action?->isModalClosedByHittingEscape()" :description="$action?->getModalDescription()" display-classes="block" :extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()" @@ -182,6 +185,7 @@ :alignment="$action?->getModalAlignment()" :close-button="$action?->hasModalCloseButton()" :close-by-clicking-away="$action?->isModalClosedByClickingAway()" + :close-by-hitting-escape="$action?->isModalClosedByHittingEscape()" :description="$action?->getModalDescription()" display-classes="block" :extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()" @@ -242,6 +246,7 @@ :alignment="$action?->getModalAlignment()" :close-button="$action?->hasModalCloseButton()" :close-by-clicking-away="$action?->isModalClosedByClickingAway()" + :close-by-hitting-escape="$action?->isModalClosedByHittingEscape()" :description="$action?->getModalDescription()" display-classes="block" :extra-modal-window-attribute-bag="$action?->getExtraModalWindowAttributeBag()" diff --git a/packages/actions/src/Concerns/CanOpenModal.php b/packages/actions/src/Concerns/CanOpenModal.php index b36fa69916b..264fbcb497d 100644 --- a/packages/actions/src/Concerns/CanOpenModal.php +++ b/packages/actions/src/Concerns/CanOpenModal.php @@ -79,6 +79,7 @@ trait CanOpenModal protected bool | Closure | null $hasModalCloseButton = null; protected bool | Closure | null $isModalClosedByClickingAway = null; + protected bool | Closure | null $isModalClosedByHittingEscape = null; protected string | Closure | null $modalIcon = null; @@ -94,6 +95,13 @@ public function closeModalByClickingAway(bool | Closure | null $condition = true return $this; } + public function closeModalByHittingEscape(bool | Closure | null $condition = true): static + { + $this->isModalClosedByHittingEscape = $condition; + + return $this; + } + /** * @deprecated Use `modalAlignment(Alignment::Center)` instead. */ @@ -600,6 +608,11 @@ public function isModalClosedByClickingAway(): bool return (bool) ($this->evaluate($this->isModalClosedByClickingAway) ?? Modal::$isClosedByClickingAway); } + public function isModalClosedByHittingEscape(): bool + { + return (bool) ($this->evaluate($this->isModalClosedByHittingEscape) ?? Modal::$isClosedByHittingEscape); + } + /** * @deprecated Use `makeModalSubmitAction()` instead. * diff --git a/packages/support/resources/views/components/modal/index.blade.php b/packages/support/resources/views/components/modal/index.blade.php index 6a3cc6a1e21..14682c13893 100644 --- a/packages/support/resources/views/components/modal/index.blade.php +++ b/packages/support/resources/views/components/modal/index.blade.php @@ -8,6 +8,7 @@ 'ariaLabelledby' => null, 'closeButton' => \Filament\Support\View\Components\Modal::$hasCloseButton, 'closeByClickingAway' => \Filament\Support\View\Components\Modal::$isClosedByClickingAway, + 'closeByHittingEscape' => \Filament\Support\View\Components\Modal::$isClosedByHittingEscape, 'closeEventName' => 'close-modal', 'description' => null, 'displayClasses' => 'inline-block', @@ -23,6 +24,7 @@ 'id' => null, 'openEventName' => 'open-modal', 'slideOver' => false, + 'closeToAction' => true, 'stickyFooter' => false, 'stickyHeader' => false, 'trigger' => null, @@ -155,7 +157,10 @@ $watch('isOpen', () => (isShown = isOpen)) }) " - x-on:keydown.window.escape="{{ $closeEventHandler }}" + @if ($closeByHittingEscape) + x-on:keydown.window.escape="{{ $closeEventHandler }}" + @endif + x-show="isShown" x-transition:enter="duration-300" x-transition:leave="duration-300" @@ -175,9 +180,10 @@ ($extraModalWindowAttributeBag ?? new \Illuminate\View\ComponentAttributeBag())->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, + 'p-10 border border-red-300 shadow shadow-4xl' => $closeToAction, // Using an arbitrary value instead of the h-dvh class that was added in Tailwind CSS v3.4.0 // to ensure compatibility with custom themes that may use an older version of Tailwind CSS. - 'h-[100dvh]' => $slideOver || ($width === MaxWidth::Screen), + 'h-[100dvh]' => ($slideOver || ($width === MaxWidth::Screen)) && !$closeToAction, 'mx-auto rounded-xl' => ! ($slideOver || ($width === MaxWidth::Screen)), 'hidden' => ! $visible, match ($width) { diff --git a/packages/support/src/View/Components/Modal.php b/packages/support/src/View/Components/Modal.php index 9b905988070..3127febf18d 100644 --- a/packages/support/src/View/Components/Modal.php +++ b/packages/support/src/View/Components/Modal.php @@ -7,6 +7,7 @@ class Modal public static bool $hasCloseButton = true; public static bool $isClosedByClickingAway = true; + public static bool $isClosedByHittingEscape = true; public static function closeButton(bool $condition = true): void { @@ -17,4 +18,9 @@ public static function closedByClickingAway(bool $condition = true): void { static::$isClosedByClickingAway = $condition; } + + public static function closedByHittingEscape(bool $condition = true): void + { + static::$isClosedByHittingEscape = $condition; + } } From e91f66d501fb01d2ccd1448e0f9b17b1bbfeb00a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borja=20Jim=C3=A9nez?= Date: Fri, 17 May 2024 00:48:17 +0200 Subject: [PATCH 05/17] prettier --- packages/actions/src/Concerns/CanOpenModal.php | 1 + .../resources/views/components/button/index.blade.php | 2 +- .../support/resources/views/components/modal/index.blade.php | 5 +---- packages/support/src/View/Components/Modal.php | 1 + 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/actions/src/Concerns/CanOpenModal.php b/packages/actions/src/Concerns/CanOpenModal.php index 264fbcb497d..865b98d1616 100644 --- a/packages/actions/src/Concerns/CanOpenModal.php +++ b/packages/actions/src/Concerns/CanOpenModal.php @@ -79,6 +79,7 @@ trait CanOpenModal protected bool | Closure | null $hasModalCloseButton = null; protected bool | Closure | null $isModalClosedByClickingAway = null; + protected bool | Closure | null $isModalClosedByHittingEscape = null; protected string | Closure | null $modalIcon = null; diff --git a/packages/support/resources/views/components/button/index.blade.php b/packages/support/resources/views/components/button/index.blade.php index 9388814b55f..10d02df0555 100644 --- a/packages/support/resources/views/components/button/index.blade.php +++ b/packages/support/resources/views/components/button/index.blade.php @@ -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'), - ] + ] ), ]); diff --git a/packages/support/resources/views/components/modal/index.blade.php b/packages/support/resources/views/components/modal/index.blade.php index 14682c13893..1e107f8ee37 100644 --- a/packages/support/resources/views/components/modal/index.blade.php +++ b/packages/support/resources/views/components/modal/index.blade.php @@ -24,7 +24,6 @@ 'id' => null, 'openEventName' => 'open-modal', 'slideOver' => false, - 'closeToAction' => true, 'stickyFooter' => false, 'stickyHeader' => false, 'trigger' => null, @@ -160,7 +159,6 @@ @if ($closeByHittingEscape) x-on:keydown.window.escape="{{ $closeEventHandler }}" @endif - x-show="isShown" x-transition:enter="duration-300" x-transition:leave="duration-300" @@ -180,10 +178,9 @@ ($extraModalWindowAttributeBag ?? new \Illuminate\View\ComponentAttributeBag())->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, - 'p-10 border border-red-300 shadow shadow-4xl' => $closeToAction, // Using an arbitrary value instead of the h-dvh class that was added in Tailwind CSS v3.4.0 // to ensure compatibility with custom themes that may use an older version of Tailwind CSS. - 'h-[100dvh]' => ($slideOver || ($width === MaxWidth::Screen)) && !$closeToAction, + 'h-[100dvh]' => $slideOver || ($width === MaxWidth::Screen), 'mx-auto rounded-xl' => ! ($slideOver || ($width === MaxWidth::Screen)), 'hidden' => ! $visible, match ($width) { diff --git a/packages/support/src/View/Components/Modal.php b/packages/support/src/View/Components/Modal.php index 3127febf18d..8fd281fe335 100644 --- a/packages/support/src/View/Components/Modal.php +++ b/packages/support/src/View/Components/Modal.php @@ -7,6 +7,7 @@ class Modal public static bool $hasCloseButton = true; public static bool $isClosedByClickingAway = true; + public static bool $isClosedByHittingEscape = true; public static function closeButton(bool $condition = true): void From 909fac9aef61683b1574433d7f3bd00d61d47b4e Mon Sep 17 00:00:00 2001 From: Simeon Benson Date: Fri, 17 May 2024 20:31:09 +0700 Subject: [PATCH 06/17] fix: comments resolve --- packages/tables/resources/views/components/groups.blade.php | 6 +++--- packages/tables/resources/views/index.blade.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/tables/resources/views/components/groups.blade.php b/packages/tables/resources/views/components/groups.blade.php index 4320780aaae..5b2e04fb62a 100644 --- a/packages/tables/resources/views/components/groups.blade.php +++ b/packages/tables/resources/views/components/groups.blade.php @@ -2,7 +2,7 @@ 'dropdownOnDesktop' => false, 'groups', 'triggerAction', - 'groupingDirectionHidden' => false, + 'direction' => false, ]) @php @@ -72,7 +72,7 @@ - @if ($groupingDirectionHidden) + @if (! $direction) - @if ($groupingDirectionHidden) + @if (! $direction) - @if (! $direction) + @if (! $directionSetting) - @if (! $direction) + @if (! $directionSetting)