Skip to content

Commit 438e1f7

Browse files
authored
Merge pull request #6 from asantibanez/features/allow-disable-sorting-and-drop
FEATURE: Added ability to enable/disable sort and/or drop
2 parents 442b83c + 65eb7fe commit 438e1f7

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,25 @@ Just add a `group` string prop to a `laravel-blade-sortable::sortable` component
237237

238238
![drag-drop](https://github.com/asantibanez/laravel-blade-sortable/raw/master/examples/drag-drop.gif)
239239

240+
### Enable/Disable sorting and/or drop
241+
242+
Use `:allow-sort=true|false` and `:allow-drop=true|false` to `x-laravel-blade-sortable::sortable` components
243+
to enable/disable sorting and/or drop of elements.
244+
245+
Both defaults to `true`.
246+
247+
```blade
248+
<x-laravel-blade-sortable::sortable
249+
group="people"
250+
:allow-sort="false"
251+
:allow-drop="false"
252+
>
253+
{{-- Items here --}}
254+
</x-laravel-blade-sortable::sortable>
255+
```
256+
257+
![disable-sort-drop](https://github.com/asantibanez/laravel-blade-sortable/raw/master/examples/disable-sort-drop.gif)
258+
240259
### Testing
241260

242261
``` bash

examples/disable-sort-drop.gif

1.45 MB
Loading

resources/views/components/scripts.blade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
ghostClass: '',
88
dragHandle: null,
99
group: null,
10+
allowSort: true,
11+
allowDrop: true,
1012
1113
wireComponent: null,
1214
wireOnSortOrderChange: null,
@@ -18,7 +20,11 @@
1820
handle: this.dragHandle,
1921
animation: this.animation,
2022
ghostClass: this.ghostClass,
21-
group: this.group,
23+
group: {
24+
name: this.group,
25+
put: this.allowDrop,
26+
},
27+
sort: this.allowSort,
2228
onSort: evt => {
2329
const previousSortOrder = [...this.sortOrder]
2430
this.sortOrder = this.computeSortOrderFromChildren()

src/Components/Sortable.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ class Sortable extends Component
2222

2323
public $group;
2424

25+
public $allowDrop;
26+
27+
public $allowSort;
28+
2529
public function __construct($as = null,
2630
$component = null,
2731
$name = null,
2832
$animation = 150,
2933
$ghostClass = '',
3034
$dragHandle = null,
31-
$group = null)
35+
$group = null,
36+
$allowSort = true,
37+
$allowDrop = true)
3238
{
3339
$this->as = $as;
3440
$this->component = $component;
@@ -37,6 +43,8 @@ public function __construct($as = null,
3743
$this->ghostClass = $ghostClass;
3844
$this->dragHandle = $dragHandle;
3945
$this->group = $group;
46+
$this->allowDrop = $allowDrop;
47+
$this->allowSort = $allowSort;
4048
}
4149

4250
public function xInit()
@@ -57,6 +65,8 @@ public function xInit()
5765
->push($hasGroup ? "group = '{$this->group}'" : null)
5866
->push($hasWireOnSortOrderChangeDirective ? 'wireComponent = $wire' : null)
5967
->push($hasWireOnSortOrderChangeDirective ? "wireOnSortOrderChange = '$wireOnSortOrderChange'" : null)
68+
->push($this->allowSort ? 'allowSort = true' : 'allowSort = false')
69+
->push($this->allowDrop ? 'allowDrop = true' : 'allowDrop = false')
6070
->push('init()')
6171
->filter(function ($line) {
6272
return $line !== null;

0 commit comments

Comments
 (0)