Skip to content

Commit eb16417

Browse files
committed
add date filter type
1 parent a840e41 commit eb16417

File tree

11 files changed

+121
-47
lines changed

11 files changed

+121
-47
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="mb-3 mb-md-0 input-group">
2+
<input
3+
wire:model="filters.{{ $key }}"
4+
wire:key="filter-{{ $key }}"
5+
id="filter-{{ $key }}"
6+
type="date"
7+
@if(isset($filter->options['min']) && strlen($filter->options['min'])) min="{{$filter->options['min']}}" @endif
8+
@if(isset($filter->options['max']) && strlen($filter->options['max'])) max="{{$filter->options['max']}}" @endif
9+
class="form-control"
10+
/>
11+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<select
2+
onclick="event.stopPropagation();"
3+
wire:model="filters.{{ $key }}"
4+
id="filter-{{ $key }}"
5+
class="form-control"
6+
>
7+
@foreach($filter->options() as $key => $value)
8+
<option value="{{ $key }}">{{ $value }}</option>
9+
@endforeach
10+
</select>

resources/views/bootstrap-4/includes/filters.blade.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,14 @@
1818
@elseif (count($customFilters))
1919
@foreach ($customFilters as $key => $filter)
2020
<div wire:key="filter-{{ $key }}" class="p-2">
21-
@if ($filter->isSelect())
22-
<label for="filter-{{ $key }}" class="mb-2">
23-
{{ $filter->name() }}
24-
</label>
2521

26-
<select
27-
onclick="event.stopPropagation();"
28-
wire:model="filters.{{ $key }}"
29-
id="filter-{{ $key }}"
30-
class="form-control"
31-
>
32-
@foreach($filter->options() as $key => $value)
33-
<option value="{{ $key }}">{{ $value }}</option>
34-
@endforeach
35-
</select>
22+
<label for="filter-{{ $key }}" class="mb-2">
23+
{{ $filter->name() }}
24+
</label>
25+
@if ($filter->isSelect())
26+
@include('livewire-tables::bootstrap-4.includes.filter-type-select')
27+
@elseif($filter->isDate())
28+
@include('livewire-tables::bootstrap-4.includes.filter-type-date')
3629
@endif
3730
</div>
3831
@endforeach
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="flex rounded-md shadow-sm mt-1">
2+
<input
3+
wire:model="filters.{{ $key }}"
4+
wire:key="filter-{{ $key }}"
5+
id="filter-{{ $key }}"
6+
type="date"
7+
@if(isset($filter->options['min']) && strlen($filter->options['min'])) min="{{$filter->options['min']}}" @endif
8+
@if(isset($filter->options['max']) && strlen($filter->options['max'])) max="{{$filter->options['max']}}" @endif
9+
class="flex-1 shadow-sm border-gray-300 block w-full transition duration-150 ease-in-out sm:text-sm sm:leading-5 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo @if (isset($filters[$key]) && strlen($filters[$key])) rounded-none rounded-l-md @else rounded-md @endif"
10+
/>
11+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<select
2+
onclick="event.stopPropagation();"
3+
wire:model="filters.{{ $key }}"
4+
id="filter-{{ $key }}"
5+
class="form-select"
6+
>
7+
@foreach($filter->options() as $key => $value)
8+
<option value="{{ $key }}">{{ $value }}</option>
9+
@endforeach
10+
</select>

resources/views/bootstrap-5/includes/filters.blade.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,14 @@
1818
@elseif (count($customFilters))
1919
@foreach ($customFilters as $key => $filter)
2020
<div wire:key="filter-{{ $key }}" class="p-2">
21-
@if ($filter->isSelect())
22-
<label for="filter-{{ $key }}" class="mb-2">
23-
{{ $filter->name() }}
24-
</label>
21+
<label for="filter-{{ $key }}" class="mb-2">
22+
{{ $filter->name() }}
23+
</label>
2524

