playbook_ui 14.10.0.pre.alpha.play16825206 → 14.10.0.pre.alpha.play16825301

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +11 -16
  3. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +1 -1
  4. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.rb +8 -1
  5. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_sort.html.erb +1 -3
  6. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_subrow_headers.html.erb +1 -1
  7. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta_subrow_headers.md +1 -1
  8. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_headers.html.erb +43 -0
  9. data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_column_headers_multiple.html.erb +58 -0
  10. data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +3 -0
  11. data/app/pb_kits/playbook/pb_advanced_table/index.js +185 -92
  12. data/app/pb_kits/playbook/pb_advanced_table/table_body.html.erb +1 -1
  13. data/app/pb_kits/playbook/pb_advanced_table/table_body.rb +55 -8
  14. data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +17 -14
  15. data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +78 -0
  16. data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +4 -3
  17. data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +13 -2
  18. data/app/pb_kits/playbook/pb_advanced_table/table_subrow_header.html.erb +2 -6
  19. data/app/pb_kits/playbook/pb_advanced_table/table_subrow_header.rb +6 -4
  20. data/app/pb_kits/playbook/pb_avatar_action_button/_avatar_action_button.scss +11 -9
  21. data/app/pb_kits/playbook/pb_badge/_badge.scss +4 -2
  22. data/app/pb_kits/playbook/pb_bread_crumbs/_bread_crumbs.scss +3 -1
  23. data/app/pb_kits/playbook/pb_button/_button.scss +3 -1
  24. data/app/pb_kits/playbook/pb_card/_card.scss +21 -3
  25. data/app/pb_kits/playbook/pb_card/docs/_card_header.html.erb +18 -0
  26. data/app/pb_kits/playbook/pb_card/docs/_card_header.jsx +40 -0
  27. data/app/pb_kits/playbook/pb_circle_icon_button/_circle_icon_button.scss +4 -2
  28. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_input_styles.scss +3 -1
  29. data/app/pb_kits/playbook/pb_date_picker/sass_partials/_overrides.scss +5 -3
  30. data/app/pb_kits/playbook/pb_date_range_inline/_date_range_inline.scss +6 -4
  31. data/app/pb_kits/playbook/pb_date_time_stacked/_date_time_stacked.scss +4 -2
  32. data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +10 -8
  33. data/app/pb_kits/playbook/pb_file_upload/_file_upload.tsx +24 -15
  34. data/app/pb_kits/playbook/pb_file_upload/docs/_file_upload_accept.jsx +3 -1
  35. data/app/pb_kits/playbook/pb_file_upload/docs/_file_upload_custom_description.jsx +4 -1
  36. data/app/pb_kits/playbook/pb_file_upload/docs/_file_upload_max_size.jsx +1 -1
  37. data/app/pb_kits/playbook/pb_form_pill/_form_pill.scss +6 -4
  38. data/app/pb_kits/playbook/pb_icon_circle/_icon_circle.scss +3 -1
  39. data/app/pb_kits/playbook/pb_label_value/_label_value.scss +4 -2
  40. data/app/pb_kits/playbook/pb_message/_message_mixins.scss +3 -1
  41. data/app/pb_kits/playbook/pb_multiple_users/_multiple_users.scss +3 -1
  42. data/app/pb_kits/playbook/pb_passphrase/_passphrase.scss +5 -3
  43. data/app/pb_kits/playbook/pb_phone_number_input/_phone_number_input.scss +10 -8
  44. data/app/pb_kits/playbook/pb_pill/_pill.scss +4 -2
  45. data/app/pb_kits/playbook/pb_progress_simple/_progress_simple.scss +4 -2
  46. data/app/pb_kits/playbook/pb_rich_text_editor/_rich_text_editor.scss +4 -2
  47. data/app/pb_kits/playbook/pb_select/_select.scss +5 -3
  48. data/app/pb_kits/playbook/pb_selectable_card/_selectable_card.scss +5 -3
  49. data/app/pb_kits/playbook/pb_table/_table.tsx +8 -1
  50. data/app/pb_kits/playbook/pb_table/docs/example.yml +2 -0
  51. data/app/pb_kits/playbook/pb_table/docs/index.js +2 -0
  52. data/app/pb_kits/playbook/pb_text_input/_text_input.scss +3 -1
  53. data/app/pb_kits/playbook/pb_text_input/docs/_text_input_mask.jsx +18 -0
  54. data/app/pb_kits/playbook/pb_text_input/inputMask.ts +22 -1
  55. data/app/pb_kits/playbook/pb_text_input/text_input.test.js +80 -0
  56. data/app/pb_kits/playbook/pb_textarea/_textarea.scss +3 -1
  57. data/app/pb_kits/playbook/pb_time_range_inline/_time_range_inline.scss +5 -4
  58. data/app/pb_kits/playbook/pb_timeline/_timeline.scss +4 -2
  59. data/app/pb_kits/playbook/pb_timeline/_timeline.tsx +5 -5
  60. data/app/pb_kits/playbook/pb_timeline/docs/_timeline_with_gap.html.erb +4 -5
  61. data/app/pb_kits/playbook/pb_timeline/docs/_timeline_with_gap.jsx +4 -4
  62. data/app/pb_kits/playbook/pb_timeline/docs/_timeline_with_gap.md +1 -1
  63. data/app/pb_kits/playbook/pb_timeline/timeline.rb +6 -6
  64. data/app/pb_kits/playbook/pb_toggle/_toggle.scss +5 -3
  65. data/dist/chunks/_typeahead-C2iCBqxQ.js +36 -0
  66. data/dist/chunks/_weekday_stacked-CWnbnW7m.js +45 -0
  67. data/dist/chunks/vendor.js +1 -1
  68. data/dist/playbook-doc.js +1 -1
  69. data/dist/playbook-rails-react-bindings.js +1 -1
  70. data/dist/playbook-rails.js +1 -1
  71. data/dist/playbook.css +1 -1
  72. data/lib/playbook/version.rb +1 -1
  73. metadata +6 -4
  74. data/dist/chunks/_typeahead-CbKUtXZa.js +0 -22
  75. data/dist/chunks/_weekday_stacked-CEpLoHbM.js +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c3686695d192a5f6435b3e5b6e8fd120a4b5910c068d87cd5308eb0af9e38a0
