Skip to content

Commit

Permalink
fix alert
Browse files Browse the repository at this point in the history
  • Loading branch information
phcurado committed Jul 15, 2024
1 parent 2cdd01d commit 16a3e58
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
22 changes: 8 additions & 14 deletions daisy_ui_components_site/storybook/core_components/flash.story.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
defmodule Storybook.CoreComponents.Flash do
use PhoenixStorybook.Story, :component
alias DaisyUIComponentsSiteWeb.CoreComponents

def function, do: &CoreComponents.flash/1
def imports, do: [{CoreComponents, [button: 1, show: 1]}]
alias DaisyUIComponents.Alert
alias DaisyUIComponents.Button
alias DaisyUIComponents.Utils

def function, do: &Alert.flash/1
def imports, do: [{Button, [button: 1]}, {Utils, [show: 1]}]

def template do
"""
Expand All @@ -20,27 +23,18 @@ defmodule Storybook.CoreComponents.Flash do
id: :info_no_title,
attributes: %{
kind: :info,
hidden: true
class: "hidden"
},
slots: ["Info message"]
},
%Variation{
id: :error_with_title,
attributes: %{
kind: :error,
hidden: true,
class: "hidden",
title: "Flash title"
},
slots: ["Error message"]
},
%Variation{
id: :no_close_button,
attributes: %{
kind: :info,
hidden: true,
close: false
},
slots: ["Info message"]
}
]
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Storybook.CoreComponents.List do
use PhoenixStorybook.Story, :component

def function, do: &DaisyUIComponentsSiteWeb.CoreComponents.list/1
def function, do: &DaisyUIComponents.CoreComponents.list/1

def variations do
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
defmodule Storybook.CoreComponents.Modal do
use PhoenixStorybook.Story, :component
alias DaisyUIComponentsSiteWeb.CoreComponents
alias DaisyUIComponents.Button
alias DaisyUIComponents.Modal

def function, do: &CoreComponents.modal/1
def imports, do: [{CoreComponents, [button: 1, hide_modal: 1, show_modal: 1]}]
def function, do: &Modal.modal/1
def imports, do: [{Button, [button: 1]}, {Modal, [hide_modal: 1, show_modal: 1]}]

def template do
"""
Expand Down
17 changes: 12 additions & 5 deletions lib/daisy_ui_components/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ defmodule DaisyUIComponents.Alert do
<.flash_group flash={@flash} />
"""
attr :flash, :map, required: true, doc: "the map of flash messages"
attr :id, :string, default: "flash-group", doc: "the optional id of flash container"
attr :flash, :map, required: true, doc: "the map of flash messages"

attr :direction, :atom,
values: [:top_left, :top_right, :bottom_left, :bottom_right],
Expand Down Expand Up @@ -98,7 +98,6 @@ defmodule DaisyUIComponents.Alert do
id={@id}
phx-click={JS.push("lv:clear-flash", value: %{key: @kind}) |> hide("##{@id}")}
role="alert"
title={@title}
color={@color}
class={[
"w-80 sm:w-96 z-50 rounded-lg p-3 ring-1",
Expand All @@ -110,15 +109,23 @@ defmodule DaisyUIComponents.Alert do
]}
{@rest}
>
<.icon name={get_icon(@color)} />
<%= msg %>
<div :if={@title} class="flex items-center">
<.icon class="mr-2" name={get_icon(@color)} />
<div class="flex flex-col">
<h3 class="font-bold"><%= @title %></h3>
<span class="text-xs"><%= msg %></span>
</div>
</div>
<.icon :if={!@title} class="mr-2" name={get_icon(@color)} />
<span :if={!@title}><%= msg %></span>
<button type="button" class="group absolute top-1 right-1 p-2" aria-label="close">
<.icon name="hero-x-mark-solid" class="h-5 w-5 opacity-40 group-hover:opacity-70" />
</button>
</.alert>
"""
end

attr :id, :string, default: nil, doc: "the optional id of alert container"
attr :class, :any, default: nil
attr :color, :string, values: ~w(info success warning error)
attr :rest, :global
Expand All @@ -139,7 +146,7 @@ defmodule DaisyUIComponents.Alert do
)

~H"""
<div class={@class}>
<div id={@id} class={@class} {@rest}>
<%= render_slot(@inner_block) %>
</div>
"""
Expand Down

0 comments on commit 16a3e58

Please sign in to comment.