Class: Daisy::Feedback::AlertComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::LinkableComponent
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 collapse

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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

Constructor Details

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

Creates a new Alert component.

Parameters:

  • args (Array)

    Positional arguments passed to the parent class.

  • kws (Hash)

    Keyword arguments for customizing the alert.

Options Hash (**kws):

  • icon (String)

    The name (or [library:]name[/variant] token) of the icon to display at the start of the alert.

  • icon_css (String)

    Additional CSS classes for the icon.

  • icon_options (Hash)

    Additional keyword arguments forwarded to the icon component that renders the icon. Rarely needed.

  • icon_html (Hash)

    Additional HTML attributes for the icon element, such as data or aria attributes. To pick an icon variant, use the icon token instead (e.g. "check-circle/solid").

  • css (String)

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

  • href (String)

    Converts alert to a clickable link.

  • target (String)

    The HTML target for the <a> tag when href is set (_blank, _parent, or a specific tab / window / iframe, etc).

  • title (String)

    The HTML title attribute for the <a> tag when href is set.

  • turbo_frame (String)

    The Turbo Frame to target, rendered as data-turbo-frame.

  • turbo_action (String, Symbol)

    How Turbo Drive updates the browser history for the visit, rendered as data-turbo-action (e.g. :advance or :replace).

  • turbo_method (String, Symbol)

    The HTTP method Turbo should use for the request, rendered as data-turbo-method (e.g. :delete).

  • turbo_confirm (String)

    A confirmation prompt Turbo shows before submitting, rendered as data-turbo-confirm.

  • action (String)

    Stimulus action to fire on click.

  • timeout (Integer)

    Auto-dismiss timeout in milliseconds. If nil, uses global configuration default. If false, no auto-dismiss.

  • autoclose (Boolean)

    Enable auto-dismiss using timeout. Must be true for auto-dismiss to work.

  • closable (Boolean)

    Show close button. Set to true to enable manual dismissal.



185
186
187
188
189
190
191
192
193
194
195
196
# File 'app/components/daisy/feedback/alert_component.rb', line 185

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

  @icon = config_option(:icon)
  @timeout = config_option(:timeout)
  @autoclose = config_option(:autoclose)
  @closable = config_option(:closable, false)

  # `action:` (and its `data-action`) is handled by ActionableComponent,
  # pulled in via LinkableComponent. Emitting it here too would render a
  # duplicate `data-action` attribute.
end

Instance Attribute Details

#closableBoolean (readonly) Also known as: closable?

Returns Whether or not this alert can be closed.

Returns:

  • (Boolean)

    Whether or not this alert can be closed.



127
128
129
# File 'app/components/daisy/feedback/alert_component.rb', line 127

def closable
  @closable
end

Instance Method Details

#before_renderObject



202
203
204
205
206
# File 'app/components/daisy/feedback/alert_component.rb', line 202

def before_render
  setup_component

  super
end

#default_icon_sizeObject



198
199
200
# File 'app/components/daisy/feedback/alert_component.rb', line 198

def default_icon_size
  "where:size-6"
end