Module: Megatron::ButtonHelper
- Defined in:
- app/helpers/megatron/button_helper.rb
Instance Method Summary collapse
- #button(text, options = {}) ⇒ Object
- #button_classes(options) ⇒ Object
- #copy_button(text, options = {}) ⇒ Object
- #destroy_button(text, options = {}) ⇒ Object
- #header_button(text, options = {}) ⇒ Object
- #primary_button(text, options = {}) ⇒ Object
- #primary_destroy_button(text, options = {}) ⇒ Object
- #primary_header_button(text, options = {}) ⇒ Object
- #text_button(text, options = {}) ⇒ Object
Instance Method Details
#button(text, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/megatron/button_helper.rb', line 3 def (text, = {}) tag_name = [:href].present? ? :a : :button opts = { class: (), data: [:data] || {} } opts[:href] = [:href] if [:href] opts[:data][:toggle] = [:toggle] if [:toggle] opts[:data].merge!([:dialog].merge(trigger: 'dialog')) if [:dialog] content_tag tag_name, opts do if [:icon] concat icon([:icon]) concat ' ' end concat text end end |
#button_classes(options) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/megatron/button_helper.rb', line 60 def () = [:type] || [:color] classes = .present? ? ["#{.to_s.gsub('_','-')}-btn"] : ["btn"] classes << [:flavor] if [:flavor] classes << [:class] if [:class] classes << [:size].to_s.gsub(/xlarge/, 'x-large') if [:size] classes << 'disabled' if [:disabled] classes end |
#copy_button(text, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/megatron/button_helper.rb', line 30 def (text, = {}) [:data] ||= {} [:data][:clipboard_target] = [:target] [:flavor] = 'copy-button' [:class] = () content_tag 'button', do concat text_icon('copy') concat text_icon('check-thin') concat ' ' concat text end end |
#destroy_button(text, options = {}) ⇒ Object
48 49 50 |
# File 'app/helpers/megatron/button_helper.rb', line 48 def (text, = {}) (text, .merge(type: :destroy)) end |
#header_button(text, options = {}) ⇒ Object
22 23 24 |
# File 'app/helpers/megatron/button_helper.rb', line 22 def (text, = {}) (text, {type: :header, flavor: 'btn'}.merge()) end |
#primary_button(text, options = {}) ⇒ Object
44 45 46 |
# File 'app/helpers/megatron/button_helper.rb', line 44 def (text, = {}) (text, .merge(type: :primary)) end |
#primary_destroy_button(text, options = {}) ⇒ Object
52 53 54 |
# File 'app/helpers/megatron/button_helper.rb', line 52 def (text, ={}) (text, .merge(type: :primary_destroy)) end |
#primary_header_button(text, options = {}) ⇒ Object
26 27 28 |
# File 'app/helpers/megatron/button_helper.rb', line 26 def (text, = {}) (text, .merge(type: :header, flavor: 'primary-btn')) end |
#text_button(text, options = {}) ⇒ Object
56 57 58 |
# File 'app/helpers/megatron/button_helper.rb', line 56 def (text, = {}) (text, .merge(type: :text)) end |