Class: Trek::ButtonComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/trek/button_component.rb

Instance Method Summary collapse

Methods included from StimulusHelpers

#stimulus_action, #stimulus_class, #stimulus_class_hash, #stimulus_class_key, #stimulus_target, #stimulus_target_hash, #stimulus_target_key, #stimulus_value, #stimulus_value_hash, #stimulus_value_key

Methods included from CssClassesHelpers

#class_for, #class_names_for, #root_class

Methods included from IdentifierHelper

#identifier

Instance Method Details

#callObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/components/trek/button_component.rb', line 52

def call
  if link?
    link_to rendered_content,
      href,
      class: classes,
      data: data_attributes,
      rel: rel,
      target: target,
      title: title
  elsif to?
    # TODO: find how to replace with `button_to` (and use `data-turbo-confirm`)
    link_to rendered_content,
      to,
      class: classes,
      data: data_attributes.merge(turbo_method: method),
      form: form,
      form_class: form_class,
      params: params
  else
     tag,
      rendered_content,
      class: classes,
      data: data_attributes,
      form:,
      type:,
      value:
  end
end

#classesObject



27
28
29
30
31
32
33
34
35
36
# File 'app/components/trek/button_component.rb', line 27

def classes
  class_names_for(
    root_class,
    classnames,
    "has-icon": icon.present?,
    "color-#{color}": color,
    "position-#{position}": position,
    "size-#{size}": size
  )
end

#data_attributesObject



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

def data_attributes
  attributes = {}
  attributes["accent-color"] = color if color
  attributes.merge(data)
end

#render?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'app/components/trek/button_component.rb', line 81

def render?
  text?
end

#rendered_contentObject



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

def rendered_content
  safe_join([
    icon,
    (:span, text, class: class_for("text")),
    content
  ])
end