Add horizontal layout option for fieldset component

This commit is contained in:
Râu Cao 2023-04-03 13:55:39 +02:00
parent 7f77ad5528
commit 6848bd739c
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
2 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,5 @@
<%= tag.public_send(@tag, class: "mb-6 last:mb-0") do %> <%= tag.public_send(@tag, class: "mb-6 last:mb-0") do %>
<% if @positioning == :vertical %>
<label class="block"> <label class="block">
<p class="font-bold <%= @descripton.present? ? "mb-1" : "mb-2" %>"> <p class="font-bold <%= @descripton.present? ? "mb-1" : "mb-2" %>">
<%= @title %> <%= @title %>
@ -10,4 +11,19 @@
<% end %> <% end %>
<%= content %> <%= content %>
</label> </label>
<% elsif @positioning == :horizontal %>
<label class="block flex items-center justify-between">
<div class="flex flex-col">
<label class="font-bold mb-1"><%= @title %></label>
<% if @descripton.present? %>
<p class="text-gray-500"><%= @descripton %></p>
<% end %>
</div>
<div class="relative ml-4 inline-flex flex-shrink-0">
<%= content %>
</div>
</label>
<% else %>
<p>Invalid <code>positioning<code> argument for <code>FieldsetComponent</code>.</p>
<% end %>
<% end %> <% end %>

View File

@ -2,10 +2,11 @@
module FormElements module FormElements
class FieldsetComponent < ViewComponent::Base class FieldsetComponent < ViewComponent::Base
def initialize(tag: "li", title:, description: nil) def initialize(tag: "li", positioning: :vertical, title:, description: nil)
@tag = tag @tag = tag
@title = title @positioning = positioning
@descripton = description @title = title
@descripton = description
end end
end end
end end