Skip to content

Commit

Permalink
[PBNTR-739] Adding Collapsible Trail to Rails Advanced Table (#4030)
Browse files Browse the repository at this point in the history
**What does this PR do?**
Adding Collapsible Trail to Rails Advanced Table

**Screenshots:** Screenshots to visualize your addition/change

![image](https://github.com/user-attachments/assets/5b5c0928-fcf6-4511-b7bf-29bb3623cc37)

**How to test?** Steps to confirm the desired behavior:
1. Go to the Advanced Table kit
2. Scroll down to the Collapsible Trail doc example


#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [x] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.
- [ ] **TESTS** I have added test coverage to my code.
  • Loading branch information
carloslimasd authored Dec 20, 2024
1 parent 8543aa2 commit e725cec
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import React from "react"
//CollapsibleTrail component
const CollapsibleTrail = ({ leftOffset }: { leftOffset: number }) => {
const style: { [key: string]: string | number } = {
position: "absolute",
left: `${leftOffset}em`,
top: 0,
bottom: 0,
width: "2px",
backgroundColor: "#E4E8F0",
}

return (
<div
className="collapsible-trail"
style={style}
style={style}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@
height: auto;
}

.collapsible-trail {
background-color: $border_light;
position: absolute;
top: 0;
bottom: 0;
width: 2px;
}

// Responsive Styles
@media only screen and (max-width: $screen-xl-min) {
&[class*="table-responsive-scroll"] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<% column_definitions = [
{
accessor: "year",
label: "Year",
cellAccessors: ["quarter", "month", "day"],
},
{
accessor: "newEnrollments",
label: "New Enrollments",
},
{
accessor: "scheduledMeetings",
label: "Scheduled Meetings",
},
{
accessor: "attendanceRate",
label: "Attendance Rate",
},
{
accessor: "completedClasses",
label: "Completed Classes",
},
{
accessor: "classCompletionRate",
label: "Class Completion Rate",
},
{
accessor: "graduatedStudents",
label: "Graduated Students",
}
] %>

<%= pb_rails("advanced_table", props: { id: "collapsible_trail", table_data: @table_data, column_definitions: column_definitions }) do %>
<%= pb_rails("advanced_table/table_header", props: { column_definitions: column_definitions }) %>
<%= pb_rails("advanced_table/table_body", props: { table_data: @table_data, column_definitions: column_definitions, collapsible_trail: false }) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`collapsible_trail` is an optional prop that is set to 'true' by default. If set to 'false', it will remove the trail on the left of the rows when subRows are toggled open.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ examples:
rails:
- advanced_table_beta: Default (Required Props)
- advanced_table_beta_subrow_headers: SubRow Headers
- advanced_table_collapsible_trail_rails: Collapsible Trail
- advanced_table_beta_sort: Enable Sorting
- advanced_table_custom_cell_rails: Custom Components for Cells

Expand Down
6 changes: 4 additions & 2 deletions playbook/app/pb_kits/playbook/pb_advanced_table/table_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ class TableBody < Playbook::KitBase
default: "header"
prop :subrow_headers, type: Playbook::Props::Array,
default: []
prop :collapsible_trail, type: Playbook::Props::Boolean,
default: true

def render_row_and_children(row, column_definitions, current_depth, first_parent_child)
output = ActiveSupport::SafeBuffer.new
is_first_child_of_subrow = current_depth.positive? && first_parent_child && subrow_headers[current_depth - 1].present?

output << pb_rails("advanced_table/table_subrow_header", props: { row: row, column_definitions: column_definitions, depth: current_depth, subrow_header: subrow_headers[current_depth - 1] }) if is_first_child_of_subrow && enable_toggle_expansion == "all"
output << pb_rails("advanced_table/table_subrow_header", props: { row: row, column_definitions: column_definitions, depth: current_depth, subrow_header: subrow_headers[current_depth - 1], collapsible_trail: collapsible_trail }) if is_first_child_of_subrow && enable_toggle_expansion == "all"

output << pb_rails("advanced_table/table_row", props: { id: id, row: row, column_definitions: column_definitions, depth: current_depth })
output << pb_rails("advanced_table/table_row", props: { id: id, row: row, column_definitions: column_definitions, depth: current_depth, collapsible_trail: collapsible_trail })

if row[:children].present?
output << content_tag(:div, class: "toggle-content", data: { advanced_table_content: row.object_id.to_s + id }) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<% object.column_definitions.each_with_index do |column, index| %>
<%= pb_rails("table/table_cell", props: { tag:"div", classname:object.td_classname}) do %>
<%= pb_rails("flex", props:{ align: "center", justify: index.zero? ? "start" : "end" }) do %>
<% if collapsible_trail && index.zero? %>
<% (1..depth).each do |i| %>
<% additional_offset = i > 1 ? (i - 1) * 0.25 : 0 %>
<% left_offset = i * 1.0 + additional_offset %>
<div class="collapsible-trail" style="left: <%= left_offset %>em"></div>
<% end %>
<% end %>

<div style="padding-left: <%= depth * 1.25 %>em">
<%= pb_rails("flex", props:{align: "center", column_gap: "xs"}) do %>
<% if index.zero? && object.row[:children].present? %>
Expand Down
2 changes: 2 additions & 0 deletions playbook/app/pb_kits/playbook/pb_advanced_table/table_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class TableRow < Playbook::KitBase
default: []
prop :row
prop :depth
prop :collapsible_trail, type: Playbook::Props::Boolean,
default: true

def classname
generate_classname("pb_table_tr", "bg-white", subrow_depth_classname, separator: " ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<% object.column_definitions.each_with_index do |column, index| %>
<%= pb_rails("table/table_cell", props: { tag: "div", classname: object.td_classname}) do %>
<%= pb_rails("flex", props:{ align: "center", justify: "start" }) do %>
<% if collapsible_trail && index.zero? %>
<% (1..depth).each do |i| %>
<% additional_offset = i > 1 ? (i - 1) * 0.25 : 0 %>
<% left_offset = i * 1.0 + additional_offset %>
<div class="collapsible-trail" style="left: <%= left_offset %>em"></div>
<% end %>
<% end %>

<div style="padding-left: <%= depth * 1.25 %>em">
<%= pb_rails("flex", props:{align: "center", column_gap: "xs"}) do %>
<% if index.zero? && object.row[:children].present? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class TableSubrowHeader < Playbook::KitBase
default: "header"
prop :subrow_header, type: Playbook::Props::String,
default: ""
prop :collapsible_trail, type: Playbook::Props::Boolean,
default: true

def classname
generate_classname("pb_table_tr", "bg-white", subrow_depth_classname, separator: " ")
Expand Down

0 comments on commit e725cec

Please sign in to comment.