Class: NitroKit::Toast::Item

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

Constant Summary collapse

VARIANTS =
i[default warning error success]

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(title: nil, description: nil, variant: :default, **attrs) ⇒ Item

Returns a new instance of Item.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/nitro_kit/toast.rb', line 27

def initialize(title: nil, description: nil, variant: :default, **attrs)
  @title = title
  @description = description
  @variant = variant

  super(
    **mattr(
      attrs,
      class: [
        base_class,
        variant_class
      ],
      role: "status",
      aria: { live: "off", atomic: "true" },
      tabindex: "0",
      data: { state: "closed" }
    )
  )
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



47
48
49
# File 'app/components/nitro_kit/toast.rb', line 47

def description
  @description
end

#titleObject (readonly)

Returns the value of attribute title.



47
48
49
# File 'app/components/nitro_kit/toast.rb', line 47

def title
  @title
end

#variantObject (readonly)

Returns the value of attribute variant.



47
48
49
# File 'app/components/nitro_kit/toast.rb', line 47

def variant
  @variant
end

Instance Method Details

#view_template(&block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/components/nitro_kit/toast.rb', line 49

def view_template(&block)
  li(**attrs) do
    div(class: "grid gap-1") do
      div(class: "text-sm font-semibold", data: { slot: "title" }) do
        title && plain(title)
      end

      div(class: "text-sm opacity-90", data: { slot: "description" }) do
        text_or_block(description, &block)
      end
    end
  end
end