Class: Panda::Core::Admin::ContainerComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/container_component.rb

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#after_template, #attrs, #before_template, #default_attrs, #merge_attrs, #tailwind_merge_attrs

Instance Method Details

#content(&block) ⇒ Object



49
50
51
52
53
54
55
56
# File 'app/components/panda/core/admin/container_component.rb', line 49

def content(&block)
  @main_content = if defined?(view_context) && view_context
    # Capture ERB content
    -> { raw(view_context.capture(&block)) }
  else
    block
  end
end

#heading(**props, &block) ⇒ Object



58
59
60
# File 'app/components/panda/core/admin/container_component.rb', line 58

def heading(**props, &block)
  @heading_content = -> { render(Panda::Core::Admin::HeadingComponent.new(**props), &block) }
end

#slideover(**props, &block) ⇒ Object Also known as: with_slideover



66
67
68
69
# File 'app/components/panda/core/admin/container_component.rb', line 66

def slideover(**props, &block)
  @slideover_title = props[:title] || "Settings"
  @slideover_block = block   # Save the block for content_for
end

#tab_bar(**props, &block) ⇒ Object



62
63
64
# File 'app/components/panda/core/admin/container_component.rb', line 62

def tab_bar(**props, &block)
  @tab_bar_content = -> { render(Panda::Core::Admin::TabBarComponent.new(**props), &block) } if defined?(Panda::Core::Admin::TabBarComponent)
end

#view_template(&block) ⇒ Object



9
10
11
12
13
14
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
# File 'app/components/panda/core/admin/container_component.rb', line 9

def view_template(&block)
  # Capture block content differently based on context (ERB vs Phlex)
  if block_given?
    if defined?(view_context) && view_context
      # Called from ERB - capture HTML output
      @body_html = view_context.capture { yield(self) }
    else
      # Called from Phlex - execute block directly to set instance variables
      yield(self)
    end
  end

  # Set content_for :sidebar if slideover is present (enables breadcrumb toggle button)
  # This must happen before rendering so the layout can use it
  if @slideover_block && @slideover_title && defined?(view_context) && view_context
    view_context.content_for(:sidebar) do
      # The block contains ERB content, capture it for the sidebar
      view_context.capture(&@slideover_block)
    end
    view_context.content_for(:sidebar_title, @slideover_title)
  end

  main(class: "overflow-auto flex-1 h-full min-h-full max-h-full") do
    div(class: "overflow-auto px-2 pt-4 mx-auto sm:px-6 lg:px-6") do
      @heading_content&.call
      @tab_bar_content&.call

      section(class: section_classes) do
        div(class: "flex-1 mt-4 w-full h-full") do
          if @main_content
            @main_content.call
          elsif @body_html
            raw(@body_html)
          end
        end
      end
    end
  end
end