Skip to content

Commit 6272844

Browse files
authored
Add sortable component
1 parent 1d1ea94 commit 6272844

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

app/javascript/controllers/sortable_controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { Sortable, Plugins, Draggable } from '@shopify/draggable'
44
export default class extends Controller {
55
static values = {
66
appendTo: String,
7+
handle: String,
78
}
89

910
connect() {
1011
this.sortable = new Sortable(this.element, {
1112
draggable: '.draggable',
13+
handle: this.handleValue,
1214
mirror: {
1315
constrainDimensions: true,
1416
appendTo: this.appendToValue,

app/views/events/settings/_donation_tiers.html.erb

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,34 @@
2626
<div data-accordion-target="content" class="rounded-xl">
2727
<div class="field mt-5">
2828
<%= form_with(url: event_donation_tiers_path(event), local: true, method: :patch) do |form| %>
29-
<% event.donation_tiers.each do |tier| %>
30-
<div class="card shadow-none border bg-gray-50 flex items-start gap-2 mb-2">
31-
<div class="flex-1">
32-
<div class="flex gap-2 w-full">
33-
<input type="text" class="flex-1 !max-w-full" placeholder="Tier name" name="tiers[<%= tier.id %>][name]" value="<%= tier.name %>" required>
34-
<div class="flex items-center gap-2 border rounded-md px-3 input min-w-0 p-0 max-w-[200px]">
35-
$
36-
<input type="text" class="!border-none !px-0" style="max-width: 95px" placeholder="Monthly cost" name="tiers[<%= tier.id %>][amount_cents]" value="<%= tier.amount_cents / 100 %>" required>
37-
/month
29+
<ul
30+
class="list-none p-0 m-0 flex flex-col gap-2"
31+
data-controller="sortable event-sort"
32+
data-sortable-append-to-value="body"
33+
data-sortable-handle-value=".draggable-handle"
34+
data-event-sort-organizer-positions-value="<%= event.donation_tiers.pluck(:id).to_json %>"
35+
data-action="sortable:stop->event-sort#sort">
36+
<% event.donation_tiers.each do |tier| %>
37+
<div class="draggable card shadow-none border bg-gray-50 flex items-start gap-2 mb-2 transition-none">
38+
<div class="flex-1">
39+
<div class="flex gap-2 w-full">
40+
<input type="text" class="flex-1 !max-w-full" placeholder="Tier name" name="tiers[<%= tier.id %>][name]" value="<%= tier.name %>" required>
41+
<div class="flex items-center gap-2 border rounded-md px-3 input min-w-0 p-0 max-w-[200px]">
42+
$
43+
<input type="text" class="!border-none !px-0" style="max-width: 95px" placeholder="Monthly cost" name="tiers[<%= tier.id %>][amount_cents]" value="<%= tier.amount_cents / 100 %>" required>
44+
/month
45+
</div>
3846
</div>
47+
<textarea class="w-100 max-w-full mt-1" placeholder="Description" name="tiers[<%= tier.id %>][description]"><%= tier.description %></textarea>
3948
</div>
40-
<textarea class="w-100 max-w-full mt-1" placeholder="Description" name="tiers[<%= tier.id %>][description]"><%= tier.description %></textarea>
41-
</div>
4249

43-
<div class="flex flex-col gap-1">
44-
<%= pop_icon_to "drag-indicator", "#" %>
45-
<%= pop_icon_to "delete", event_donation_tiers_path(event, tier), method: :delete, data: { turbo_confirm: "Are you sure?" } %>
50+
<div class="flex flex-col gap-1">
51+
<%= pop_icon_to "drag-indicator", "#", class: "draggable-handle cursor-move" %>
52+
<%= pop_icon_to "delete", event_donation_tiers_path(event, tier), method: :delete, data: { turbo_confirm: "Are you sure?" } %>
53+
</div>
4654
</div>
47-
</div>
48-
<% end %>
55+
<% end %>
56+
</ul>
4957

5058
<div class="flex gap-3 mt-4">
5159
<button type="button" class="btn bg-muted flex-1 gap-2" onclick="document.getElementById('createTier').requestSubmit();">

0 commit comments

Comments
 (0)