Class: Tramway::TooltipComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/tramway/tooltip_component.rb

Overview

Default Tramway tooltip

Constant Summary collapse

EVENTS =
%i[hover onclick].freeze

Constants included from Helpers::ViewsHelper

Helpers::ViewsHelper::FORM_SIZES

Instance Method Summary collapse

Methods included from Helpers::ViewsHelper

#tramway_back_button, #tramway_badge, #tramway_button, #tramway_cell, #tramway_chat, #tramway_container, #tramway_flash, #tramway_form_for, #tramway_header, #tramway_main_container, #tramway_row, #tramway_table, #tramway_title, #tramway_tooltip

Methods included from Helpers::ComponentHelper

#component

Methods included from Helpers::DecorateHelper

#tramway_decorate

Instance Method Details

#normalized_eventObject



53
54
55
# File 'app/components/tramway/tooltip_component.rb', line 53

def normalized_event
  event.to_sym
end

#tooltip_classesObject



49
50
51
# File 'app/components/tramway/tooltip_component.rb', line 49

def tooltip_classes
  (base_tooltip_classes + event_tooltip_classes).join(' ')
end

#tooltip_dataObject



43
44
45
46
47
# File 'app/components/tramway/tooltip_component.rb', line 43

def tooltip_data
  return {} unless normalized_event == :onclick

  { 'tramway-tooltip-target': 'panel' }
end

#trigger_classesObject



17
18
19
20
21
22
# File 'app/components/tramway/tooltip_component.rb', line 17

def trigger_classes
  {
    hover: %w[peer inline-flex w-fit],
    onclick: %w[inline-flex w-fit cursor-pointer]
  }[normalized_event].join(' ')
end

#trigger_dataObject



37
38
39
40
41
# File 'app/components/tramway/tooltip_component.rb', line 37

def trigger_data
  return {} unless normalized_event == :onclick

  { action: 'click->tramway-tooltip#toggle' }
end

#wrapper_classesObject



13
14
15
# File 'app/components/tramway/tooltip_component.rb', line 13

def wrapper_classes
  (base_wrapper_classes + options[:class].to_s.split).compact.join(' ')
end

#wrapper_dataObject



24
25
26
27
28
29
30
31
# File 'app/components/tramway/tooltip_component.rb', line 24

def wrapper_data
  return options[:data] || {} unless normalized_event == :onclick

  (options[:data] || {}).merge(
    controller: merged_controller,
    action: merged_action
  )
end

#wrapper_optionsObject



33
34
35
# File 'app/components/tramway/tooltip_component.rb', line 33

def wrapper_options
  options.except(:class, :data).merge(data: wrapper_data)
end