The personal finance app for everyone (by everyone)
Ruby
refactor(misc): migrate misc badges to DS::Pill (#1751 PR D) (#1919)
Guillem Arias Faustee15349d57e87
diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rbindex d79535146f..adc964f7b8 100644--- a/app/helpers/reports_helper.rb+++ b/app/helpers/reports_helper.rb@@ -1,15 +1,13 @@module ReportsHelper- # Returns CSS classes for tax treatment badge styling- def tax_treatment_badge_classes(treatment)+ # Returns the DS::Pill tone for a given tax treatment. Mirrors the+ # mapping used by `accounts/_tax_treatment_badge.html.erb` so the+ # report and the per-account badge stay visually aligned.+ def tax_treatment_pill_tone(treatment)case treatment.to_sym- when :tax_exempt- "bg-green-500/10 text-green-600 theme-dark:text-green-400"- when :tax_deferred- "bg-blue-500/10 text-blue-600 theme-dark:text-blue-400"- when :tax_advantaged- "bg-purple-500/10 text-purple-600 theme-dark:text-purple-400"- else- "bg-gray-500/10 text-secondary"+ when :tax_exempt then :green+ when :tax_deferred then :indigo # was raw blue-500/10 → closest DS tone+ when :tax_advantaged then :violet # was raw purple-500/10 → closest DS tone+ else :neutralendenddiff --git a/app/views/accounts/_tax_treatment_badge.html.erb b/app/views/accounts/_tax_treatment_badge.html.erbindex cd38232715..b27da23816 100644--- a/app/views/accounts/_tax_treatment_badge.html.erb+++ b/app/views/accounts/_tax_treatment_badge.html.erb@@ -1,17 +1,17 @@<%# locals: (account:) %><%treatment = account.tax_treatment- badge_classes = case treatment- when :tax_exempt- "bg-green-500/10 text-green-600 theme-dark:text-green-400"- when :tax_deferred- "bg-blue-500/10 text-blue-600 theme-dark:text-blue-400"- when :tax_advantaged- "bg-purple-500/10 text-purple-600 theme-dark:text-purple-400"- else- "bg-gray-tint-10 text-secondary"- end+ tone = case treatment+ when :tax_exempt then :green+ when :tax_deferred then :indigo # was raw blue-500/10 → maps to closest DS tone+ when :tax_advantaged then :violet # was raw purple-500/10 → maps to closest DS tone+ else :neutral+ end%>-<span class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium <%= badge_classes %>" title="<%= t("accounts.tax_treatment_descriptions.#{treatment}") %>">- <%= account.tax_treatment_label %>-</span>+<%= render DS::Pill.new(+ label: account.tax_treatment_label,+ tone: tone,+ marker: false,+ show_dot: false,+ title: t("accounts.tax_treatment_descriptions.#{treatment}")+) %>diff --git a/app/views/import/qif_category_selections/show.html.erb b/app/views/import/qif_category_selections/show.html.erbindex 4976d99612..f2b4430045 100644--- a/app/views/import/qif_category_selections/show.html.erb+++ b/app/views/import/qif_category_selections/show.html.erb@@ -83,7 +83,7 @@<div class="col-span-8 flex items-center gap-2"><span class="text-sm text-primary"><%= category %></span><% if is_split %>- <span class="inline-flex items-center rounded-full bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning"><%= t(".split_badge") %></span>+ <%= render DS::Pill.new(label: t(".split_badge"), tone: :warning, marker: false, show_dot: false) %><% end %></div><span class="col-span-3 text-sm text-secondary text-right">diff --git a/app/views/investment_activity/_badge.html.erb b/app/views/investment_activity/_badge.html.erbindex 549d5b33f0..646e04d4d1 100644--- a/app/views/investment_activity/_badge.html.erb+++ b/app/views/investment_activity/_badge.html.erb@@ -1,33 +1,14 @@<%# locals: (label:) %>-<%# Simple non-interactive badge for displaying activity labels %>+<%# Simple non-interactive badge for displaying activity labels. %><%- # Color mapping for different investment activity labels- color = case label- when "Buy"- "rgb(59 130 246)" # blue- when "Sell"- "rgb(239 68 68)" # red- when "Dividend", "Interest"- "rgb(34 197 94)" # green- when "Contribution"- "rgb(168 85 247)" # purple- when "Withdrawal"- "rgb(249 115 22)" # orange- when "Fee"- "rgb(107 114 128)" # gray- when "Transfer", "Sweep In", "Sweep Out", "Exchange"- "rgb(107 114 128)" # gray- when "Reinvestment"- "rgb(59 130 246)" # blue- else- "rgb(107 114 128)" # gray for "Other"- end+ tone = case label+ when "Buy", "Reinvestment" then :indigo # was raw blue+ when "Sell" then :red+ when "Dividend", "Interest" then :green+ when "Contribution" then :violet # was raw purple+ when "Withdrawal" then :amber # was raw orange+ when "Fee", "Transfer", "Sweep In", "Sweep Out", "Exchange" then :gray+ else :gray+ end%>--<span class="inline-flex items-center gap-1 text-xs font-medium rounded px-1.5 py-0.5 border"- style="- background-color: color-mix(in oklab, <%= color %> 10%, transparent);- border-color: color-mix(in oklab, <%= color %> 20%, transparent);- color: <%= color %>;">- <%= label %>-</span>+<%= render DS::Pill.new(label: label, tone: tone, marker: false, show_dot: false) %>diff --git a/app/views/reports/_investment_performance.html.erb b/app/views/reports/_investment_performance.html.erbindex 10f6b80342..23a922ebc9 100644--- a/app/views/reports/_investment_performance.html.erb+++ b/app/views/reports/_investment_performance.html.erb@@ -118,9 +118,13 @@<% investment_metrics[:gains_by_tax_treatment].each do |treatment, data| %><div class="bg-container-inset rounded-lg p-4 space-y-3 flex-1 min-w-64"><div class="flex items-center justify-between">- <span class="inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium <%= tax_treatment_badge_classes(treatment) %>" title="<%= t("accounts.tax_treatment_descriptions.#{treatment}") %>">- <%= t("accounts.tax_treatments.#{treatment}") %>- </span>+ <%= render DS::Pill.new(+ label: t("accounts.tax_treatments.#{treatment}"),+ tone: tax_treatment_pill_tone(treatment),+ marker: false,+ show_dot: false,+ title: t("accounts.tax_treatment_descriptions.#{treatment}")+ ) %><span class="text-sm font-semibold text-primary privacy-sensitive"><%= format_money(data[:total_gain]) %></span>diff --git a/app/views/shared/_badge.html.erb b/app/views/shared/_badge.html.erbindex 810a5fc082..7d46618ec0 100644--- a/app/views/shared/_badge.html.erb+++ b/app/views/shared/_badge.html.erb@@ -1,22 +1,22 @@<%# locals: (color: nil, pulse: false) %>-+<%#+ Thin shim over DS::Pill: maps the shared/_badge string color values+ (`success` / `error` / `warning` / nil) to semantic tones and renders+ the yielded block as the pill label. `pulse: true` wraps the pill in+ an `animate-pulse` span (DS::Pill itself doesn't support pulse).+%><%- def badge_classes(c, p)- classes = case c- when "success"- "bg-green-500/5 text-green-500"- when "error"- "bg-red-500/5 text-red-500"- when "warning"- "bg-orange-500/5 text-orange-500"- else- "bg-gray-tint-5 text-secondary"- end-- p ? "#{classes} animate-pulse" : classes- end+ tone = case color+ when "success" then :success+ when "error" then :error+ when "warning" then :warning+ else :neutral+ end+ label = yield+ pill = render DS::Pill.new(label: label, tone: tone, marker: false, show_dot: false)%>--<span class="inline-flex items-center px-2 py-0.5 rounded-full ring ring-alpha-black-50 text-xs <%= badge_classes(color, pulse) %>">- <%= yield %>-</span>+<% if pulse %>+ <span class="animate-pulse inline-flex"><%= pill %></span>+<% else %>+ <%= pill %>+<% end %>