playbook_ui 13.24.0 → 13.25.0.pre.alpha.PBNTR291Dropdownrailsv22812

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/app/pb_kits/playbook/_playbook.scss +2 -0
  3. data/app/pb_kits/playbook/index.js +2 -0
  4. data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +10 -14
  5. data/app/pb_kits/playbook/pb_advanced_table/table_body.html.erb +5 -9
  6. data/app/pb_kits/playbook/pb_advanced_table/table_header.html.erb +2 -6
  7. data/app/pb_kits/playbook/pb_advanced_table/table_row.html.erb +2 -6
  8. data/app/pb_kits/playbook/pb_avatar/avatar.html.erb +1 -6
  9. data/app/pb_kits/playbook/pb_avatar_action_button/avatar_action_button.html.erb +1 -6
  10. data/app/pb_kits/playbook/pb_background/_background.tsx +7 -5
  11. data/app/pb_kits/playbook/pb_background/background.html.erb +2 -11
  12. data/app/pb_kits/playbook/pb_badge/badge.html.erb +1 -6
  13. data/app/pb_kits/playbook/pb_bar_graph/_bar_graph.tsx +41 -6
  14. data/app/pb_kits/playbook/pb_bar_graph/bar_graph.rb +4 -0
  15. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_negative_numbers.html.erb +23 -0
  16. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_negative_numbers.jsx +35 -0
  17. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_secondary_y_axis.html.erb +26 -0
  18. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_secondary_y_axis.jsx +36 -0
  19. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_secondary_y_axis.md +3 -0
  20. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_stacked.html.erb +22 -0
  21. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_stacked.jsx +34 -0
  22. data/app/pb_kits/playbook/pb_bar_graph/docs/_bar_graph_stacked.md +1 -0
  23. data/app/pb_kits/playbook/pb_bar_graph/docs/example.yml +6 -0
  24. data/app/pb_kits/playbook/pb_bar_graph/docs/index.js +3 -0
  25. data/app/pb_kits/playbook/pb_body/_body.scss +3 -3
  26. data/app/pb_kits/playbook/pb_body/_body.tsx +1 -1
  27. data/app/pb_kits/playbook/pb_body/body.html.erb +1 -6
  28. data/app/pb_kits/playbook/pb_bread_crumbs/bread_crumb_item.html.erb +1 -6
  29. data/app/pb_kits/playbook/pb_bread_crumbs/bread_crumbs.html.erb +2 -7
  30. data/app/pb_kits/playbook/pb_button/_button.scss +1 -1
  31. data/app/pb_kits/playbook/pb_button/button.html.erb +2 -3
  32. data/app/pb_kits/playbook/pb_button_toolbar/button_toolbar.html.erb +2 -7
  33. data/app/pb_kits/playbook/pb_caption/caption.html.erb +1 -6
  34. data/app/pb_kits/playbook/pb_card/card.html.erb +1 -7
  35. data/app/pb_kits/playbook/pb_card/card_body.html.erb +1 -6
  36. data/app/pb_kits/playbook/pb_card/card_header.html.erb +1 -6
  37. data/app/pb_kits/playbook/pb_checkbox/_checkbox.scss +49 -0
  38. data/app/pb_kits/playbook/pb_checkbox/_checkbox.tsx +3 -0
  39. data/app/pb_kits/playbook/pb_checkbox/checkbox.html.erb +1 -6
  40. data/app/pb_kits/playbook/pb_checkbox/checkbox.rb +2 -1
  41. data/app/pb_kits/playbook/pb_checkbox/checkbox.test.js +14 -0
  42. data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_disabled.html.erb +23 -0
  43. data/app/pb_kits/playbook/pb_checkbox/docs/_checkbox_disabled.jsx +29 -0
  44. data/app/pb_kits/playbook/pb_checkbox/docs/example.yml +2 -0
  45. data/app/pb_kits/playbook/pb_checkbox/docs/index.js +1 -0
  46. data/app/pb_kits/playbook/pb_circle_icon_button/circle_icon_button.html.erb +1 -6
  47. data/app/pb_kits/playbook/pb_collapsible/collapsible.html.erb +1 -6
  48. data/app/pb_kits/playbook/pb_collapsible/collapsible_content.html.erb +1 -6
  49. data/app/pb_kits/playbook/pb_collapsible/collapsible_main.html.erb +1 -7
  50. data/app/pb_kits/playbook/pb_contact/contact.html.erb +1 -6
  51. data/app/pb_kits/playbook/pb_currency/currency.html.erb +1 -6
  52. data/app/pb_kits/playbook/pb_currency/docs/_currency_alignment_swift.md +43 -0
  53. data/app/pb_kits/playbook/pb_currency/docs/_currency_props_swift.md +12 -0
  54. data/app/pb_kits/playbook/pb_currency/docs/_currency_size_swift.md +31 -0
  55. data/app/pb_kits/playbook/pb_currency/docs/example.yml +5 -0
  56. data/app/pb_kits/playbook/pb_dashboard_value/dashboard_value.html.erb +1 -6
  57. data/app/pb_kits/playbook/pb_date/date.html.erb +1 -6
  58. data/app/pb_kits/playbook/pb_date_picker/date_picker.html.erb +2 -6
  59. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_on_change.md +3 -1
  60. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_on_close.md +3 -1
  61. data/app/pb_kits/playbook/pb_date_picker/docs/_date_picker_quick_pick_range_limit.md +1 -1
  62. data/app/pb_kits/playbook/pb_date_range_inline/date_range_inline.html.erb +1 -5
  63. data/app/pb_kits/playbook/pb_date_range_stacked/date_range_stacked.html.erb +1 -5
  64. data/app/pb_kits/playbook/pb_date_range_stacked/docs/_date_range_stacked_default_swift.md +14 -0
  65. data/app/pb_kits/playbook/pb_date_range_stacked/docs/_date_range_stacked_props_swift.md +9 -0
  66. data/app/pb_kits/playbook/pb_date_range_stacked/docs/example.yml +4 -0
  67. data/app/pb_kits/playbook/pb_date_stacked/date_stacked.html.erb +1 -5
  68. data/app/pb_kits/playbook/pb_date_time/date_time.html.erb +1 -6
  69. data/app/pb_kits/playbook/pb_date_time_stacked/date_time_stacked.html.erb +1 -7
  70. data/app/pb_kits/playbook/pb_date_year_stacked/date_year_stacked.html.erb +1 -5
  71. data/app/pb_kits/playbook/pb_detail/detail.html.erb +1 -6
  72. data/app/pb_kits/playbook/pb_dialog/_dialog.scss +4 -2
  73. data/app/pb_kits/playbook/pb_dialog/dialog.html.erb +1 -6
  74. data/app/pb_kits/playbook/pb_dialog/dialog_body.html.erb +2 -7
  75. data/app/pb_kits/playbook/pb_dialog/dialog_footer.html.erb +1 -5
  76. data/app/pb_kits/playbook/pb_dialog/dialog_header.html.erb +2 -6
  77. data/app/pb_kits/playbook/pb_dialog/docs/example.yml +1 -1
  78. data/app/pb_kits/playbook/pb_dropdown/_dropdown.scss +164 -0
  79. data/app/pb_kits/playbook/pb_dropdown/_dropdown.tsx +253 -0
  80. data/app/pb_kits/playbook/pb_dropdown/context/index.tsx +5 -0
  81. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.html.erb +10 -0
  82. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.jsx +32 -0
  83. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_default.md +1 -0
  84. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.html.erb +17 -0
  85. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.jsx +42 -0
  86. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_subcomponent_structure.md +7 -0
  87. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.jsx +84 -0
  88. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete.md +1 -0
  89. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.jsx +101 -0
  90. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_autocomplete_and_custom_display.md +1 -0
  91. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.html.erb +60 -0
  92. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.jsx +104 -0
  93. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_display.md +5 -0
  94. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.html.erb +45 -0
  95. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.jsx +63 -0
  96. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_options.md +1 -0
  97. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.html.erb +17 -0
  98. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.jsx +48 -0
  99. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_padding.md +1 -0
  100. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.html.erb +47 -0
  101. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.jsx +77 -0
  102. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_custom_trigger.md +1 -0
  103. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_external_control.jsx +59 -0
  104. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_hook.jsx +72 -0
  105. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.html.erb +10 -0
  106. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.jsx +39 -0
  107. data/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_with_label.md +1 -0
  108. data/app/pb_kits/playbook/pb_dropdown/docs/example.yml +23 -0
  109. data/app/pb_kits/playbook/pb_dropdown/docs/index.js +11 -0
  110. data/app/pb_kits/playbook/pb_dropdown/dropdown.html.erb +21 -0
  111. data/app/pb_kits/playbook/pb_dropdown/dropdown.rb +20 -0
  112. data/app/pb_kits/playbook/pb_dropdown/dropdown.test.jsx +207 -0
  113. data/app/pb_kits/playbook/pb_dropdown/dropdown_container.html.erb +15 -0
  114. data/app/pb_kits/playbook/pb_dropdown/dropdown_container.rb +19 -0
  115. data/app/pb_kits/playbook/pb_dropdown/dropdown_option.html.erb +22 -0
  116. data/app/pb_kits/playbook/pb_dropdown/dropdown_option.rb +22 -0
  117. data/app/pb_kits/playbook/pb_dropdown/dropdown_trigger.html.erb +38 -0
  118. data/app/pb_kits/playbook/pb_dropdown/dropdown_trigger.rb +30 -0
  119. data/app/pb_kits/playbook/pb_dropdown/hooks/useDropdown.tsx +17 -0
  120. data/app/pb_kits/playbook/pb_dropdown/hooks/useHandleOnKeydown.tsx +61 -0
  121. data/app/pb_kits/playbook/pb_dropdown/index.js +154 -0
  122. data/app/pb_kits/playbook/pb_dropdown/keyboard_accessibility.js +77 -0
  123. data/app/pb_kits/playbook/pb_dropdown/scss_partials/_dropdown_animation.scss +18 -0
  124. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownContainer.tsx +109 -0
  125. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownOption.tsx +118 -0
  126. data/app/pb_kits/playbook/pb_dropdown/subcomponents/DropdownTrigger.tsx +190 -0
  127. data/app/pb_kits/playbook/pb_dropdown/utilities/clickOutsideHelper.tsx +41 -0
  128. data/app/pb_kits/playbook/pb_dropdown/utilities/index.ts +2 -0
  129. data/app/pb_kits/playbook/pb_dropdown/utilities/subComponentHelper.tsx +61 -0
  130. data/app/pb_kits/playbook/pb_file_upload/file_upload.html.erb +1 -6
  131. data/app/pb_kits/playbook/pb_filter/filter.html.erb +1 -5
  132. data/app/pb_kits/playbook/pb_fixed_confirmation_toast/fixed_confirmation_toast.html.erb +1 -6
  133. data/app/pb_kits/playbook/pb_flex/flex.html.erb +1 -5
  134. data/app/pb_kits/playbook/pb_flex/flex_item.html.erb +2 -6
  135. data/app/pb_kits/playbook/pb_form_group/form_group.html.erb +1 -6
  136. data/app/pb_kits/playbook/pb_form_pill/form_pill.html.erb +1 -1
  137. data/app/pb_kits/playbook/pb_hashtag/hashtag.html.erb +1 -6
  138. data/app/pb_kits/playbook/pb_highlight/highlight.html.erb +1 -5
  139. data/app/pb_kits/playbook/pb_home_address_street/home_address_street.html.erb +1 -5
  140. data/app/pb_kits/playbook/pb_icon_circle/_icon_circle.scss +1 -1
  141. data/app/pb_kits/playbook/pb_icon_circle/_icon_circle.tsx +1 -1
  142. data/app/pb_kits/playbook/pb_icon_circle/icon_circle.html.erb +2 -7
  143. data/app/pb_kits/playbook/pb_icon_circle/icon_circle.rb +1 -1
  144. data/app/pb_kits/playbook/pb_icon_circle/icon_circle.test.js +3 -3
  145. data/app/pb_kits/playbook/pb_icon_stat_value/icon_stat_value.html.erb +1 -6
  146. data/app/pb_kits/playbook/pb_icon_value/icon_value.html.erb +1 -6
  147. data/app/pb_kits/playbook/pb_label_pill/label_pill.html.erb +1 -6
  148. data/app/pb_kits/playbook/pb_label_value/label_value.html.erb +1 -6
  149. data/app/pb_kits/playbook/pb_layout/body.html.erb +1 -5
  150. data/app/pb_kits/playbook/pb_layout/footer.html.erb +1 -5
  151. data/app/pb_kits/playbook/pb_layout/header.html.erb +1 -5
  152. data/app/pb_kits/playbook/pb_layout/item.html.erb +1 -5
  153. data/app/pb_kits/playbook/pb_layout/layout.html.erb +1 -5
  154. data/app/pb_kits/playbook/pb_layout/sidebar.html.erb +1 -5
  155. data/app/pb_kits/playbook/pb_list/_list_item.tsx +2 -2
  156. data/app/pb_kits/playbook/pb_list/item.html.erb +2 -8
  157. data/app/pb_kits/playbook/pb_list/list.html.erb +2 -8
  158. data/app/pb_kits/playbook/pb_loading_inline/loading_inline.html.erb +1 -6
  159. data/app/pb_kits/playbook/pb_message/message.html.erb +1 -6
  160. data/app/pb_kits/playbook/pb_message/message_mention.html.erb +1 -6
  161. data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.html.erb +1 -6
  162. data/app/pb_kits/playbook/pb_multiple_users/multiple_users.html.erb +1 -6
  163. data/app/pb_kits/playbook/pb_multiple_users_stacked/multiple_users_stacked.html.erb +1 -6
  164. data/app/pb_kits/playbook/pb_nav/item.html.erb +3 -14
  165. data/app/pb_kits/playbook/pb_nav/nav.html.erb +1 -6
  166. data/app/pb_kits/playbook/pb_online_status/online_status.html.erb +2 -6
  167. data/app/pb_kits/playbook/pb_pagination/pagination.html.erb +1 -6
  168. data/app/pb_kits/playbook/pb_passphrase/passphrase.html.erb +1 -1
  169. data/app/pb_kits/playbook/pb_person/person.html.erb +7 -12
  170. data/app/pb_kits/playbook/pb_person_contact/person_contact.html.erb +1 -6
  171. data/app/pb_kits/playbook/pb_pill/pill.html.erb +1 -6
  172. data/app/pb_kits/playbook/pb_popover/popover.html.erb +1 -6
  173. data/app/pb_kits/playbook/pb_progress_pills/progress_pills.html.erb +2 -6
  174. data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.html.erb +3 -0
  175. data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.jsx +16 -0
  176. data/app/pb_kits/playbook/pb_progress_simple/docs/_progress_simple_flex.md +1 -0
  177. data/app/pb_kits/playbook/pb_progress_simple/docs/example.yml +2 -0
  178. data/app/pb_kits/playbook/pb_progress_simple/docs/index.js +1 -0
  179. data/app/pb_kits/playbook/pb_progress_simple/progress_simple.html.erb +3 -6
  180. data/app/pb_kits/playbook/pb_progress_simple/progress_simple.rb +1 -1
  181. data/app/pb_kits/playbook/pb_progress_step/progress_step.html.erb +1 -5
  182. data/app/pb_kits/playbook/pb_progress_step/progress_step_item.html.erb +1 -5
  183. data/app/pb_kits/playbook/pb_radio/_radio.scss +35 -0
  184. data/app/pb_kits/playbook/pb_radio/_radio.tsx +3 -0
  185. data/app/pb_kits/playbook/pb_radio/docs/_radio_alignment.jsx +4 -1
  186. data/app/pb_kits/playbook/pb_radio/docs/_radio_default.jsx +4 -1
  187. data/app/pb_kits/playbook/pb_radio/docs/_radio_disabled.html.erb +26 -0
  188. data/app/pb_kits/playbook/pb_radio/docs/_radio_disabled.jsx +31 -0
  189. data/app/pb_kits/playbook/pb_radio/docs/_radio_error.jsx +2 -1
  190. data/app/pb_kits/playbook/pb_radio/docs/example.yml +2 -0
  191. data/app/pb_kits/playbook/pb_radio/docs/index.js +1 -0
  192. data/app/pb_kits/playbook/pb_radio/radio.html.erb +2 -8
  193. data/app/pb_kits/playbook/pb_radio/radio.rb +5 -0
  194. data/app/pb_kits/playbook/pb_radio/radio.test.js +17 -0
  195. data/app/pb_kits/playbook/pb_section_separator/_section_separator.scss +6 -2
  196. data/app/pb_kits/playbook/pb_section_separator/_section_separator_mixin.scss +11 -1
  197. data/app/pb_kits/playbook/pb_section_separator/section_separator.html.erb +1 -6
  198. data/app/pb_kits/playbook/pb_select/select.html.erb +1 -5
  199. data/app/pb_kits/playbook/pb_selectable_card/selectable_card.html.erb +1 -5
  200. data/app/pb_kits/playbook/pb_selectable_card_icon/selectable_card_icon.html.erb +1 -4
  201. data/app/pb_kits/playbook/pb_selectable_icon/selectable_icon.html.erb +1 -5
  202. data/app/pb_kits/playbook/pb_selectable_list/selectable_list.html.erb +1 -6
  203. data/app/pb_kits/playbook/pb_selectable_list/selectable_list_item.html.erb +1 -6
  204. data/app/pb_kits/playbook/pb_source/source.html.erb +1 -5
  205. data/app/pb_kits/playbook/pb_source/source.test.js +2 -2
  206. data/app/pb_kits/playbook/pb_star_rating/star_rating.html.erb +1 -5
  207. data/app/pb_kits/playbook/pb_stat_change/stat_change.html.erb +1 -5
  208. data/app/pb_kits/playbook/pb_stat_value/stat_value.html.erb +1 -5
  209. data/app/pb_kits/playbook/pb_table/table.html.erb +2 -12
  210. data/app/pb_kits/playbook/pb_table/table_body.html.erb +6 -16
  211. data/app/pb_kits/playbook/pb_table/table_cell.html.erb +6 -16
  212. data/app/pb_kits/playbook/pb_table/table_head.html.erb +6 -16
  213. data/app/pb_kits/playbook/pb_table/table_header.html.erb +4 -13
  214. data/app/pb_kits/playbook/pb_table/table_row.html.erb +6 -16
  215. data/app/pb_kits/playbook/pb_textarea/textarea.html.erb +1 -5
  216. data/app/pb_kits/playbook/pb_time/time.html.erb +1 -5
  217. data/app/pb_kits/playbook/pb_time_range_inline/time_range_inline.html.erb +1 -5
  218. data/app/pb_kits/playbook/pb_time_stacked/time_stacked.html.erb +1 -5
  219. data/app/pb_kits/playbook/pb_timeline/item.html.erb +3 -7
  220. data/app/pb_kits/playbook/pb_timeline/timeline.html.erb +1 -5
  221. data/app/pb_kits/playbook/pb_timestamp/timestamp.html.erb +1 -6
  222. data/app/pb_kits/playbook/pb_title/title.html.erb +1 -6
  223. data/app/pb_kits/playbook/pb_title_count/title_count.html.erb +1 -6
  224. data/app/pb_kits/playbook/pb_title_detail/title_detail.html.erb +1 -5
  225. data/app/pb_kits/playbook/pb_toggle/toggle.html.erb +1 -6
  226. data/app/pb_kits/playbook/pb_tooltip/tooltip.html.erb +1 -5
  227. data/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx +27 -19
  228. data/app/pb_kits/playbook/pb_typeahead/components/MenuList.tsx +4 -2
  229. data/app/pb_kits/playbook/pb_typeahead/components/index.tsx +19 -0
  230. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_custom_menu_list.jsx +51 -0
  231. data/app/pb_kits/playbook/pb_typeahead/docs/_typeahead_with_highlight.jsx +1 -1
  232. data/app/pb_kits/playbook/pb_typeahead/docs/example.yml +1 -0
  233. data/app/pb_kits/playbook/pb_typeahead/docs/index.js +1 -0
  234. data/app/pb_kits/playbook/pb_user/user.html.erb +1 -6
  235. data/app/pb_kits/playbook/pb_user_badge/user_badge.html.erb +1 -6
  236. data/app/pb_kits/playbook/pb_weekday_stacked/weekday_stacked.html.erb +1 -6
  237. data/app/pb_kits/playbook/playbook-doc.js +2 -0
  238. data/app/pb_kits/playbook/playbook-rails.js +3 -0
  239. data/app/pb_kits/playbook/tokens/_colors.scss +1 -1
  240. data/dist/menu.yml +5 -1
  241. data/dist/playbook-rails.js +6 -6
  242. data/lib/playbook/kit_base.rb +21 -1
  243. data/lib/playbook/version.rb +2 -2
  244. metadata +80 -6
  245. /data/app/pb_kits/playbook/pb_dialog/docs/{_dialog_props_table.md → _dialog_props_swift.md} +0 -0
