Improve notifications, fix styles not being added
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:
2022-02-21 11:03:43 -06:00
parent 8102fa1230
commit 7d66b75216
11 changed files with 214 additions and 58 deletions
+9
View File
@@ -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