Class: Flowbite::Toast

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/flowbite/toast.rb,
app/components/flowbite/toast/icon.rb

Overview

Renders a toast notification element.

Examples:

Usage

<%= render(Flowbite::Toast.new(message: "Something has happened!")) %>

See Also:

Defined Under Namespace

Classes: Icon

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, dismissible: true, style: :default, class: nil, **options) ⇒ Toast

Returns a new instance of Toast.

Parameters:

  • class (Array<String>) (defaults to: nil)

    Additional CSS classes for the toast container.

  • dismissible (Boolean) (defaults to: true)

    Whether the toast can be dismissed (default: true).

  • message (String)

    The message to display in the toast.

  • options (Hash)

    Additional HTML options for the toast container.

  • style (Symbol) (defaults to: :default)

    The color style of the toast (:default, :success, :danger, :warning).



25
26
27
28
29
30
31
# File 'app/components/flowbite/toast.rb', line 25

def initialize(message:, dismissible: true, style: :default, class: nil, **options)
  @message = message
  @style = style
  @dismissible = dismissible
  @class = Array.wrap(binding.local_variable_get(:class))
  @options = options
end

Instance Attribute Details

#dismissibleObject (readonly)

Returns the value of attribute dismissible.



18
19
20
# File 'app/components/flowbite/toast.rb', line 18

def dismissible
  @dismissible
end

#messageObject (readonly)

Returns the value of attribute message.



18
19
20
# File 'app/components/flowbite/toast.rb', line 18

def message
  @message
end

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'app/components/flowbite/toast.rb', line 18

def options
  @options
end

#styleObject (readonly)

Returns the value of attribute style.



18
19
20
# File 'app/components/flowbite/toast.rb', line 18

def style
  @style
end

Class Method Details

.classesObject



13
14
15
# File 'app/components/flowbite/toast.rb', line 13

def classes
  ["flex", "items-center", "w-full", "max-w-xs", "p-4", "text-body", "bg-neutral-primary-soft", "rounded-base", "shadow-xs", "border", "border-default"]
end

Instance Method Details

#container_classesObject



33
34
35
# File 'app/components/flowbite/toast.rb', line 33

def container_classes
  self.class.classes + @class
end