Class: DaisyUI::TabWithContent

Inherits:
Base
  • Object
show all
Defined in:
lib/daisy_ui/tab_with_content.rb

Constant Summary

Constants inherited from Base

Base::BOOLS, Base::COLOR_MODIFIERS

Instance Method Summary collapse

Methods inherited from Base

inherited, register_modifiers

Constructor Details

#initialize(content:, label: nil, id: nil) ⇒ TabWithContent

Returns a new instance of TabWithContent.



8
9
10
11
12
13
# File 'lib/daisy_ui/tab_with_content.rb', line 8

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

Instance Method Details

#view_templateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/daisy_ui/tab_with_content.rb', line 15

def view_template
  # Build explicit attributes in correct order
  tab_attrs = {
    type: :radio,
    name: id,
    class: classes, # This deletes :class from options
    role: :tab,
    aria: { label: @label }
  }

  # Now get remaining attributes (class has been deleted by classes method)
  attrs = attributes.dup

  # Handle modifiers and keyword args that should be HTML attributes
  # Order matters: modifiers come before keyword args in the original call
  closed_from_modifier = modifiers.include?(:closed)
  open_from_modifier = modifiers.include?(:open)
  closed_from_kwarg = attrs.delete(:closed) == true
  open_from_kwarg = attrs.delete(:open) == true

  # Add attributes from modifiers first (they appear earlier in args)
  tab_attrs[:closed] = true if closed_from_modifier
  tab_attrs[:checked] = true if open_from_modifier

  # Then add attributes from keyword args (they appear later in args)
  tab_attrs[:closed] = true if closed_from_kwarg && !closed_from_modifier
  tab_attrs[:checked] = true if open_from_kwarg && !open_from_modifier

  # Merge remaining attributes
  tab_attrs.merge!(attrs)

  # Render the radio input for the tab
  input(**tab_attrs)

  # Render the content
  @content&.call
end