Skip to content

Commit fa9864f

Browse files
authored
Merge pull request #399 from amvisor/tooltips
can set tooltip to column
2 parents 730f198 + 203315a commit fa9864f

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

resources/views/livewire/datatables/datatable.blade.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
</div>
66
@endif
77
<div class="relative">
8-
<div class="flex justify-between items-center mb-1">
9-
<div class="h-10 flex items-center">
8+
<div class="flex items-center justify-between mb-1">
9+
<div class="flex items-center h-10">
1010
@if($this->searchableColumns()->count())
11-
<div class="w-96 flex rounded-lg shadow-sm">
11+
<div class="flex rounded-lg w-96 shadow-sm">
1212
<div class="relative flex-grow focus-within:z-10">
13-
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
14-
<svg class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" stroke="currentColor" fill="none">
13+
<div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
14+
<svg class="w-5 h-5 text-gray-400" viewBox="0 0 20 20" stroke="currentColor" fill="none">
1515
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
1616
</svg>
1717
</div>
18-
<input wire:model.debounce.500ms="search" class="w-full pl-10 py-3 text-sm leading-4 block rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50 focus:outline-none" placeholder="{{__('Search in')}} {{ $this->searchableColumns()->map->label->join(', ') }}" type="text" />
19-
<div class="absolute inset-y-0 right-0 pr-2 flex items-center">
18+
<input wire:model.debounce.500ms="search" class="block w-full py-3 pl-10 text-sm border-gray-300 leading-4 rounded-md shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50 focus:outline-none" placeholder="{{__('Search in')}} {{ $this->searchableColumns()->map->label->join(', ') }}" type="text" />
19+
<div class="absolute inset-y-0 right-0 flex items-center pr-2">
2020
<button wire:click="$set('search', null)" class="text-gray-300 hover:text-red-600 focus:outline-none">
21-
<x-icons.x-circle class="h-5 w-5 stroke-current" />
21+
<x-icons.x-circle class="w-5 h-5 stroke-current" />
2222
</button>
2323
</div>
2424
</div>
@@ -31,10 +31,10 @@
3131
@endif
3232

3333
<div class="flex flex-wrap items-center space-x-1">
34-
<x-icons.cog wire:loading class="h-9 w-9 animate-spin text-gray-400" />
34+
<x-icons.cog wire:loading class="text-gray-400 h-9 w-9 animate-spin" />
3535

3636
@if($this->activeFilters)
37-
<button wire:click="clearAllFilters" class="flex items-center space-x-2 px-3 border border-red-400 rounded-md bg-white text-red-500 text-xs leading-4 font-medium uppercase tracking-wider hover:bg-red-200 focus:outline-none"><span>{{ __('Reset') }}</span>
37+
<button wire:click="clearAllFilters" class="flex items-center px-3 text-xs font-medium tracking-wider text-red-500 uppercase bg-white border border-red-400 space-x-2 rounded-md leading-4 hover:bg-red-200 focus:outline-none"><span>{{ __('Reset') }}</span>
3838
<x-icons.x-circle class="m-2" />
3939
</button>
4040
@endif
@@ -43,7 +43,7 @@
4343
<div x-data="{ init() {
4444
window.livewire.on('startDownload', link => window.open(link, '_blank'))
4545
} }" x-init="init">
46-
<button wire:click="export" class="flex items-center space-x-2 px-3 border border-green-400 rounded-md bg-white text-green-500 text-xs leading-4 font-medium uppercase tracking-wider hover:bg-green-200 focus:outline-none"><span>{{ __('Export') }}</span>
46+
<button wire:click="export" class="flex items-center px-3 text-xs font-medium tracking-wider text-green-500 uppercase bg-white border border-green-400 space-x-2 rounded-md leading-4 hover:bg-green-200 focus:outline-none"><span>{{ __('Export') }}</span>
4747
<x-icons.excel class="m-2" /></button>
4848
</div>
4949
@endif
@@ -54,7 +54,7 @@
5454

