All Projects → nextapps-be → livewire-sortablejs

nextapps-be / livewire-sortablejs

Licence: MIT License
A Laravel Livewire plugin that makes it easy to use Sortable.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to livewire-sortablejs

Goodwork
Self hosted project management and collaboration tool powered by TALL stack
Stars: ✭ 1,730 (+2444.12%)
Mutual labels:  livewire, laravel-livewire
laravel-livewire-ui
Laravel Livewire UI, Auth, & CRUD starter kit.
Stars: ✭ 92 (+35.29%)
Mutual labels:  livewire, laravel-livewire
powergrid-demo
⚡ PowerGrid fully configured in a Laravel project.
Stars: ✭ 38 (-44.12%)
Mutual labels:  livewire, laravel-livewire
laravel-livewire-modals
Dynamic Laravel Livewire Bootstrap modals.
Stars: ✭ 63 (-7.35%)
Mutual labels:  livewire, laravel-livewire
guild
Guild - Build Your Guild and award employees with Crypto 💰
Stars: ✭ 3 (-95.59%)
Mutual labels:  livewire
dflex
The sophisticated Drag and Drop library you've been waiting for 🥳
Stars: ✭ 806 (+1085.29%)
Mutual labels:  sortable
todo
ToDo List built with Laravel, Livewire, Tailwind, Heroicons UI.
Stars: ✭ 38 (-44.12%)
Mutual labels:  livewire
CodeIgniter-Adjacency-List
Simple implementation with nestedSortable plugin.
Stars: ✭ 18 (-73.53%)
Mutual labels:  sortable
laravel-boilerplate
This is how I start new Laravel projects.
Stars: ✭ 0 (-100%)
Mutual labels:  livewire
markdom
A markdown parser for laravel for making beautiful html
Stars: ✭ 42 (-38.24%)
Mutual labels:  livewire
Multipurpose-Laravel-and-Livewire-Application
Multipurpose Laravel and Livewire Application. This is a part of tutorial series on Youtube.
Stars: ✭ 78 (+14.71%)
Mutual labels:  laravel-livewire
livewired
Reusable components for @livewire applications
Stars: ✭ 12 (-82.35%)
Mutual labels:  livewire
tall-toasts
A Toast notification library for the Laravel TALL stack. You can push notifications from the backend or frontend to render customizable toasts with almost zero footprint on the published CSS/JS 🔥🚀
Stars: ✭ 296 (+335.29%)
Mutual labels:  livewire
react-table
simple react sortable searchable table
Stars: ✭ 16 (-76.47%)
Mutual labels:  sortable
modal
Livewire component that provides you with a modal that supports multiple child modals while maintaining state.
Stars: ✭ 664 (+876.47%)
Mutual labels:  livewire
vue-dnd-zone
vue.js plugin for drag and drop functionality
Stars: ✭ 144 (+111.76%)
Mutual labels:  sortable
Limg
An image hosting service powered by Laravel
Stars: ✭ 41 (-39.71%)
Mutual labels:  livewire
CRUD-Laravel-Livewire-SPA
CRUD Laravel 7 & Livewire (SPA) Single Page Application
Stars: ✭ 34 (-50%)
Mutual labels:  livewire
zero-drag
Minimal abstraction of DOM drag-and-drop interactions
Stars: ✭ 17 (-75%)
Mutual labels:  sortable
ciid
Chronological Image Identifier – Uniquely identify image files while keeping the ability to sort them chronologically by name.
Stars: ✭ 25 (-63.24%)
Mutual labels:  sortable

Livewire Sortable.js

Latest Version on NPM NPM total downloads NPM downloads per month

A plugin/wrapper around Sortable.js package.

Why use this instead of Livewire's official livewire-sortable package?

The livewire-sortable package uses Shopify's sortable package. We noticed some issues with that package compared to Sortable.js:

  • Shopify's sortable package does not retain an item's original height and width while dragging. Sortable.js does this by default.
  • Sortable.js also works well in combination with Alpine.js while Shopify's sortable package can cause errors while dragging, especially when using Alpine.js x-for method in an draggable item.

Do you want to make the switch from livewire-sortable to livewire-sortable.js? That's easy, because this package works exactly the same! The only difference is the javascript package it uses in the background. You will not have to change any Livewire attributes or methods!

Installation

CDN

<script src="https://unpkg.com/@nextapps-be/[email protected]/dist/livewire-sortable.js"></script>

NPM

npm install @nextapps-be/livewire-sortablejs --save-dev

Import the package in your bundle:

import '@nextapps-be/livewire-sortablejs';

// or

require('@nextapps-be/livewire-sortablejs');

Usage

One group with draggable items

When you only have one list of draggable items (e.g. to-do list), you have to add the following attributes to your html:

  • wire:sortable="methodName": This attribute should be added to the html element that encapsulates all draggable items. The value of this attribute is the Livewire method that will be executed when an item has been dragged.
  • wire:sortable.item="itemIdentifier": This atttribute should be added to each individual draggable item. The value of this attribute will be used to inform you about the updated order.
  • wire:sortable.handle: This is an optional attribute. If you provide this attribute, then you will only be able to drag an item by dragging this html element. If you do not provide it, then the complete item will draggable.
