playbook_ui_docs 14.8.0.pre.alpha.PLAY16254545 → 14.8.0.pre.alpha.play1648heightglobalprops4606
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d97db2e39cfc6ee27efbcfaf85977399003b39fe3bf389389b7a28826be67b9
|
4
|
+
data.tar.gz: 1fe46159e6bd0e0bc61fc568cee38f37ca442a74fcbb0feae6ac627a2cb32723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a66ad50e885da2ef7d0272f25daf0b2c5341daee7a27d4124d97ed123fdddc1156f9591de96a42b8d2c36c7d679a59b642e96fd2c5aa1479641928aed57cd86
|
7
|
+
data.tar.gz: 10e17eb1ae5a331a5cd0d3936f4104d9b4b5518e2225f3ccb3757fe9b61143f814fab29b5a54ad80b3807fa369b9f8114bdd3a574bd44d4ebab87bc7727c0cdf
|
@@ -1,7 +1,84 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
name:
|
5
|
-
|
6
|
-
|
7
|
-
}) %>
|
1
|
+
<% checkboxes = [
|
2
|
+
{ name: 'Coffee', id: 'coffee', checked: false },
|
3
|
+
{ name: 'Ice Cream', id: 'ice-cream', checked: false },
|
4
|
+
{ name: 'Chocolate', id: 'chocolate', checked: true }
|
5
|
+
] %>
|
6
|
+
|
7
|
+
<%= pb_rails("table", props: { container: false, size: "md" }) do %>
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<th>
|
11
|
+
<%= pb_rails("checkbox", props: {
|
12
|
+
checked: true,
|
13
|
+
text: "Uncheck All",
|
14
|
+
value: "checkbox-value",
|
15
|
+
name: "main-checkbox",
|
16
|
+
indeterminate: true,
|
17
|
+
id: "indeterminate-checkbox"
|
18
|
+
}) %>
|
19
|
+
</th>
|
20
|
+
</tr>
|
21
|
+
</thead>
|
22
|
+
|
23
|
+
<tbody>
|
24
|
+
<% checkboxes.each do |checkbox| %>
|
25
|
+
<tr>
|
26
|
+
<td>
|
27
|
+
<%= pb_rails("checkbox", props: {
|
28
|
+
checked: checkbox[:checked],
|
29
|
+
text: checkbox[:name],
|
30
|
+
value: checkbox[:id],
|
31
|
+
name: "#{checkbox[:id]}-indeterminate-checkbox",
|
32
|
+
id: "#{checkbox[:id]}-indeterminate-checkbox",
|
33
|
+
}) %>
|
34
|
+
</td>
|
35
|
+
</tr>
|
36
|
+
<% end %>
|
37
|
+
</tbody>
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
<script>
|
41
|
+
document.addEventListener('DOMContentLoaded', function() {
|
42
|
+
const mainCheckboxWrapper = document.getElementById('indeterminate-checkbox');
|
43
|
+
const mainCheckbox = document.getElementsByName("main-checkbox")[0];
|
44
|
+
const childCheckboxes = document.querySelectorAll('input[type="checkbox"][id$="indeterminate-checkbox"]');
|
45
|
+
|
46
|
+
const updateMainCheckbox = () => {
|
47
|
+
// Count the number of checked child checkboxes
|
48
|
+
const checkedCount = Array.from(childCheckboxes).filter(cb => cb.checked).length;
|
49
|
+
// Determine if the main checkbox should be in an indeterminate state
|
50
|
+
const indeterminate = checkedCount > 0 && checkedCount < childCheckboxes.length;
|
51
|
+
|
52
|
+
// Set the main checkbox states
|
53
|
+
mainCheckbox.indeterminate = indeterminate;
|
54
|
+
mainCheckbox.checked = checkedCount > 0;
|
55
|
+
|
56
|
+
// Determine the main checkbox label based on the number of checked checkboxes
|
57
|
+
const text = checkedCount === 0 ? 'Check All' : 'Uncheck All';
|
58
|
+
|
59
|
+
// Determine the icon class to add and remove based on the number of checked checkboxes
|
60
|
+
const iconClassToAdd = checkedCount === 0 ? 'pb_checkbox_checkmark' : 'pb_checkbox_indeterminate';
|
61
|
+
const iconClassToRemove = checkedCount === 0 ? 'pb_checkbox_indeterminate' : 'pb_checkbox_checkmark';
|
62
|
+
|
63
|
+
// Update main checkbox label
|
64
|
+
mainCheckboxWrapper.getElementsByClassName('pb_body_kit')[0].textContent = text;
|
65
|
+
|
66
|
+
// Add and remove the icon class to the main checkbox wrapper
|
67
|
+
mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.add(iconClassToAdd);
|
68
|
+
mainCheckboxWrapper.querySelector('[data-pb-checkbox-icon-span]').classList.remove(iconClassToRemove);
|
69
|
+
|
70
|
+
// Toggle the visibility of the checkbox icon based on the indeterminate state
|
71
|
+
mainCheckboxWrapper.getElementsByClassName("indeterminate_icon")[0].classList.toggle('hidden', !indeterminate);
|
72
|
+
mainCheckboxWrapper.getElementsByClassName("check_icon")[0].classList.toggle('hidden', indeterminate);
|
73
|
+
};
|
74
|
+
|
75
|
+
mainCheckbox.addEventListener('change', function() {
|
76
|
+
childCheckboxes.forEach(cb => cb.checked = this.checked);
|
77
|
+
updateMainCheckbox();
|
78
|
+
});
|
79
|
+
|
80
|
+
childCheckboxes.forEach(cb => {
|
81
|
+
cb.addEventListener('change', updateMainCheckbox);
|
82
|
+
});
|
83
|
+
});
|
84
|
+
</script>
|