Skip to content

Commit

Permalink
Merge pull request #6 from asantibanez/features/allow-disable-sorting…
Browse files Browse the repository at this point in the history
…-and-drop

FEATURE: Added ability to enable/disable sort and/or drop
  • Loading branch information
asantibanez authored Apr 4, 2021
2 parents 442b83c + 65eb7fe commit 438e1f7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ Just add a `group` string prop to a `laravel-blade-sortable::sortable` component

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

### Enable/Disable sorting and/or drop

Use `:allow-sort=true|false` and `:allow-drop=true|false` to `x-laravel-blade-sortable::sortable` components
to enable/disable sorting and/or drop of elements.

Both defaults to `true`.

```blade
<x-laravel-blade-sortable::sortable
group="people"
:allow-sort="false"
:allow-drop="false"
>
{{-- Items here --}}
</x-laravel-blade-sortable::sortable>
```

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

### Testing

``` bash
Expand Down
Binary file added examples/disable-sort-drop.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion resources/views/components/scripts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
ghostClass: '',
dragHandle: null,
group: null,
allowSort: true,
allowDrop: true,
wireComponent: null,
wireOnSortOrderChange: null,
Expand All @@ -18,7 +20,11 @@
handle: this.dragHandle,
animation: this.animation,
ghostClass: this.ghostClass,
group: this.group,
group: {
name: this.group,
put: this.allowDrop,
},
sort: this.allowSort,
onSort: evt => {
const previousSortOrder = [...this.sortOrder]
this.sortOrder = this.computeSortOrderFromChildren()
Expand Down
12 changes: 11 additions & 1 deletion src/Components/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ class Sortable extends Component

public $group;

public $allowDrop;

public $allowSort;

public function __construct($as = null,
$component = null,
$name = null,
$animation = 150,
$ghostClass = '',
$dragHandle = null,
$group = null)
$group = null,
$allowSort = true,
$allowDrop = true)
{
$this->as = $as;
$this->component = $component;
Expand All @@ -37,6 +43,8 @@ public function __construct($as = null,
$this->ghostClass = $ghostClass;
$this->dragHandle = $dragHandle;
$this->group = $group;
$this->allowDrop = $allowDrop;
$this->allowSort = $allowSort;
}

public function xInit()
Expand All @@ -57,6 +65,8 @@ public function xInit()
->push($hasGroup ? "group = '{$this->group}'" : null)
->push($hasWireOnSortOrderChangeDirective ? 'wireComponent = $wire' : null)
->push($hasWireOnSortOrderChangeDirective ? "wireOnSortOrderChange = '$wireOnSortOrderChange'" : null)
->push($this->allowSort ? 'allowSort = true' : 'allowSort = false')
->push($this->allowDrop ? 'allowDrop = true' : 'allowDrop = false')
->push('init()')
->filter(function ($line) {
return $line !== null;
Expand Down

0 comments on commit 438e1f7

Please sign in to comment.