4
- data.tar.gz: da63348971a44ce424f553d0b5220bc10276d9110b9d7f26f59d3a8e0d446a78
3
+ metadata.gz: bcddb88a9dfb415486e86df29a22c55884190ed39205451c9034a621311c75f8
4
+ data.tar.gz: 344f303ea394159d8314f69334c59620cc6f1ab1c5781768cb700e7b17ac09e4
5
5
  SHA512:
6
- metadata.gz: 3a48fa614326e140e32a7a1352a160de4946f2ec72a992558519613ac2e6032fbbf015109fae16cba5f16121494c9d69bd709bc646f2a8df448c4d5364f255d1
7
- data.tar.gz: 19a0afe7eef42092273a30082159872df0cd9e51304b2e5bee2df47d8f16c6d66c3fae0df0862256502ecd4e860f6f984659e282ef39623976a06942aa004ba4
6
+ metadata.gz: 40d48f3e79dffff5949ede088d54fbf2042a1b7f9443a84f9222d9aaa640cd4428fe4f8c19342558360c760e011a9457cff979e9d27a980446014b3bdb2db999
7
+ data.tar.gz: ac66fc8ced8a8332815151154d12cd7628813ddae7ea3b22b84997923228edc5efcf40c4fb2f0d08acbf565b0f4c1c6e84c7d439f3d0e226ebd96eba2b451ea7
@@ -36,35 +36,29 @@
36
36
  .last-header-cell {
37
37
  border-right: 1px solid $border_light !important;
38
38
  }
