ubicloud/views/components/button.erb
Jeremy Evans 750ebdc055 Change from erb_formatter to herb/formatter
Currently, herb/formatter has at least 4 bugs the prevent us from
switching to it (https://github.com/marcoroth/herb/issues 476, 477,
478, and 479). This includes manual fixes for each issue.

herb/formatter also introduces a rubocop violation for the
Layout/AssignmentIndentation cop. This disables that cop.
2025-09-05 14:01:01 -07:00

33 lines
1.4 KiB
Text

<%# 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 %>
<%== part("components/icon", 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 %>
<%== part("components/icon", name: icon, classes: "h-5 w-5 #{(text && !text.empty?) ? "ml-0.5 mr-1.5" : "mx-0"}") %>
<% end %>
<%= text %>
<% if right_icon %>
<%== part("components/icon", name: right_icon, classes: "ml-1.5 -mr-1 h-5 w-5") %>
<% end %>
</button>
<% end %>