5555
@foreach ($columnGroups as $name => $group)
5656
<button wire:click="toggleGroup('{{ $name }}')"
57-
class="px-3 py-2 border border-green-400 rounded-md bg-white text-green-500 text-xs leading-4 font-medium uppercase tracking-wider hover:bg-green-200 focus:outline-none">
57+
class="px-3 py-2 text-xs font-medium tracking-wider text-green-500 uppercase bg-white border border-green-400 rounded-md leading-4 hover:bg-green-200 focus:outline-none">
5858
<span class="flex items-center h-5">{{ isset($this->groupLabels[$name]) ? __($this->groupLabels[$name]) : __('Toggle :group', ['group' => $name]) }}</span>
5959
</button>
6060
@endforeach
@@ -76,15 +76,15 @@ class="px-3 py-2 border border-green-400 rounded-md bg-white text-green-500 text
7676

7777
<div wire:loading.class="opacity-50" class="rounded-lg @unless($complex || $this->hidePagination) rounded-b-none @endunless shadow-lg bg-white max-w-screen overflow-x-scroll border-4 @if($this->activeFilters) border-blue-500 @else border-transparent @endif @if($complex) rounded-b-none border-b-0 @endif">
7878
<div>
79-
<div class="table align-middle min-w-full">
79+
<div class="table min-w-full align-middle">
8080
@unless($this->hideHeader)
8181
<div class="table-row divide-x divide-gray-200">
8282
@foreach($this->columns as $index => $column)
8383
@if($hideable === 'inline')
8484
@include('datatables::header-inline-hide', ['column' => $column, 'sort' => $sort])
8585
@elseif($column['type'] === 'checkbox')
8686
@unless($column['hidden'])
87-
<div class=" table-cell h-12 w-32 py-4 flex justify-center overflow-hidden align-top px-6 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider focus:outline-none">
87+
<div class="flex justify-center table-cell w-32 h-12 px-6 py-4 overflow-hidden text-xs font-medium tracking-wider text-left text-gray-500 uppercase align-top border-b border-gray-200 bg-gray-50 leading-4 focus:outline-none">
8888
<div class="px-3 py-1 rounded @if(count($selected)) bg-orange-400 @else bg-gray-200 @endif text-white text-center">
8989
{{ count($selected) }}
9090
</div>
@@ -96,17 +96,19 @@ class="px-3 py-2 border border-green-400 rounded-md bg-white text-green-500 text
9696
@endforeach
9797
</div>
9898

99-
<div class="table-row divide-x divide-blue-200 bg-blue-100">
99+
<div class="table-row bg-blue-100 divide-x divide-blue-200">
100100
@foreach($this->columns as $index => $column)
101101
@if($column['hidden'])
102102
@if($hideable === 'inline')
103103
<div class="table-cell w-5 overflow-hidden align-top bg-blue-100"></div>
104104
@endif
105105
@elseif($column['type'] === 'checkbox')
106-
<div class="overflow-hidden align-top bg-blue-100 px-6 py-5 border-b border-gray-200 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider flex h-full flex-col items-center space-y-2 focus:outline-none">
106+
<div
107+
@if (isset($column['tooltip']['text'])) title="{{ $column['tooltip']['text'] }}" @endif
108+
class="flex flex-col items-center h-full px-6 py-5 overflow-hidden text-xs font-medium tracking-wider text-left text-gray-500 uppercase align-top bg-blue-100 border-b border-gray-200 leading-4 space-y-2 focus:outline-none">
107109
<div>SELECT ALL</div>
108110
<div>
109-
<input type="checkbox" wire:click="toggleSelectAll" @if(count($selected) === $this->results->total()) checked @endif class="form-checkbox mt-1 h-4 w-4 text-blue-600 transition duration-150 ease-in-out" />
111+
<input type="checkbox" wire:click="toggleSelectAll" @if(count($selected) === $this->results->total()) checked @endif class="w-4 h-4 mt-1 text-blue-600 form-checkbox transition duration-150 ease-in-out" />
110112
</div>
111113
</div>
112114
@elseif($column['type'] === 'label')
@@ -174,11 +176,11 @@ class="px-3 py-2 border border-green-400 rounded-md bg-white text-green-500 text
174176

