Skip to content

Commit

Permalink
Adding Collapsible Trail to Rails Advanced Table
Browse files Browse the repository at this point in the history
  • Loading branch information
carloslimasd committed Dec 19, 2024
1 parent a5305c7 commit 7886616
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 7 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 @@ -4,6 +4,7 @@ examples:
- advanced_table_beta_subrow_headers: SubRow Headers
- advanced_table_beta_sort: Enable Sorting
- advanced_table_custom_cell_rails: Custom Components for Cells
- advanced_table_collapsible_trail_rails: Collapsible Trail

react:
- advanced_table_default: Default (Required Props)
Expand Down
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_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

0 comments on commit 7886616

Please sign in to comment.