Skip to content

Commit 767ab6f

Browse files
authored
Initial Commit
1 parent 76e4b77 commit 767ab6f

File tree

7 files changed

+108
-18
lines changed

7 files changed

+108
-18
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,38 @@
33
<div
44
@class([
55
'mb-3 mb-md-0 input-group' => $this->isBootstrap,
6-
'flex rounded-md shadow-sm' => $this->isTailwind,
6+
'rounded-md shadow-sm' => $this->isTailwind,
7+
'flex' => !$this->hasSearchIcon,
8+
'relative inline-flex flex-row' => $this->hasSearchIcon,
79
])>
10+
11+
@if($this->hasSearchIcon)
12+
<div class="relative inset-y-0 left-6
13+
inline-flex items-center
14+
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+
/>
21+
22+
</div>
23+
@endif
24+
825
<input
926
wire:model{{ $this->getSearchOptions() }}="search"
1027
placeholder="{{ $this->getSearchPlaceholder() }}"
1128
type="text"
1229
{{
1330
$attributes->merge($this->getSearchFieldAttributes())
1431
->class([
15-
'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)),
16-
'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)),
32+
'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)),
33+
'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)),
1734
'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)),
1835
'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)),
19-
36+
'block w-full' => !$this->hasSearchIcon,
37+
'pl-8 pr-4' => $this->hasSearchIcon,
2038
'form-control' => $this->isBootstrap && $this->getSearchFieldAttributes()['default'] ?? true,
2139
])
2240
->except(['default','default-styling','default-colors'])

src/Traits/Configuration/SearchConfiguration.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ public function setSearchPlaceholder(string $placeholder): self
154154
return $this;
155155
}
156156

157-
public function setSearchFieldAttributes(array $attributes = []): self
158-
{
159-
$this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
160-
161-
return $this;
162-
}
163-
164157
public function setTrimSearchString(bool $status): self
165158
{
166159
$this->trimSearchString = $status;

src/Traits/Helpers/SearchHelpers.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ public function hasSearchPlaceholder(): bool
135135
return $this->searchPlaceholder !== null;
136136
}
137137

138-
public function getSearchFieldAttributes(): array
139-
{
140-
return $this->getCustomAttributes('searchFieldAttributes', true);
141-
}
142-
143138
public function shouldTrimSearchString(): bool
144139
{
145140
return $this->trimSearchString ?? false;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration;
4+
5+
trait SearchFieldStylingConfiguration
6+
{
7+
protected function setSearchIcon(string $searchIcon): self
8+
{
9+
$this->searchIcon = $searchIcon;
10+
$this->searchIconSet = true;
11+
12+
return $this;
13+
}
14+
15+
public function setSearchIconAttributes(array $attributes = []): self
16+
{
17+
$this->setCustomAttributes('searchIconAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
18+
19+
return $this;
20+
}
21+
22+
23+
public function setSearchFieldAttributes(array $attributes = []): self
24+
{
25+
$this->setCustomAttributes('searchFieldAttributes', array_merge(['default' => false, 'default-colors' => false, 'default-styling' => false], $attributes));
26+
27+
return $this;
28+
}
29+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling;
4+
5+
use Rappasoft\LaravelLivewireTables\Traits\Styling\Configuration\SearchFieldStylingConfiguration;
6+
use Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers\SearchFieldStylingHelpers;
7+
8+
trait HasSearchFieldStyling
9+
{
10+
use SearchFieldStylingConfiguration,
11+
SearchFieldStylingHelpers;
12+
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];
20+
21+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits\Styling\Helpers;
4+
5+
use Livewire\Attributes\Computed;
6+
7+
trait SearchFieldStylingHelpers
8+
{
9+
10+
public function getSearchFieldAttributes(): array
11+
{
12+
return $this->getCustomAttributes('searchFieldAttributes', true);
13+
}
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 getSearchIconAttributes(): array
29+
{
30+
return $this->getCustomAttributes('searchIconAttributes', true, false);
31+
}
32+
33+
}

src/Traits/WithSearch.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
use Rappasoft\LaravelLivewireTables\Traits\Configuration\SearchConfiguration;
99
use Rappasoft\LaravelLivewireTables\Traits\Core\QueryStrings\HasQueryStringForSearch;
1010
use Rappasoft\LaravelLivewireTables\Traits\Helpers\SearchHelpers;
11+
use Rappasoft\LaravelLivewireTables\Traits\Styling\HasSearchFieldStyling;
1112

1213
trait WithSearch
1314
{
1415
use SearchConfiguration,
1516
SearchHelpers;
1617
use HasQueryStringForSearch;
18+
use HasSearchFieldStyling;
1719

1820
public string $search = '';
1921

@@ -36,10 +38,9 @@ trait WithSearch
3638

3739
protected ?int $searchFilterThrottle = null;
3840

39-
protected array $searchFieldAttributes = [];
40-
4141
protected bool $trimSearchString = false;
4242

43+
4344
// TODO
4445
public function applySearch(): Builder
4546
{

0 commit comments

Comments
 (0)