<ul wire:sortable="updateTaskOrder">
    @foreach ($tasks as $task)
        <li wire:sortable.item="{{ $task->id }}" wire:key="task-{{ $task->id }}">
            <h4>{{ $task->title }}</h4>
            <button wire:sortable.handle>drag</button>
        </li>
    @endforeach
</ul>

When the order is updated, you will receive the following array structure in your Livewire method:

[
    [
        'order' => 1,   // order of item (starts at 1, not 0)
        'value' => 20,  // item id
    ],
]

Multiple groups with draggable items

When you have multiple lists, each with items that can be moved between those different lists, you have to add the following attributes to your html:

  • wire:sortable-group="methodName": This attribute should be added to the html element that encapsulates all lists. The value of this attribute is the Livewire method that will be executed when an item has been dragged.
  • wire:sortable-group.item-group="groupIdentifier": This atttribute should be added to the root element of a list with draggable items. The value of this attribute will be used to inform you about the updated order.
  • wire:sortable-group.item="itemIdentifier": This atttribute should be added to each individual draggable item in each list. The value of this attribute will be used to inform you about the updated order.
  • wire:sortable-group.handle: This is an optional attribute. If you provide this attribute, then you will only be able to drag an item by dragging this html element. If you do not provide it, then the complete item will draggable.
<div wire:sortable-group="updateTaskOrder" style="display: flex">
    @foreach ($groups as $group)
        <div wire:key="group-{{ $group->id }}">
            <h4>{{ $group->label }}</h4>

            <ul wire:sortable-group.item-group="{{ $group->id }}">
                @foreach ($group->tasks()->orderBy('order')->get() as $task)
                    <li wire:sortable-group.item="{{ $task->id }}" wire:key="task-{{ $task->id }}">
                        <span>{{ $task->title }}</span>
                        <button wire:sortable-group.handle>drag</button>
                    </li>
                @endforeach
            </ul>
        </div>
    @endforeach
</div>

When an item is dragged, you will receive the following array structure in the Livewire method you provided to the wire:sortable-group directive (in this example, the updateTaskOrder method):

[
    [
        'order' => 1,            // order of group (starts at 1, not 0)
        'value' => 20,           // group id
        'items' => [
            [
                'order' => 1,    // order of item within group (starts at 1, not 0)
                'value' => 50,   // item id
            ]
        ]
    ]
]

Multiple draggable groups with draggable items

When you have multiple lists, each with items that can be moved between those different lists and the lists themselves also need to be draggable, you have to add the following attributes to your html:

  • wire:sortable="methodName": This attribute should be added to the html element that encapsulates all draggable groups. The value of this attribute is the Livewire method that will be executed when a group has been dragged.

  • wire:sortable.item="groupIdentifier": This atttribute should be added to each individual draggable group. The value of this attribute will be used to inform you about the updated group order.

  • wire:sortable.handle: This is an optional attribute. If you provide this attribute, then you will only be able to drag a group by dragging this html element. If you do not provide it, then the complete group will draggable.

  • wire:sortable-group="methodName": This attribute should be added to the html element that encapsulates all lists. The value of this attribute is the Livewire method that will be executed when an item has been dragged.

  • wire:sortable-group.item-group="groupIdentifier": This atttribute should be added to the root element of a list with draggable items. The value of this attribute will be used to inform you about the updated order.

  • wire:sortable-group.item="itemIdentifier": This atttribute should be added to each individual draggable item in each list. The value of this attribute will be used to inform you about the updated order.

  • wire:sortable-group.handle: This is an optional attribute. If you provide this attribute, then you will only be able to drag an item by dragging this html element. If you do not provide it, then the complete item will draggable.

<div wire:sortable="updateGroupOrder" wire:sortable-group="updateTaskOrder" style="display: flex">
    @foreach ($groups as $group)
        <div wire:sortable.item="{{ $group->id }}" wire:key="group-{{ $group->id }}">
            <h4>{{ $group->label }}</h4>
            <button wire:sortable.handle>drag group</button>

            <ul wire:sortable-group.item-group="{{ $group->id }}">
                @foreach ($group->tasks()->orderBy('order')->get() as $task)
                    <li wire:sortable-group.item="{{ $task->id }}" wire:key="task-{{ $task->id }}">
                        <span>{{ $task->title }}</span>
                        <button wire:sortable.handle>drag item</button>
                    </li>
                @endforeach
            </ul>
        </div>
    @endforeach
</div>

When an item is dragged, you will receive the following array structure in the Livewire method you provided to the wire:sortable-group directive (in this example, the updateTaskOrder method):

[
    [
        'order' => 1,            // order of group (starts at 1, not 0)
        'value' => 20,           // group id
        'items' => [
            [
                'order' => 1,    // order of item within group (starts at 1, not 0)
                'value' => 50,   // item id
            ]
        ]
    ]
]

When a group is dragged, you will receive the following array structure in the Livewire method you provided to the wire:sortable directive (in this example, the updateGroupOrder method):

[
    [
        'order' => 1,            // order of group (starts at 1, not 0)
        'value' => 20,           // group id
    ]
]

Building

npm run build

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

This package is inspired by Livewire's official livewire-sortable plugin.

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].