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 overlays_box (because of z-index-hierarchy) * c) the stimulus controller always adds the class .dropdown-panel to the panel.
-
#modal(button_content, title = nil, options = {}, &panel_content) ⇒ Object
modal helper what it does: * a) wraps the button_content in element like: %button{ data: { controller: ‘modal’, … } } and renders it at place * b) wraps the panel_content in a full-screen overlay element and renders it to the overlays_box (because of z-index-hierarchy) * c) the stimulus controller always adds the class .modal-panel to the panel and .modal-overlay to the backdrop.
-
#tooltip(tip, options = {}) ⇒ Object
tooltip helper what it does: * a) wraps the label in element like: %span{ data: { controller: ‘tooltip’, … } } and renders it at place * b) wraps the tip in a corresponding panel element and renders it to the overlays_box (because of z-index-hierarchy) * c) the stimulus controller always adds the class .tooltip-panel to the panel.
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 overlays_box (because of z-index-hierarchy)
-
c) the stimulus controller always adds the class .dropdown-panel to the panel
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 64 |
# File 'lib/stimulus_overlay_helpers/view_helpers.rb', line 13 def dropdown(, title = nil, = {}, &panel_content) if title.is_a?(Hash) = title.dup title = nil end panel_at_place = .delete(:panel_at_place) src = .delete(:src) = [.delete(:button_class) || 'dropdown-button', [:class]].compact.join(' ') panel_class = [.delete(:class), 'dropdown-panel'].compact.join(' ') close_btn_proc = StimulusOverlayHelpers. id = "dropdown-panel-#{SecureRandom.hex(4)}" # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the Button # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = capture(& = ) if .is_a?(Proc) = .merge(class: , data: { controller: 'hotwire-svelte-helpers-dropdown', panel_id: id }) = content_tag(:div, , ) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the panel # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .merge(class: panel_class, style: 'display: none;', id: id) ['data-src'] = src if src.present? panel_element = 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', data: { close: true }) } end, content_tag(:div, class: 'content') do capture(&panel_content) if block_given? end ]) end # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # return the result # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if panel_at_place + panel_element else content_for(:overlays_box, panel_element) end end |
#modal(button_content, title = nil, options = {}, &panel_content) ⇒ Object
modal helper
what it does:
-
a) wraps the button_content in element like: %button{ data: { controller: ‘modal’, … } } and renders it at place
-
b) wraps the panel_content in a full-screen overlay element and renders it to the overlays_box (because of z-index-hierarchy)
-
c) the stimulus controller always adds the class .modal-panel to the panel and .modal-overlay to the backdrop
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 |
# File 'lib/stimulus_overlay_helpers/view_helpers.rb', line 74 def modal(, title = nil, = {}, &panel_content) if title.is_a?(Hash) = title.dup title = nil end panel_at_place = .delete(:panel_at_place) src = .delete(:src) = [.delete(:button_class) || 'modal-button', [:class]].compact.join(' ') panel_class = [.delete(:class), 'modal-panel'].compact.join(' ') close_btn_proc = StimulusOverlayHelpers. id = "modal-overlay-#{SecureRandom.hex(4)}" # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the Button # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = capture(&) if .is_a?(Proc) = .merge(class: , data: { controller: 'hotwire-svelte-helpers-modal', panel_id: id }) = content_tag(:div, , ) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the overlay # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .merge(class: panel_class) ['data-src'] = src if src.present? = content_tag(:div, class: 'modal-overlay', style: 'display:none;', id: id) do 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', data: { close: true }) } end, content_tag(:div, class: 'content') do capture(&panel_content) if block_given? end ]) end end # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # return the result # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if panel_at_place + else content_for(:overlays_box, ) end end |
#tooltip(tip, options = {}) ⇒ Object
tooltip helper
what it does:
-
a) wraps the label in element like: %span{ data: { controller: ‘tooltip’, … } } and renders it at place
-
b) wraps the tip in a corresponding panel element and renders it to the overlays_box (because of z-index-hierarchy)
-
c) the stimulus controller always adds the class .tooltip-panel to the panel
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/stimulus_overlay_helpers/view_helpers.rb', line 138 def tooltip(tip, = {}, &) label = capture(&) if block_given? tip = capture &tip if tip.is_a?(Proc) return '' if label.blank? return label if tip.blank? panel_at_place = .delete(:panel_at_place) || false delay = .delete(:delay) || 0.4 src = .delete(:src) label_class = [.delete(:label_class) || 'tooltip-label', [:class]].compact.join(' ') panel_class = [.delete(:class), 'tooltip-panel'].compact.join(' ') id = "tooltip-#{SecureRandom.hex(4)}" # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the Label # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .merge(class: label_class, data: { controller: 'hotwire-svelte-helpers-tooltip', panel_id: id, delay: delay }) label_element = content_tag(:span, label, ) # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # create the panel # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx = .merge(class: panel_class, style: 'display: none', id: id) ['data-src'] = src if src.present? panel_element = content_tag(:div, ) do content_tag( :div, '', id: "arrow") + content_tag(:div, tip, class: 'tooltip-content') end # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # return the result # xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if panel_at_place label_element + panel_element else content_for(:overlays_box, panel_element) label_element end end |