playbook_ui_docs 14.8.0.pre.alpha.play1648heightglobalprops4606 → 14.8.0.pre.alpha.revert3916revert3893PBNTR667railstypeaheadformintegration4565

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: 2d97db2e39cfc6ee27efbcfaf85977399003b39fe3bf389389b7a28826be67b9
4
- data.tar.gz: 1fe46159e6bd0e0bc61fc568cee38f37ca442a74fcbb0feae6ac627a2cb32723
3
+ metadata.gz: '034329dd9e821ebcd88723d5ea01d5da58e1fa4dccb5e1f4742ddf82d98014cc'
4
+ data.tar.gz: 4758bbd46b10aac25e1ec5324949d50501c9f25225e99bb5b5806b743652096c
5
5
  SHA512:
6
- metadata.gz: 2a66ad50e885da2ef7d0272f25daf0b2c5341daee7a27d4124d97ed123fdddc1156f9591de96a42b8d2c36c7d679a59b642e96fd2c5aa1479641928aed57cd86
7
- data.tar.gz: 10e17eb1ae5a331a5cd0d3936f4104d9b4b5518e2225f3ccb3757fe9b61143f814fab29b5a54ad80b3807fa369b9f8114bdd3a574bd44d4ebab87bc7727c0cdf
6
+ metadata.gz: 9c302e09b241ff4b27635fdf6c11bb122a7a74a8bd9bcf3c07cba824e774e487934a34ca8553ea5a00cc42f349c03c1fe2da1aedb02ae8f69e5abcf84f21f9b1
7
+ data.tar.gz: 3a70062b639fd9a3c0f07906c701fdc800009ebe1e1381966b4cf5d591e6d98724a58af2462867710a4d5d82d14662a7367484428c623811350c5891ea7268c9
@@ -1,84 +1,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>
1
+ <%= pb_rails("checkbox" , props: {
2
+ text: "Select ",
3
+ value: "checkbox-value",
4
+ name: "main",
5
+ indeterminate: true,
6
+ id: "test-indeterminate-js"
7
+ }) %>
@@ -23,7 +23,7 @@
23
23
  %>
24
24
 
25
25
  <%= pb_form_with(scope: :example, url: "", method: :get) do |form| %>
26
- <%= form.typeahead :example_user, props: { data: { typeahead_example1: true, user: {} }, placeholder: "Search for a user" } %>
26
+ <%= form.typeahead :example_typeahead, props: { data: { typeahead_example1: true, user: {} }, label: true, placeholder: "Search for a user" } %>
27
27
  <%= form.text_field :example_text_field, props: { label: true } %>
28
28
  <%= form.phone_number_field :example_phone_number_field, props: { label: "Example phone field" } %>
29
29
  <%= form.email_field :example_email_field, props: { label: true } %>
@@ -92,7 +92,7 @@
92
92
  const selectedUserData = JSON.parse(selectedUserJSON)
93
93
 
94
94
  // set the input field's value
95
- event.target.querySelector('input[name=example_user]').value = selectedUserData.login
95
+ event.target.querySelector('input[name=example_typeahead]').value = selectedUserData.login
96
96
 
97
97
  // log the selected option's dataset
98
98
  console.log('The selected user data:')
@@ -1,5 +1,5 @@
1
1
  <%= pb_form_with(scope: :example, url: "", method: :get, loading: true) do |form| %>
2
- <%= form.text_field :example_text_field, props: { label: true } %>
2
+ <%= form.text_field :example_text_field_loading, props: { label: true } %>
3
3
 
4
4
  <%= form.actions do |action| %>
5
5
  <%= action.submit %>
@@ -22,23 +22,74 @@
22
22
  %>
23
23
 
24
24
  <%= pb_form_with(scope: :example, method: :get, url: "", validate: true) do |form| %>
