Class: ShadcnPhlexcomponents::Toast

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/toast.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(variant: :default, side: :top, duration: 5000, **attributes) ⇒ Toast

Returns a new instance of Toast.



30
31
32
33
34
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 30

def initialize(variant: :default, side: :top, duration: 5000, **attributes)
  @class_variants = { variant: variant, side: side }
  @duration = duration
  super(**attributes)
end

Instance Method Details

#action(**attributes) ⇒ Object



48
49
50
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 48

def action(**attributes, &)
  ToastAction(**attributes, &)
end

#action_to(name = nil, options = nil, html_options = nil) ⇒ Object



52
53
54
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 52

def action_to(name = nil, options = nil, html_options = nil, &)
  ToastActionTo(name, options, html_options, &)
end

#content(**attributes) ⇒ Object



36
37
38
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 36

def content(**attributes, &)
  ToastContent(**attributes, &)
end

#default_attributes ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 56

def default_attributes
  {
    role: "status",
    tabindex: 0,
    aria: {
      live: "off",
      atomic: "true",
    },
    data: {
      duration: @duration,
      state: "open",
      controller: "toast",
      action: <<~HEREDOC,
        focus->toast#cancelClose
        blur->toast#close
        mouseover->toast#cancelClose
        mouseout->toast#close
      HEREDOC
    },
  }
end

#description(**attributes) ⇒ Object



44
45
46
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 44

def description(**attributes, &)
  ToastDescription(**attributes, &)
end

#title(**attributes) ⇒ Object



40
41
42
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 40

def title(**attributes, &)
  ToastTitle(**attributes, &)
end

#view_template ⇒ Object



78
79
80
# File 'lib/shadcn_phlexcomponents/components/toast.rb', line 78

def view_template(&)
  li(**@attributes, &)
end