175177
@unless($this->hidePagination)
176178
<div class="max-w-screen bg-white @unless($complex) rounded-b-lg @endunless border-4 border-t-0 border-b-0 @if($this->activeFilters) border-blue-500 @else border-transparent @endif">
177-
<div class="p-2 sm:flex items-center justify-between">
179+
<div class="items-center justify-between p-2 sm:flex">
178180
{{-- check if there is any data --}}
179181
@if(count($this->results))
180-
<div class="my-2 sm:my-0 flex items-center">
181-
<select name="perPage" class="mt-1 form-select block w-full pl-3 pr-10 py-2 text-base leading-6 border-gray-300 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 sm:text-sm sm:leading-5" wire:model="perPage">
182+
<div class="flex items-center my-2 sm:my-0">
183+
<select name="perPage" class="block w-full py-2 pl-3 pr-10 mt-1 text-base border-gray-300 form-select leading-6 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 sm:text-sm sm:leading-5" wire:model="perPage">
182184
@foreach(config('livewire-datatables.per_page_options', [ 10, 25, 50, 100 ]) as $per_page_option)
183185
<option value="{{ $per_page_option }}">{{ $per_page_option }}</option>
184186
@endforeach
@@ -191,7 +193,7 @@ class="px-3 py-2 border border-green-400 rounded-md bg-white text-green-500 text
191193
<span class="space-x-2">{{ $this->results->links('datatables::tailwind-simple-pagination') }}</span>
192194
</div>
193195

194-
<div class="hidden lg:flex justify-center">
196+
<div class="justify-center hidden lg:flex">
195197
<span>{{ $this->results->links('datatables::tailwind-pagination') }}</span>
196198
</div>
197199
</div>
@@ -217,5 +219,5 @@ class="px-3 py-2 border border-green-400 rounded-md bg-white text-green-500 text
217219
@include($afterTableSlot)
218220
</div>
219221
@endif
220-
<span class="hidden text-sm leading-5 text-gray-900 text-left text-center text-right bg-gray-50 bg-gray-100 bg-yellow-100"></span>
222+
<span class="hidden text-sm text-left text-center text-right text-gray-900 bg-gray-100 bg-yellow-100 leading-5 bg-gray-50"></span>
221223
</div>

resources/views/livewire/datatables/header-no-hide.blade.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@unless($column['hidden'])
2-
<div class="relative table-cell h-12 overflow-hidden align-top" @include('datatables::style-width')>
2+
<div
3+
@if (isset($column['tooltip']['text'])) title="{{ $column['tooltip']['text'] }}" @endif
4+
class="relative table-cell h-12 overflow-hidden align-top" @include('datatables::style-width')>
35
@if($column['unsortable'])
46
<div class="w-full h-full px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider flex items-center focus:outline-none @if($column['align'] === 'right') justify-end @elseif($column['align'] === 'center') justify-center @endif">
57
<span class="inline ">{{ str_replace('_', ' ', $column['label']) }}</span>
@@ -10,9 +12,9 @@
1012
<span class="inline text-xs text-blue-400">
1113
@if($sort === $index)
1214
@if($direction)
13-
<x-icons.chevron-up wire:loading.remove class="h-6 w-6 text-green-600 stroke-current" />
15+
<x-icons.chevron-up wire:loading.remove class="w-6 h-6 text-green-600 stroke-current" />
1416
@else
15-
<x-icons.chevron-down wire:loading.remove class="h-6 w-6 text-green-600 stroke-current" />
17+
<x-icons.chevron-down wire:loading.remove class="w-6 h-6 text-green-600 stroke-current" />
1618
@endif
1719
@endif
1820
</span>

src/Column.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Column
1111
public $type = 'string';
1212
public $index = 0;
1313
public $label;
14+
public $tooltip;
1415
public $name;
1516
public $select;
1617
public $joins;
@@ -156,6 +157,16 @@ public function setIndex($index)
156157
return $this;
157158
}
158159

160+
public function tooltip($text, $label = null)
161+
{
162+
$this->tooltip = [
163+
'text' => $text,
164+
'label' => $label,
165+
];
166+
167+
return $this;
168+
}
169+
159170
public function sortBy($column)
160171
{
161172
$this->sort = $column;

src/Http/Livewire/LivewireDatatable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ public function getViewColumns()
267267
'index',
268268
'hidden',
269269
'label',
270+
'tooltip',
270271
'group',
271272
'summary',
272273
'content',

0 commit comments

Comments
 (0)