25
- <%= form.text_field :example_text_field, props: { label: true, required: true } %>
26
- <%= form.phone_number_field :example_phone_number_field, props: { label: "Example phone field" } %>
27
- <%= form.email_field :example_email_field, props: { label: true, required: true } %>
28
- <%= form.number_field :example_number_field, props: { label: true, required: true } %>
29
- <%= form.search_field :example_project_number, props: { label: true, required: true, validation: { pattern: "[0-9]{2}-[0-9]{5}", message: "Please enter a valid project number (example: 33-12345)." } } %>
30
- <%= form.password_field :example_password_field, props: { label: true, required: true } %>
31
- <%= form.url_field :example_url_field, props: { label: true, required: true } %>
32
- <%= form.text_area :example_text_area, props: { label: true, required: true } %>
33
- <%= form.dropdown_field :example_dropdown, props: { label: true, options: example_dropdown_options, required: true } %>
34
- <%= form.select :example_select, [ ["Yes", 1], ["No", 2] ], props: { label: true, blank_selection: "Select One...", required: true } %>
35
- <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
25
+ <%= form.typeahead :example_typeahead_validation, props: { data: { typeahead_example2: true, user: {} }, label: true, placeholder: "Search for a user", required: true, validation: { message: "Please select a user." } } %>
26
+ <%= form.text_field :example_text_field_validation, props: { label: true, required: true } %>
27
+ <%= form.phone_number_field :example_phone_number_field_validation, props: { label: "Example phone field" } %>
28
+ <%= form.email_field :example_email_field_validation, props: { label: true, required: true } %>
29
+ <%= form.number_field :example_number_field_validation, props: { label: true, required: true } %>
30
+ <%= form.search_field :example_project_number_validation, props: { label: true, required: true, validation: { pattern: "[0-9]{2}-[0-9]{5}", message: "Please enter a valid project number (example: 33-12345)." } } %>
31
+ <%= form.password_field :example_password_field_validation, props: { label: true, required: true } %>
32
+ <%= form.url_field :example_url_field_validation, props: { label: true, required: true } %>
33
+ <%= form.text_area :example_text_area_validation, props: { label: true, required: true } %>
34
+ <%= form.dropdown_field :example_dropdown_validation, props: { label: true, options: example_dropdown_options, required: true } %>
35
+ <%= form.select :example_select_validation, [ ["Yes", 1], ["No", 2] ], props: { label: true, blank_selection: "Select One...", required: true } %>
36
+ <%= form.collection_select :example_collection_select_validation, example_collection, :value, :name, props: { label: true, blank_selection: "Select One...", required: true } %>
36
37
  <%= form.check_box :example_checkbox, props: { text: "Example Checkbox", label: true, required: true } %>
37
38
  <%= form.date_picker :example_date_picker_2, props: { label: true, required: true } %>
38
- <%= form.star_rating_field :example_star_rating, props: { variant: "interactive", label: true, required: true } %>
39
+ <%= form.star_rating_field :example_star_rating_validation, props: { variant: "interactive", label: true, required: true } %>
39
40
 
40
41
  <%= form.actions do |action| %>
41
42
  <%= action.submit %>
42
43
  <%= action.button props: { type: "reset", text: "Cancel", variant: "secondary" } %>
43
44
  <% end %>
44
45
  <% end %>
46
+
47
+ <!-- form.typeahead user results example template -->
48
+ <template data-typeahead-example-result-option>
49
+ <%= pb_rails("user", props: {
50
+ name: tag(:slot, name: "name"),
51
+ orientation: "horizontal",
52
+ align: "left",
53
+ avatar_url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII=",
54
+ avatar: true
55
+ }) %>
56
+ </template>
57
+
58
+ <!-- form.typeahead JS example implementation -->
59
+ <%= javascript_tag defer: "defer" do %>
60
+ document.addEventListener("pb-typeahead-kit-search", function(event) {
61
+ if (!event.target.dataset || !event.target.dataset.typeaheadExample2) return
62
+
63
+ fetch(`https://api.github.com/search/users?q=${encodeURIComponent(event.detail.searchingFor)}`)
64
+ .then(response => response.json())
65
+ .then((result) => {
66
+ const resultOptionTemplate = document.querySelector("[data-typeahead-example-result-option]")
67
+
68
+ event.detail.setResults((result.items || []).map((user) => {
69
+ const wrapper = resultOptionTemplate.content.cloneNode(true)
70
+ wrapper.children[0].dataset.user = JSON.stringify(user)
71
+ wrapper.querySelector('slot[name="name"]').replaceWith(user.login)
72
+ wrapper.querySelector('img').dataset.src = user.avatar_url
73
+ return wrapper
74
+ }))
75
+ })
76
+ })
77
+
78
+
79
+ document.addEventListener("pb-typeahead-kit-result-option-selected", function(event) {
80
+ if (!event.target.dataset.typeaheadExample2) return
81
+
82
+ const selectedUserJSON = event.detail.selected.firstElementChild.dataset.user
83
+ const selectedUserData = JSON.parse(selectedUserJSON)
84
+
85
+ // set the input field's value
86
+ event.target.querySelector('input[name=example_typeahead_validation]').value = selectedUserData.login
87
+
88
+ // log the selected option's dataset
89
+ console.log('The selected user data:')
90
+ console.dir(selectedUserData)
91
+
92
+ // do even more with the data later - TBD
93
+ event.target.dataset.user = selectedUserJSON
94
+ })
95
+ <% end %>
@@ -6,7 +6,6 @@
6
6
  value: "selected_with_icon",
7
7
  checked: true,
8
8
  icon: true,
9
-
10
9
  }) do %>
11
10
  Selected, with icon
12
11
  <% end %>
@@ -37,4 +36,4 @@
37
36
  Disabled
38
37
  <% end %>
39
38
 
40
- </div>
39
+ </div>