Class: PhlexyUI::Tab

Inherits:
Base
  • Object
show all
Defined in:
lib/phlexy_ui/tab.rb

Instance Method Summary collapse

Methods inherited from Base

modifiers

Constructor Details

#initialize(id: nil) ⇒ Tab



6
7
8
9
# File 'lib/phlexy_ui/tab.rb', line 6

def initialize(*, id: nil, **)
  super(*, **)
  @id = id
end

Instance Method Details

#content(**options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/phlexy_ui/tab.rb', line 27

def content(*, **options, &)
  unless id
    raise ArgumentError,
      "You must pass an id to Tabs#new if you want to add content"
  end

  @content = -> do
    generate_classes!(
      # "tab-content"
      component_html_class: :"tab-content",
      options:
    ).then do |classes|
      div role: :tabpanel, class: classes, **options, &
    end
  end
end

#view_template {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (PhlexyUI::Tab)

    the object that the method was called on



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/phlexy_ui/tab.rb', line 11

def view_template(&)
  yield(self) if block_given?

  if @content
    render TabWithContent.new(
      *base_modifiers,
      id:,
      content: @content,
      **options,
      &
    )
  else
    render TabWithoutContent.new(*base_modifiers, id:, **options, &)
  end
end