Module: NfgUi::Components::TooltipHelper

Defined in:
app/helpers/nfg_ui/components/tooltip_helper.rb

Instance Method Summary collapse

Instance Method Details

#browser_is_a_touch_device?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/helpers/nfg_ui/components/tooltip_helper.rb', line 19

def browser_is_a_touch_device?
  browser.mobile? || browser.tablet?
end

#tooltip(tooltip_content, placement = :top, data = {}) ⇒ Object

Raises:

  • (StandardError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/nfg_ui/components/tooltip_helper.rb', line 4

def tooltip(tooltip_content, placement = :top, data = {})
  # IMPORTANT NOTE: This must be included as the first argument within your element.
  # Working Example: # %span{ bootstrap_tooltip(t(".tooltips.group_name"), :top), class: "my-class" }

  acceptable_placement_directions = %i[right top bottom left]

  raise StandardError.new("Acceptable placement options are :right, :top, :bottom or :left, only... and you assigned #{placement}") unless acceptable_placement_directions.include?(placement)

  if browser_is_a_touch_device?
    {}
  else
    { title: tooltip_content, data: data.merge(placement: placement, toggle: "tooltip", html: 'true') }
  end
end