Class: Fluxbit::AlertComponent
- Includes:
- Config::AlertComponent
- Defined in:
- app/components/fluxbit/alert_component.rb
Overview
The ‘Fluxbit::AlertComponent` is a customizable alert component that extends `Fluxbit::Component`. It provides various options to display alert messages with different styles, icons, and behaviors such as close functionality and animations.
Example usage:
= render Fluxbit::AlertComponent.new(color: :success, icon: "check").with_content("Alert message")
Constant Summary
Constants inherited from Component
Instance Method Summary collapse
- #animation_props(dismiss_timeout:, fade_in_animation:, out_animation:) ⇒ Object
- #call ⇒ Object
-
#initialize(**props) ⇒ Fluxbit::AlertComponent
constructor
Initializes the alert component with the given properties.
Methods inherited from Component
#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #options, #random_id, #remove_class, #render_popover_or_tooltip, #target
Constructor Details
#initialize(**props) ⇒ Fluxbit::AlertComponent
Initializes the alert component with the given properties.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/components/fluxbit/alert_component.rb', line 34 def initialize(**props) super @props = props @color = define_color(@props.delete(:color) || @@color) @icon = define_icon(@props.delete(:icon) || :default, @props.delete(:class_icon) || "") @can_close = @props[:can_close].nil? ? @@can_close : @props.delete(:can_close) @all_rounded = @props[:all_rounded].nil? ? @@all_rounded : @props.delete(:all_rounded) @props["id"] = fx_id if @props["id"].nil? @props[:role] = "alert" prop_fade_in_automation = @props.delete(:fade_in_animation) animation_props( dismiss_timeout: [ (@props.delete(:dismiss_timeout) || @@dismiss_timeout).to_i, 0 ].max, fade_in_animation: prop_fade_in_automation.nil? ? @@fade_in_animation : prop_fade_in_automation, out_animation: @props.delete(:out_animation) || @@out_animation ) declare_classes @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class]) end |
Instance Method Details
#animation_props(dismiss_timeout:, fade_in_animation:, out_animation:) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/components/fluxbit/alert_component.rb', line 54 def animation_props(dismiss_timeout:, fade_in_animation:, out_animation:) return if [ :dont_remove, nil ].include?(out_animation) || dismiss_timeout.to_i == 0 @props["data-controller"] = "notification" @props["data-action"] = "notification#hide" @props["data-notification-delay-value"] = dismiss_timeout.to_s add(to: @props, class: "transition transform duration-1000 hidden") if fade_in_animation @props["data-transition-enter-from"] = "opacity-0" @props["data-transition-enter-to"] = "opacity-100" else @props["data-transition-enter-from"] = "opacity-100" @props["data-transition-enter-to"] = "opacity-100" end @props["data-transition-leave-from"] = styles[:animations][out_animation.to_sym][:from] @props["data-transition-leave-to"] = styles[:animations][out_animation.to_sym][:to] end |
#call ⇒ Object
75 76 77 78 79 80 81 |
# File 'app/components/fluxbit/alert_component.rb', line 75 def call content_tag :div, @props do concat @icon concat content_tag(:div, content, class: "ml-3 text-sm font-medium") concat end end |