Class: NitroKit::Toast

Inherits:
Component
  • Object
show all
Defined in:
app/components/nitro_kit/toast.rb

Defined Under Namespace

Classes: FlashMessages, Item

Instance Attribute Summary

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(**attrs) ⇒ Toast

Returns a new instance of Toast.



85
86
87
88
89
90
91
92
93
# File 'app/components/nitro_kit/toast.rb', line 85

def initialize(**attrs)
  super(
    attrs,
    role: "region",
    tabindex: "-1",
    aria: { label: "Notifications" },
    class: "pointer-events-none"
  )
end

Instance Method Details

#flash_sinkObject



111
112
113
114
115
# File 'app/components/nitro_kit/toast.rb', line 111

def flash_sink
  div(id: "nk--toast-sink", data: { nk__toast_target: "sink" }, hidden: true) do
    render(FlashMessages.new(view_context.flash))
  end
end

#item(title: nil, description: nil, **attrs, &block) ⇒ Object



107
108
109
# File 'app/components/nitro_kit/toast.rb', line 107

def item(title: nil, description: nil, **attrs, &block)
  render(Item.new(title:, description:, **attrs), &block)
end

#view_templateObject



95
96
97
98
99
100
101
102
103
104
105
# File 'app/components/nitro_kit/toast.rb', line 95

def view_template
  div(**attrs) do
    ol(class: list_class, data: { nk__toast_target: "list" })
  end

  flash_sink

  template(data: { nk__toast_target: "template" }) do
    item
  end
end