Skip to content

Commit 7f1ae43

Browse files
committed
Tailwind drag and drop
1 parent 71658bc commit 7f1ae43

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

resources/views/tailwind/components/table/heading.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@props([
22
'column',
3+
'sortingEnabled' => true,
34
'sortable' => null,
45
'direction' => null,
56
'text' => null,
@@ -8,7 +9,7 @@
89
<th
910
{{ $attributes->merge(['class' => 'px-3 py-2 md:px-6 md:py-3 bg-gray-50'])->only('class') }}
1011
>
11-
@unless ($sortable)
12+
@unless ($sortingEnabled && $sortable)
1213
<span class="block text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
1314
{{ $text ?? $slot }}
1415
</span>

resources/views/tailwind/components/table/table.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="align-middle min-w-full overflow-x-auto shadow overflow-hidden rounded-none md:rounded-lg">
2-
<table class="min-w-full divide-y divide-gray-200">
2+
<table {{ $attributes->except('wire:sortable') }} class="min-w-full divide-y divide-gray-200">
33
<thead>
44
<tr>
55
{{ $head }}
66
</tr>
77
</thead>
88

9-
<tbody class="bg-white divide-y divide-gray-200">
9+
<tbody {{ $attributes->only('wire:sortable') }} class="bg-white divide-y divide-gray-200">
1010
{{ $body }}
1111
</tbody>
1212
</table>

resources/views/tailwind/includes/bulk-select-row.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if (count($bulkActions) && (($selectPage && $rows->total() > $rows->count()) || count($selected)))
22
<x-livewire-tables::table.row wire:key="row-message" class="bg-indigo-50">
3-
<x-livewire-tables::table.cell :colspan="count($bulkActions) ? count($columns) + 1 : count($columns)">
3+
<x-livewire-tables::table.cell :colspan="$colspan">
44
@if (count($selected) && !$selectAll && !$selectPage)
55
<div>
66
<span>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if ($showFilterDropdown && ($filtersView || count($customFilters)))
1+
@if ($filtersEnabled && $showFilterDropdown && ($filtersView || count($customFilters)))
22
<div
33
x-data="{ open: false }"
44
@keydown.escape.stop="open = false"

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
<x-livewire-tables::table>
1+
<x-livewire-tables::table wire:sortable="{{ $reorderRows }}">
22
<x-slot name="head">
3+
@if (is_string($reorderRows))
4+
<x-livewire-tables::table.heading />
5+
@endif
6+
37
@if (count($bulkActions))
48
<x-livewire-tables::table.heading>
59
<div class="inline-flex rounded-md shadow-sm">
@@ -20,6 +24,7 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
2024
<x-livewire-tables::table.heading />
2125
@else
2226
<x-livewire-tables::table.heading
27+
:sortingEnabled="$sortingEnabled"
2328
:sortable="$column->isSortable()"
2429
:column="$column->column()"
2530
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
@@ -32,12 +37,19 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
3237
</x-slot>
3338

3439
<x-slot name="body">
40+
@php
41+
$colspan = count($columns);
42+
if (count($bulkActions)) $colspan++;
43+
if (is_string($reorderRows)) $colspan++;
44+
@endphp
45+
3546
@include('livewire-tables::tailwind.includes.bulk-select-row')
3647

3748
@forelse ($rows as $index => $row)
3849
<x-livewire-tables::table.row
3950
wire:loading.class.delay="opacity-50"
40-
wire:key="table-row-{{ $row->getKey() }}"
51+
wire:key="table-row-{{ $row->{$primaryKey} }}"
52+
wire:sortable.item="{{ $row->{$primaryKey} }}"
4153
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
4254
:class="
4355
($index % 2 === 0 ?
@@ -49,6 +61,14 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
4961
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
5062
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"
5163
>
64+
@if (is_string($reorderRows))
65+
<x-livewire-tables::table.cell wire:sortable.handle>
66+
<svg xmlns="http://www.w3.org/2000/svg" style="width:1em;height:1em;" fill="none" viewBox="0 0 24 24" stroke="currentColor">
67+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
68+
</svg>
69+
</x-livewire-tables::table.cell>
70+
@endif
71+
5272
@if (count($bulkActions))
5373
<x-livewire-tables::table.cell>
5474
<div class="inline-flex rounded-md shadow-sm">

0 commit comments

Comments
 (0)