Module: UI::AlertBehavior
- Included in:
- Alert, AlertComponent
- Defined in:
- app/behaviors/ui/alert_behavior.rb
Overview
UI::AlertBehavior
Instance Method Summary collapse
-
#alert_base_classes ⇒ Object
Base CSS classes for alert container Uses grid layout that adapts when SVG icons are present.
-
#alert_classes ⇒ Object
Merge base classes with variant and custom classes.
-
#alert_html_attributes ⇒ Object
Build complete HTML attributes hash for alert container.
-
#alert_variant_classes ⇒ Object
Variant-specific classes.
-
#render_alert(&content_block) ⇒ Object
Renders the alert HTML (for ERB partials).
Instance Method Details
#alert_base_classes ⇒ Object
Base CSS classes for alert container Uses grid layout that adapts when SVG icons are present
27 28 29 |
# File 'app/behaviors/ui/alert_behavior.rb', line 27 def alert_base_classes "relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current" end |
#alert_classes ⇒ Object
Merge base classes with variant and custom classes
42 43 44 |
# File 'app/behaviors/ui/alert_behavior.rb', line 42 def alert_classes TailwindMerge::Merger.new.merge([alert_base_classes, alert_variant_classes, @classes].compact.join(" ")) end |
#alert_html_attributes ⇒ Object
Build complete HTML attributes hash for alert container
47 48 49 50 51 52 53 54 |
# File 'app/behaviors/ui/alert_behavior.rb', line 47 def alert_html_attributes base_attrs = @attributes || {} base_attrs.merge( class: alert_classes, role: "alert", "data-slot": "alert" ) end |
#alert_variant_classes ⇒ Object
Variant-specific classes
32 33 34 35 36 37 38 39 |
# File 'app/behaviors/ui/alert_behavior.rb', line 32 def alert_variant_classes case @variant when :destructive "border-destructive text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90" else # :default "bg-card text-card-foreground" end end |
#render_alert(&content_block) ⇒ Object
Renders the alert HTML (for ERB partials)
57 58 59 60 |
# File 'app/behaviors/ui/alert_behavior.rb', line 57 def render_alert(&content_block) all_attributes = alert_html_attributes.deep_merge(@attributes || {}) content_tag(:div, **all_attributes, &content_block) end |