-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1144 from sul-dlss/flash
Extract a flash view_component
- Loading branch information
Showing
6 changed files
with
40 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% each_type do |value, alert_class| %> | ||
<div role="alert" class="alert <%= alert_class %> d-flex shadow-sm align-items-center alert-dismissible mt-3"> | ||
<div class="bi bi-exclamation-triangle-fill fs-3 me-3 align-self-center d-flex justify-content-center"></div> | ||
<div class="text-body"> | ||
<div><%= value.html_safe %></div> | ||
</div> | ||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
class FlashMessageComponent < ViewComponent::Base | ||
TYPES = [:success, :notice, :error, :alert].freeze | ||
|
||
def initialize(flash:) | ||
@flash = flash | ||
super | ||
end | ||
|
||
def render? | ||
!@flash.empty? | ||
end | ||
|
||
def each_type | ||
TYPES.each do |level| | ||
yield @flash[level], bs_class(level) if @flash[level] | ||
end | ||
end | ||
|
||
def bs_class(level) | ||
case level | ||
when :success then 'alert-success' | ||
when :notice then 'alert-info' | ||
when :alert then 'alert-warning' | ||
when :error then 'alert-danger' | ||
else "alert-#{level}" | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.