Method: Primer::Alpha::Tooltip#initialize

Defined in:
app/components/primer/alpha/tooltip.rb

#initialize(type:, for_id:, text:, direction: DIRECTION_DEFAULT, **system_arguments) ⇒ Tooltip

Returns a new instance of Tooltip.

Parameters:

  • for_id (String)

    The ID of the element that the tooltip should be attached to.

  • type (Symbol)

    <%= one_of(Primer::Alpha::Tooltip::TYPE_OPTIONS) %>

  • direction (Symbol) (defaults to: DIRECTION_DEFAULT)

    <%= one_of(Primer::Alpha::Tooltip::DIRECTION_OPTIONS) %>

  • text (String)

    The text content of the tooltip. This should be brief and no longer than a sentence.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>

Raises:

  • (TypeError)
[View source]

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/primer/alpha/tooltip.rb', line 39

def initialize(type:, for_id:, text:, direction: DIRECTION_DEFAULT, **system_arguments)
  raise TypeError, "tooltip text must be a string" unless text.is_a?(String)

  @text = text
  @system_arguments = system_arguments
  @id = @system_arguments[:id] ||= self.class.generate_id
  @system_arguments[:tag] = :"tool-tip"
  @system_arguments[:for] = for_id
  @system_arguments[:popover] = "manual"
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "sr-only"
  )
  @system_arguments[:position] = :absolute
  @system_arguments[:"data-direction"] = fetch_or_fallback(DIRECTION_OPTIONS, direction, DIRECTION_DEFAULT).to_s
  @system_arguments[:"data-type"] = fetch_or_fallback(TYPE_OPTIONS, type, TYPE_FALLBACK).to_s
end