Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PBNTR-739] Adding Collapsible Trail to Rails Advanced Table #4030

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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
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
Loading