-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
179 additions
and
78 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 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 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
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,56 @@ | ||
class Alchemy::Admin::FlashMessage < ViewComponent::Base | ||
def initialize(message, type: "notice", auto_dismiss: true, closable: true) | ||
@message = message | ||
@type = type | ||
@auto_dismiss = (auto_dismiss == true) ? variant != "danger" : false | ||
@closable = closable | ||
end | ||
|
||
def call | ||
content_tag("sl-alert", message, attributes) do | ||
content_tag("sl-icon", nil, name: icon, slot: "icon") + message | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :message, :type, :auto_dismiss, :closable | ||
|
||
def icon | ||
case type.to_s | ||
when "warning", "warn", "alert" | ||
"exclamation-triangle-fill" | ||
when "notice" | ||
"check-lg" | ||
when "error" | ||
"bug-fill" | ||
else | ||
"info-circle-fill" | ||
end | ||
end | ||
|
||
def variant | ||
case type.to_s | ||
when "warning", "warn", "alert" | ||
"warning" | ||
when "notice", "success" | ||
"success" | ||
when "error" | ||
"danger" | ||
when "info" | ||
"primary" | ||
else | ||
"neutral" | ||
end | ||
end | ||
|
||
def attributes | ||
{ | ||
variant: variant, | ||
open: true | ||
}.tap do |a| | ||
a[:duration] = 3000 if auto_dismiss | ||
a[:closable] = true if closable | ||
end.compact! | ||
end | ||
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
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,66 @@ | ||
import "@shoelace/alert" | ||
import { registerIconLibrary } from "@shoelace/icon-library" | ||
|
||
registerIconLibrary("default", { | ||
resolver: (name) => | ||
`https://cdn.jsdelivr.net/npm/[email protected]/icons/${name}.svg` | ||
}) | ||
|
||
function notify( | ||
message, | ||
variant = "primary", | ||
icon = "info-circle-fill", | ||
duration = 3000 | ||
) { | ||
const alert = Object.assign(document.createElement("sl-alert"), { | ||
variant, | ||
closable: true, | ||
innerHTML: ` | ||
<sl-icon name="${icon}" slot="icon"></sl-icon> | ||
${message} | ||
` | ||
}) | ||
if (variant !== "danger") { | ||
alert.duration = duration | ||
} | ||
document.body.append(alert) | ||
alert.toast() | ||
} | ||
|
||
function messageIcon(messageType) { | ||
switch (messageType) { | ||
case "alert": | ||
case "warn": | ||
case "warning": | ||
return "exclamation-triangle-fill" | ||
case "notice": | ||
return "check-lg" | ||
case "error": | ||
return "bug-fill" | ||
default: | ||
return "info-circle-fill" | ||
} | ||
} | ||
|
||
function messageStyle(messageType) { | ||
switch (messageType) { | ||
case "alert": | ||
case "warn": | ||
case "warning": | ||
return "warning" | ||
case "notice": | ||
case "success": | ||
return "success" | ||
case "danger": | ||
case "error": | ||
return "danger" | ||
case "info": | ||
return "primary" | ||
default: | ||
return "neutral" | ||
} | ||
} | ||
|
||
export default function (message, style = "notice") { | ||
notify(message, messageStyle(style), messageIcon(style)) | ||
} |
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 |
---|---|---|
@@ -1,4 +1 @@ | ||
<div class="flash <%= flash_type %>"> | ||
<%= render_icon message_icon_class(flash_type) %> | ||
<%= message %> | ||
</div> | ||
<%= render Alchemy::Admin::FlashMessage.new(message, type: flash_type) %> |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<div id="flash_notices" style="display: <%= flash.keys.blank? ? "none" : "block" %>"> | ||
<% flash.keys.each do |flash_type| %> | ||
<%= render_flash_notice(flash[flash_type.to_sym], flash_type) if flash[flash_type.to_sym].present? %> | ||
<% end %> | ||
<div class="sl-toast-stack"> | ||
<% flash.keys.each do |flash_type| %> | ||
<% message = flash[flash_type.to_sym] %> | ||
<% if message.present? %> | ||
<%= render "alchemy/admin/partials/flash", | ||
message: message, | ||
flash_type: flash_type %> | ||
<% end %> | ||
<% end %> | ||
</div> |
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 |
---|---|---|
@@ -1 +1 @@ | ||
<%= render_flash_notice @notice, :error %> | ||
<%= render "alchemy/admin/partials/flash", flash_type: :error, message: @notice %> |
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 |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
pin "lodash-es/max", to: "https://ga.jspm.io/npm:[email protected]/max.js", preload: true | ||
pin "sortablejs", to: "https://ga.jspm.io/npm:[email protected]/modular/sortable.esm.js", preload: true | ||
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true | ||
|
||
pin "@shoelace/alert", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/alert/alert.js", preload: true | ||
pin "@shoelace/icon-library", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/utilities/icon-library.js", preload: true | ||
pin "@shoelace/switch", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/switch/switch.js", preload: true | ||
pin "@shoelace/tab", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/tab/tab.js", preload: true | ||
pin "@shoelace/tab-group", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/tab-group/tab-group.js", preload: true | ||
|