Files
ubicloud/views/components/page_header.erb
Jeremy Evans cb389c5144 Use Roda part plugin to simplify render calls with locals
This uses the new part plugin to simplify and optimize render
calls with locals.

```ruby
render(:template, locals: {foo: 'bar'})

part(:template, foo: 'bar')
```

This simplifies a large number of calls in Clover, since
rendering with locals is one of the most common method
calls in the templates.

The main advantage of this is simplicity, but the part method
is also more optimized, and will be even more optimized when
we upgrade to Ruby 3.4.

Diff best reviewed with:

```
git diff -b --color-words --word-diff-regex='\\w+|[^[:space:]]'
```
2025-01-31 09:47:06 -08:00

47 lines
1.7 KiB
Plaintext

<%# locals: (title: @page_title, breadcrumbs: [], left_items: nil, right_items: nil, back: breadcrumbs.dig(-2, 1) || "#") %>
<div class="space-y-1 sticky -mx-10 mb-0.5 px-10 top-[2.9rem] bg-gray-50 z-30">
<% unless breadcrumbs.empty? %>
<div>
<nav class="sm:hidden" aria-label="Back">
<a href="<%= back %>" class="flex items-center text-sm font-medium text-gray-500 hover:text-gray-700">
<div class="-ml-1 mr-1 flex-shrink-0 text-gray-400">
<%== part("components/icon", name: "hero-chevron-left", classes: "w-5 h-5") %>
</div>
Back
</a>
</nav>
<nav class="hidden sm:flex" aria-label="Breadcrumb">
<ol role="list" class="flex items-center space-x-4">
<% breadcrumbs.each_with_index do |(name, url), index| %>
<li>
<div class="flex items-center">
<% if index > 0 %>
<%== part("components/icon", name: "hero-chevron-right", classes: "w-5 h-5 flex-shrink-0 text-gray-400 mr-4") %>
<% end %>
<a href="<%= url %>" class="text-sm font-medium text-gray-500 hover:text-gray-700"><%= name %></a>
</div>
</li>
<% end %>
</ol>
</nav>
</div>
<% end %>
<div class="md:flex md:items-center md:justify-between pb-4">
<div class="min-w-0">
<h2 class="text-2xl font-bold leading-7 text-gray-900 sm:text-3xl sm:tracking-tight"><%= title %></h2>
</div>
<% if left_items %>
<div class="mt-4 flex md:ml-4 md:mt-0 mr-auto">
<%== left_items.join %>
</div>
<% end %>
<% if right_items %>
<div class="mt-4 flex md:ml-4 md:mt-0">
<%== right_items.join %>
</div>
<% end %>
</div>
</div>