39
-
40
39
  th {
41
40
  border-radius: 0px !important;
42
41
  border-width: 0 0 1px 0 !important;
43
42
  }
44
43
  th:first-child {
45
44
  border-left-width: 1px !important;
46
- @media only screen and (max-width: $screen-xl-min) {
47
- border-left-width: 0 !important;
48
- }
49
- }
50
- th:last-child {
51
- border-right-width: 1px !important;
52
- @media only screen and (max-width: $screen-xl-min) {
53
- border-right-width: 0 !important;
54
- }
55
45
  }
56
46
  }
57
47
  th[colspan]:not([colspan="1"]) {
58
- border-right: 1px solid $border_light;
48
+ border-right: 1px solid $border_light !important;
59
49
  }
60
-
61
-
62
50
  }
63
51
 
64
52
  .pb_advanced_table_body {
65
53
  .last-cell {
66
54
  border-right: 1px solid $border_light !important;
67
55
  }
56
+ tr td:first-child {
57
+ padding-left: 8px !important;
58
+ }
59
+ tr .pb_table_td:last-child {
60
+ padding-right: 8px !important;
61
+ }
68
62
  }
69
63
 
70
64
 
@@ -134,7 +128,7 @@
134
128
  }
135
129
 
136
130
  .toggle-content {
137
- display: none;
131
+ display: none !important;
138
132
  height: 0;
139
133
  padding-bottom: 0 !important;
140
134
  padding-top: 0 !important;
@@ -143,7 +137,7 @@
143
137
  }
144
138
 
145
139
  .toggle-content.is-visible {
146
- display: contents;
140
+ display: table-row !important;
147
141
  height: auto;
148
142
  }
149
143
 
@@ -166,7 +160,7 @@
166
160
  width: 100%;
167
161
  [class^=pb_table].table-sm.table-card thead tr th:first-child,
168
162
  [class^=pb_table].table-sm:not(.no-hover).table-card tbody tr td:first-child {
169
- border-left-width: 0px;
163
+ border-left-width: 0px !important;
170
164
  }
171
165
  [class^=pb_table].table-sm.table-card thead tr th:last-child,
172
166
  [class^=pb_table].table-sm:not(.no-hover).table-card tbody tr td:last-child {
@@ -192,6 +186,7 @@
192
186
  .bg-white td:first-child {
193
187
  background-color: $white;
194
188
  }
189
+
195
190
  }
196
191
  }
197
192
  @media only screen and (min-width: $screen-xl-min) {
@@ -1,5 +1,5 @@
1
1
  <%= pb_content_tag do %>
2
- <%= pb_rails("table", props: { size: "sm", tag:"div", data_table: true, number_spacing:"tabular", responsive:"none", dark: dark }) do %>
2
+ <%= pb_rails("table", props: { size: "sm", data_table: true, number_spacing:"tabular", responsive:"none", dark: dark }) do %>
3
3
  <% if content.present? %>
4
4
  <% content.presence %>
5
5
  <% else %>
@@ -10,9 +10,16 @@ module Playbook
10
10
  prop :enable_toggle_expansion, type: Playbook::Props::Enum,
11
11
  values: %w[all header none],
12
12
  default: "header"
13
+ prop :responsive, type: Playbook::Props::Enum,
14
+ values: %w[none scroll],
15
+ default: "none"
13
16
 
14
17
  def classname
15
- generate_classname("pb_advanced_table")
18
+ generate_classname("pb_advanced_table", responsive_classname, separator: " ")
19
+ end
20
+
21
+ def responsive_classname
22
+ responsive == "scroll" ? "advanced-table-responsive-scroll" : "advanced-table-responsive-none"
16
23
  end
17
24
  end
18
25
  end
@@ -49,11 +49,9 @@
49
49
  label: "Graduated Students",
50
50
  }
51
51
  ]
52
-
53
- subrow_headers = ["Quarter", "Month", "Day"]
54
52
  %>
55
53
 
