Class: NitroKit::Toast::Item
- Defined in:
- app/components/nitro_kit/toast.rb
Constant Summary collapse
- VARIANTS =
%i[default info success warning error].freeze
- ASSERTIVE_VARIANTS =
%i[error].freeze
Constants inherited from Component
Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#dismissible ⇒ Object
readonly
Returns the value of attribute dismissible.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
-
#initialize(title: nil, description: nil, variant: :default, dismissible: true, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Item
constructor
A new instance of Item.
- #view_template(&block) ⇒ Object
Constructor Details
#initialize(title: nil, description: nil, variant: :default, dismissible: true, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Item
Returns a new instance of Item.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/components/nitro_kit/toast.rb', line 14 def initialize( title: nil, description: nil, variant: :default, dismissible: true, id: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) @title = optional_text(:title, title) @description = optional_text(:description, description) @variant = validate_choice!(:variant, variant, VARIANTS) @dismissible = validate_boolean!(:dismissible, dismissible) super( component: :toast_item, attributes: { id:, role: ASSERTIVE_VARIANTS.include?(@variant) ? "alert" : "status", aria: { atomic: true }, data: { state: "open", turbo_temporary: true, nk__toast_target: "item", nk__toast_permanent: dismissible ? nil : "true", action: [ "pointerenter->nk--toast#pause", "pointerleave->nk--toast#resume", "focusin->nk--toast#pause", "focusout->nk--toast#resume", "transitionend->nk--toast#remove" ].join(" ") } }, html:, aria:, data:, variant:, desperately_need_a_class: ) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
58 59 60 |
# File 'app/components/nitro_kit/toast.rb', line 58 def description @description end |
#dismissible ⇒ Object (readonly)
Returns the value of attribute dismissible.
58 59 60 |
# File 'app/components/nitro_kit/toast.rb', line 58 def dismissible @dismissible end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
58 59 60 |
# File 'app/components/nitro_kit/toast.rb', line 58 def title @title end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
58 59 60 |
# File 'app/components/nitro_kit/toast.rb', line 58 def variant @variant end |
Instance Method Details
#view_template(&block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/components/nitro_kit/toast.rb', line 60 def view_template(&block) if title.nil? && description.nil? && !block raise ArgumentError, "Toast item requires a title, description, or block" end li(**root_attributes) do div(**slot_attributes(:content)) do p(**slot_attributes(:title)) { plain(title) } if title div(**slot_attributes(:description)) do block ? yield : plain(description.to_s) end if description || block end if dismissible end end |