Skip to content

Commit e087920

Browse files
authored
[PBNTR-862]Testing Draggable Kit with Table Kit (#4234)
Testing to see if we can use our Draggable kit with Table kit on Rails side TLDR: - We can use it with the subcomponent structure, but we will need to add a `tag` prop for draggable_container AND draggable_item so we can set it to tbody and tr. - This is a good addition to the kit for the long run, we should add it on the React side as well - We can also build the draggable piece into the Table kit, but this should be enough to allow devs to use it https://github.com/user-attachments/assets/7611c048-ab4b-41dd-a3f0-aa07bd1148a0
1 parent d447baa commit e087920

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<% initial_items = [
2+
{
3+
id: "1",
4+
title: "Task 1",
5+
assignee_name: "Terry Miles",
6+
assignee_img: "https://randomuser.me/api/portraits/men/44.jpg",
7+
},
8+
{
9+
id: "2",
10+
title: "Task 2",
11+
assignee_name: "Sophia Miles",
12+
assignee_img: "https://randomuser.me/api/portraits/women/8.jpg",
13+
},
14+
{
15+
id: "3",
16+
title: "Task 3",
17+
assignee_name: "Alice Jones",
18+
assignee_img: "https://randomuser.me/api/portraits/women/10.jpg",
19+
},
20+
{
21+
id: "4",
22+
title: "Task 4",
23+
assignee_name: "Mike James",
24+
assignee_img: "https://randomuser.me/api/portraits/men/8.jpg",
25+
},
26+
{
27+
id: "5",
28+
title: "Task 5",
29+
assignee_name: "James Guy",
30+
assignee_img: "https://randomuser.me/api/portraits/men/18.jpg",
31+
}
32+
] %>
33+
34+
35+
36+
<%= pb_rails("draggable", props: {initial_items: initial_items}) do %>
37+
<%= pb_rails("table", props: { size: "sm", responsive:"none" }) do %>
38+
<%= pb_rails("table/table_head") do %>
39+
<%= pb_rails("table/table_row") do %>
40+
<%= pb_rails("table/table_header", props: { text: "id"}) %>
41+
<%= pb_rails("table/table_header", props: { text: "name"}) %>
42+
<%= pb_rails("table/table_header", props: { text: "task number"}) %>
43+
<% end %>
44+
<% end %>
45+
46+
<%= pb_rails("draggable/draggable_container", props: {tag:"tbody"}) do %>
47+
<% initial_items.each do |item| %>
48+
<%= pb_rails("draggable/draggable_item", props:{drag_id: item[:id], tag:"tr"}) do %>
49+
<%= pb_rails("table/table_cell", props: { text: item[:id]}) %>
50+
<%= pb_rails("table/table_cell") do %>
51+
<%= pb_rails("flex", props:{align:"center"}) do %>
52+
<%= pb_rails("avatar", props: {size: "xs", image_url: item[:assignee_img]}) %>
53+
<%= pb_rails("body", props: {text: item[:assignee_name], padding_left:"sm"}) %>
54+
<% end %>
55+
<% end %>
56+
<%= pb_rails("table/table_cell", props: { text: item[:title]}) %>
57+
<% end %>
58+
<% end %>
59+
<% end %>
60+
<% end %>
61+
<% end %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The draggable kit can also be used in conjunction with the table kit to create draggable table rows. To do this, make use of the `tag` prop on the draggable_container to set it to 'tbody' and the same prop on the draggable_item to set that to 'tr'. This will create the functionality seen here.

playbook/app/pb_kits/playbook/pb_draggable/docs/example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ examples:
1010
- draggable_with_list_rails: Draggable with List Kit
1111
- draggable_with_selectable_list_rails: Draggable with SelectableList Kit
1212
- draggable_with_cards_rails: Draggable with Cards
13+
- draggable_with_table: Draggable with Table
1314
- draggable_multiple_containers_rails: Dragging Across Multiple Containers
1415

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<%= pb_content_tag do %>
2-
<%= content.presence %>
3-
<% end %>
1+
<%= pb_content_tag(object.tag) do %>
2+
<%= content.presence %>
3+
<% end %>

playbook/app/pb_kits/playbook/pb_draggable/draggable_container.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Playbook
44
module PbDraggable
55
class DraggableContainer < ::Playbook::KitBase
6+
prop :tag, type: Playbook::Props::String,
7+
default: "div"
68
prop :container, type: Playbook::Props::String,
79
default: ""
810

playbook/app/pb_kits/playbook/pb_draggable/draggable_item.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= pb_content_tag(:div, {
1+
<%= pb_content_tag(object.tag, {
22
id: "item_#{object.drag_id}",
33
draggable: true
44
}) do %>

playbook/app/pb_kits/playbook/pb_draggable/draggable_item.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module PbDraggable
55
class DraggableItem < ::Playbook::KitBase
66
prop :drag_id, type: Playbook::Props::String,
77
default: ""
8+
prop :tag, type: Playbook::Props::String,
9+
default: "div"
810
prop :container, type: Playbook::Props::String,
911
default: ""
1012

0 commit comments

Comments
 (0)