Class: Arara::ButtonComponent

Inherits:
ActionView::Component::Base
  • Object
show all
Includes:
BaseComponent
Defined in:
app/components/arara/button_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseComponent

#default_html_class, #default_html_tag, #html_data, #html_tag, included

Constructor Details

#initialize(variant: "text", content: "Label", dense: false, icon: nil, type: nil, name: nil, value: nil, tag: "button", **kw) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



6
7
8
9
10
11
12
13
14
# File 'app/components/arara/button_component.rb', line 6

def initialize(variant: "text", content: "Label", dense: false, icon: nil, type: nil, name: nil, value: nil, tag: "button", **kw)
  @dense = dense
  @icon = icon
  @html_class = html_class
  @type = type
  @name = name
  @value = value
  super(tag: tag, variant: variant, content: content, **kw)
end

Instance Attribute Details

#dataObject (readonly)

private



17
18
19
# File 'app/components/arara/button_component.rb', line 17

def data
  @data
end

#iconObject (readonly)

private



17
18
19
# File 'app/components/arara/button_component.rb', line 17

def icon
  @icon
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'app/components/arara/button_component.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'app/components/arara/button_component.rb', line 4

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'app/components/arara/button_component.rb', line 4

def value
  @value
end

Instance Method Details

#default_data_controllerObject



33
34
35
# File 'app/components/arara/button_component.rb', line 33

def default_data_controller
  "mdc-ripple"
end

#has_icon?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/components/arara/button_component.rb', line 29

def has_icon?
  @icon.present?
end

#html_classObject



19
20
21
22
23
24
25
26
27
# File 'app/components/arara/button_component.rb', line 19

def html_class
  klass = ["mdc-button"]
  klass.push("mdc-button--dense") if @dense
  klass.push("mdc-button--raised") if @user_variant == "raised"
  klass.push("mdc-button--unelevated") if @user_variant == "unelevated"
  klass.push("mdc-button--outlined") if @user_variant == "outlined"
  klass.push("#{@html_class}") if @html_class
  klass
end

#html_contentObject



44
45
46
47
48
# File 'app/components/arara/button_component.rb', line 44

def html_content
  return content if content
  return value if value
  user_content
end

#html_optionsObject



37
38
39
40
41
42
# File 'app/components/arara/button_component.rb', line 37

def html_options
  opts = super
  opts.merge!(
    class: html_class, data: html_data, type: type, name: name, value: value
  )
end