Class: Panda::Core::Admin::PageHeaderComponent

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

Overview

Page header component with title, optional breadcrumbs, and action buttons.

Follows Tailwind UI Plus pattern for page headers with responsive layout and support for multiple action buttons.

Examples:

Basic header with title only

render Panda::Core::Admin::PageHeaderComponent.new(
  title: "Back End Developer"
)

Header with breadcrumbs

render Panda::Core::Admin::PageHeaderComponent.new(
  title: "Back End Developer",
  breadcrumbs: [
    { text: "Jobs", href: "/admin/jobs" },
    { text: "Engineering", href: "/admin/jobs/engineering" },
    { text: "Back End Developer", href: "/admin/jobs/engineering/1" }
  ]
)

Header with action buttons using block

render Panda::Core::Admin::PageHeaderComponent.new(
  title: "Back End Developer",
  breadcrumbs: breadcrumb_items
) do |header|
  header.button(text: "Edit", variant: :secondary, href: edit_path)
  header.button(text: "Publish", variant: :primary, href: publish_path)
end

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: "", breadcrumbs: nil, show_back: true, **attrs, &block) ⇒ PageHeaderComponent

Returns a new instance of PageHeaderComponent.



36
37
38
39
40
41
42
43
# File 'app/components/panda/core/admin/page_header_component.rb', line 36

def initialize(title: "", breadcrumbs: nil, show_back: true, **attrs, &block)
  @title = title
  @breadcrumbs = breadcrumbs
  @show_back = show_back
  @buttons = []
  @setup_block = block
  super(**attrs)
end

Instance Attribute Details

Returns the value of attribute breadcrumbs.



45
46
47
# File 'app/components/panda/core/admin/page_header_component.rb', line 45

def breadcrumbs
  @breadcrumbs
end

#show_backObject (readonly)

Returns the value of attribute show_back.



45
46
47
# File 'app/components/panda/core/admin/page_header_component.rb', line 45

def show_back
  @show_back
end

#titleObject (readonly)

Returns the value of attribute title.



45
46
47
# File 'app/components/panda/core/admin/page_header_component.rb', line 45

def title
  @title
end

Instance Method Details

#button(text:, variant: :secondary, href: "#", **props) ⇒ Object

Define a button to be rendered in the header actions area

Parameters:

  • text (String)

    Button text

  • variant (Symbol) (defaults to: :secondary)

    Button variant (:primary or :secondary)

  • href (String) (defaults to: "#")

    Link href

  • props (Hash)

    Additional button properties



69
70
71
# File 'app/components/panda/core/admin/page_header_component.rb', line 69

def button(text:, variant: :secondary, href: "#", **props)
  @buttons << {text: text, variant: variant, href: href, **props}
end

#buttonsObject

Lazy accessor that ensures buttons are registered before returning them. Supports two patterns:

  1. Block passed to new() - executed here (for tests)
  2. Block passed to render() - executed via content (for ERB templates)


51
52
53
54
55
56
57
58
59
60
61
# File 'app/components/panda/core/admin/page_header_component.rb', line 51

def buttons
  unless @buttons_registered
    if @setup_block
      @setup_block.call(self)
    else
      content
    end
    @buttons_registered = true
  end
  @buttons
end