Module: StimulusOverlayHelpers::ViewHelpers
- Defined in:
- lib/stimulus_overlay_helpers/view_helpers.rb
Instance Method Summary collapse
-
#dropdown(button_content, title = nil, options = {}, &panel_content) ⇒ Object
dropdown helper what it does: * a) wraps the button_content in element like: %button{ data: { controller: ‘dropdown’, … } } and renders it at place * b) wraps the panel_content in a corresponding element and renders it to the dropdown_panels-box (because of z-index-hierarchy) * c) the stimulus controller always adds the class .dropdown-panel to the panel.
- #tooltip(label, options = {}, &content) ⇒ Object
Instance Method Details
#dropdown(button_content, title = nil, options = {}, &panel_content) ⇒ Object
dropdown helper
what it does:
-
a) wraps the button_content in element like: %button{ data: { controller: ‘dropdown’, … } } and renders it at place
-
b) wraps the panel_content in a corresponding element and renders it to the dropdown_panels-box (because of z-index-hierarchy)
-
c) the stimulus controller always adds the class .dropdown-panel to the panel
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stimulus_overlay_helpers/view_helpers.rb', line 11 def dropdown(, title = nil, = {}, &panel_content) if title.is_a?(Hash) = title.dup title = nil end panel_at_place = .delete(:panel_at_place) id = "dropdown-panel-#{SecureRandom.hex(4)}" src = .delete(:src) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the Button # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .dup [:class] = [[:class], 'dropdown-button'].compact.join(' ') = .merge(data: { controller: 'csedl-dropdown', panel_id: id }) = capture(&) if .is_a?(Proc) btn = content_tag(:div, , ) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the panel # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .dup [:class] = [[:class], 'dropdown-panel'].compact.join(' ') [:style] = "display: none;" [:id] = id ['data-src'] = src if src close_btn_proc = StimulusOverlayHelpers. panel = content_tag(:div, ) do safe_join([ content_tag(:div, class: 'header') do concat content_tag(:div, title, class: 'title') concat content_tag(:div, class: 'buttons') { close_btn_proc.present? ? close_btn_proc.call(self) : content_tag(:span, 'X', class: 'close-button') } end, content_tag(:div, class: 'content') do capture(&panel_content) if block_given? end ]) end if panel_at_place btn + panel else content_for(:dropdown_panels, panel) btn end end |
#tooltip(label, options = {}, &content) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/stimulus_overlay_helpers/view_helpers.rb', line 66 def tooltip(label, = {}, &content) panel_at_place = .delete(:panel_at_place) || false delay = .delete(:delay) || 0.4 src = .delete(:src) label_class = .delete(:label_class) || 'tooltip-label' id = ['tooltip', SecureRandom.hex(4)].join('-') lab = if label.is_a?(Proc) capture &label else label end cont = capture(&content) if block_given? # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the Label # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .dup [:id] = .delete(:id) [:class] = [[:class], label_class].compact.join(' ') = .merge(data: { controller: 'csedl-tooltip', panel_id: id, delay: delay }) label_element = if block_given? && cont.present? content_tag(:span, ) do lab end else lab end # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the panel # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .dup [:class] = [[:class], 'tooltip-panel'].compact.join(' ') [:id] = id [:style] = 'display: none;' ['data-src'] = src if src panel_element = if block_given? && cont.present? content_tag(:div, ) do content_tag(:div, class: 'content') do cont end end end # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # return the result # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if !panel_element label_element elsif panel_at_place r = label_element r << panel_element else content_for(:dropdown_panels) do panel_element end label_element end end |