Skip to content

Commit 9c34730

Browse files
committed
Undo bootstrap container
- Make new WithSearch trait
1 parent 795e2da commit 9c34730

File tree

10 files changed

+77
-49
lines changed

10 files changed

+77
-49
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
1010

1111
### Changed
1212

13-
- Removed default padding on bootstrap tables
1413
- Clarified where rowView looks in read me
14+
- Null the search filter when it's empty
15+
16+
### Removed
17+
18+
- Removed `text-secondary` class from sorting title
1519

1620
## [1.1.0] - 2021-04-21
1721

resources/views/bootstrap-4/datatable.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
wire:poll="{{ $refresh }}"
1111
@endif
1212
@endif
13+
class="container-fluid"
1314
>
1415
@include('livewire-tables::bootstrap-4.includes.offline')
1516
@include('livewire-tables::bootstrap-4.includes.sorting-pills')

resources/views/bootstrap-4/includes/filter-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if ($showFilters && count(array_filter($filters)) && !(count(array_filter($filters)) === 1 && isset($filters['search'])))
22
<div class="mb-3">
3-
<small class="text-secondary">@lang('Applied Filters'):</small>
3+
<small>@lang('Applied Filters'):</small>
44

55
@foreach($filters as $key => $value)
66
@if ($key !== 'search' && strlen($value))

resources/views/bootstrap-4/includes/sorting-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if ($showSorting && count($sorts))
22
<div class="mb-3">
3-
<small class="text-secondary">@lang('Applied Sorting'):</small>
3+
<small>@lang('Applied Sorting'):</small>
44

55
@foreach($sorts as $col => $dir)
66
<span

resources/views/bootstrap-5/datatable.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
wire:poll="{{ $refresh }}"
1111
@endif
1212
@endif
13+
class="container-fluid"
1314
>
1415
@include('livewire-tables::bootstrap-5.includes.offline')
1516
@include('livewire-tables::bootstrap-5.includes.sorting-pills')

resources/views/bootstrap-5/includes/filter-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if ($showFilters && count(array_filter($filters)) && !(count(array_filter($filters)) === 1 && isset($filters['search'])))
22
<div class="mb-3">
3-
<small class="text-secondary">@lang('Applied Filters'):</small>
3+
<small>@lang('Applied Filters'):</small>
44

55
@foreach($filters as $key => $value)
66
@if ($key !== 'search' && strlen($value))

resources/views/bootstrap-5/includes/sorting-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if ($showSorting && count($sorts))
22
<div class="mb-3">
3-
<small class="text-secondary">@lang('Applied Sorting'):</small>
3+
<small>@lang('Applied Sorting'):</small>
44

55
@foreach($sorts as $col => $dir)
66
<span

src/DataTableComponent.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Rappasoft\LaravelLivewireTables\Traits\WithCustomPagination;
1111
use Rappasoft\LaravelLivewireTables\Traits\WithFilters;
1212
use Rappasoft\LaravelLivewireTables\Traits\WithPerPagePagination;
13+
use Rappasoft\LaravelLivewireTables\Traits\WithSearch;
1314
use Rappasoft\LaravelLivewireTables\Traits\WithSorting;
1415

1516
/**
@@ -23,6 +24,7 @@ abstract class DataTableComponent extends Component
2324
use WithCustomPagination;
2425
use WithFilters;
2526
use WithPerPagePagination;
27+
use WithSearch;
2628
use WithSorting;
2729

2830
/**
@@ -32,13 +34,6 @@ abstract class DataTableComponent extends Component
3234
*/
3335
public $paginationTheme = 'tailwind';
3436

35-
/**
36-
* Show the search field.
37-
*
38-
* @var bool
39-
*/
40-
public bool $showSearch = true;
41-
4237
/**
4338
* Whether or not to refresh the table at a certain interval
4439
* false is off

src/Traits/WithFilters.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,6 @@ trait WithFilters
3030
'search' => null,
3131
];
3232

33-
/**
34-
* @var int|null
35-
*/
36-
public ?int $searchFilterDebounce = null;
37-
38-
/**
39-
* @var bool|null
40-
*/
41-
public ?bool $searchFilterDefer = null;
42-
43-
/**
44-
* @var bool|null
45-
*/
46-
public ?bool $searchFilterLazy = null;
47-
4833
/**
4934
* Prebuild the $filters array
5035
*/
@@ -57,28 +42,6 @@ public function mountWithFilters(): void
5742
}
5843
}
5944

60-
/**
61-
* Build Livewire model options for the search input
62-
*
63-
* @return string
64-
*/
65-
public function getSearchFilterOptionsProperty(): string
66-
{
67-
if ($this->searchFilterDebounce) {
68-
return '.debounce.' . $this->searchFilterDebounce . 'ms';
69-
}
70-
71-
if ($this->searchFilterDefer) {
72-
return '.defer';
73-
}
74-
75-
if ($this->searchFilterLazy) {
76-
return '.lazy';
77-
}
78-
79-
return '';
80-
}
81-
8245
/**
8346
* Reset the filters array but keep the value for search
8447
*/

src/Traits/WithSearch.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits;
4+
5+
/**
6+
* Trait WithSearch.
7+
*/
8+
trait WithSearch
9+
{
10+
/**
11+
* Show the search field.
12+
*
13+
* @var bool
14+
*/
15+
public bool $showSearch = true;
16+
17+
/**
18+
* @var int|null
19+
*/
20+
public ?int $searchFilterDebounce = null;
21+
22+
/**
23+
* @var bool|null
24+
*/
25+
public ?bool $searchFilterDefer = null;
26+
27+
/**
28+
* @var bool|null
29+
*/
30+
public ?bool $searchFilterLazy = null;
31+
32+
/**
33+
* Remove the search filter when it's empty
34+
*/
35+
public function updatedFilters(): void
36+
{
37+
if (isset($this->filters['search']) && $this->filters['search'] === '')
38+
{
39+
$this->filters['search'] = null;
40+
}
41+
}
42+
43+
/**
44+
* Build Livewire model options for the search input
45+
*
46+
* @return string
47+
*/
48+
public function getSearchFilterOptionsProperty(): string
49+
{
50+
if ($this->searchFilterDebounce) {
51+
return '.debounce.' . $this->searchFilterDebounce . 'ms';
52+
}
53+
54+
if ($this->searchFilterDefer) {
55+
return '.defer';
56+
}
57+
58+
if ($this->searchFilterLazy) {
59+
return '.lazy';
60+
}
61+
62+
return '';
63+
}
64+
}

0 commit comments

Comments
 (0)