playbook_ui 14.20.0.pre.alpha.revert4453PBNTR933reactdraggablebugdragbtwnexamples7854 → 14.20.0.pre.alpha.revert4637revert4621PLAY2033atactionbarrails7855
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +16 -8
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.rb +9 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_beta.md +6 -2
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_default.md +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_actions_rails.html.erb +137 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_actions_rails.md +3 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.html.erb +40 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_advanced_table/index.js +155 -12
- data/app/pb_kits/playbook/pb_advanced_table/table_action_bar.html.erb +23 -0
- data/app/pb_kits/playbook/pb_advanced_table/table_action_bar.rb +19 -0
- data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +4 -0
- data/app/pb_kits/playbook/pb_draggable/context/index.tsx +58 -17
- data/dist/chunks/{_typeahead-C-CI5Vgw.js → _typeahead-BmOWdDtp.js} +1 -1
- data/dist/chunks/{_weekday_stacked-BCiM3zWM.js → _weekday_stacked-CvcuQyr9.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb057816a6e246cd6fdb0328481780c4c643745f743a30a7d8e8d7e3945edb52
|
4
|
+
data.tar.gz: 5cbbcb97be3bdb84207a0c02564c0d69526dbcc6ab4c225be46054eaa7d7e835
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a8324314d5a306344d06b8624cc9778135d054a604935fe18b48aacd834206f9af94ef059d56e8b4cc6dc10644b6d18358bc59353893e0be2fd36a43de3d6c6
|
7
|
+
data.tar.gz: 1cc55b5f08ff76e1acad406002cf428b9606c8e8c3c75a137a3f89b3a2c7be299fee1c93d2ae57e921cf59994779a13f8c98074e8af00da71cc0d5aabe2f7589
|
@@ -1,10 +1,18 @@
|
|
1
1
|
<%= pb_content_tag do %>
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
<% if object.id && object.selectable_rows && object.show_actions_bar %>
|
3
|
+
<%= pb_rails("advanced_table/table_action_bar", props: {
|
4
|
+
actions: object.actions,
|
5
|
+
is_visible: false,
|
6
|
+
selected_count: 0
|
7
|
+
}) %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<%= pb_rails("table", props: { size: "sm", data_table: true, number_spacing:"tabular", responsive:"none", dark: dark, classname: object.loading ? "content-loading" : "" }.merge(object.table_props)) do %>
|
11
|
+
<% if content.present? %>
|
12
|
+
<% content.presence %>
|
13
|
+
<% else %>
|
14
|
+
<%= pb_rails("advanced_table/table_header", props: { column_definitions: object.column_definitions, enable_toggle_expansion: object.enable_toggle_expansion, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, show_actions_bar: object.show_actions_bar }) %>
|
15
|
+
<%= pb_rails("advanced_table/table_body", props: { id: object.id, table_data: object.table_data, column_definitions: object.column_definitions, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, enable_toggle_expansion: object.enable_toggle_expansion }) %>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
10
18
|
<% end %>
|
@@ -25,6 +25,10 @@ module Playbook
|
|
25
25
|
default: "auto"
|
26
26
|
prop :selectable_rows, type: Playbook::Props::Boolean,
|
27
27
|
default: false
|
28
|
+
prop :show_actions_bar, type: Playbook::Props::Boolean,
|
29
|
+
default: true
|
30
|
+
prop :actions, type: Playbook::Props::Array,
|
31
|
+
default: []
|
28
32
|
|
29
33
|
def classname
|
30
34
|
additional_classes = [responsive_classname, max_height_classname]
|
@@ -47,6 +51,11 @@ module Playbook
|
|
47
51
|
def selected_rows_length
|
48
52
|
selected_rows.length
|
49
53
|
end
|
54
|
+
|
55
|
+
def is_action_bar_visible
|
56
|
+
# Action bar visibility is controlled by JS based on selection
|
57
|
+
false
|
58
|
+
end
|
50
59
|
end
|
51
60
|
end
|
52
61
|
end
|
@@ -1,4 +1,8 @@
|
|
1
|
-
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has
|
1
|
+
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has three required props__:
|
2
|
+
|
3
|
+
### id
|
4
|
+
|
5
|
+
A unique `id` is required to allow the table functionality to work properly. Without it, certain functions like the action bar will not be able to properly reference the correct table.
|
2
6
|
|
3
7
|
### table_data
|
4
8
|
|
@@ -13,6 +17,6 @@ Column definitions are the single most important part of building a table as the
|
|
13
17
|
- `accessor`: this is the key from your data for the value you want rendered in that column
|
14
18
|
- `label`: this is what will be rendered as the column header label
|
15
19
|
|
16
|
-
There is also one optional item that is only required if the table has nested data:
|
20
|
+
There is also one optional item that is only required if the table has nested data:
|
17
21
|
|
18
22
|
- `cellAccessors`: This is an array of strings that represent keys from your data object. This is only required for the first column in case of nested data. If you have nested data, the AdvancedTable needs to know what to render in that first column for nested items. This array represents the nested data in the order you want it rendered.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<br />
|
4
4
|
<br />
|
5
5
|
|
6
|
-
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has two required props__:
|
6
|
+
The AdvancedTable kit accepts tree data and automatically renders expansion controls for nested subrows, to any depth, based on the data it is given. In it's simplest form, __the kit has two required props__:
|
7
7
|
|
8
8
|
### tableData
|
9
9
|
|
@@ -0,0 +1,137 @@
|
|
1
|
+
<% column_definitions = [
|
2
|
+
{
|
3
|
+
accessor: "year",
|
4
|
+
label: "Year",
|
5
|
+
cellAccessors: ["quarter", "month", "day"],
|
6
|
+
},
|
7
|
+
{
|
8
|
+
accessor: "newEnrollments",
|
9
|
+
label: "New Enrollments",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
accessor: "scheduledMeetings",
|
13
|
+
label: "Scheduled Meetings",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
accessor: "attendanceRate",
|
17
|
+
label: "Attendance Rate",
|
18
|
+
},
|
19
|
+
{
|
20
|
+
accessor: "completedClasses",
|
21
|
+
label: "Completed Classes",
|
22
|
+
},
|
23
|
+
{
|
24
|
+
accessor: "classCompletionRate",
|
25
|
+
label: "Class Completion Rate",
|
26
|
+
},
|
27
|
+
{
|
28
|
+
accessor: "graduatedStudents",
|
29
|
+
label: "Graduated Students",
|
30
|
+
}
|
31
|
+
]
|
32
|
+
|
33
|
+
actions = [
|
34
|
+
pb_rails("circle_icon_button", props: {
|
35
|
+
icon: "file-csv",
|
36
|
+
variant: "link",
|
37
|
+
id: "export-selected-rows-btn",
|
38
|
+
data: {
|
39
|
+
action_type: "export"
|
40
|
+
}
|
41
|
+
}),
|
42
|
+
pb_rails("circle_icon_button", props: {
|
43
|
+
icon: "trash-alt",
|
44
|
+
variant: "link",
|
45
|
+
id: "delete-selected-rows-btn",
|
46
|
+
data: {
|
47
|
+
action_type: "delete"
|
48
|
+
}
|
49
|
+
})
|
50
|
+
]
|
51
|
+
%>
|
52
|
+
|
53
|
+
<%= pb_rails("advanced_table", props: {
|
54
|
+
id: "selectable_rows_with_actions",
|
55
|
+
table_data: @table_data_no_subrows,
|
56
|
+
column_definitions: column_definitions,
|
57
|
+
selectable_rows: true,
|
58
|
+
enable_toggle_expansion: "none",
|
59
|
+
actions: actions
|
60
|
+
}) %>
|
61
|
+
|
62
|
+
<script>
|
63
|
+
// Handle action clicks using the data-selected-rows attribute
|
64
|
+
window.handleActionClick = function(actionType) {
|
65
|
+
const tableContainer = document.getElementById('selectable_rows_with_actions');
|
66
|
+
if (!tableContainer) return;
|
67
|
+
|
68
|
+
// Get selected rows from the data attribute
|
69
|
+
const selectedRowsJSON = tableContainer.getAttribute('data-selected-rows');
|
70
|
+
let selectedRowIds = [];
|
71
|
+
|
72
|
+
try {
|
73
|
+
// Parse the JSON string from the data attribute
|
74
|
+
if (selectedRowsJSON) {
|
75
|
+
selectedRowIds = JSON.parse(selectedRowsJSON);
|
76
|
+
}
|
77
|
+
} catch (e) {
|
78
|
+
// Fallback if JSON parsing fails
|
79
|
+
const checkboxes = tableContainer.querySelectorAll('input[type="checkbox"]:checked');
|
80
|
+
const selectedCheckboxes = Array.from(checkboxes).filter(checkbox =>
|
81
|
+
checkbox.id !== 'select-all-rows' &&
|
82
|
+
!checkbox.closest('#select-all-rows')
|
83
|
+
);
|
84
|
+
selectedRowIds = selectedCheckboxes.map(checkbox => checkbox.id);
|
85
|
+
}
|
86
|
+
|
87
|
+
// Show appropriate message
|
88
|
+
if (!selectedRowIds || selectedRowIds.length === 0) {
|
89
|
+
alert('No Selection Made');
|
90
|
+
} else {
|
91
|
+
if (actionType === 'export') {
|
92
|
+
alert(`Row ids ${selectedRowIds.join(', ')} will be exported!`);
|
93
|
+
} else if (actionType === 'delete') {
|
94
|
+
alert(`Row ids ${selectedRowIds.join(', ')} will be deleted!`);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
99
|
+
// Add event listeners when the DOM is ready
|
100
|
+
document.addEventListener('DOMContentLoaded', function() {
|
101
|
+
// Get the buttons
|
102
|
+
const exportBtn = document.getElementById('export-selected-rows-btn');
|
103
|
+
const deleteBtn = document.getElementById('delete-selected-rows-btn');
|
104
|
+
|
105
|
+
// Add click event listeners
|
106
|
+
if (exportBtn) {
|
107
|
+
exportBtn.addEventListener('click', function(e) {
|
108
|
+
e.preventDefault();
|
109
|
+
window.handleActionClick('export');
|
110
|
+
});
|
111
|
+
}
|
112
|
+
|
113
|
+
if (deleteBtn) {
|
114
|
+
deleteBtn.addEventListener('click', function(e) {
|
115
|
+
e.preventDefault();
|
116
|
+
window.handleActionClick('delete');
|
117
|
+
});
|
118
|
+
}
|
119
|
+
|
120
|
+
// Optional: Event delegation through the action bar
|
121
|
+
const actionBar = document.querySelector('.row-selection-actions-card');
|
122
|
+
if (actionBar) {
|
123
|
+
actionBar.addEventListener('click', function(e) {
|
124
|
+
const exportButton = e.target.closest('#export-selected-rows-btn');
|
125
|
+
const deleteButton = e.target.closest('#delete-selected-rows-btn');
|
126
|
+
|
127
|
+
if (exportButton) {
|
128
|
+
e.preventDefault();
|
129
|
+
window.handleActionClick('export');
|
130
|
+
} else if (deleteButton) {
|
131
|
+
e.preventDefault();
|
132
|
+
window.handleActionClick('delete');
|
133
|
+
}
|
134
|
+
});
|
135
|
+
}
|
136
|
+
});
|
137
|
+
</script>
|
data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_actions_rails.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
Custom actions content can be rendered within the Actions Bar as shown in this doc example. The component passed to `actions` will be rendered on the right of the actionsBar.
|
2
|
+
|
3
|
+
You can utilize script tags with your actions to provide your buttons with any clickable events needed.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<% column_definitions = [
|
2
|
+
{
|
3
|
+
accessor: "year",
|
4
|
+
label: "Year",
|
5
|
+
cellAccessors: ["quarter", "month", "day"],
|
6
|
+
},
|
7
|
+
{
|
8
|
+
accessor: "newEnrollments",
|
9
|
+
label: "New Enrollments",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
accessor: "scheduledMeetings",
|
13
|
+
label: "Scheduled Meetings",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
accessor: "attendanceRate",
|
17
|
+
label: "Attendance Rate",
|
18
|
+
},
|
19
|
+
{
|
20
|
+
accessor: "completedClasses",
|
21
|
+
label: "Completed Classes",
|
22
|
+
},
|
23
|
+
{
|
24
|
+
accessor: "classCompletionRate",
|
25
|
+
label: "Class Completion Rate",
|
26
|
+
},
|
27
|
+
{
|
28
|
+
accessor: "graduatedStudents",
|
29
|
+
label: "Graduated Students",
|
30
|
+
}
|
31
|
+
] %>
|
32
|
+
|
33
|
+
<%= pb_rails("advanced_table", props: {
|
34
|
+
id: "selectable_rows_with_actions",
|
35
|
+
table_data: @table_data_no_subrows,
|
36
|
+
column_definitions: column_definitions,
|
37
|
+
selectable_rows: true,
|
38
|
+
enable_toggle_expansion: "none",
|
39
|
+
show_actions_bar: false
|
40
|
+
}) %>
|
data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
`show_actions_bar` is an optional prop that renders the header at the top showing the row count. This is set to `true` by default but can be toggled off by setting it to `false`
|
@@ -15,6 +15,8 @@ examples:
|
|
15
15
|
- advanced_table_column_border_color_rails: Column Group Border Color
|
16
16
|
- advanced_table_selectable_rows_rails: Selectable Rows
|
17
17
|
- advanced_table_selectable_rows_no_subrows_rails: Selectable Rows (No Subrows)
|
18
|
+
- advanced_table_selectable_rows_actions_rails: Selectable Rows (With Actions)
|
19
|
+
- advanced_table_selectable_rows_header_rails: Selectable Rows (No Actions Bar)
|
18
20
|
|
19
21
|
react:
|
20
22
|
- advanced_table_default: Default (Required Props)
|
@@ -79,7 +79,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
79
79
|
}
|
80
80
|
if (!allChildrenChecked) {
|
81
81
|
parentRow.classList.remove("bg-row-selection");
|
82
|
-
|
82
|
+
|
83
83
|
if (this.isRowExpanded(parentRow)) {
|
84
84
|
parentRow.classList.remove("bg-silver");
|
85
85
|
parentRow.classList.add("bg-white");
|
@@ -201,15 +201,15 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
201
201
|
this.toggleElement(this.target);
|
202
202
|
}
|
203
203
|
});
|
204
|
-
|
204
|
+
|
205
205
|
this.hideCloseIcon();
|
206
|
-
|
206
|
+
|
207
207
|
const table = this.element.closest("table");
|
208
|
-
|
208
|
+
|
209
209
|
// Prevent duplicate initialization
|
210
210
|
if (table.dataset.pbAdvancedTableInitialized) return;
|
211
211
|
table.dataset.pbAdvancedTableInitialized = "true";
|
212
|
-
|
212
|
+
|
213
213
|
// Bind checkbox change handlers for all row checkboxes
|
214
214
|
const checkboxLabels = table.querySelectorAll("label[data-row-id]");
|
215
215
|
checkboxLabels.forEach((label) => {
|
@@ -219,7 +219,7 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
219
219
|
this.handleCheckboxClick(event);
|
220
220
|
});
|
221
221
|
});
|
222
|
-
|
222
|
+
|
223
223
|
// Bind nested row expansion logic
|
224
224
|
const nestedButtons = table.querySelectorAll("[data-advanced-table]");
|
225
225
|
nestedButtons.forEach((button) => {
|
@@ -233,18 +233,18 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
233
233
|
}
|
234
234
|
});
|
235
235
|
});
|
236
|
-
|
236
|
+
|
237
237
|
// Bind select-all logic for this table
|
238
238
|
const selectAllCheckbox = table.querySelector("#select-all-rows");
|
239
239
|
if (selectAllCheckbox) {
|
240
240
|
selectAllCheckbox.addEventListener("change", () => {
|
241
241
|
const checkboxInput = selectAllCheckbox.querySelector('input[type="checkbox"]');
|
242
242
|
const checkAll = checkboxInput.checked;
|
243
|
-
|
243
|
+
|
244
244
|
const checkboxes = Array.from(
|
245
245
|
table.querySelectorAll("label[data-row-id] input[type='checkbox']")
|
246
246
|
);
|
247
|
-
|
247
|
+
|
248
248
|
checkboxes.forEach((cb) => {
|
249
249
|
cb.checked = checkAll;
|
250
250
|
const rowId = cb.id;
|
@@ -260,14 +260,14 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
260
260
|
rowEl?.classList.add("bg-white");
|
261
261
|
}
|
262
262
|
});
|
263
|
-
|
263
|
+
|
264
264
|
checkboxes.forEach((cb) => this.updateParentCheckboxes(cb));
|
265
|
-
|
265
|
+
|
266
266
|
this.updateTableSelectedRowsAttribute();
|
267
267
|
});
|
268
268
|
}
|
269
269
|
}
|
270
|
-
|
270
|
+
|
271
271
|
|
272
272
|
hideCloseIcon() {
|
273
273
|
const closeIcon = this.element.querySelector(UP_ARROW_SELECTOR);
|
@@ -449,6 +449,149 @@ export default class PbAdvancedTable extends PbEnhancedElement {
|
|
449
449
|
}
|
450
450
|
}
|
451
451
|
|
452
|
+
// Isolate action bar functionality so it doesn't mix with existing functionality
|
453
|
+
class PbAdvancedTableActionBar {
|
454
|
+
constructor() {
|
455
|
+
this.init();
|
456
|
+
}
|
457
|
+
|
458
|
+
init() {
|
459
|
+
// Initialize action bars for all advanced tables with action bars
|
460
|
+
document.addEventListener('DOMContentLoaded', () => {
|
461
|
+
this.setupActionBars();
|
462
|
+
});
|
463
|
+
|
464
|
+
// Also run immediately in case DOM is already loaded
|
465
|
+
if (document.readyState === 'loading') {
|
466
|
+
// DOM is still loading
|
467
|
+
} else {
|
468
|
+
// DOM is already loaded
|
469
|
+
this.setupActionBars();
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
setupActionBars() {
|
474
|
+
const advancedTables = document.querySelectorAll('.pb_advanced_table');
|
475
|
+
|
476
|
+
advancedTables.forEach(table => {
|
477
|
+
// Only proceed if this table has both selectable rows AND an action bar
|
478
|
+
if (!this.shouldEnableActionBar(table)) return;
|
479
|
+
|
480
|
+
const actionBar = table.querySelector('.row-selection-actions-card');
|
481
|
+
if (!actionBar) return; // Skip tables without action bars
|
482
|
+
|
483
|
+
// Initialize action bar styles
|
484
|
+
this.initializeActionBar(actionBar);
|
485
|
+
|
486
|
+
// Set up checkbox listeners for this table
|
487
|
+
this.setupCheckboxListeners(table, actionBar);
|
488
|
+
});
|
489
|
+
}
|
490
|
+
|
491
|
+
shouldEnableActionBar(table) {
|
492
|
+
// Check if the table has selectable rows
|
493
|
+
const hasSelectableRows = table.querySelector('input[type="checkbox"]') !== null;
|
494
|
+
|
495
|
+
// Check if the table has a row selection action bar (not other types of action bars)
|
496
|
+
const hasRowSelectionActionBar = table.querySelector('.row-selection-actions-card') !== null;
|
497
|
+
|
498
|
+
// Additional check: look for the presence of row checkboxes with data-row-id
|
499
|
+
const hasRowCheckboxes = table.querySelector('label[data-row-id] input[type="checkbox"]') !== null;
|
500
|
+
|
501
|
+
// Only enable if ALL conditions are met:
|
502
|
+
// 1. Has selectable checkboxes
|
503
|
+
// 2. Has the specific row selection action bar
|
504
|
+
// 3. Has row checkboxes (not just other types of checkboxes)
|
505
|
+
return hasSelectableRows && hasRowSelectionActionBar && hasRowCheckboxes;
|
506
|
+
}
|
507
|
+
|
508
|
+
initializeActionBar(actionBar) {
|
509
|
+
// Set initial hidden state
|
510
|
+
Object.assign(actionBar.style, {
|
511
|
+
height: '0px',
|
512
|
+
overflow: 'hidden',
|
513
|
+
display: 'block',
|
514
|
+
opacity: '0'
|
515
|
+
});
|
516
|
+
|
517
|
+
// Remove any visibility classes
|
518
|
+
actionBar.classList.remove("p_xs", "is-visible", "show-action-card");
|
519
|
+
actionBar.classList.add("p_none");
|
520
|
+
}
|
521
|
+
|
522
|
+
setupCheckboxListeners(table, actionBar) {
|
523
|
+
// Only listen to row checkboxes (those with data-row-id), not all checkboxes
|
524
|
+
const rowCheckboxes = table.querySelectorAll('label[data-row-id] input[type="checkbox"]');
|
525
|
+
|
526
|
+
rowCheckboxes.forEach(checkbox => {
|
527
|
+
checkbox.addEventListener('change', () => {
|
528
|
+
// Use setTimeout to ensure this runs after the main checkbox logic
|
529
|
+
setTimeout(() => {
|
530
|
+
this.updateActionBarVisibility(table, actionBar);
|
531
|
+
}, 0);
|
532
|
+
});
|
533
|
+
});
|
534
|
+
|
535
|
+
// Special handling for select-all checkbox (only if it exists)
|
536
|
+
const selectAllCheckbox = table.querySelector("#select-all-rows");
|
537
|
+
if (selectAllCheckbox) {
|
538
|
+
const selectAllInput = selectAllCheckbox.querySelector('input[type="checkbox"]');
|
539
|
+
if (selectAllInput) {
|
540
|
+
selectAllInput.addEventListener('change', () => {
|
541
|
+
// Use setTimeout to ensure this runs after the main select-all logic
|
542
|
+
setTimeout(() => {
|
543
|
+
this.updateActionBarVisibility(table, actionBar);
|
544
|
+
}, 10); // Slightly longer delay for select-all to ensure all row checkboxes are updated
|
545
|
+
});
|
546
|
+
}
|
547
|
+
}
|
548
|
+
}
|
549
|
+
|
550
|
+
updateActionBarVisibility(table, actionBar) {
|
551
|
+
// Only count row checkboxes (those with data-row-id), not all checkboxes
|
552
|
+
const rowCheckboxes = table.querySelectorAll('label[data-row-id] input[type="checkbox"]');
|
553
|
+
|
554
|
+
// Get all checked row checkboxes
|
555
|
+
const selectedRowCheckboxes = Array.from(rowCheckboxes).filter(cb => cb.checked);
|
556
|
+
|
557
|
+
// Get the selected count
|
558
|
+
const selectedCount = selectedRowCheckboxes.length;
|
559
|
+
|
560
|
+
if (selectedCount > 0) {
|
561
|
+
this.showActionBar(actionBar, selectedCount);
|
562
|
+
} else {
|
563
|
+
this.hideActionBar(actionBar);
|
564
|
+
}
|
565
|
+
}
|
566
|
+
|
567
|
+
showActionBar(actionBar, selectedCount) {
|
568
|
+
// Show action bar directly
|
569
|
+
actionBar.style.height = 'auto';
|
570
|
+
actionBar.style.overflow = 'visible';
|
571
|
+
actionBar.style.opacity = '1';
|
572
|
+
actionBar.classList.remove("p_none");
|
573
|
+
actionBar.classList.add("p_xs", "is-visible", "show-action-card");
|
574
|
+
|
575
|
+
// Update the count
|
576
|
+
const countElement = actionBar.querySelector(".selected-count");
|
577
|
+
if (countElement) {
|
578
|
+
countElement.textContent = `${selectedCount} Selected`;
|
579
|
+
}
|
580
|
+
}
|
581
|
+
|
582
|
+
hideActionBar(actionBar) {
|
583
|
+
// Hide action bar directly
|
584
|
+
actionBar.style.height = '0px';
|
585
|
+
actionBar.style.overflow = 'hidden';
|
586
|
+
actionBar.style.opacity = '0';
|
587
|
+
actionBar.classList.add("p_none");
|
588
|
+
actionBar.classList.remove("p_xs", "is-visible", "show-action-card");
|
589
|
+
}
|
590
|
+
}
|
591
|
+
|
592
|
+
// Initialize the isolated action bar functionality
|
593
|
+
new PbAdvancedTableActionBar();
|
594
|
+
|
452
595
|
window.expandAllRows = (element) => {
|
453
596
|
PbAdvancedTable.handleToggleAllHeaders(element);
|
454
597
|
};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%= pb_rails("card", props: {
|
2
|
+
border_none: object.is_visible,
|
3
|
+
classname: object.classname,
|
4
|
+
padding: object.is_visible ? "xs" : "none",
|
5
|
+
data: {
|
6
|
+
action_bar: true
|
7
|
+
}
|
8
|
+
}) do %>
|
9
|
+
<%= pb_rails("flex", props: { align_items: "center", justify: "between" }) do %>
|
10
|
+
<%= pb_rails("caption", props: { color: "light", padding_left: "xs", size: "xs" }) do %>
|
11
|
+
<span class="selected-count"><%= object.selected_count %> Selected</span>
|
12
|
+
<% end %>
|
13
|
+
<%= pb_rails("flex/flex_item") do %>
|
14
|
+
<%= pb_rails("flex") do %>
|
15
|
+
<% if object.actions.present? %>
|
16
|
+
<% object.actions.each do |action| %>
|
17
|
+
<%= action %>
|
18
|
+
<% end %>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Playbook
|
4
|
+
module PbAdvancedTable
|
5
|
+
class TableActionBar < Playbook::KitBase
|
6
|
+
prop :actions, type: Playbook::Props::Array,
|
7
|
+
default: []
|
8
|
+
prop :is_visible, type: Playbook::Props::Boolean,
|
9
|
+
default: false
|
10
|
+
prop :selected_count, type: Playbook::Props::Number,
|
11
|
+
default: 0
|
12
|
+
|
13
|
+
def classname
|
14
|
+
# Just use row-selection-actions-card as the base class
|
15
|
+
generate_classname("row-selection-actions-card", separator: " ")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -15,6 +15,8 @@ module Playbook
|
|
15
15
|
default: "scroll"
|
16
16
|
prop :selectable_rows, type: Playbook::Props::Boolean,
|
17
17
|
default: false
|
18
|
+
prop :show_actions_bar, type: Playbook::Props::Boolean,
|
19
|
+
default: true
|
18
20
|
|
19
21
|
def classname
|
20
22
|
additional_classes = []
|
@@ -27,6 +29,7 @@ module Playbook
|
|
27
29
|
def th_classname(is_first_column: false)
|
28
30
|
additional_classes = []
|
29
31
|
additional_classes << "pinned-left" if is_first_column && responsive == "scroll" && !selectable_rows
|
32
|
+
additional_classes << "header-cells-with-actions" if selectable_rows && show_actions_bar
|
30
33
|
|
31
34
|
generate_classname("table-header-cells", *additional_classes, separator: " ")
|
32
35
|
end
|
@@ -46,6 +49,7 @@ module Playbook
|
|
46
49
|
if selectable_rows
|
47
50
|
additional_classes = []
|
48
51
|
additional_classes << "table-header-cells-custom"
|
52
|
+
additional_classes << "header-cells-with-actions" if show_actions_bar
|
49
53
|
additional_classes << "checkbox-cell-header"
|
50
54
|
additional_classes << "pinned-left" if responsive == "scroll"
|
51
55
|
pb_rails("table/table_header", props: {
|