app/components/coco/app/elements/alert/alert.rb in coveragebook_components-0.9.1 vs app/components/coco/app/elements/alert/alert.rb in coveragebook_components-0.10.0
- old
+ new
@@ -1,25 +1,14 @@
module Coco
module App
module Elements
class Alert < Coco::Component
- include Concerns::WithIcon
+ include Concerns::AcceptsOptions
include Concerns::AcceptsTheme
THEMES = %W[positive warning negative info positive-vivid warning-vivid negative-vivid info-vivid]
- THEME_ICONS = {
- positive: :check_circle,
- positive_vivid: :check_circle,
- warning: :alert_triangle,
- warning_vivid: :alert_triangle,
- negative: :alert_circle,
- negative_vivid: :alert_circle,
- info: :info,
- info_vivid: :info
- }.freeze
-
accepts_option :dismissable, from: [true, false], default: false
accepts_option :dismiss_after_action, from: [true, false], default: true
accepts_option :banner, from: [true, false], default: false
accepts_option :theme, from: THEMES, default: "info"
accepts_option :single_line, from: [true, false]
@@ -43,17 +32,13 @@
theme = vivid? ? nil : unvividify(get_option_value(:theme))
@link_data = {args: args, kwargs: kwargs.merge(theme: theme), block: block}
end
before_render do
- theme = get_option_value(:theme)
-
unless tag_attr?(:id)
set_tag_attr(:id, "alert-#{rand(1000)}")
end
-
- icon(name: THEME_ICONS[theme.tr("-", "_").to_sym])
end
def dismissable?
get_option_value(:dismissable)
end
@@ -75,9 +60,19 @@
theme.to_s.match?(/vivid$/) ? theme.to_s.underscore.gsub("_vivid", "").to_sym : theme
end
def button_size
get_option_value(:condensed) ? :xs : :sm
+ end
+
+ def stamp
+ type = unvividify(get_option_value(:theme))&.to_sym
+ style = if get_option_value(:banner)
+ :compact
+ else
+ vivid? ? :inverse : :subtle
+ end
+ coco_stamp(type, style:)
end
end
end
end
end