Skip to content

Commit

Permalink
chore: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed Aug 13, 2024
1 parent 11e6513 commit 125962d
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions example/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { draggy } from "@sebkolind/draggy";
import {draggy} from "@sebkolind/draggy";

draggy({
target: ".column",
placement: "any",
selection: {
enabled: true,
},
onStart(_, { shadow, multiple }) {
onStart(_, {shadow, multiple}) {
if (!multiple?.length) return;

const label = document.createElement("div");
Expand All @@ -24,4 +24,29 @@ draggy({

shadow?.append(label);
},
onDrop(_, {origin, zone}) {
const el = origin?.querySelector(".status")
if (!el) return;
const status = el.textContent?.toLowerCase().replace(" ", "-");
const newStatus = zone?.dataset.status;
if (!newStatus || !status) return;
if (status === newStatus) return;

el.textContent = formatStatus(newStatus);
el.classList.remove(status);
el.classList.add(newStatus);
}
});

function formatStatus(status: string) {
switch (status) {
case "to-do":
return "To-do";
case "in-progress":
return "In Progress";
case "done":
return "Done";
default:
return status;
}
}

0 comments on commit 125962d

Please sign in to comment.