Packages
phoenix_duskmoon
9.6.3
9.9.2
9.9.1
9.9.0
9.8.0
9.7.1
9.7.0
9.6.4
9.6.3
9.6.2
9.6.1
9.6.0
9.5.4
9.5.3
9.5.2
9.5.1
9.5.0
9.4.3
9.4.2
9.4.1
9.4.0
9.3.0
9.2.0
9.1.4
9.1.3
9.1.1
9.1.1-rc.1
retired
9.0.1
9.0.0-rc.3
9.0.0-rc.2
9.0.0-rc.1
8.0.0
7.2.1
7.2.0
7.1.3
7.1.2
7.1.1
6.3.2
6.3.1
6.3.0
6.2.0
6.1.3
6.1.2
6.1.1
6.1.0
6.0.10
6.0.9
6.0.8
6.0.7
6.0.6
6.0.5
6.0.4
6.0.3
6.0.2
6.0.1
6.0.0
5.2.0-beta.5
5.2.0-beta.4
5.2.0-beta.3
5.2.0-beta.2
5.2.0-beta.1
5.1.0
5.0.6
5.0.5
5.0.4
5.0.3
5.0.2
5.0.1
5.0.0
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.1
4.6.0
4.5.2
4.5.1
4.5.0
4.4.4
4.4.3
4.4.2
4.4.1
4.4.0
4.3.2
4.3.1
4.3.0
4.2.0
4.1.1
4.1.0
4.0.0
Duskmoon UI component library for Phoenix LiveView
Current section
Files
Jump to
Current section
Files
lib/phoenix_duskmoon/component/feedback/snackbar.ex
defmodule PhoenixDuskmoon.Component.Feedback.Snackbar do
@moduledoc """
Snackbar component using `@duskmoon-dev/core` CSS classes.
Renders brief notification messages, similar to toasts but with
action buttons and different positioning. Snackbars provide brief
feedback about an operation through a message at the edge of the screen.
## Examples
<.dm_snackbar_container position="bottom">
<.dm_snackbar type="info">
<:message>File saved successfully</:message>
<:action>Undo</:action>
</.dm_snackbar>
</.dm_snackbar_container>
<.dm_snackbar type="error">
<:message>Failed to upload file</:message>
<:action>Retry</:action>
<:close />
</.dm_snackbar>
"""
use Phoenix.Component
import PhoenixDuskmoon.Component.Icon.Icons
@doc """
Renders a snackbar notification.
## Examples
<.dm_snackbar type="success">
<:message>Operation completed</:message>
</.dm_snackbar>
"""
@doc type: :component
attr(:id, :any, default: nil, doc: "HTML id attribute")
attr(:class, :any, default: nil, doc: "Additional CSS classes")
attr(:type, :string,
default: nil,
values: [
nil,
"info",
"success",
"warning",
"error",
"primary",
"secondary",
"tertiary",
"dark"
],
doc: "Color/type variant"
)
attr(:open, :boolean, default: false, doc: "Whether the snackbar is visible")
attr(:multiline, :boolean, default: false, doc: "Multiline layout for longer messages")
attr(:position, :string,
default: nil,
values: [nil, "bottom", "bottom-left", "bottom-right", "top", "top-left", "top-right"],
doc: "Standalone position (when not inside a container)"
)
attr(:rest, :global)
slot(:message, required: true, doc: "Message content")
attr(:close_label, :string, default: "Close", doc: "Accessible label for the close button")
slot(:action, doc: "Action button")
slot(:close, doc: "Close button")
def dm_snackbar(assigns) do
~H"""
<div
id={@id}
class={[
"snackbar",
@type && "snackbar-#{@type}",
@open && "snackbar-show",
@multiline && "snackbar-multiline",
@position && "snackbar-#{@position}",
@class
]}
role="alert"
aria-live="assertive"
aria-atomic="true"
{@rest}
>
<span class="snackbar-message">{render_slot(@message)}</span>
<button :for={action <- @action} type="button" class="snackbar-action">
{render_slot(action)}
</button>
<button :for={_close <- @close} type="button" class="snackbar-close" aria-label={@close_label}>
<.dm_mdi name="close" class="w-4 h-4" />
</button>
</div>
"""
end
@doc """
Renders a snackbar container for positioning multiple snackbars.
## Examples
<.dm_snackbar_container position="bottom-right">
<.dm_snackbar type="info" open>
<:message>New notification</:message>
</.dm_snackbar>
</.dm_snackbar_container>
"""
@doc type: :component
attr(:id, :any, default: nil, doc: "HTML id attribute")
attr(:class, :any, default: nil, doc: "Additional CSS classes")
attr(:position, :string,
default: "bottom",
values: ["bottom", "bottom-left", "bottom-right", "top", "top-left", "top-right"],
doc: "Position of the container"
)
attr(:rest, :global)
slot(:inner_block, required: true)
def dm_snackbar_container(assigns) do
~H"""
<div
id={@id}
class={["snackbar-container", "snackbar-container-#{@position}", @class]}
{@rest}
>
{render_slot(@inner_block)}
</div>
"""
end
end