26-
<select
27-
onclick="event.stopPropagation();"
28-
wire:model="filters.{{ $key }}"
29-
id="filter-{{ $key }}"
30-
class="form-select"
31-
>
32-
@foreach($filter->options() as $key => $value)
33-
<option value="{{ $key }}">{{ $value }}</option>
34-
@endforeach
35-
</select>
25+
@if ($filter->isSelect())
26+
@include('livewire-tables::bootstrap-5.includes.filter-type-select')
27+
@elseif($filter->isDate())
28+
@include('livewire-tables::bootstrap-5.includes.filter-type-date')
3629
@endif
3730
</div>
3831
@endforeach
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="flex rounded-md shadow-sm mt-1">
2+
<input
3+
wire:model="filters.{{ $key }}"
4+
wire:key="filter-{{ $key }}"
5+
id="filter-{{ $key }}"
6+
type="date"
7+
@if(isset($filter->options['min']) && strlen($filter->options['min'])) min="{{$filter->options['min']}}" @endif
8+
@if(isset($filter->options['max']) && strlen($filter->options['max'])) max="{{$filter->options['max']}}" @endif
9+
class="flex-1 shadow-sm border-gray-300 block w-full transition duration-150 ease-in-out sm:text-sm sm:leading-5 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo @if (isset($filters[$key]) && strlen($filters[$key])) rounded-none rounded-l-md @else rounded-md @endif"
10+
/>
11+
</div>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="mt-1 relative rounded-md shadow-sm">
2+
<select
3+
wire:model="filters.{{ $key }}"
4+
wire:key="filter-{{ $key }}"
5+
id="filter-{{ $key }}"
6+
class="rounded-md shadow-sm block w-full pl-3 pr-10 py-2 text-base leading-6 border-gray-300 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo sm:text-sm sm:leading-5"
7+
>
8+
@foreach($filter->options() as $key => $value)
9+
<option value="{{ $key }}">{{ $value }}</option>
10+
@endforeach
11+
</select>
12+
</div>

resources/views/tailwind/includes/filters.blade.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class="relative block md:inline-block text-left"
88
<div>
99
<button
1010
type="button"
11-
class="inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo" id="filters-menu" @click="open = !open" aria-haspopup="true" x-bind:aria-expanded="open" aria-expanded="true">
11+
class="inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo"
12+
id="filters-menu" @click="open = !open" aria-haspopup="true" x-bind:aria-expanded="open"
13+
aria-expanded="true">
1214
@lang('Filters')
1315

1416
@if (count($this->getFiltersWithoutSearch()))
@@ -17,8 +19,10 @@ class="inline-flex justify-center w-full rounded-md border border-gray-300 shado
1719
</span>
1820
@endif
1921

20-
<svg class="-mr-1 ml-2 h-5 w-5" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
21-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" />
22+
<svg class="-mr-1 ml-2 h-5 w-5" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none"
23+
viewBox="0 0 24 24" stroke="currentColor">
24+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
25+
d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"/>
2226
</svg>
2327
</button>
2428
</div>
@@ -43,23 +47,14 @@ class="origin-top-right absolute right-0 mt-2 w-full md:w-56 rounded-md shadow-l
4347
@foreach ($customFilters as $key => $filter)
4448
<div class="py-1" role="none">
4549
<div class="block px-4 py-2 text-sm text-gray-700" role="menuitem">
50+
<label for="filter-{{ $key }}"
51+
class="block text-sm font-medium leading-5 text-gray-700">
52+
{{ $filter->name() }}
53+
</label>
4654
@if ($filter->isSelect())
47-
<label for="filter-{{ $key }}" class="block text-sm font-medium leading-5 text-gray-700">
48-
{{ $filter->name() }}
49-
</label>
50-
51-
<div class="mt-1 relative rounded-md shadow-sm">
52-
<select
53-
wire:model="filters.{{ $key }}"
54-
wire:key="filter-{{ $key }}"
55-
id="filter-{{ $key }}"
56-
class="rounded-md shadow-sm block w-full pl-3 pr-10 py-2 text-base leading-6 border-gray-300 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo sm:text-sm sm:leading-5"
57-
>
58-
@foreach($filter->options() as $key => $value)
59-
<option value="{{ $key }}">{{ $value }}</option>
60-
@endforeach
61-
</select>
62-
</div>
55+
@include('livewire-tables::tailwind.includes.filter-type-select')
56+
@elseif($filter->isDate())
57+
@include('livewire-tables::tailwind.includes.filter-type-date')
6358
@endif
6459
</div>
6560
</div>

src/Traits/WithFilters.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public function cleanFilters(): void
149149
}
150150
}
151151

152+
if ($filterDefinitions[$filterName]->isDate()) {
153+
return true;
154+
}
155+
152156
return false;
153157
})->toArray();
154158
}

0 commit comments

Comments
 (0)