Class: NitroKit::Tooltip

Inherits:
Component
  • Object
show all
Defined in:
app/components/nitro_kit/tooltip.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(content: nil, placement: nil, **attrs) ⇒ Tooltip

Returns a new instance of Tooltip.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/components/nitro_kit/tooltip.rb', line 5

def initialize(content: nil, placement: nil, **attrs)
  @string_content = content
  @placement = placement

  super(
    attrs,
    data: {
      action: "mouseover->nk--tooltip#open mouseout->nk--tooltip#close",
      controller: "nk--tooltip",
      nk__tooltip_placement_value: placement
    }
  )
end

Instance Attribute Details

#placementObject (readonly)

Returns the value of attribute placement.



19
20
21
# File 'app/components/nitro_kit/tooltip.rb', line 19

def placement
  @placement
end

#string_contentObject (readonly)

Returns the value of attribute string_content.



19
20
21
# File 'app/components/nitro_kit/tooltip.rb', line 19

def string_content
  @string_content
end

Instance Method Details

#content(text = nil, **attrs, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/components/nitro_kit/tooltip.rb', line 28

def content(text = nil, **attrs, &block)
  builder do
    div(
      **mattr(
        attrs,
        class: tooltip_class,
        data: {
          state: "closed",
          nk__tooltip_target: "content"
        }
      )
    ) do
      text_or_block(text, &block)
    end
  end
end

#view_templateObject



21
22
23
24
25
26
# File 'app/components/nitro_kit/tooltip.rb', line 21

def view_template
  span(**attrs) do
    content(string_content) if string_content
    yield
  end
end