Skip to content

Commit 2ed5b9d

Browse files
committed
Initial Commit
1 parent 0127339 commit 2ed5b9d

File tree

11 files changed

+323
-101
lines changed

11 files changed

+323
-101
lines changed

docs/search/available-methods.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,37 @@ public function configure(): void
192192
$this->setTrimSearchStringDisabled();
193193
}
194194
```
195+
196+
## Search Icon
197+
198+
To help customise, a "Search Input Icon" has been added, allowing for the addition of an icon to the search input field.
199+
200+
At present, the Search Icon is only available as a "left aligned" icon.
201+
202+
### setSearchIcon
203+
204+
This adds an Icon to the Search Input Field, which expects an icon path (e.g. heroicon-m-magnifying-glass)
205+
206+
```php
207+
public function configure(): void
208+
{
209+
$this->setSearchIcon('heroicon-m-magnifying-glass');
210+
}
211+
```
212+
213+
### setSearchIconAttributes
214+
215+
This allows you to specify attributes for the Search Icon for the Input Field.
216+
217+
Note that classes will be injected prior to styles, due to the behaviour of icons.
218+
219+
```php
220+
public function configure(): void
221+
{
222+
$this->setSearchIconAttributes([
223+
'class' => 'h-4 w-4',
224+
'style' => 'color: #000000',
225+
]);
226+
}
227+
228+
```

resources/views/components/tools/toolbar/items/search-field.blade.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212
<div class="relative inset-y-0 left-6
1313
inline-flex items-center
1414
pointer-events-none">
15-
<x-heroicon-m-magnifying-glass {{ $attributes->merge($this->getSearchIconAttributes())
16-
->class([
17-
'w-4 h-4' => (($this->getSearchIconAttributes()['default'] ?? true) || ($this->getSearchIconAttributes()['default-styling'] ?? true)),
18-
])
19-
}}
20-
/>
15+
16+
@svg($this->getSearchIcon, $this->getSearchIconClasses, $this->getSearchIconOtherAttributes())
2117

2218
</div>
2319
@endif

src/Traits/Configuration/SearchConfiguration.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ public function setSearchLazy(): self
147147
return $this;
148148
}
149149

150-
public function setSearchPlaceholder(string $placeholder): self
151-
{
152-
$this->searchPlaceholder = $placeholder;
153-
154-
return $this;
155-
}
156150

157151
public function setTrimSearchString(bool $status): self
158152
{

src/Traits/Helpers/SearchHelpers.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,6 @@ public function getSearchOptions(): string
121121
return '.live';
122122
}
123123

124-
public function getSearchPlaceholder(): string
125-
{
126-
if ($this->hasSearchPlaceholder()) {
127-
return $this->searchPlaceholder;
128-
}
129-
130-
return __($this->getLocalisationPath().'Search');
131-
}
132-
133-
public function hasSearchPlaceholder(): bool
134-
{
135-
return $this->searchPlaceholder !== null;
136-
}
137-
138124
public function shouldTrimSearchString(): bool
139125
{
140126
return $this->trimSearchString ?? false;

src/Traits/Styling/Configuration/SearchFieldStylingConfiguration.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Traits/Styling/HasSearchFieldStyling.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Traits\Styling;
44

5-
use Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration\SearchFieldStylingConfiguration;
6-
use Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers\SearchFieldStylingHelpers;
5+
use Rappasoft\LaravelLivewireTables\Traits\Styling\Search\{HasSearchIcon, HasSearchInput};
76

87
trait HasSearchFieldStyling
98
{
10-
use SearchFieldStylingConfiguration,
11-
SearchFieldStylingHelpers;
9+
use HasSearchIcon,
10+
HasSearchInput;
1211

13-
protected array $searchFieldAttributes = [];
14-
15-
protected bool $searchIconSet = false;
16-
17-
protected ?string $searchIcon = null;
18-
19-
protected array $searchIconAttributes = ['default-colors' => true, 'default-styling' => true];
2012
}

src/Traits/Styling/Helpers/SearchFieldStylingHelpers.php

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Search;
4+
5+
use Livewire\Attributes\Computed;
6+
7+
trait HasSearchIcon
8+
{
9+
protected bool $searchIconSet = false;
10+
11+
protected ?string $searchIcon = null;
12+
13+
protected array $searchIconAttributes = ['class' => 'h-4 w-4', 'style' => 'color: #000000'];
14+
15+
#[Computed]
16+
public function hasSearchIcon(): bool
17+
{
18+
return $this->searchIconSet;
19+
}
20+
21+
#[Computed]
22+
public function getSearchIcon(): string
23+
{
24+
return $this->hasSearchIcon() ? $this->searchIcon : 'heroicon-m-magnifying-glass';
25+
}
26+
27+
#[Computed]
28+
public function getSearchIconClasses(): string
29+
{
30+
return $this->getSearchIconAttributes()['class'];
31+
32+
}
33+
34+
#[Computed]
35+
public function getSearchIconAttributes(): array
36+
{
37+
return $this->searchIconAttributes;
38+
}
39+
40+
#[Computed]
41+
public function getSearchIconOtherAttributes(): array
42+
{
43+
return collect($this->getSearchIconAttributes())->except('class')->toArray();
44+
}
45+
46+
47+
protected function setSearchIconStatus(bool $searchIconStatus): self
48+
{
49+
$this->searchIconSet = $searchIconStatus;
50+
return $this;
51+
}
52+
53+
protected function searchIconEnabled(): self
54+
{
55+
return $this->setSearchIconStatus(true);
56+
}
57+
58+
protected function searchIconDisabled(): self
59+
{
60+
return $this->setSearchIconStatus(false);
61+
}
62+
63+
protected function setSearchIcon(string $searchIcon): self
64+
{
65+
$this->searchIcon = $searchIcon;
66+
67+
return $this->searchIconEnabled();
68+
}
69+
70+
protected function setSearchIconAttributes(array $searchIconAttributes): self
71+
{
72+
$this->searchIconAttributes = array_merge($this->searchIconAttributes, $searchIconAttributes);
73+
74+
return $this->searchIconEnabled();
75+
}
76+
77+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Search;
4+
5+
use Livewire\Attributes\Computed;
6+
7+
trait HasSearchInput
8+
{
9+
protected array $searchFieldAttributes = [];
10+
11+
protected ?string $searchPlaceholder = null;
12+
13+
protected function setSearchFieldAttributes(array $attributes = []): self
14+
{
15+
$this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
16+
17+
return $this;
18+
}
19+
20+
public function getSearchFieldAttributes(): array
21+
{
22+
return $this->getCustomAttributes('searchFieldAttributes', true);
23+
}
24+
25+
public function setSearchPlaceholder(string $placeholder): self
26+
{
27+
$this->searchPlaceholder = $placeholder;
28+
29+
return $this;
30+
}
31+
32+
public function getSearchPlaceholder(): string
33+
{
34+
if ($this->hasSearchPlaceholder()) {
35+
return $this->searchPlaceholder;
36+
}
37+
38+
return __($this->getLocalisationPath().'Search');
39+
}
40+
41+
public function hasSearchPlaceholder(): bool
42+
{
43+
return $this->searchPlaceholder !== null;
44+
}
45+
46+
}

src/Traits/WithSearch.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ trait WithSearch
2222
#[Locked]
2323
public bool $searchStatus = true;
2424

25-
protected ?string $searchPlaceholder = null;
26-
2725
protected bool $searchVisibilityStatus = true;
2826

2927
protected ?bool $searchFilterBlur = null;

0 commit comments

Comments
 (0)