56
54
  <%= pb_rails("advanced_table", props: { table_data: @table_data, column_definitions: column_definitions }) do %>
57
55
  <%= pb_rails("advanced_table/table_header", props: { column_definitions: column_definitions }) %>
58
- <%= pb_rails("advanced_table/table_body", props: { id: "beta_sort", table_data: @table_data, column_definitions: column_definitions, subrow_headers: subrow_headers, enable_toggle_expansion: "all" }) %>
56
+ <%= pb_rails("advanced_table/table_body", props: { id: "beta_sort", table_data: @table_data, column_definitions: column_definitions, enable_toggle_expansion: "all" }) %>
59
57
  <% end %>
@@ -36,5 +36,5 @@
36
36
 
37
37
  <%= pb_rails("advanced_table", props: { table_data: @table_data, column_definitions: column_definitions }) do %>
38
38
  <%= pb_rails("advanced_table/table_header", props: { column_definitions: column_definitions }) %>
39
- <%= pb_rails("advanced_table/table_body", props: { id: "subrow_headers", table_data: @table_data, column_definitions: column_definitions, subrow_headers: subrow_headers, enable_toggle_expansion: "all" }) %>
39
+ <%= pb_rails("advanced_table/table_body", props: { id: "test_table", table_data: @table_data, column_definitions: column_definitions, subrow_headers: subrow_headers, enable_toggle_expansion: "all" }) %>
40
40
  <% end %>
@@ -1,3 +1,3 @@
1
1
  `subrow_headers` is an optional prop that if present will add header rows at each level of the nested data. The prop takes an array of strings, each string being the text for each header row. The array of strings must be in the order in which they need to be rendered in the UI according to depth.
2
2
 
3
- `enable_toggle_expansion` is an additional optional prop that can be used in conjunction with the subRowHeaders prop. `enable_toggle_expansion` is a string that can be "all", "header" or "none". If set to "all", the toggle exapansion button will appear in the table header as well as in the subRow headers. If set to "header" button will only appear in header and NOT in subRow headers. This is set to "header" by default.
3
+ `enable_toggle_expansion` is an additional optional prop that can be used in conjunction with the subRowHeaders prop. `enable_toggle_expansion` is a string that can be "all", "header" or "none". If set to "all", the toggle expansion button will appear in the table header as well as in the subRow headers. If set to "header", the button will only appear in header and NOT in subRow headers. This prop is set to "header" by default.
@@ -0,0 +1,43 @@
1
+ <% column_definitions = [
2
+ {
3
+ accessor: "year",
4
+ label: "Year",
5
+ cellAccessors: ["quarter", "month", "day"],
6
+ },
7
+ {
8
+ label: "Enrollment Data",
9
+ columns: [
10
+ {
11
+ accessor: "newEnrollments",
12
+ label: "New Enrollments",
13
+ },
14
+ {
15
+ accessor: "scheduledMeetings",
16
+ label: "Scheduled Meetings",
17
+ },
18
+ ],
19
+ },
20
+ {
21
+ label: "Performance Data",
22
+ columns: [
23
+ {
24
+ accessor: "attendanceRate",
25
+ label: "Attendance Rate",
26
+ },
27
+ {
28
+ accessor: "completedClasses",
29
+ label: "Completed Classes",
30
+ },
31
+ {
32
+ accessor: "classCompletionRate",
33
+ label: "Class Completion Rate",
34
+ },
35
+ {
36
+ accessor: "graduatedStudents",
37
+ label: "Graduated Students",
38
+ },
39
+ ],
40
+ },
41
+ ] %>
42
+
43
+ <%= pb_rails("advanced_table", props: { id: "beta_table_with_headers", table_data: @table_data, column_definitions: column_definitions }) %>
@@ -0,0 +1,58 @@
1
+ <% column_definitions = [
2
+ {
3
+ accessor: "year",
4
+ label: "Year",
5
+ cellAccessors: ["quarter", "month", "day"],
6
+ },
7
+ {
8
+ label: "Enrollment Data",
9
+ columns: [
10
+ {
11
+ label: "Enrollment Stats",
12
+ columns: [
13
+ {
14
+ accessor: "newEnrollments",
15
+ label: "New Enrollments",
16
+ },
17
+ {
18
+ accessor: "scheduledMeetings",
19
+ label: "Scheduled Meetings",
20
+ },
21
+ ],
22
+ },
23
+ ],
24
+ },
25
+ {
26
+ label: "Performance Data",
27
+ columns: [
28
+ {
29
+ label: "Completion Metrics",
30
+ columns: [
31
+ {
32
+ accessor: "completedClasses",
33
+ label: "Completed Classes",
34
+ },
35
+ {
36
+ accessor: "classCompletionRate",
37
+ label: "Class Completion Rate",
38
+ },
39
+ ],
40
+ },
41
+ {
42
+ label: "Attendance",
43
+ columns: [
44
+ {
45
+ accessor: "attendanceRate",
46
+ label: "Attendance Rate",
47
+ },
48
+ {
49
+ accessor: "scheduledMeetings",
50
+ label: "Scheduled Meetings",
51
+ },
52
+ ],
53
+ },
54
+ ],
55
+ },
56
+ ] %>
57
+
58
+ <%= pb_rails("advanced_table", props: { id: "beta_table_with_muilti_headers", table_data: @table_data, column_definitions: column_definitions }) %>
@@ -5,6 +5,9 @@ examples:
5
5
  - advanced_table_collapsible_trail_rails: Collapsible Trail
