Module: Megatron::ButtonHelper

Defined in:
app/helpers/megatron/button_helper.rb

Instance Method Summary collapse

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 button(text, options = {})
  tag_name = options[:href].present? ? :a : :button
  opts = {
    class: button_classes(options),
    data: options[:data] || {}
  }
  opts[:href] = options[:href] if options[:href]
  opts[:data][:toggle] = options[:toggle] if options[:toggle]
  opts[:data].merge!(options[:dialog].merge(trigger: 'dialog')) if options[:dialog]

   tag_name, opts do
    if options[:icon]
      concat icon(options[: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 button_classes(options)
  button_type = options[:type] || options[:color]
  classes = button_type.present? ? ["#{button_type.to_s.gsub('_','-')}-btn"] : ["btn"]
  classes << options[:flavor] if options[:flavor]
  classes << options[:class] if options[:class]
  classes << options[:size].to_s.gsub(/xlarge/, 'x-large') if options[:size]
  classes << 'disabled' if options[: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 copy_button(text, options = {})
  options[:data] ||= {}
  options[:data][:clipboard_target] = options[:target]
  options[:flavor] = 'copy-button'
  options[:class] = button_classes(options)

   'button', options 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 destroy_button(text, options = {})
  button(text, options.merge(type: :destroy))
end

#header_button(text, options = {}) ⇒ Object



22
23
24
# File 'app/helpers/megatron/button_helper.rb', line 22

def header_button(text, options = {})
  button(text, {type: :header, flavor: 'btn'}.merge(options))
end

#primary_button(text, options = {}) ⇒ Object



44
45
46
# File 'app/helpers/megatron/button_helper.rb', line 44

def primary_button(text, options = {})
  button(text, options.merge(type: :primary))
end

#primary_destroy_button(text, options = {}) ⇒ Object



52
53
54
# File 'app/helpers/megatron/button_helper.rb', line 52

def primary_destroy_button(text, options={})
  button(text, options.merge(type: :primary_destroy))
end

#primary_header_button(text, options = {}) ⇒ Object



26
27
28
# File 'app/helpers/megatron/button_helper.rb', line 26

def primary_header_button(text, options = {})
  button(text, options.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_button(text, options = {})
  button(text, options.merge(type: :text))
end