Skip to content

Commit 4686a6f

Browse files
dflclaude
andcommitted
Accept symbol or string keys for inline_icon
Coerce icon arg with to_s in icon lookups and switch literal call sites to symbols. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent de6df56 commit 4686a6f

8 files changed

Lines changed: 11 additions & 11 deletions

app/components/back_button_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<% extra_class = html_attrs&.delete(:class) %>
22
<% label_content = capture do %>
33
<span class="inline-flex items-center justify-center gap-cfa-xsm">
4-
<%= inline_icon("arrow_left", size: 24, aria_hidden: true) %>
4+
<%= inline_icon(:arrow_left, size: 24, aria_hidden: true) %>
55
<%= I18n.t("back") %>
66
</span>
77
<% end %>

app/components/base_component.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ def initialize(html_attrs:)
5757
end
5858

5959
def icon_image_path(icon)
60-
ICONS.dig(icon, :path) || ""
60+
ICONS.dig(icon.to_s, :path) || ""
6161
end
6262

6363
def icon_alt_text(icon)
64-
base = ICONS.dig(icon, :alt)
64+
base = ICONS.dig(icon.to_s, :alt)
6565
base ? "#{base} icon" : ""
6666
end
6767

6868
# Render the icon as a CSS-masked span so it inherits CSS `color`
6969
# via `background-color: currentColor`. Uses the same image-rasterization
7070
# path as `<img src=...>`, preserving pixel-perfect positioning.
7171
def inline_icon(icon, size: 20, css_class: nil, aria_hidden: false)
72-
path = ICONS.dig(icon, :path)
72+
path = ICONS.dig(icon.to_s, :path)
7373
return "".html_safe unless path
7474

7575
style = "--icon-url: url('#{image_path(path)}'); width: #{size}px; height: #{size}px"
@@ -87,7 +87,7 @@ def required_class
8787
def checkbox_wrap(checkbox_html, small: false)
8888
size = small ? 16 : 24
8989
box = small ? "h-4 w-4" : "h-6 w-6"
90-
icon = inline_icon("check", size:, aria_hidden: true, css_class: "absolute inset-0 pointer-events-none text-text-default")
90+
icon = inline_icon(:check, size:, aria_hidden: true, css_class: "absolute inset-0 pointer-events-none text-text-default")
9191
content_tag :span, checkbox_html + icon, class: "cfa-checkbox-wrap relative inline-flex #{box}"
9292
end
9393
end

app/components/checkboxes_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<%= render(FormErrorsComponent.new(form: @form, method: @method, small: @small)) %>
3131
<% if has_warning? %>
3232
<p class="form_warning flex items-center gap-cfa-sm text-text-body-secondary">
33-
<%= inline_icon("alert", size: icon_size, css_class: "text-warning") %>
33+
<%= inline_icon(:alert, size: icon_size, css_class: "text-warning") %>
3434
<span><%= @warning_message %></span>
3535
</p>
3636
<% end %>

app/components/form_errors_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<% if @form.object.errors[@method].any? %>
22
<p class="form_errors flex items-center gap-cfa-sm text-text-body-secondary">
3-
<%= inline_icon("error", size: @small ? 16 : 24, css_class: "text-error") %>
3+
<%= inline_icon(:error, size: @small ? 16 : 24, css_class: "text-error") %>
44
<span>
55
<%= safe_join(
66
@form.object.errors.where(@method).map { |e| e.message.html_safe? ? e.full_message.html_safe : e.full_message },

app/components/modal_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="space-x-cfa-xl flex flex-row">
66
<h2 :id="$id('<%= @name %>-title')"><%= header %></h2>
77
<div class="w-[25px] shrink-0">
8-
<a href="#" @click="toggle()" class="flex flex-col items-start cursor-pointer" style="color: inherit" aria-label="<%= t("cfaui.modal.close_aria") %>"><%= inline_icon("xmark", size: 25, aria_hidden: true) %></a>
8+
<a href="#" @click="toggle()" class="flex flex-col items-start cursor-pointer" style="color: inherit" aria-label="<%= t("cfaui.modal.close_aria") %>"><%= inline_icon(:xmark, size: 25, aria_hidden: true) %></a>
99
</div>
1010
</div>
1111
<div :id="$id('<%= @name %>-description')" class="space-y-cfa-med">

app/components/radio_buttons_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<%= render(FormErrorsComponent.new(form: @form, method: @method, small: @small)) %>
3030
<% if has_warning? %>
3131
<p class="form_warning flex items-center gap-cfa-sm text-text-body-secondary">
32-
<%= inline_icon("alert", size: icon_size, css_class: "text-warning") %>
32+
<%= inline_icon(:alert, size: icon_size, css_class: "text-warning") %>
3333
<span><%= @warning_message %></span>
3434
</p>
3535
<% end %>

app/components/reveal_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<% end %>
77
<%= @summary_text %>
88
</p>
9-
<span class="ml-[10px] inline-flex items-center transition-transform duration-200 group-open:rotate-180"><%= inline_icon("chevron_down", size: 25, aria_hidden: true) %></span>
9+
<span class="ml-[10px] inline-flex items-center transition-transform duration-200 group-open:rotate-180"><%= inline_icon(:chevron_down, size: 25, aria_hidden: true) %></span>
1010
</summary>
1111

1212
<div class="space-y-cfa-med mt-cfa-sm">

app/components/yes_no_buttons_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class="yes-no-buttons__button"
77
@click="selected = '<%= val %>'"
88
:class="{ 'is-selected': selected === '<%= val %>' }">
9-
<%= inline_icon("circle_check", size: 24, aria_hidden: true, css_class: "yes-no-buttons__check") %>
9+
<%= inline_icon(:circle_check, size: 24, aria_hidden: true, css_class: "yes-no-buttons__check") %>
1010
<span class="yes-no-buttons__label"><%= label %></span>
1111
</button>
1212
<% end %>

0 commit comments

Comments
 (0)