Files
ubicloud/views/components/button.erb
2025-01-21 16:19:12 +05:30

39 lines
1.5 KiB
Plaintext

<%# locals: (text:, type: "primary", link: nil, icon: nil, attributes: {}, extra_class: nil, right_icon: nil) %>
<% color = BUTTON_COLOR[type] %>
<% if link %>
<a
href="<%= link %>"
class="inline-flex items-center justify-center rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 <%= color %> disabled:pointer-events-none disabled:opacity-50 <%= extra_class %>"
<% attributes.each do |atr_key, atr_value| %>
<%= atr_key %>="<%= atr_value %>"
<% end%>
>
<% if icon %>
<%== render("components/icon", locals: { name: icon, classes: "h-5 w-5" }) %>
<% end %>
<%= text %>
</a>
<% else %>
<button
class="inline-flex items-center justify-center rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 <%= color %> disabled:pointer-events-none disabled:opacity-50 <%= extra_class %>"
<% attributes.compact.each do |atr_key, atr_value| %>
<%= atr_key %>="<%= atr_value %>"
<% end%>
>
<% if icon %>
<%== render(
"components/icon",
locals: {
name: icon,
classes: "h-5 w-5 #{(text && !text.empty?) ? "ml-0.5 mr-1.5" : "mx-0"}"
}
) %>
<% end %>
<%= text %>
<% if right_icon %>
<%== render("components/icon", locals: { name: right_icon, classes: "ml-1.5 -mr-1 h-5 w-5" }) %>
<% end %>
</button>
<% end %>