Class: Daisy::Feedback::ToastComponent

Inherits:
LocoMotion::BaseComponent show all
Defined in:
app/components/daisy/feedback/toast_component.rb

Overview

Note:

This component only handles positioning. For show/hide behavior, use the AlertComponent options on the alerts inside the toast — autoclose (with timeout) auto-dismisses an alert and closable renders a manual close button, both driven by the loco-alert Stimulus controller. As with loco-theme, the consuming app must register that controller (the npm package's AlertController) for dismissal to work.

The ToastComponent provides a container for displaying non-critical messages to users, typically positioned at the edges of the viewport. Toasts are commonly used for temporary notifications, success messages, or error alerts that don't require immediate user action.

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 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) ⇒ ToastComponent

Creates a new Toast component.

Parameters:

  • args (Array)

    Positional arguments passed to the parent class.

  • kws (Hash)

    Keyword arguments for customizing the toast.

Options Hash (**kws):

  • css (String)

    Additional CSS classes for styling. By default, toasts are positioned in the bottom-right corner of the viewport. Common options include:

    • Position modifiers: toast-top, toast-middle, toast-bottom, toast-start, toast-center, toast-end
    • Stack order: z-50


50
51
52
# File 'app/components/daisy/feedback/toast_component.rb', line 50

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

Instance Method Details

#before_renderObject



54
55
56
# File 'app/components/daisy/feedback/toast_component.rb', line 54

def before_render
  add_css(:component, "toast")
end

#callObject



58
59
60
# File 'app/components/daisy/feedback/toast_component.rb', line 58

def call
  part(:component) { content }
end