Class: UI::SonnerToasterComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ToasterBehavior
Defined in:
app/view_components/ui/sonner_toaster_component.rb

Overview

Sonner Toaster component (ViewComponent) Container for toast notifications - render once in your layout

Examples:

Basic usage

<%= render UI::ToasterComponent.new %>

With options

<%= render UI::ToasterComponent.new(
  position: "top-center",
  theme: "dark",
  rich_colors: true,
  close_button: true
) %>

Instance Method Summary collapse

Constructor Details

#initialize(position: "bottom-right", theme: "system", rich_colors: false, expand: false, duration: 4000, close_button: false, visible_toasts: 3, classes: "", **attributes) ⇒ SonnerToasterComponent

Returns a new instance of SonnerToasterComponent.

Parameters:

  • position (String) (defaults to: "bottom-right")

    Toast position (top-left, top-center, top-right, bottom-left, bottom-center, bottom-right)

  • theme (String) (defaults to: "system")

    Theme (light, dark, system)

  • rich_colors (Boolean) (defaults to: false)

    Use rich colors for toast types

  • expand (Boolean) (defaults to: false)

    Expand toasts on hover

  • duration (Integer) (defaults to: 4000)

    Default toast duration in milliseconds

  • close_button (Boolean) (defaults to: false)

    Show close button on toasts

  • visible_toasts (Integer) (defaults to: 3)

    Maximum number of visible toasts

  • classes (String) (defaults to: "")

    Additional CSS classes

  • attributes (Hash)

    Additional HTML attributes



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/view_components/ui/sonner_toaster_component.rb', line 28

def initialize(
  position: "bottom-right",
  theme: "system",
  rich_colors: false,
  expand: false,
  duration: 4000,
  close_button: false,
  visible_toasts: 3,
  classes: "",
  **attributes
)
  @position = position
  @theme = theme
  @rich_colors = rich_colors
  @expand = expand
  @duration = duration
  @close_button = close_button
  @visible_toasts = visible_toasts
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



50
51
52
# File 'app/view_components/ui/sonner_toaster_component.rb', line 50

def call
   :ol, "", **toaster_html_attributes
end