@@ -0,0 +1,154 @@
1
+ import PbEnhancedElement from "../pb_enhanced_element";
2
+ import { PbDropdownKeyboard } from "./keyboard_accessibility";
3
+
4
+ const DROPDOWN_SELECTOR = "[data-pb-dropdown]";
5
+ const TRIGGER_SELECTOR = "[data-dropdown-trigger]";
6
+ const CONTAINER_SELECTOR = "[data-dropdown-container]";
7
+ const DOWN_ARROW_SELECTOR = "#dropdown_open_icon";
8
+ const UP_ARROW_SELECTOR = "#dropdown_close_icon";
9
+ const OPTION_SELECTOR = "[data-dropdown-option-label]";
10
+ const CUSTOM_DISPLAY_SELECTOR = "[data-dropdown-custom-trigger]";
11
+
12
+ export default class PbDropdown extends PbEnhancedElement {
13
+ static get selector() {
14
+ return DROPDOWN_SELECTOR;
15
+ }
16
+
17
+ connect() {
18
+ this.keyboardHandler = new PbDropdownKeyboard(this);
19
+ this.bindEventListeners();
20
+ this.updateArrowDisplay(false);
21
+ }
22
+
23
+ bindEventListeners() {
24
+ const customTrigger =
25
+ this.element.querySelector(CUSTOM_DISPLAY_SELECTOR) || this.element;
26
+ customTrigger.addEventListener("click", () =>
27
+ this.toggleElement(this.target)
28
+ );
29
+
30
+ this.target.addEventListener("click", this.handleOptionClick.bind(this));
31
+ document.addEventListener(
32
+ "click",
33
+ this.handleDocumentClick.bind(this),
34
+ true
35
+ );
36
+ }
37
+
38
+ handleOptionClick(event) {
39
+ const option = event.target.closest(OPTION_SELECTOR);
40
+ const hiddenInput = this.element.querySelector("#dropdown-selected-option");
41
+ if (option) {
42
+ const value = option.dataset.dropdownOptionLabel;
43
+ hiddenInput.value = JSON.parse(value).id;
44
+ this.onOptionSelected(value, option);
45
+ }
46
+ }
47
+
48
+ handleDocumentClick(event) {
49
+ if (this.isClickOutside(event) && this.target.classList.contains("open")) {
50
+ this.hideElement(this.target);
51
+ this.updateArrowDisplay(false);
52
+ }
53
+ }
54
+
55
+ isClickOutside(event) {
56
+ const customTrigger = this.element.querySelector(CUSTOM_DISPLAY_SELECTOR);
57
+ if (customTrigger) {
58
+ return !customTrigger.contains(event.target);
59
+ } else {
60
+ const triggerElement = this.element.querySelector(TRIGGER_SELECTOR);
61
+ const containerElement =
62
+ this.element.parentNode.querySelector(CONTAINER_SELECTOR);
63
+
64
+ const isOutsideTrigger = triggerElement
65
+ ? !triggerElement.contains(event.target)
66
+ : true;
67
+ const isOutsideContainer = containerElement
68
+ ? !containerElement.contains(event.target)
69
+ : true;
70
+
71
+ return isOutsideTrigger && isOutsideContainer;
72
+ }
73
+ }
74
+
75
+ onOptionSelected(value, selectedOption) {
76
+ const triggerElement = this.element.querySelector(
77
+ "#dropdown_trigger_display"
78
+ );
79
+ const customDisplayElement = this.element.querySelector(
80
+ "#dropdown_trigger_custom_display"
81
+ );
82
+ if (triggerElement) {
83
+ const selectedLabel = JSON.parse(value).label;
84
+ triggerElement.textContent = selectedLabel;
85
+ if (customDisplayElement) {
86
+ customDisplayElement.style.display = "block";
87
+ customDisplayElement.style.paddingRight = "8px";
88
+ }
89
+ }
90
+
91
+ const customTrigger = this.element.querySelector(CUSTOM_DISPLAY_SELECTOR);
92
+ if (customTrigger) {
93
+ if (this.target.classList.contains("open")) {
94
+ this.hideElement(this.target);
95
+ this.updateArrowDisplay(false);
96
+ }
97
+ }
98
+
99
+ const options = this.element.querySelectorAll(OPTION_SELECTOR);
100
+ options.forEach((option) => {
101
+ option.classList.remove("pb_dropdown_option_selected");
102
+ });
103
+ selectedOption.classList.add("pb_dropdown_option_selected");
104
+ console.log(`Selected value: ${value}`);
105
+ }
106
+
107
+ get target() {
108
+ return this.element.parentNode.querySelector(CONTAINER_SELECTOR);
109
+ }
110
+
111
+ showElement(elem) {
112
+ elem.classList.remove("close");
113
+ elem.classList.add("open");
114
+ elem.style.height = elem.scrollHeight + "px";
115
+ }
116
+
117
+ hideElement(elem) {
118
+ elem.style.height = elem.scrollHeight + "px";
119
+ window.setTimeout(() => {
120
+ elem.classList.add("close");
121
+ elem.classList.remove("open");
122
+ this.resetFocus();
123
+ }, 0);
124
+ }
125
+
126
+ resetFocus() {
127
+ if (this.keyboardHandler) {
128
+ this.keyboardHandler.focusedOptionIndex = -1;
129
+ const options = this.element.querySelectorAll(OPTION_SELECTOR);
130
+ options.forEach((option) =>
131
+ option.classList.remove("pb_dropdown_option_focused")
132
+ );
133
+ }
134
+ }
135
+
136
+ toggleElement(elem) {
137
+ if (elem.classList.contains("open")) {
138
+ this.hideElement(elem);
139
+ this.updateArrowDisplay(false);
140
+ return;
141
+ }
142
+ this.showElement(elem);
143
+ this.updateArrowDisplay(true);
144
+ }
145
+
146
+ updateArrowDisplay(isOpen) {
147
+ const downArrow = this.element.querySelector(DOWN_ARROW_SELECTOR);
148
+ const upArrow = this.element.querySelector(UP_ARROW_SELECTOR);
149
+ if (downArrow && upArrow) {
150
+ downArrow.style.display = isOpen ? "none" : "inline-block";
151
+ upArrow.style.display = isOpen ? "inline-block" : "none";
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,77 @@
1
+ const OPTION_SELECTOR = "[data-dropdown-option-label]";
2
+ export class PbDropdownKeyboard {
3
+ constructor(dropdown) {
4
+ this.dropdown = dropdown;
5
+ this.dropdownElement = dropdown.element;
6
+ this.options = Array.from(
7
+ this.dropdownElement.querySelectorAll(OPTION_SELECTOR)
8
+ );
9
+ this.focusedOptionIndex = -1;
10
+ this.init();
11
+ }
12
+
13
+ init() {
14
+ this.dropdownElement.addEventListener(
15
+ "keydown",
16
+ this.handleKeyDown.bind(this)
17
+ );
18
+ }
19
+
20
+ handleKeyDown(event) {
21
+ switch (event.key) {
22
+ case "ArrowDown":
23
+ event.preventDefault();
24
+ if (!this.dropdown.target.classList.contains("open")) {
25
+ this.dropdown.showElement(this.dropdown.target);
26
+ this.dropdown.updateArrowDisplay(true);
27
+ }
28
+ this.moveFocus(1);
29
+ break;
30
+ case "ArrowUp":
31
+ event.preventDefault();
32
+ this.moveFocus(-1);
33
+ break;
34
+ case "Enter":
35
+ event.preventDefault();
36
+ if (this.focusedOptionIndex !== -1) {
37
+ this.selectOption();
38
+ } else {
39
+ if (!this.dropdown.target.classList.contains("open")) {
40
+ this.dropdown.showElement(this.dropdown.target);
41
+ this.dropdown.updateArrowDisplay(true);
42
+ }
43
+ }
44
+ break;
45
+ case "Escape":
46
+ this.dropdown.hideElement(this.dropdown.target);
47
+ break;
48
+ case "Tab":
49
+ this.dropdown.hideElement(this.dropdown.target);
50
+ this.dropdown.updateArrowDisplay(false);
51
+ this.resetFocus();
52
+ break;
53
+ default:
54
+ break;
55
+ }
56
+ }
57
+
58
+ moveFocus(direction) {
59
+ if (this.focusedOptionIndex !== -1) {
60
+ this.options[this.focusedOptionIndex].classList.remove(
61
+ "pb_dropdown_option_focused"
62
+ );
63
+ }
64
+ this.focusedOptionIndex =
65
+ (this.focusedOptionIndex + direction + this.options.length) %
66
+ this.options.length;
67
+ this.options[this.focusedOptionIndex].classList.add(
68
+ "pb_dropdown_option_focused"
69
+ );
70
+ }
71
+
72
+ selectOption() {
73
+ const option = this.options[this.focusedOptionIndex];
74
+ this.dropdown.onOptionSelected(option.dataset.dropdownOptionLabel, option);
75
+ this.dropdown.hideElement(this.dropdown.target);
76
+ }
77
+ }
@@ -0,0 +1,18 @@
1
+ @keyframes fadeIn {
2
+ from {
3
+ opacity: 0;
4
+ }
5
+
6
+ to {
7
+ opacity: 1;
8
+ }
9
+ }
10
+ @keyframes fadeOut {
11
+ from {
12
+ opacity: 1;
13
+ }
14
+
15
+ to {
16
+ opacity: 0;
17
+ }
18
+ }
@@ -0,0 +1,109 @@
1
+ import React, { useContext } from "react";
2
+ import classnames from "classnames";
3
+ import {
4
+ buildAriaProps,
5
+ buildCss,
6
+ buildDataProps,
7
+ buildHtmlProps
8
+ } from "../../utilities/props";
9
+ import { globalProps } from "../../utilities/globalProps";
10
+
11
+ import DropdownContext from "../context";
12
+
13
+ import List from "../../pb_list/_list";
14
+ import ListItem from "../../pb_list/_list_item";
15
+ import TextInput from "../../pb_text_input/_text_input";
16
+ import Body from "../../pb_body/_body";
17
+
18
+ type DropdownContainerProps = {
19
+ aria?: { [key: string]: string };
20
+ children?: React.ReactChild[] | React.ReactChild;
21
+ className?: string;
22
+ dark?: boolean;
23
+ data?: { [key: string]: string };
24
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
25
+ id?: string;
26
+ searchbar?: boolean;
27
+ };
28
+
29
+ const DropdownContainer = (props: DropdownContainerProps) => {
30
+ const {
31
+ aria = {},
32
+ children,
33
+ className,
34
+ dark = false,
35
+ data = {},
36
+ htmlOptions = {},
37
+ id,
38
+ searchbar = false,
39
+ } = props;
40
+
41
+ const {
42
+ dropdownContainerRef,
43
+ filteredOptions,
44
+ filterItem,
45
+ handleChange,
46
+ inputRef,
47
+ isDropDownClosed,
48
+ setFocusedOptionIndex,
49
+ triggerRef
50
+ } = useContext(DropdownContext);
51
+
52
+ const ariaProps = buildAriaProps(aria);
53
+ const dataProps = buildDataProps(data);
54
+ const htmlProps = buildHtmlProps(htmlOptions);
55
+ const classes = classnames(
56
+ buildCss("pb_dropdown_container"),
57
+ `${isDropDownClosed ? "close" : "open"}`,
58
+ globalProps(props),
59
+ className
60
+ );
61
+
62
+ return (
63
+ <div {...ariaProps}
64
+ {...dataProps}
65
+ {...htmlProps}
66
+ className={classes}
67
+ id={id}
68
+ onMouseEnter={() => setFocusedOptionIndex(-1)}
69
+ ref={dropdownContainerRef}
70
+ style={triggerRef ? {} : { position: "absolute"}}
71
+ >
72
+ {searchbar && (
73
+ <TextInput dark={dark}
74
+ paddingTop="xs"
75
+ paddingX="xs"
76
+ >
77
+ <input
78
+ onChange={handleChange}
79
+ placeholder="Select..."
80
+ ref={inputRef}
81
+ value={filterItem}
82
+ />
83
+ </TextInput>
84
+ )}
85
+ <List dark={dark}>
86
+ {
87
+ filteredOptions?.length === 0 ? (
88
+ <ListItem dark={dark}
89
+ display="flex"
90
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
91
+ // @ts-ignore
92
+ justifyContent="center"
93
+ padding="xs"
94
+ >
95
+ <Body color="light"
96
+ dark={dark}
97
+ text="no option"
98
+ />
99
+ </ListItem>
100
+ ): (
101
+ children
102
+ )
103
+ }
104
+ </List>
105
+ </div>
106
+ );
107
+ };
108
+
109
+ export default DropdownContainer;
@@ -0,0 +1,118 @@
1
+ import React, { useContext } from "react";
2
+ import classnames from "classnames";
3
+ import {
4
+ buildAriaProps,
5
+ buildCss,
6
+ buildDataProps,
7
+ buildHtmlProps,
8
+ } from "../../utilities/props";
9
+ import { globalProps, GlobalProps } from "../../utilities/globalProps";
10
+
11
+ import DropdownContext from "../context";
12
+
13
+ import Flex from "../../pb_flex/_flex";
14
+ import Body from "../../pb_body/_body";
15
+ import ListItem from "../../pb_list/_list_item";
16
+ import { GenericObject } from "../../types";
17
+
18
+ type DropdownOptionProps = {
19
+ aria?: { [key: string]: string };
20
+ children?: React.ReactChild[] | React.ReactChild;
21
+ className?: string;
22
+ dark?: boolean;
23
+ data?: { [key: string]: string };
24
+ htmlOptions?: { [key: string]: string | number | boolean | (() => void) };
25
+ id?: string;
26
+ key?: string;
27
+ option?: GenericObject;
28
+ padding?: string;
29
+ } & GlobalProps;
30
+
31
+ const DropdownOption = (props: DropdownOptionProps) => {
32
+ const {
33
+ aria = {},
34
+ children,
35
+ className,
36
+ dark = false,
37
+ data = {},
38
+ htmlOptions = {},
39
+ id,
40
+ key,
41
+ option,
42
+ padding = "xs",
43
+ } = props;
44
+
45
+ const {
46
+ filteredOptions,
47
+ filterItem,
48
+ focusedOptionIndex,
49
+ handleOptionClick,
50
+ selected,
51
+ } = useContext(DropdownContext);
52
+
53
+ const isItemMatchingFilter = (option: GenericObject) =>
54
+ option?.label.toLowerCase().includes(filterItem.toLowerCase());
55
+
56
+ if (!isItemMatchingFilter(option)) {
57
+ return null;
58
+ }
59
+ const isFocused =
60
+ focusedOptionIndex >= 0 &&
61
+ filteredOptions[focusedOptionIndex].label === option.label;
62
+ const focusedClass = isFocused && "focused";
63
+
64
+ const selectedClass = `${
65
+ selected.label === option.label
66
+ ? "selected"
67
+ : "list"
68
+ }`;
69
+ const ariaProps = buildAriaProps(aria);
70
+ const dataProps = buildDataProps(data);
71
+ const htmlProps = buildHtmlProps(htmlOptions);
72
+ const classes = classnames(
73
+ buildCss(
74
+ "pb_dropdown_option",
75
+ selectedClass,
76
+ focusedClass,
77
+ ),
78
+ globalProps(props, {padding}),
79
+ className
80
+ );
81
+
82
+ return (
83
+ <div
84
+ {...ariaProps}
85
+ {...dataProps}
86
+ {...htmlProps}
87
+ className={classes}
88
+ id={id}
89
+ key={key}
90
+ onClick= {() => handleOptionClick(option)}
91
+ >
92
+ <ListItem
93
+ cursor="pointer"
94
+ dark={dark}
95
+ data-name={option.value}
96
+ key={option.label}
97
+ padding="none"
98
+ >
99
+ <Flex
100
+ align="center"
101
+ className="dropdown_option_wrapper"
102
+ justify="between"
103
+ paddingX="sm"
104
+ paddingY="xxs"
105
+ >
106
+ {children ?
107
+ children :
108
+ <Body dark={dark}
109
+ text={option.label}
110
+ />
111
+ }
112
+ </Flex>
113
+ </ListItem>
114
+ </div>
115
+ );
116
+ };
117
+
118
+ export default DropdownOption;
@@ -0,0 +1,190 @@
1
+ import React, { useContext } from "react";
2
+ import classnames from "classnames";
3
+ import {
4
+ buildAriaProps,
5
+ buildCss,
6
+ buildDataProps,
7
+ buildHtmlProps
8
+ } from "../../utilities/props";
9
+ import { globalProps } from "../../utilities/globalProps";
10
+ import { useHandleOnKeyDown } from "../hooks/useHandleOnKeydown";
11
+
12
+ import DropdownContext from "../context";
13
+
14
+ import Body from "../../pb_body/_body";
15
+ import Icon from "../../pb_icon/_icon";
16
+ import Flex from "../../pb_flex/_flex";
17
+ import FlexItem from "../../pb_flex/_flex_item";
18
+
19
+ type DropdownTriggerProps = {
20
+ aria?: { [key: string]: string };
21
+ children?: React.ReactChild[] | React.ReactChild;
22
+ className?: string;
23
+ customDisplay?: React.ReactChild[] | React.ReactChild;
24
+ dark?: boolean;
25
+ data?: { [key: string]: string };
26
+ htmlOptions?: {[key: string]: string | number | boolean | (() => void)},
27
+ id?: string;
28
+ placeholder?: string;
29
+ };
30
+
31
+ const DropdownTrigger = (props: DropdownTriggerProps) => {
32
+ const {
33
+ aria = {},
34
+ children,
35
+ className,
36
+ customDisplay,
37
+ dark = false,
38
+ data = {},
39
+ htmlOptions = {},
40
+ id,
41
+ placeholder,
42
+ } = props;
43
+
44
+ const {
45
+ autocomplete,
46
+ filterItem,
47
+ handleChange,
48
+ handleWrapperClick,
49
+ inputRef,
50
+ inputWrapperRef,
51
+ isDropDownClosed,
52
+ isInputFocused,
53
+ selected,
54
+ setIsInputFocused,
55
+ toggleDropdown,
56
+ triggerRef,
57
+ } = useContext(DropdownContext);
58
+
59
+ const handleKeyDown = useHandleOnKeyDown();
60
+
61
+ const ariaProps = buildAriaProps(aria);
62
+ const dataProps = buildDataProps(data);
63
+ const htmlProps = buildHtmlProps(htmlOptions);
64
+ const classes = classnames(
65
+ buildCss("pb_dropdown_trigger"),
66
+ globalProps(props),
67
+ className
68
+ );
69
+
70
+ const triggerWrapperClasses = buildCss(
71
+ "dropdown_trigger_wrapper",
72
+ isInputFocused && "focus",
73
+ !autocomplete && "select_only"
74
+ );
75
+
76
+ const customDisplayPlaceholder = selected.label ? (
77
+ <b>{selected.label}</b>
78
+ ) : autocomplete ? (
79
+ ""
80
+ ) : placeholder ? (
81
+ placeholder
82
+ ) : (
83
+ "Select..."
84
+ );
85
+
86
+ const defaultDisplayPlaceholder = selected.label
87
+ ? selected.label
88
+ : autocomplete
89
+ ? ""
90
+ : placeholder
91
+ ? placeholder
92
+ : "Select...";
93
+
94
+ return (
95
+ <div {...ariaProps}
96
+ {...dataProps}
97
+ {...htmlProps}
98
+ className={classes}
99
+ id={id}
100
+ >
101
+ {
102
+ !triggerRef && (
103
+ children ? (
104
+ <div
105
+ onClick={() => toggleDropdown()}
106
+ onKeyDown= {handleKeyDown}
107
+ ref={inputWrapperRef}
108
+ style={{ display: "inline-block" }}
109
+ tabIndex= {0}
110
+ >
111
+ {children}
112
+ </div>
113
+ ) : (
114
+ <>
115
+ <Flex
116
+ align="center"
117
+ borderRadius="lg"
118
+ className={triggerWrapperClasses}
119
+ cursor={`${autocomplete ? "text" : "pointer"}`}
120
+ htmlOptions={{
121
+ onClick: () => handleWrapperClick(),
122
+ onKeyDown: handleKeyDown,
123
+ tabIndex: "0",
124
+ ref:inputWrapperRef
125
+ }}
126
+ justify="between"
127
+ paddingX="sm"
128
+ paddingY="xs"
129
+ >
130
+ <FlexItem>
131
+ <Flex align="center">
132
+ {customDisplay ? (
133
+ <Flex align="center">
134
+ {customDisplay}
135
+ <Body dark={dark}
136
+ paddingLeft={`${selected.label ? "xs" : "none"}`}
137
+ >
138
+ {customDisplayPlaceholder}
139
+ </Body>
140
+ </Flex>
141
+ ) : (
142
+ <Body dark={dark}
143
+ text={defaultDisplayPlaceholder}
144
+ />
145
+ )}
146
+ {autocomplete && (
147
+ <input
148
+ className="dropdown_input"
149
+ onChange={handleChange}
150
+ onClick={() => toggleDropdown()}
151
+ onFocus={() => setIsInputFocused(true)}
152
+ onKeyDown={handleKeyDown}
153
+ placeholder={
154
+ selected.label
155
+ ? ""
156
+ : placeholder
157
+ ? placeholder
158
+ : "Select..."
159
+ }
160
+ ref={inputRef}
161
+ value={filterItem}
162
+ />
163
+ )}
164
+ </Flex>
165
+ </FlexItem>
166
+ <Body
167
+ dark={dark}
168
+ display="flex"
169
+ htmlOptions={{
170
+ onClick: (e: Event) => {e.stopPropagation();handleWrapperClick()}
171
+ }}
172
+ key={`${isDropDownClosed ? "chevron-down" : "chevron-up"}`}
173
+ >
174
+ <Icon
175
+ cursor="pointer"
176
+ dark={dark}
177
+ icon={`${isDropDownClosed ? "chevron-down" : "chevron-up"}`}
178
+ size="sm"
179
+ />
180
+ </Body>
181
+ </Flex>
182
+ </>
183
+ )
184
+ )
185
+ }
186
+ </div>
187
+ );
188
+ };
189
+
190
+ export default DropdownTrigger;
@@ -0,0 +1,41 @@
1
+ type HandleClickOutsideType = {
2
+ inputWrapperRef?: React.RefObject<HTMLDivElement>;
3
+ dropdownContainerRef?: React.RefObject<HTMLDivElement>;
4
+ setIsDropDownClosed?: (value: boolean) => void;
5
+ setFocusedOptionIndex?: (value: number) => void;
6
+ setIsInputFocused?: (value: boolean) => void;
7
+ };
8
+
9
+ export const handleClickOutside =
10
+ ({
11
+ inputWrapperRef,
12
+ dropdownContainerRef,
13
+ setIsDropDownClosed,
14
+ setFocusedOptionIndex,
15
+ setIsInputFocused,
16
+ }: HandleClickOutsideType) =>
17
+ (e: MouseEvent) => {
18
+ let targetElement = e.target as HTMLElement;
19
+ let shouldClose = true;
20
+
21
+ //Only needed for when useDropdown hook used with external trigger
22
+ while (targetElement && shouldClose) {
23
+ if (
24
+ targetElement.getAttribute("data-dropdown") === "pb-dropdown-trigger"
25
+ ) {
26
+ shouldClose = false;
27
+ }
28
+ targetElement = targetElement.parentElement as HTMLElement;
29
+ }
30
+ if (
31
+ inputWrapperRef.current &&
32
+ !inputWrapperRef.current.contains((e.target as HTMLElement)) &&
33
+ dropdownContainerRef.current &&
34
+ !dropdownContainerRef.current.contains((e.target as HTMLElement)) &&
35
+ shouldClose
36
+ ) {
37
+ setIsDropDownClosed(true);
38
+ setFocusedOptionIndex(-1);
39
+ setIsInputFocused(false);
40
+ }
41
+ };