From 767ab6fd022e36227fd1576501733ba9b6b2552d Mon Sep 17 00:00:00 2001
From: Joe <104938042+lrljoe@users.noreply.github.com>
Date: Wed, 27 Nov 2024 20:44:22 +0000
Subject: [PATCH 1/5] Initial Commit
---
.../toolbar/items/search-field.blade.php | 26 ++++++++++++---
.../Configuration/SearchConfiguration.php | 7 ----
src/Traits/Helpers/SearchHelpers.php | 5 ---
.../SearchFieldStylingConfiguration.php | 29 ++++++++++++++++
src/Traits/Styling/HasSearchFieldStyling.php | 21 ++++++++++++
.../Helpers/SearchFieldStylingHelpers.php | 33 +++++++++++++++++++
src/Traits/WithSearch.php | 5 +--
7 files changed, 108 insertions(+), 18 deletions(-)
create mode 100644 src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
create mode 100644 src/Traits/Styling/HasSearchFieldStyling.php
create mode 100644 src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
diff --git a/resources/views/components/tools/toolbar/items/search-field.blade.php b/resources/views/components/tools/toolbar/items/search-field.blade.php
index 6bc8bb9c5..c934d49a9 100644
--- a/resources/views/components/tools/toolbar/items/search-field.blade.php
+++ b/resources/views/components/tools/toolbar/items/search-field.blade.php
@@ -3,8 +3,25 @@
$this->isBootstrap,
- 'flex rounded-md shadow-sm' => $this->isTailwind,
+ 'rounded-md shadow-sm' => $this->isTailwind,
+ 'flex' => !$this->hasSearchIcon,
+ 'relative inline-flex flex-row' => $this->hasSearchIcon,
])>
+
+ @if($this->hasSearchIcon)
+
+ merge($this->getSearchIconAttributes())
+ ->class([
+ 'w-4 h-4' => (($this->getSearchIconAttributes()['default'] ?? true) || ($this->getSearchIconAttributes()['default-styling'] ?? true)),
+ ])
+ }}
+ />
+
+
+ @endif
+
getSearchOptions() }}="search"
placeholder="{{ $this->getSearchPlaceholder() }}"
@@ -12,11 +29,12 @@
{{
$attributes->merge($this->getSearchFieldAttributes())
->class([
- 'block w-full rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-none rounded-l-md focus:ring-0 focus:border-gray-300' => $this->isTailwind && $this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)),
- 'block w-full rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-md focus:ring focus:ring-opacity-50' => $this->isTailwind && !$this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)),
+ 'rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-none rounded-l-md focus:ring-0 focus:border-gray-300' => $this->isTailwind && $this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)),
+ 'rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 rounded-md focus:ring focus:ring-opacity-50' => $this->isTailwind && !$this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-styling'] ?? true)),
'border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-600 focus:border-gray-300' => $this->isTailwind && $this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-colors'] ?? true)),
'border-gray-300 dark:bg-gray-700 dark:text-white dark:border-gray-600 focus:border-indigo-300 focus:ring-indigo-200' => $this->isTailwind && !$this->hasSearch() && (($this->getSearchFieldAttributes()['default'] ?? true) || ($this->getSearchFieldAttributes()['default-colors'] ?? true)),
-
+ 'block w-full' => !$this->hasSearchIcon,
+ 'pl-8 pr-4' => $this->hasSearchIcon,
'form-control' => $this->isBootstrap && $this->getSearchFieldAttributes()['default'] ?? true,
])
->except(['default','default-styling','default-colors'])
diff --git a/src/Traits/Configuration/SearchConfiguration.php b/src/Traits/Configuration/SearchConfiguration.php
index 77590071f..09b7d6de7 100644
--- a/src/Traits/Configuration/SearchConfiguration.php
+++ b/src/Traits/Configuration/SearchConfiguration.php
@@ -154,13 +154,6 @@ public function setSearchPlaceholder(string $placeholder): self
return $this;
}
- public function setSearchFieldAttributes(array $attributes = []): self
- {
- $this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
-
- return $this;
- }
-
public function setTrimSearchString(bool $status): self
{
$this->trimSearchString = $status;
diff --git a/src/Traits/Helpers/SearchHelpers.php b/src/Traits/Helpers/SearchHelpers.php
index b9637b13c..90f0838d1 100644
--- a/src/Traits/Helpers/SearchHelpers.php
+++ b/src/Traits/Helpers/SearchHelpers.php
@@ -135,11 +135,6 @@ public function hasSearchPlaceholder(): bool
return $this->searchPlaceholder !== null;
}
- public function getSearchFieldAttributes(): array
- {
- return $this->getCustomAttributes('searchFieldAttributes', true);
- }
-
public function shouldTrimSearchString(): bool
{
return $this->trimSearchString ?? false;
diff --git a/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php b/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
new file mode 100644
index 000000000..039141f45
--- /dev/null
+++ b/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
@@ -0,0 +1,29 @@
+searchIcon = $searchIcon;
+ $this->searchIconSet = true;
+
+ return $this;
+ }
+
+ public function setSearchIconAttributes(array $attributes = []): self
+ {
+ $this->setCustomAttributes('searchIconAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
+
+ return $this;
+ }
+
+
+ public function setSearchFieldAttributes(array $attributes = []): self
+ {
+ $this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
+
+ return $this;
+ }
+}
\ No newline at end of file
diff --git a/src/Traits/Styling/HasSearchFieldStyling.php b/src/Traits/Styling/HasSearchFieldStyling.php
new file mode 100644
index 000000000..2a15b148c
--- /dev/null
+++ b/src/Traits/Styling/HasSearchFieldStyling.php
@@ -0,0 +1,21 @@
+ true, 'default-styling' => true];
+
+}
\ No newline at end of file
diff --git a/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php b/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
new file mode 100644
index 000000000..d04b7e24a
--- /dev/null
+++ b/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
@@ -0,0 +1,33 @@
+getCustomAttributes('searchFieldAttributes', true);
+ }
+
+ #[Computed]
+ public function hasSearchIcon(): bool
+ {
+ return $this->searchIconSet;
+ }
+
+ #[Computed]
+ public function getSearchIcon(): string
+ {
+ return $this->hasSearchIcon() ? $this->searchIcon : 'heroicon-m-magnifying-glass';
+ }
+
+ #[Computed]
+ public function getSearchIconAttributes(): array
+ {
+ return $this->getCustomAttributes('searchIconAttributes', true, false);
+ }
+
+}
\ No newline at end of file
diff --git a/src/Traits/WithSearch.php b/src/Traits/WithSearch.php
index ddfe98553..ba40a9f42 100644
--- a/src/Traits/WithSearch.php
+++ b/src/Traits/WithSearch.php
@@ -8,12 +8,14 @@
use Rappasoft\LaravelLivewireTables\Traits\Configuration\SearchConfiguration;
use Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings\HasQueryStringForSearch;
use Rappasoft\LaravelLivewireTables\Traits\Helpers\SearchHelpers;
+use Rappasoft\LaravelLivewireTables\Traits\Styling\HasSearchFieldStyling;
trait WithSearch
{
use SearchConfiguration,
SearchHelpers;
use HasQueryStringForSearch;
+ use HasSearchFieldStyling;
public string $search = '';
@@ -36,10 +38,9 @@ trait WithSearch
protected ?int $searchFilterThrottle = null;
- protected array $searchFieldAttributes = [];
-
protected bool $trimSearchString = false;
+
// TODO
public function applySearch(): Builder
{
From 0127339d8e642c80c249afbdd7a5e3f0b73fffe7 Mon Sep 17 00:00:00 2001
From: lrljoe
Date: Wed, 27 Nov 2024 20:44:53 +0000
Subject: [PATCH 2/5] Fix styling
---
.../SearchFieldStylingConfiguration.php | 57 ++++++++---------
src/Traits/Styling/HasSearchFieldStyling.php | 41 ++++++------
.../Helpers/SearchFieldStylingHelpers.php | 64 +++++++++----------
src/Traits/WithSearch.php | 1 -
4 files changed, 79 insertions(+), 84 deletions(-)
diff --git a/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php b/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
index 039141f45..8b2d33575 100644
--- a/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
+++ b/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
@@ -1,29 +1,28 @@
-searchIcon = $searchIcon;
- $this->searchIconSet = true;
-
- return $this;
- }
-
- public function setSearchIconAttributes(array $attributes = []): self
- {
- $this->setCustomAttributes('searchIconAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
-
- return $this;
- }
-
-
- public function setSearchFieldAttributes(array $attributes = []): self
- {
- $this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
-
- return $this;
- }
-}
\ No newline at end of file
+searchIcon = $searchIcon;
+ $this->searchIconSet = true;
+
+ return $this;
+ }
+
+ public function setSearchIconAttributes(array $attributes = []): self
+ {
+ $this->setCustomAttributes('searchIconAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
+
+ return $this;
+ }
+
+ public function setSearchFieldAttributes(array $attributes = []): self
+ {
+ $this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
+
+ return $this;
+ }
+}
diff --git a/src/Traits/Styling/HasSearchFieldStyling.php b/src/Traits/Styling/HasSearchFieldStyling.php
index 2a15b148c..682262e36 100644
--- a/src/Traits/Styling/HasSearchFieldStyling.php
+++ b/src/Traits/Styling/HasSearchFieldStyling.php
@@ -1,21 +1,20 @@
- true, 'default-styling' => true];
-
-}
\ No newline at end of file
+ true, 'default-styling' => true];
+}
diff --git a/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php b/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
index d04b7e24a..d62fb2aec 100644
--- a/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
+++ b/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
@@ -1,33 +1,31 @@
-getCustomAttributes('searchFieldAttributes', true);
- }
-
- #[Computed]
- public function hasSearchIcon(): bool
- {
- return $this->searchIconSet;
- }
-
- #[Computed]
- public function getSearchIcon(): string
- {
- return $this->hasSearchIcon() ? $this->searchIcon : 'heroicon-m-magnifying-glass';
- }
-
- #[Computed]
- public function getSearchIconAttributes(): array
- {
- return $this->getCustomAttributes('searchIconAttributes', true, false);
- }
-
-}
\ No newline at end of file
+getCustomAttributes('searchFieldAttributes', true);
+ }
+
+ #[Computed]
+ public function hasSearchIcon(): bool
+ {
+ return $this->searchIconSet;
+ }
+
+ #[Computed]
+ public function getSearchIcon(): string
+ {
+ return $this->hasSearchIcon() ? $this->searchIcon : 'heroicon-m-magnifying-glass';
+ }
+
+ #[Computed]
+ public function getSearchIconAttributes(): array
+ {
+ return $this->getCustomAttributes('searchIconAttributes', true, false);
+ }
+}
diff --git a/src/Traits/WithSearch.php b/src/Traits/WithSearch.php
index ba40a9f42..41c5dbeb5 100644
--- a/src/Traits/WithSearch.php
+++ b/src/Traits/WithSearch.php
@@ -40,7 +40,6 @@ trait WithSearch
protected bool $trimSearchString = false;
-
// TODO
public function applySearch(): Builder
{
From 2ed5b9da9a5e2fd377a0e154a5e1f384e41305e1 Mon Sep 17 00:00:00 2001
From: LRLJoe
Date: Wed, 27 Nov 2024 22:00:52 +0000
Subject: [PATCH 3/5] Initial Commit
---
docs/search/available-methods.md | 34 ++++
.../toolbar/items/search-field.blade.php | 8 +-
.../Configuration/SearchConfiguration.php | 6 -
src/Traits/Helpers/SearchHelpers.php | 14 --
.../SearchFieldStylingConfiguration.php | 28 ---
src/Traits/Styling/HasSearchFieldStyling.php | 14 +-
.../Helpers/SearchFieldStylingHelpers.php | 31 ----
src/Traits/Styling/Search/HasSearchIcon.php | 77 ++++++++
src/Traits/Styling/Search/HasSearchInput.php | 46 +++++
src/Traits/WithSearch.php | 2 -
.../Configuration/SearchConfigurationTest.php | 164 +++++++++++++++++-
11 files changed, 323 insertions(+), 101 deletions(-)
delete mode 100644 src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
delete mode 100644 src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
create mode 100644 src/Traits/Styling/Search/HasSearchIcon.php
create mode 100644 src/Traits/Styling/Search/HasSearchInput.php
diff --git a/docs/search/available-methods.md b/docs/search/available-methods.md
index 1d8397a5f..7dc412afe 100644
--- a/docs/search/available-methods.md
+++ b/docs/search/available-methods.md
@@ -192,3 +192,37 @@ public function configure(): void
$this->setTrimSearchStringDisabled();
}
```
+
+## Search Icon
+
+To help customise, a "Search Input Icon" has been added, allowing for the addition of an icon to the search input field.
+
+At present, the Search Icon is only available as a "left aligned" icon.
+
+### setSearchIcon
+
+This adds an Icon to the Search Input Field, which expects an icon path (e.g. heroicon-m-magnifying-glass)
+
+```php
+public function configure(): void
+{
+ $this->setSearchIcon('heroicon-m-magnifying-glass');
+}
+```
+
+### setSearchIconAttributes
+
+This allows you to specify attributes for the Search Icon for the Input Field.
+
+Note that classes will be injected prior to styles, due to the behaviour of icons.
+
+```php
+public function configure(): void
+{
+ $this->setSearchIconAttributes([
+ 'class' => 'h-4 w-4',
+ 'style' => 'color: #000000',
+ ]);
+}
+
+```
\ No newline at end of file
diff --git a/resources/views/components/tools/toolbar/items/search-field.blade.php b/resources/views/components/tools/toolbar/items/search-field.blade.php
index c934d49a9..a52f06427 100644
--- a/resources/views/components/tools/toolbar/items/search-field.blade.php
+++ b/resources/views/components/tools/toolbar/items/search-field.blade.php
@@ -12,12 +12,8 @@
- merge($this->getSearchIconAttributes())
- ->class([
- 'w-4 h-4' => (($this->getSearchIconAttributes()['default'] ?? true) || ($this->getSearchIconAttributes()['default-styling'] ?? true)),
- ])
- }}
- />
+
+ @svg($this->getSearchIcon, $this->getSearchIconClasses, $this->getSearchIconOtherAttributes())
@endif
diff --git a/src/Traits/Configuration/SearchConfiguration.php b/src/Traits/Configuration/SearchConfiguration.php
index 09b7d6de7..6a2c47ccb 100644
--- a/src/Traits/Configuration/SearchConfiguration.php
+++ b/src/Traits/Configuration/SearchConfiguration.php
@@ -147,12 +147,6 @@ public function setSearchLazy(): self
return $this;
}
- public function setSearchPlaceholder(string $placeholder): self
- {
- $this->searchPlaceholder = $placeholder;
-
- return $this;
- }
public function setTrimSearchString(bool $status): self
{
diff --git a/src/Traits/Helpers/SearchHelpers.php b/src/Traits/Helpers/SearchHelpers.php
index 90f0838d1..387155271 100644
--- a/src/Traits/Helpers/SearchHelpers.php
+++ b/src/Traits/Helpers/SearchHelpers.php
@@ -121,20 +121,6 @@ public function getSearchOptions(): string
return '.live';
}
- public function getSearchPlaceholder(): string
- {
- if ($this->hasSearchPlaceholder()) {
- return $this->searchPlaceholder;
- }
-
- return __($this->getLocalisationPath().'Search');
- }
-
- public function hasSearchPlaceholder(): bool
- {
- return $this->searchPlaceholder !== null;
- }
-
public function shouldTrimSearchString(): bool
{
return $this->trimSearchString ?? false;
diff --git a/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php b/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
deleted file mode 100644
index 8b2d33575..000000000
--- a/src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php
+++ /dev/null
@@ -1,28 +0,0 @@
-searchIcon = $searchIcon;
- $this->searchIconSet = true;
-
- return $this;
- }
-
- public function setSearchIconAttributes(array $attributes = []): self
- {
- $this->setCustomAttributes('searchIconAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
-
- return $this;
- }
-
- public function setSearchFieldAttributes(array $attributes = []): self
- {
- $this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
-
- return $this;
- }
-}
diff --git a/src/Traits/Styling/HasSearchFieldStyling.php b/src/Traits/Styling/HasSearchFieldStyling.php
index 682262e36..ee6fcefe3 100644
--- a/src/Traits/Styling/HasSearchFieldStyling.php
+++ b/src/Traits/Styling/HasSearchFieldStyling.php
@@ -2,19 +2,11 @@
namespace Rappasoft\LaravelLivewireTables\Traits\Styling;
-use Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration\SearchFieldStylingConfiguration;
-use Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers\SearchFieldStylingHelpers;
+use Rappasoft\LaravelLivewireTables\Traits\Styling\Search\{HasSearchIcon, HasSearchInput};
trait HasSearchFieldStyling
{
- use SearchFieldStylingConfiguration,
- SearchFieldStylingHelpers;
+ use HasSearchIcon,
+ HasSearchInput;
- protected array $searchFieldAttributes = [];
-
- protected bool $searchIconSet = false;
-
- protected ?string $searchIcon = null;
-
- protected array $searchIconAttributes = ['default-colors' => true, 'default-styling' => true];
}
diff --git a/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php b/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
deleted file mode 100644
index d62fb2aec..000000000
--- a/src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php
+++ /dev/null
@@ -1,31 +0,0 @@
-getCustomAttributes('searchFieldAttributes', true);
- }
-
- #[Computed]
- public function hasSearchIcon(): bool
- {
- return $this->searchIconSet;
- }
-
- #[Computed]
- public function getSearchIcon(): string
- {
- return $this->hasSearchIcon() ? $this->searchIcon : 'heroicon-m-magnifying-glass';
- }
-
- #[Computed]
- public function getSearchIconAttributes(): array
- {
- return $this->getCustomAttributes('searchIconAttributes', true, false);
- }
-}
diff --git a/src/Traits/Styling/Search/HasSearchIcon.php b/src/Traits/Styling/Search/HasSearchIcon.php
new file mode 100644
index 000000000..300a01a5c
--- /dev/null
+++ b/src/Traits/Styling/Search/HasSearchIcon.php
@@ -0,0 +1,77 @@
+ 'h-4 w-4', 'style' => 'color: #000000'];
+
+ #[Computed]
+ public function hasSearchIcon(): bool
+ {
+ return $this->searchIconSet;
+ }
+
+ #[Computed]
+ public function getSearchIcon(): string
+ {
+ return $this->hasSearchIcon() ? $this->searchIcon : 'heroicon-m-magnifying-glass';
+ }
+
+ #[Computed]
+ public function getSearchIconClasses(): string
+ {
+ return $this->getSearchIconAttributes()['class'];
+
+ }
+
+ #[Computed]
+ public function getSearchIconAttributes(): array
+ {
+ return $this->searchIconAttributes;
+ }
+
+ #[Computed]
+ public function getSearchIconOtherAttributes(): array
+ {
+ return collect($this->getSearchIconAttributes())->except('class')->toArray();
+ }
+
+
+ protected function setSearchIconStatus(bool $searchIconStatus): self
+ {
+ $this->searchIconSet = $searchIconStatus;
+ return $this;
+ }
+
+ protected function searchIconEnabled(): self
+ {
+ return $this->setSearchIconStatus(true);
+ }
+
+ protected function searchIconDisabled(): self
+ {
+ return $this->setSearchIconStatus(false);
+ }
+
+ protected function setSearchIcon(string $searchIcon): self
+ {
+ $this->searchIcon = $searchIcon;
+
+ return $this->searchIconEnabled();
+ }
+
+ protected function setSearchIconAttributes(array $searchIconAttributes): self
+ {
+ $this->searchIconAttributes = array_merge($this->searchIconAttributes, $searchIconAttributes);
+
+ return $this->searchIconEnabled();
+ }
+
+}
\ No newline at end of file
diff --git a/src/Traits/Styling/Search/HasSearchInput.php b/src/Traits/Styling/Search/HasSearchInput.php
new file mode 100644
index 000000000..94de24469
--- /dev/null
+++ b/src/Traits/Styling/Search/HasSearchInput.php
@@ -0,0 +1,46 @@
+setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
+
+ return $this;
+ }
+
+ public function getSearchFieldAttributes(): array
+ {
+ return $this->getCustomAttributes('searchFieldAttributes', true);
+ }
+
+ public function setSearchPlaceholder(string $placeholder): self
+ {
+ $this->searchPlaceholder = $placeholder;
+
+ return $this;
+ }
+
+ public function getSearchPlaceholder(): string
+ {
+ if ($this->hasSearchPlaceholder()) {
+ return $this->searchPlaceholder;
+ }
+
+ return __($this->getLocalisationPath().'Search');
+ }
+
+ public function hasSearchPlaceholder(): bool
+ {
+ return $this->searchPlaceholder !== null;
+ }
+
+}
\ No newline at end of file
diff --git a/src/Traits/WithSearch.php b/src/Traits/WithSearch.php
index 41c5dbeb5..f4befabf9 100644
--- a/src/Traits/WithSearch.php
+++ b/src/Traits/WithSearch.php
@@ -22,8 +22,6 @@ trait WithSearch
#[Locked]
public bool $searchStatus = true;
- protected ?string $searchPlaceholder = null;
-
protected bool $searchVisibilityStatus = true;
protected ?bool $searchFilterBlur = null;
diff --git a/tests/Unit/Traits/Configuration/SearchConfigurationTest.php b/tests/Unit/Traits/Configuration/SearchConfigurationTest.php
index 9daec3aeb..6ea2864bf 100644
--- a/tests/Unit/Traits/Configuration/SearchConfigurationTest.php
+++ b/tests/Unit/Traits/Configuration/SearchConfigurationTest.php
@@ -4,6 +4,7 @@
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
+use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
final class SearchConfigurationTest extends TestCase
{
@@ -180,11 +181,168 @@ public function test_can_set_search_placeholder(): void
public function test_can_set_search_field_attributes(): void
{
- $this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $this->basicTable->getSearchFieldAttributes());
+ $mock = new class extends PetsTable
+ {
+ public ?array $testAttributesArray;
- $this->basicTable->setSearchFieldAttributes(['class' => 'bg-blue', 'style' => 'font-size: 3em;']);
+ public function configure(): void
+ {
+ $this->setDataTableFingerprint('test');
+ }
- $this->assertSame(['class' => 'bg-blue', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'style' => 'font-size: 3em;'], $this->basicTable->getSearchFieldAttributes());
+ public function pubSetSearchFieldAttributes(array $attributes)
+ {
+ $this->setSearchFieldAttributes($attributes);
+ }
+ };
+
+ $mock->configure();
+ $mock->boot();
+
+ $this->assertSame(['default' => true, 'default-colors' => true, 'default-styling' => true], $mock->getSearchFieldAttributes());
+
+ $mock->pubSetSearchFieldAttributes(['class' => 'bg-blue', 'style' => 'font-size: 3em;']);
+
+ $this->assertSame(['class' => 'bg-blue', 'default' => false, 'default-colors' => false, 'default-styling' => false, 'style' => 'font-size: 3em;'], $mock->getSearchFieldAttributes());
+
+ }
+
+ public function test_can_set_search_icon(): void
+ {
+ $mock = new class extends PetsTable
+ {
+ public ?array $testAttributesArray;
+
+ public function configure(): void
+ {
+ $this->setDataTableFingerprint('test');
+ }
+
+ public function pubSetSearchFieldAttributes(array $attributes)
+ {
+ $this->setSearchFieldAttributes($attributes);
+ }
+
+ public function pubSetSearchIcon(string $searchIcon)
+ {
+ $this->setSearchIcon($searchIcon);
+ }
+
+ public function pubSetSearchIconAttributes(array $attributes)
+ {
+ $this->setSearchIconAttributes($attributes);
+ }
+
+
+ };
+
+ $mock->configure();
+ $mock->boot();
+
+ $this->assertFalse($mock->hasSearchIcon());
+ $mock->pubSetSearchIcon('heroicon-m-magnifying-glass-2');
+ $this->assertTrue($mock->hasSearchIcon());
+
+ $this->assertSame($mock->getSearchIcon(), 'heroicon-m-magnifying-glass-2');
+
+ }
+
+ public function test_can_set_search_icon_status(): void
+ {
+ $mock = new class extends PetsTable
+ {
+ public ?array $testAttributesArray;
+
+ public function configure(): void
+ {
+ $this->setDataTableFingerprint('test');
+ }
+
+ public function pubSetSearchFieldAttributes(array $attributes)
+ {
+ $this->setSearchFieldAttributes($attributes);
+ }
+
+ public function pubSetSearchIconEnabled()
+ {
+ $this->searchIconEnabled();
+ }
+
+ public function pubSetSearchIconDisabled()
+ {
+ $this->searchIconDisabled();
+ }
+
+
+ };
+
+ $mock->configure();
+ $mock->boot();
+
+ $this->assertFalse($mock->hasSearchIcon());
+ $mock->pubSetSearchIconEnabled();
+
+ $this->assertTrue($mock->hasSearchIcon());
+ $mock->pubSetSearchIconDisabled();
+ $this->assertFalse($mock->hasSearchIcon());
+
+
+ }
+
+ public function test_can_set_search_icon_attributes(): void
+ {
+ $mock = new class extends PetsTable
+ {
+ public ?array $testAttributesArray;
+
+ public function configure(): void
+ {
+ $this->setDataTableFingerprint('test');
+
+ }
+
+ public function pubSetSearchFieldAttributes(array $attributes)
+ {
+ $this->setSearchFieldAttributes($attributes);
+ }
+
+ public function pubSetSearchIcon(string $searchIcon)
+ {
+ $this->setSearchIcon($searchIcon);
+ }
+
+ public function pubSetSearchIconAttributes(array $attributes)
+ {
+ $this->setSearchIconAttributes($attributes);
+ }
+
+
+ };
+
+ $mock->configure();
+ $mock->boot();
+
+ $this->assertSame('h-4 w-4', $mock->getSearchIconClasses());
+ $this->assertSame([
+ 'style' => 'color: #000000',
+ ], $mock->getSearchIconOtherAttributes());
+
+ $mock->pubSetSearchIconAttributes([
+ 'style' => 'color: #FF0000',
+ 'class' => 'h-6 w-6',
+ ]);
+
+ $this->assertSame('h-6 w-6', $mock->getSearchIconClasses());
+ $this->assertSame([
+ 'style' => 'color: #FF0000',
+ ], $mock->getSearchIconOtherAttributes());
+
+ $this->assertSame([
+ 'class' => 'h-6 w-6',
+ 'style' => 'color: #FF0000',
+ ], $mock->getSearchIconAttributes());
}
+
+
}
From eacf37ede5d69ee497d6d651ad6320ef11983d94 Mon Sep 17 00:00:00 2001
From: lrljoe
Date: Wed, 27 Nov 2024 22:01:19 +0000
Subject: [PATCH 4/5] Fix styling
---
src/Traits/Configuration/SearchConfiguration.php | 1 -
src/Traits/Styling/HasSearchFieldStyling.php | 1 -
src/Traits/Styling/Search/HasSearchIcon.php | 7 +++----
src/Traits/Styling/Search/HasSearchInput.php | 5 ++---
.../Configuration/SearchConfigurationTest.php | 13 ++-----------
5 files changed, 7 insertions(+), 20 deletions(-)
diff --git a/src/Traits/Configuration/SearchConfiguration.php b/src/Traits/Configuration/SearchConfiguration.php
index 6a2c47ccb..2a1c6e926 100644
--- a/src/Traits/Configuration/SearchConfiguration.php
+++ b/src/Traits/Configuration/SearchConfiguration.php
@@ -147,7 +147,6 @@ public function setSearchLazy(): self
return $this;
}
-
public function setTrimSearchString(bool $status): self
{
$this->trimSearchString = $status;
diff --git a/src/Traits/Styling/HasSearchFieldStyling.php b/src/Traits/Styling/HasSearchFieldStyling.php
index ee6fcefe3..01283773e 100644
--- a/src/Traits/Styling/HasSearchFieldStyling.php
+++ b/src/Traits/Styling/HasSearchFieldStyling.php
@@ -8,5 +8,4 @@ trait HasSearchFieldStyling
{
use HasSearchIcon,
HasSearchInput;
-
}
diff --git a/src/Traits/Styling/Search/HasSearchIcon.php b/src/Traits/Styling/Search/HasSearchIcon.php
index 300a01a5c..3a7cbd656 100644
--- a/src/Traits/Styling/Search/HasSearchIcon.php
+++ b/src/Traits/Styling/Search/HasSearchIcon.php
@@ -43,10 +43,10 @@ public function getSearchIconOtherAttributes(): array
return collect($this->getSearchIconAttributes())->except('class')->toArray();
}
-
protected function setSearchIconStatus(bool $searchIconStatus): self
{
$this->searchIconSet = $searchIconStatus;
+
return $this;
}
@@ -66,12 +66,11 @@ protected function setSearchIcon(string $searchIcon): self
return $this->searchIconEnabled();
}
-
+
protected function setSearchIconAttributes(array $searchIconAttributes): self
{
$this->searchIconAttributes = array_merge($this->searchIconAttributes, $searchIconAttributes);
return $this->searchIconEnabled();
}
-
-}
\ No newline at end of file
+}
diff --git a/src/Traits/Styling/Search/HasSearchInput.php b/src/Traits/Styling/Search/HasSearchInput.php
index 94de24469..f937f5ef5 100644
--- a/src/Traits/Styling/Search/HasSearchInput.php
+++ b/src/Traits/Styling/Search/HasSearchInput.php
@@ -28,7 +28,7 @@ public function setSearchPlaceholder(string $placeholder): self
return $this;
}
-
+
public function getSearchPlaceholder(): string
{
if ($this->hasSearchPlaceholder()) {
@@ -42,5 +42,4 @@ public function hasSearchPlaceholder(): bool
{
return $this->searchPlaceholder !== null;
}
-
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Traits/Configuration/SearchConfigurationTest.php b/tests/Unit/Traits/Configuration/SearchConfigurationTest.php
index 6ea2864bf..cc55f8362 100644
--- a/tests/Unit/Traits/Configuration/SearchConfigurationTest.php
+++ b/tests/Unit/Traits/Configuration/SearchConfigurationTest.php
@@ -3,8 +3,8 @@
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Traits\Configuration;
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
-use Rappasoft\LaravelLivewireTables\Tests\TestCase;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
+use Rappasoft\LaravelLivewireTables\Tests\TestCase;
final class SearchConfigurationTest extends TestCase
{
@@ -232,8 +232,6 @@ public function pubSetSearchIconAttributes(array $attributes)
{
$this->setSearchIconAttributes($attributes);
}
-
-
};
$mock->configure();
@@ -272,8 +270,6 @@ public function pubSetSearchIconDisabled()
{
$this->searchIconDisabled();
}
-
-
};
$mock->configure();
@@ -286,7 +282,6 @@ public function pubSetSearchIconDisabled()
$mock->pubSetSearchIconDisabled();
$this->assertFalse($mock->hasSearchIcon());
-
}
public function test_can_set_search_icon_attributes(): void
@@ -298,7 +293,7 @@ public function test_can_set_search_icon_attributes(): void
public function configure(): void
{
$this->setDataTableFingerprint('test');
-
+
}
public function pubSetSearchFieldAttributes(array $attributes)
@@ -315,8 +310,6 @@ public function pubSetSearchIconAttributes(array $attributes)
{
$this->setSearchIconAttributes($attributes);
}
-
-
};
$mock->configure();
@@ -343,6 +336,4 @@ public function pubSetSearchIconAttributes(array $attributes)
], $mock->getSearchIconAttributes());
}
-
-
}
From 439497422ddd5f9139c4c7b59c8c0c86a86a40d9 Mon Sep 17 00:00:00 2001
From: LRLJoe
Date: Wed, 27 Nov 2024 23:01:33 +0000
Subject: [PATCH 5/5] Add note - only tailwind for now
---
docs/search/available-methods.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/search/available-methods.md b/docs/search/available-methods.md
index 7dc412afe..422757c37 100644
--- a/docs/search/available-methods.md
+++ b/docs/search/available-methods.md
@@ -199,6 +199,8 @@ To help customise, a "Search Input Icon" has been added, allowing for the additi
At present, the Search Icon is only available as a "left aligned" icon.
+This is presently only available for Tailwind implementations
+
### setSearchIcon
This adds an Icon to the Search Input Field, which expects an icon path (e.g. heroicon-m-magnifying-glass)