Class: Panda::Core::Admin::BreadcrumbComponent

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

Overview

Breadcrumb navigation component with responsive behavior.

Shows a “Back” link on mobile and full breadcrumb trail on larger screens. Follows Tailwind UI Plus pattern for breadcrumb navigation.

Examples:

Basic breadcrumbs

render Panda::Core::Admin::BreadcrumbComponent.new(
  items: [
    { text: "Pages", href: "/admin/pages" },
    { text: "Blog Posts", href: "/admin/pages/blog" },
    { text: "Edit Post", href: "/admin/pages/blog/1/edit" }
  ]
)

Without back link (first page in section)

render Panda::Core::Admin::BreadcrumbComponent.new(
  items: [
    { text: "Dashboard", href: "/admin" }
  ],
  show_back: false
)

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

#view_templateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/components/panda/core/admin/breadcrumb_component.rb', line 32

def view_template
  div do
    # Mobile back link
    if @show_back && @items.any?
      nav(
        aria: {label: "Back"},
        class: "sm:hidden"
      ) do
        a(
          href: back_link_href,
          class: "flex items-center text-sm font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"
        ) do
          render_chevron_left_icon
          plain "Back"
        end
      end
    end

    # Desktop breadcrumb trail
    nav(
      aria: {label: "Breadcrumb"},
      class: "hidden sm:flex"
    ) do
      ol(
        role: "list",
        class: "flex items-center space-x-4"
      ) do
        @items.each_with_index do |item, index|
          li do
            if index.zero?
              # First item (no separator)
              div(class: "flex") do
                a(
                  href: item[:href],
                  class: breadcrumb_link_classes(index)
                ) { item[:text] }
              end
            else
              # Subsequent items (with separator)
              div(class: "flex items-center") do
                render_chevron_right_icon
                a(
                  href: item[:href],
                  aria: ((index == @items.length - 1) ? {current: "page"} : nil),
                  class: breadcrumb_link_classes(index)
                ) { item[:text] }
              end
            end
          end
        end
      end
    end
  end
end