Skip to content

Commit

Permalink
Render all panel section through a single helper
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Jan 15, 2024
1 parent 77bcfeb commit 3bf12d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
19 changes: 4 additions & 15 deletions admin/app/components/solidus_admin/ui/panel/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,18 @@
<% end %>

<% if @title %>
<section class="border-gray-100 border-t w-full first-of-type:border-t-0 p-6">
<%= render_section do %>
<h2>
<span class="font-semibold text-xl"><%= @title %></span>
<%= render component("ui/toggletip").new(text: @title_hint) if @title_hint %>
</h2>
</section>
<% end %>
<% end %>

<% sections.each do |section| %>
<%= section %>
<% end %>

<% if content.present? %>
<section class="border-gray-100 border-t w-full first-of-type:border-t-0 p-6">
<%= content %>
</section>
<% end %>

<% if action? %>
<section class="border-gray-100 border-t w-full first-of-type:border-t-0 p-6">
<div class="flex justify-between items-center">
<%= action %>
</div>
</section>
<% end %>
<%= render_section { content } if content.present? %>
<%= render_section { tag.div(action, class: "flex justify-between items-center") } if action? %>
</div>
18 changes: 11 additions & 7 deletions admin/app/components/solidus_admin/ui/panel/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ class SolidusAdmin::UI::Panel::Component < SolidusAdmin::BaseComponent
)
}

renders_many :sections, ->(wide: false, high: false, **args, &block) do
tag.section(**args, class: "
border-gray-100 border-t w-full first-of-type:border-t-0
#{'px-6' unless wide}
#{'py-6' unless high}
#{args[:class]}
", &block)
renders_many :sections, ->(**args, &block) do
render_section(**args, &block)
end

renders_many :menus, ->(name, url, **args) do
Expand All @@ -33,4 +28,13 @@ def initialize(title: nil, title_hint: nil)
@title = title
@title_hint = title_hint
end

def render_section(wide: false, high: false, **args, &block)
tag.section(**args, class: "
border-gray-100 border-t w-full first-of-type:border-t-0
#{'px-6' unless wide}
#{'py-6' unless high}
#{args[:class]}
", &block)
end
end

0 comments on commit 3bf12d0

Please sign in to comment.