Class: Daisy::Feedback::AlertComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Feedback::AlertComponent
- 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.
Component Parts
The AlertComponent allows for customization of the following parts by
passing the {part_name}_css and
{part_name}_html options to the component.
Examples
Basic Alert
= daisy_alert do
This is a standard alert message.
Alert with Icon
= daisy_alert(icon: "information-circle") do
Here's some important information!
Alert Types
= daisy_alert(icon: "information-circle", css: "alert-info") do
Information alert.
= daisy_alert(icon: "check-circle", css: "alert-success") do
Success alert.
= daisy_alert(icon: "exclamation-triangle", css: "alert-warning") do
Warning alert.
= daisy_alert(icon: "exclamation-circle", css: "alert-error") do
Error alert.
Default
= daisy_alert do
This is an default alert.
Info
= daisy_alert(css: "alert-info") do
This is an info alert.
Success
= daisy_alert(css: "alert-success") do
This is a success alert.
Warning
= daisy_alert(css: "alert-warning") do
This is a warning alert.
Error
= daisy_alert(css: "alert-error") do
This is an error alert.
Soft Info
= daisy_alert(css: "alert-info alert-soft") do
This is a soft info alert.
Soft Success
= daisy_alert(css: "alert-success alert-soft") do
This is a soft success alert.
Soft Warning
= daisy_alert(css: "alert-warning alert-soft") do
This is a soft warning alert.
Soft Error
= daisy_alert(css: "alert-error alert-soft") do
This is a soft error alert.
Outline Info
= daisy_alert(css: "alert-info alert-outline") do
This is an outline info alert.
Outline Success
= daisy_alert(css: "alert-success alert-outline") do
This is an outline success alert.
Outline Warning
= daisy_alert(css: "alert-warning alert-outline") do
This is an outline warning alert.
Outline Error
= daisy_alert(css: "alert-error alert-outline") do
This is an outline error alert.
Dash Info
= daisy_alert(css: "alert-info alert-dash") do
This is a dash info alert.
Dash Success
= daisy_alert(css: "alert-success alert-dash") do
This is a dash success alert.
Dash Warning
= daisy_alert(css: "alert-warning alert-dash") do
This is a dash warning alert.
Dash Error
= daisy_alert(css: "alert-error alert-dash") do
This is a dash error alert.
Closable Alert
= daisy_alert(icon: "information-circle", css: "alert-info", closable: true) do
This alert can be closed manually.
Auto-dismissing Alert
= daisy_alert(icon: "check-circle", css: "alert-success", autoclose: true, timeout: 3000) do
This alert will auto-dismiss in 3 seconds.
Clickable Link Alert
= daisy_alert(icon: "information-circle", css: "alert-info", href: "/docs") do
Click to view documentation.
Stimulus Action Alert
= daisy_alert(icon: "exclamation-triangle", css: "alert-warning", action: "click->my-controller#handle") do
Click to trigger custom action.
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#closable ⇒ Boolean
(also: #closable?)
readonly
Whether or not this alert can be closed.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
- #before_render ⇒ Object
- #default_icon_size ⇒ Object
-
#initialize(*args, **kws, &block) ⇒ AlertComponent
constructor
Creates a new Alert component.
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
Constructor Details
#initialize(*args, **kws, &block) ⇒ AlertComponent
Creates a new Alert component.
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
#closable ⇒ Boolean (readonly) Also known as: closable?
Returns 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_render ⇒ Object
202 203 204 205 206 |
# File 'app/components/daisy/feedback/alert_component.rb', line 202 def before_render setup_component super end |
#default_icon_size ⇒ Object
198 199 200 |
# File 'app/components/daisy/feedback/alert_component.rb', line 198 def default_icon_size "where:size-6" end |