defmodule Shino.Notification.Base do @moduledoc """ Provides base components for deriving various types of notifications. """ use Phoenix.Component import Shino.UI.Helpers, only: [icon: 1] alias Phoenix.LiveView.JS @types [:flash, :"lv-flash", :"lv-toast"] @kinds [:info, :success, :warning, :critical] @type kind :: :info | :success | :warning | :critical @doc false def kinds, do: @kinds @doc """ Base notification component. Based on the look and feel of [Sonner](https://sonner.emilkowal.ski/). """ attr :id, :string, required: true, doc: "the DOM id of notification" attr :group_id, :string, required: true, doc: "the DOM id of notification group" attr :type, :atom, required: true, values: @types, doc: "the type of notification" attr :kind, :atom, required: true, values: @kinds, doc: "the kind of notification message" attr :duration, :integer, default: nil, doc: "the time in milliseconds before the message is automatically dismissed" attr :icon, :any, default: nil attr :title, :string, default: nil attr :message, :string, default: nil attr :action, :any, default: nil attr :component, :any, default: nil, doc: """ An alternative component, which accepts all the attrs of current component. """ attr :rest, :global, doc: "the arbitrary attributes to add to the notification container" slot :inner_block def notification(assigns) do ~H"""
<%= if @icon do %> <%= @icon.(assigns) %> <% end %> <%= @title %>
<%= @body %>