Improve notifications, fix styles not being added
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Based on https://petr.codes/blog/rails/modern-rails-flash-messages/part-3/
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# @param type [String] Classic notification type `error`, `alert` and `info` + custom `success`
|
||||
# @param data [String, Hash] `String` for backward compatibility,
|
||||
# `Hash` for the new functionality `{title: '', body: '', timeout: 5, countdown: false, action: { url: '', method: '', name: ''}}`.
|
||||
# The `title` attribute for `Hash` is mandatory.
|
||||
class NotificationComponent < ViewComponent::Base
|
||||
def initialize(type:, data:)
|
||||
@type = type
|
||||
@data = prepare_data(data)
|
||||
@icon_name = icon_name
|
||||
@icon_color_class = icon_color_class
|
||||
|
||||
@data[:timeout] ||= 5
|
||||
@data[:action][:method] ||= "get" if @data[:action]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_data(data)
|
||||
case data
|
||||
when Hash
|
||||
|
||||
Reference in New Issue
Block a user