Class: UI::Toast

Inherits:
Base
  • Object
show all
Defined in:
app/views/ui/toast.rb

Constant Summary collapse

AUTO_DISMISS_DELAY =
8000

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template

Constructor Details

#initialize(**props) ⇒ Toast

Returns a new instance of Toast.



13
14
15
16
# File 'app/views/ui/toast.rb', line 13

def initialize(**props)
  super
  @action = nil
end

Instance Method Details

#action(href:, text:) ⇒ Object



42
43
44
45
# File 'app/views/ui/toast.rb', line 42

def action(href:, text:)
  @action = {href:, text:}
  nil
end

#view_templateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/views/ui/toast.rb', line 18

def view_template
  output(
    data: {
      controller: "dismissable",
      dismissable_auto_dismiss_time_value: auto_dismiss_delay
    },
    class: classes
  ) do
    div class: "w-full min-h-8 py-1 px-2 inline-flex items-start justify-between gap-6" do
      span(class: "mt-0.5") { yield }

      span(class: "flex items-center gap-x-6") do
        render_action

        if dismissable?
          button data: {action: "dismissable#dismiss"}, class: button_classes do
            Icon(name: :x_mark, variant: :outline, class: "mt-px")
          end
        end
      end
    end
  end
end