Module: MaquinaComponents::ToastHelper
- Defined in:
- app/helpers/maquina_components/toast_helper.rb
Overview
Toast Helper
Provides helpers for rendering toast notifications.
Constant Summary collapse
- FLASH_VARIANTS =
Flash type to toast variant mapping
{ notice: :success, success: :success, alert: :error, error: :error, warning: :warning, warn: :warning, info: :info }.freeze
Instance Method Summary collapse
-
#toast(variant, title, description: nil, **options) ⇒ String
Render a single toast.
-
#toast_error(title, **options) ⇒ String
Render an error toast.
-
#toast_flash_messages(exclude: []) ⇒ String
Render all flash messages as toasts.
-
#toast_info(title, **options) ⇒ String
Render an info toast.
-
#toast_success(title, **options) ⇒ String
Render a success toast.
-
#toast_warning(title, **options) ⇒ String
Render a warning toast.
Instance Method Details
#toast(variant, title, description: nil, **options) ⇒ String
Render a single toast
60 61 62 63 64 65 66 |
# File 'app/helpers/maquina_components/toast_helper.rb', line 60 def toast(variant, title, description: nil, **) render "components/toast", variant: variant, title: title, description: description, ** end |
#toast_error(title, **options) ⇒ String
Render an error toast
82 83 84 |
# File 'app/helpers/maquina_components/toast_helper.rb', line 82 def toast_error(title, **) toast(:error, title, **) end |
#toast_flash_messages(exclude: []) ⇒ String
Render all flash messages as toasts
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/maquina_components/toast_helper.rb', line 38 def (exclude: []) return "" if flash.empty? toasts = flash.map do |type, | next if exclude.include?(type.to_sym) next if .blank? variant = flash_to_variant(type) render "components/toast", variant: variant, title: end safe_join(toasts.compact) end |
#toast_info(title, **options) ⇒ String
Render an info toast
100 101 102 |
# File 'app/helpers/maquina_components/toast_helper.rb', line 100 def toast_info(title, **) toast(:info, title, **) end |
#toast_success(title, **options) ⇒ String
Render a success toast
73 74 75 |
# File 'app/helpers/maquina_components/toast_helper.rb', line 73 def toast_success(title, **) toast(:success, title, **) end |
#toast_warning(title, **options) ⇒ String
Render a warning toast
91 92 93 |
# File 'app/helpers/maquina_components/toast_helper.rb', line 91 def toast_warning(title, **) toast(:warning, title, **) end |