diff --git a/app/components/DS/alert.html.erb b/app/components/DS/alert.html.erb index 419a4607c..efda08221 100644 --- a/app/components/DS/alert.html.erb +++ b/app/components/DS/alert.html.erb @@ -1,15 +1,37 @@ -
- <%= helpers.icon icon_name, size: "sm", color: icon_color, class: "shrink-0 mt-0.5" %> +<%= tag.div(class: container_classes, role: aria_role, "aria-labelledby": (aria_role && title.present?) ? title_id : nil) do %> + <% if title.present? %> +
+ <%= helpers.icon icon_name, size: "sm", color: icon_color, class: "shrink-0 -mt-0.5" %> +

+ <%= variant_label %>: + <%= title %> +

+
-
- <% if title.present? %> -

<%= title %>

+ <% if content.present? || message.present? %> +
+ <% if content.present? %> + <%= content %> + <% else %> + <%= message %> + <% end %> +
<% end %> - - <% if content.present? %> - <%= content %> - <% elsif message.present? %> - <%= message %> - <% end %> -
-
+ <% elsif content.present? %> +
+ <%= helpers.icon icon_name, size: "sm", color: icon_color, class: "shrink-0" %> +
+ <%= variant_label %>: + <%= content %> +
+
+ <% elsif message.present? %> +
+ <%= helpers.icon icon_name, size: "sm", color: icon_color, class: "shrink-0 -mt-0.5" %> +

+ <%= variant_label %>: + <%= message %> +

+
+ <% end %> +<% end %> diff --git a/app/components/DS/alert.rb b/app/components/DS/alert.rb index dc7025eb7..050beaf66 100644 --- a/app/components/DS/alert.rb +++ b/app/components/DS/alert.rb @@ -1,22 +1,34 @@ class DS::Alert < DesignSystemComponent VARIANTS = %i[info success warning error destructive].freeze + LIVE_MODES = %i[none status alert].freeze - def initialize(message: nil, title: nil, variant: :info) + def initialize(message: nil, title: nil, variant: :info, live: :none) @message = message @title = title @variant = normalize_variant(variant) + @live = normalize_live(live) end private - attr_reader :message, :title, :variant + attr_reader :message, :title, :variant, :live def normalize_variant(raw) sym = raw.respond_to?(:to_sym) ? raw.to_sym : nil VARIANTS.include?(sym) ? sym : :info end + def normalize_live(raw) + sym = raw.respond_to?(:to_sym) ? raw.to_sym : nil + case sym + when :polite then :status + when :assertive then :alert + when *LIVE_MODES then sym + else :none + end + end + def container_classes - base_classes = "flex items-start gap-3 p-4 rounded-lg border" + base_classes = "p-4 rounded-lg border" variant_classes = case variant when :info @@ -57,4 +69,19 @@ class DS::Alert < DesignSystemComponent "info" end end + + def aria_role + case live + when :status then "status" + when :alert then "alert" + end + end + + def variant_label + I18n.t("ds.alert.variants.#{variant}") + end + + def title_id + @title_id ||= "DS-alert-title-#{SecureRandom.hex(4)}" + end end diff --git a/app/views/settings/providers/_binance_panel.html.erb b/app/views/settings/providers/_binance_panel.html.erb index f93eeea47..49b8cd0d4 100644 --- a/app/views/settings/providers/_binance_panel.html.erb +++ b/app/views/settings/providers/_binance_panel.html.erb @@ -3,10 +3,8 @@ <%= render DS::Alert.new( variant: :warning, - message: safe_join([ - content_tag(:p, t("settings.providers.binance_panel.no_withdraw_title"), class: "font-medium"), - content_tag(:p, t("settings.providers.binance_panel.no_withdraw_body"), class: "mt-1") - ]) + title: t("settings.providers.binance_panel.no_withdraw_title"), + message: t("settings.providers.binance_panel.no_withdraw_body") ) %>
diff --git a/app/views/settings/providers/_enable_banking_panel.html.erb b/app/views/settings/providers/_enable_banking_panel.html.erb index 4085520ef..45344ea55 100644 --- a/app/views/settings/providers/_enable_banking_panel.html.erb +++ b/app/views/settings/providers/_enable_banking_panel.html.erb @@ -71,10 +71,8 @@ <% if has_authenticated_connections && !is_new_record %> <%= render DS::Alert.new( variant: :warning, - message: safe_join([ - content_tag(:p, "Configuration locked", class: "font-medium"), - content_tag(:p, "Disconnect all linked banks before changing these credentials.", class: "mt-1") - ]) + title: "Configuration locked", + message: "Disconnect all linked banks before changing these credentials." ) %> <% end %> diff --git a/app/views/settings/providers/show.html.erb b/app/views/settings/providers/show.html.erb index b78a19a96..9108eabcd 100644 --- a/app/views/settings/providers/show.html.erb +++ b/app/views/settings/providers/show.html.erb @@ -4,10 +4,8 @@ <% if @encryption_error %> <%= render DS::Alert.new( variant: :error, - message: safe_join([ - content_tag(:h2, t("settings.providers.encryption_error.title"), class: "font-medium"), - content_tag(:p, t("settings.providers.encryption_error.message"), class: "text-sm mt-1") - ]) + title: t("settings.providers.encryption_error.title"), + message: t("settings.providers.encryption_error.message") ) %> <% else %>
diff --git a/config/locales/views/components/en.yml b/config/locales/views/components/en.yml index 9230a79ec..b17124e37 100644 --- a/config/locales/views/components/en.yml +++ b/config/locales/views/components/en.yml @@ -1,5 +1,13 @@ --- en: + ds: + alert: + variants: + info: Info + success: Success + warning: Warning + error: Error + destructive: Error provider_sync_summary: title: Sync summary last_sync: "Last sync: %{time_ago} ago"