Class: Daisy::Feedback::AlertComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::IconableComponent
Defined in:
app/components/daisy/feedback/alert_component.rb

Overview

The AlertComponent displays an important message to users. It can be used to show information, success messages, warnings, or errors. Alerts can include an optional icon at the start and customizable content.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods included from LocoMotion::Concerns::IconableComponent

#has_icons?, #left_icon_html, #render_left_icon, #render_right_icon, #right_icon_html

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Constructor Details

#initialize(*args, **kws, &block) ⇒ AlertComponent

Creates a new Alert component.

Options Hash (**kws):

  • icon (String)

    The name of the Heroicon to display at the start of the alert.

  • icon_html (Hash)

    Additional HTML attributes for the icon element. Options include ‘variant: :outline` or `variant: :solid`.

  • css (String)

    Additional CSS classes for the alert. Use ‘alert-info`, `alert-success`, `alert-warning`, or `alert-error` for different alert types.

  • style (String)

    The style of the alert.

    :info, :success, :warning, :error, :default
  • soft (Boolean)

    Use the soft style variant.

  • outline (Boolean)

    Use the outline style variant.

  • dash (Boolean)

    Use the dash style variant.



134
135
136
137
138
# File 'app/components/daisy/feedback/alert_component.rb', line 134

def initialize(*args, **kws, &block)
  super

  @icon = config_option(:icon)
end

Instance Method Details

#before_renderObject



144
145
146
147
# File 'app/components/daisy/feedback/alert_component.rb', line 144

def before_render
  add_css(:component, "alert")
  add_html(:component, { role: "alert" })
end

#default_icon_sizeObject



140
141
142
# File 'app/components/daisy/feedback/alert_component.rb', line 140

def default_icon_size
  "where:size-6"
end