6
6
  - advanced_table_beta_sort: Enable Sorting
7
7
  - advanced_table_custom_cell_rails: Custom Components for Cells
8
+ - advanced_table_column_headers: Multi-Header Columns
9
+ - advanced_table_column_headers_multiple: Multi-Header Columns (Multiple Levels)
10
+
8
11
 
9
12
  react:
10
13
  - advanced_table_default: Default (Required Props)
@@ -1,138 +1,231 @@
1
- import PbEnhancedElement from '../pb_enhanced_element'
1
+ import PbEnhancedElement from "../pb_enhanced_element";
2
2
 
3
- const ADVANCED_TABLE_SELECTOR = '[data-advanced-table]'
4
- const CONTENT_SELECTOR = '[data-advanced-table-content="id"]'
5
- const DOWN_ARROW_SELECTOR = '#advanced-table_open_icon'
6
- const UP_ARROW_SELECTOR = '#advanced-table_close_icon'
3
+ const ADVANCED_TABLE_SELECTOR = "[data-advanced-table]";
4
+ const DOWN_ARROW_SELECTOR = "#advanced-table_open_icon";
5
+ const UP_ARROW_SELECTOR = "#advanced-table_close_icon";
7
6
 
8
7
  export default class PbAdvancedTable extends PbEnhancedElement {
9
8
  static get selector() {
10
- return ADVANCED_TABLE_SELECTOR
9
+ return ADVANCED_TABLE_SELECTOR;
11
10
  }
12
11
 
13
12
  get target() {
14
- return document.querySelector(CONTENT_SELECTOR.replace("id", this.element.id))
13
+ const table = this.element.closest("table");
14
+ return table.querySelectorAll(`[data-row-parent="${this.element.id}"]`);
15
15
  }
16
-
17
- static expandedRows = new Set()
18
- static isCollapsing = false
16
+
17
+ static expandedRows = new Set();
18
+ static isCollapsing = false;
19
19
 
20
20
  connect() {
21
- this.element.addEventListener('click', () => {
21
+ this.element.addEventListener("click", () => {
22
22
  if (!PbAdvancedTable.isCollapsing) {
23
- const isExpanded = this.element.querySelector(UP_ARROW_SELECTOR).style.display === 'inline-block'
23
+ const isExpanded =
24
+ this.element.querySelector(UP_ARROW_SELECTOR).style.display ===
25
+ "inline-block";
24
26
  if (!isExpanded) {
25
- PbAdvancedTable.expandedRows.add(this.element.id)
27
+ PbAdvancedTable.expandedRows.add(this.element.id);
26
28
  } else {
27
- PbAdvancedTable.expandedRows.delete(this.element.id)
29
+ PbAdvancedTable.expandedRows.delete(this.element.id);
28
30
  }
31
+ this.toggleElement(this.target);
29
32
  }
30
- this.toggleElement(this.target)
31
- })
33
+ });
34
+
35
+ const nestedButtons = this.element
36
+ .closest("table")
37
+ .querySelectorAll("[data-advanced-table]");
38
+ nestedButtons.forEach((button) => {
39
+ button.addEventListener("click", () => {
40
+ const isExpanded =
41
+ button.querySelector(UP_ARROW_SELECTOR).style.display ===
42
+ "inline-block";
43
+ if (isExpanded) {
44
+ PbAdvancedTable.expandedRows.add(button.id);
45
+ } else {
46
+ PbAdvancedTable.expandedRows.delete(button.id);
47
+ }
48
+ });
49
+ });
32
50
  }
33
51
 
34
- showElement(elem) {
35
- const getHeight = () => {
36
- elem.style.display = 'block'
37
- const height = elem.scrollHeight + 'px'
38
- elem.style.display = ''
39
- return height
40
- }
41
-
42
- const height = getHeight()
43
- elem.classList.add('is-visible')
44
- elem.style.height = height
45
- elem.style.overflow = "hidden"
46
-
47
- window.setTimeout(() => {
48
- elem.style.height = ''
49
- elem.style.overflow = "visible"
50
- }, 250)
52
+ showElement(elements) {
53
+ elements.forEach((elem) => {
54
+ elem.style.display = "table-row";
55
+ elem.classList.add("is-visible");
56
+ const childRowsAll = this.element
57
+ .closest("table")
58
+ .querySelectorAll(
59
+ `[data-advanced-table-content^="${elem.dataset.advancedTableContent}-"]`
60
+ );
61
+
62
+ childRowsAll.forEach((childRow) => {
63
+ const dataContent = childRow.dataset.advancedTableContent;
64
+
65
+ if (!dataContent) {
66
+ return;
67
+ }
68
+ // Split the dataContent to get all ancestor IDs, check against ExpandedRows
69
+ const ancestorIds = dataContent.split("-").slice(0, -1);
70
+
71
+ const prefixedAncestorIds = ancestorIds.map(
72
+ (id) => `${childRow.id}_${id}`
73
+ );
74
+ const allAncestorsExpanded = prefixedAncestorIds.every((id) =>
75
+ PbAdvancedTable.expandedRows.has(id)
76
+ );
77
+
78
+ const checkIfParentIsExpanded = () => {
79
+ if (dataContent.endsWith("sr")) {
80
+ const parentRowId = childRow.dataset.rowParent;
81
+ const isParentVisible =
82
+ childRow.previousElementSibling.classList.contains("is-visible");
83
+ if (parentRowId) {
84
+ const isInSet = PbAdvancedTable.expandedRows.has(parentRowId);
85
+ if (isInSet && isParentVisible) {
86
+ return true;
87
+ }
88
+ }
89
+ }
90
+ return false;
91
+ };
92
+
93
+ if (allAncestorsExpanded || checkIfParentIsExpanded()) {
94
+ childRow.style.display = "table-row";
95
+ childRow.classList.add("is-visible");
96
+ } else {
97
+ childRow.style.display = "none";
98
+ childRow.classList.remove("is-visible");
99
+ }
100
+ });
101
+ });
51
102
  }
52
103
 
53
- hideElement(elem) {
54
- elem.style.height = elem.scrollHeight + 'px'
104
+ hideElement(elements) {
105
+ elements.forEach((elem) => {
106
+ elem.style.display = "none";
107
+ elem.classList.remove("is-visible");
55
108
 
56
- window.setTimeout(() => {
57
- elem.style.height = '0'
58
- elem.style.paddingTop = '0'
59
- elem.style.paddingBottom = '0'
60
- elem.style.overflow = "hidden"
61
- }, 1)
109
+ // Remove the row ID from expandedRows when this row is hidden
110
+ if (PbAdvancedTable.expandedRows.has(elem.id)) {
111
+ PbAdvancedTable.expandedRows.delete(elem.id);
112
+ }
62
113
 
63
- window.setTimeout(() => {
64
- elem.classList.remove('is-visible')
65
- elem.style.overflow = ""
66
- }, 200)
114
+ const childrenArray = elem.dataset.advancedTableContent.split("-");
115
+ const currentDepth = parseInt(elem.dataset.rowDepth);
116
+ if (childrenArray.length > currentDepth) {
117
+ // Find the child rows corresponding to this parent row
118
+ const childRows = this.element
119
+ .closest("table")
120
+ .querySelectorAll(
121
+ `[data-advanced-table-content^="${elem.dataset.advancedTableContent}-"]`
122
+ );
123
+
124
+ childRows.forEach((childRow) => {
125
+ childRow.style.display = "none";
126
+ childRow.classList.remove("is-visible");
127
+ });
128
+ }
129
+ });
67
130
  }
68
131
 
69
- toggleElement(elem) {
70
- if (elem.classList.contains('is-visible')) {
71
- this.hideElement(elem)
72
- this.displayDownArrow()
73
- return
74
- }
132
+ toggleElement(elements) {
133
+ if (!elements.length) return;
75
134
 
76
- this.showElement(elem)
77
- this.displayUpArrow()
135
+ const isVisible = elements[0].classList.contains("is-visible");
136
+ if (isVisible) {
137
+ this.hideElement(elements);
138
+ this.displayDownArrow();
139
+ } else {
140
+ this.showElement(elements);
141
+ this.displayUpArrow();
142
+ }
78
143
  }
79
144
 
80
145
  displayDownArrow() {
81
- this.element.querySelector(DOWN_ARROW_SELECTOR).style.display = 'inline-block'
82
- this.element.querySelector(UP_ARROW_SELECTOR).style.display = 'none'
146
+ this.element.querySelector(DOWN_ARROW_SELECTOR).style.display =
147
+ "inline-block";
148
+ this.element.querySelector(UP_ARROW_SELECTOR).style.display = "none";
83
149
  }
84
150
 
85
151
  displayUpArrow() {
86
- this.element.querySelector(UP_ARROW_SELECTOR).style.display = 'inline-block'
87
- this.element.querySelector(DOWN_ARROW_SELECTOR).style.display = 'none'
152
+ this.element.querySelector(UP_ARROW_SELECTOR).style.display =
153
+ "inline-block";
154
+ this.element.querySelector(DOWN_ARROW_SELECTOR).style.display = "none";
88
155
  }
89
156
 
90
157
  static handleToggleAllHeaders(element) {
91
- const table = element.closest('.pb_table')
92
- const firstLevelButtons = table.querySelectorAll('.pb_advanced_table_body > .pb_table_tr [data-advanced-table]')
93
-
94
- const expandedRows = Array.from(firstLevelButtons).filter(button =>
95
- button.querySelector(UP_ARROW_SELECTOR).style.display === 'inline-block'
96
- )
97
-
98
- if (expandedRows.length === firstLevelButtons.length) {
99
- expandedRows.forEach(button => {
100
- button.click()
101
- })
102
- this.expandedRows.clear()
158
+ const table = element.closest(".pb_table");
159
+ const firstLevelButtons = table.querySelectorAll(
160
+ ".pb_advanced_table_body > .pb_table_tr[data-row-depth='0'] [data-advanced-table]"
161
+ );
162
+
163
+ const allExpanded = Array.from(firstLevelButtons).every(
164
+ (button) =>
165
+ button.querySelector(UP_ARROW_SELECTOR).style.display === "inline-block"
166
+ );
167
+
168
+ if (allExpanded) {
169
+ firstLevelButtons.forEach((button) => {
170
+ button.click();
171
+ PbAdvancedTable.expandedRows.delete(button.id);
172
+ });
103
173
  } else {
104
- firstLevelButtons.forEach(button => {
105
- if (!this.expandedRows.has(button.id)) {
106
- button.click()
174
+ firstLevelButtons.forEach((button) => {
175
+ if (!PbAdvancedTable.expandedRows.has(button.id)) {
176
+ button.click();
177
+ PbAdvancedTable.expandedRows.add(button.id);
178
+ }
179
+ });
180
+
181
+ PbAdvancedTable.expandedRows.forEach((rowId) => {
182
+ const nestedButton = table.querySelector(
183
+ `[data-advanced-table][id="${rowId}"]`
184
+ );
185
+ if (nestedButton && !firstLevelButtons.contains(nestedButton)) {
186
+ nestedButton.click();
107
187
  }
108
- })
188
+ });
109
189
  }
110
190
  }
191
+
111
192
  static handleToggleAllSubRows(element, rowDepth) {
112
- const parentElement = element.closest(".toggle-content")
113
- const subrowButtons = parentElement.querySelectorAll('.depth-sub-row-' + rowDepth + ' [data-advanced-table]')
114
-
115
- const expandedSubRows = Array.from(subrowButtons).filter(button =>
116
- button.querySelector(UP_ARROW_SELECTOR).style.display === 'inline-block'
117
- )
118
-
119
- if (expandedSubRows.length === subrowButtons.length) {
120
- expandedSubRows.forEach(button => {
121
- button.click()
122
- })
193
+ const table = element.closest(".pb_table");
194
+ const parentRow = element.closest("tr");
195
+ if (!parentRow) {
196
+ return;
197
+ }
198
+ const rowParentId = parentRow.dataset.rowParent;
199
+ // Select all buttons that for subrows at that depth and with same rowParent
200
+ const subRowButtons = table.querySelectorAll(
201
+ `.pb_advanced_table_body > .pb_table_tr[data-row-depth='${rowDepth}'].pb_table_tr[data-row-parent='${rowParentId}'] [data-advanced-table]`
202
+ );
203
+
204
+ const allExpanded = Array.from(subRowButtons).every(
205
+ (button) =>
206
+ button.querySelector(UP_ARROW_SELECTOR).style.display === "inline-block"
207
+ );
208
+
209
+ if (allExpanded) {
210
+ subRowButtons.forEach((button) => {
211
+ button.click();
212
+ PbAdvancedTable.expandedRows.delete(button.id);
213
+ });
123
214
  } else {
124
- subrowButtons.forEach(button => {
125
- if (!this.expandedRows.has(button.id)) {
126
- button.click()
215
+ subRowButtons.forEach((button) => {
216
+ if (!PbAdvancedTable.expandedRows.has(button.id)) {
217
+ button.click();
218
+ PbAdvancedTable.expandedRows.add(button.id);
127
219
  }
128
- })
220
+ });
129
221
  }
130
222
  }
131
223
  }
132
224
 
133
225
  window.expandAllRows = (element) => {
134
- PbAdvancedTable.handleToggleAllHeaders(element)
135
- }
226
+ PbAdvancedTable.handleToggleAllHeaders(element);
227
+ };
228
+
136
229
  window.expandAllSubRows = (element, rowDepth) => {
137
- PbAdvancedTable.handleToggleAllSubRows(element, rowDepth)
138
- }
230
+ PbAdvancedTable.handleToggleAllSubRows(element, rowDepth);
231
+ };
@@ -1,4 +1,4 @@
1
- <%= pb_content_tag do %>
1
+ <%= pb_content_tag(:tbody) do %>
2
2
  <% object.table_data.each do |row| %>
3
3
  <%= render_row_and_children(row, object.column_definitions, 0, false) %>
4
4
  <% end %>