Class: PhlexKit::ToastItem

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/toast/toast_item.rb

Overview

A single toast

  • — rendered server-side (flash) or cloned from a skeleton template by the toaster. The phlex-kit--toast controller runs the auto-close timer (pause on hover), swipe-to-dismiss, and Escape. The toaster stacks it via inline --y-offset/--scale/--opacity. See toast_region.rb.

  • Constant Summary collapse

    VARIANTS =
    {
      default: "default",
      success: "success",
      error: "error",
      warning: "warning",
      info: "info",
      loading: "loading"
    }.freeze
    ALERT_VARIANTS =

    Variants announced assertively (role="alert" instead of "status").

    %i[error].freeze

    Instance Method Summary collapse

    Methods inherited from BaseComponent

    #on

    Constructor Details

    #initialize(variant: :default, id: nil, duration: nil, dismissible: true, invert: false, on_dismiss: nil, on_auto_close: nil, **attrs) ⇒ ToastItem

    Returns a new instance of ToastItem.

    
    
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    # File 'app/components/phlex_kit/toast/toast_item.rb', line 19
    
    def initialize(
      variant: :default,
      id: nil,
      duration: nil,
      dismissible: true,
      invert: false,
      on_dismiss: nil,
      on_auto_close: nil,
      **attrs
    )
      @variant = variant.to_sym
      @id = id
      @duration = duration
      @dismissible = dismissible
      @invert = invert
      @on_dismiss = on_dismiss
      @on_auto_close = on_auto_close
      @attrs = attrs
    end

    Instance Method Details

    #view_templateObject

    
    
    39
    40
    41
    # File 'app/components/phlex_kit/toast/toast_item.rb', line 39
    
    def view_template(&)
      li(**mix(item_attrs, @attrs), &)
    end