Class: RubyUI::ToastRegion

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_ui/toast/toast_region.rb

Constant Summary collapse

SKELETON_VARIANTS =
%i[default success error warning info loading].freeze

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Constructor Details

#initialize(position: :bottom_right, expand: false, max: 3, duration: 4000, gap: 14, offset: 24, theme: :system, rich_colors: false, close_button: false, hotkey: %w[alt t],, dir: :ltr, flash: nil, **attrs) ⇒ ToastRegion

Returns a new instance of ToastRegion.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_ui/toast/toast_region.rb', line 7

def initialize(
  position: :bottom_right,
  expand: false,
  max: 3,
  duration: 4000,
  gap: 14,
  offset: 24,
  theme: :system,
  rich_colors: false,
  close_button: false,
  hotkey: %w[alt t],
  dir: :ltr,
  flash: nil,
  **attrs
)
  @position = position.to_sym
  @expand = expand
  @max = max
  @duration = duration
  @gap = gap
  @offset = offset
  @theme = theme.to_sym
  @rich_colors = rich_colors
  @close_button = close_button
  @hotkey = hotkey
  @dir = dir
  @flash = flash
  super(**attrs)
end

Instance Method Details

#view_template(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_ui/toast/toast_region.rb', line 37

def view_template(&block)
  div(**attrs) do
    ol(id: "ruby-ui-toaster", class: "pointer-events-auto relative m-0 p-0 list-none w-[356px] max-w-full") do
      render_flash if @flash
      yield(self) if block
    end
    SKELETON_VARIANTS.each { |v| skeleton(v) }
    slot_template("actionTpl") { render RubyUI::ToastAction.new(label: "") }
    slot_template("cancelTpl") { render RubyUI::ToastCancel.new(label: "") }
    slot_template("closeTpl") { render RubyUI::ToastClose.new }
  end
end