Skip to content

Commit

Permalink
Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagomajesk committed Mar 21, 2023
1 parent 33278a4 commit 39f0f48
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
35 changes: 23 additions & 12 deletions lib/swish/dialog.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Swish.Dialog.Transitions do
defmodule Swish.Dialog.Transitions do
@moduledoc false
defstruct [:show_content, :hide_content, :show_backdrop, :hide_backdrop]
end
Expand Down Expand Up @@ -36,8 +36,17 @@ defmodule Swish.Dialog do
@type t :: %Swish.Dialog{}

@enforce_keys [:id, :portal_id, :open, :static, :close_delay, :open_delay, :transitions]
defstruct [:id, :portal_id, :js_show, :js_hide, :open, :static,
:close_delay, :open_delay, :transitions]
defstruct [
:id,
:portal_id,
:js_show,
:js_hide,
:open,
:static,
:close_delay,
:open_delay,
:transitions
]

use Phoenix.Component

Expand Down Expand Up @@ -77,15 +86,17 @@ defmodule Swish.Dialog do
slot(:inner_block, required: true)

def root(assigns) do
assigns = assign_new(assigns, :dialog, fn ->
%{ Dialog.new() |
open: assigns.open,
static: assigns.static,
open_delay: assigns.open_delay,
close_delay: assigns.close_delay,
transitions: assigns.transitions
}
end)
assigns =
assign_new(assigns, :dialog, fn ->
%{
Dialog.new()
| open: assigns.open,
static: assigns.static,
open_delay: assigns.open_delay,
close_delay: assigns.close_delay,
transitions: assigns.transitions
}
end)

~H"""
<div id={@dialog.id} {@rest}>
Expand Down
24 changes: 20 additions & 4 deletions lib/swish/js.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,32 @@ defmodule Swish.JS do
|> JS.set_attribute({"data-state", "open"}, to: "##{dialog.id}-backdrop")
|> JS.set_attribute({"data-state", "open"}, to: "##{dialog.id}-content")
|> JS.set_attribute({"aria-expanded", "true"}, to: "##{dialog.id}-trigger")
|> JS.show(to: "##{dialog.id}-backdrop", transition: dialog.transitions.show_backdrop, time: dialog.open_delay)
|> JS.show(to: "##{dialog.id}-content", transition: dialog.transitions.show_content, time: dialog.open_delay)
|> JS.show(
to: "##{dialog.id}-backdrop",
transition: dialog.transitions.show_backdrop,
time: dialog.open_delay
)
|> JS.show(
to: "##{dialog.id}-content",
transition: dialog.transitions.show_content,
time: dialog.open_delay
)
|> JS.focus_first(to: "##{dialog.id}-content")
end

def hide_dialog(js \\ %JS{}, %Swish.Dialog{} = dialog) do
js
|> JS.pop_focus()
|> JS.hide(to: "##{dialog.id}-backdrop", transition: dialog.transitions.hide_backdrop, time: dialog.close_delay)
|> JS.hide(to: "##{dialog.id}-content", transition: dialog.transitions.hide_content, time: dialog.close_delay)
|> JS.hide(
to: "##{dialog.id}-backdrop",
transition: dialog.transitions.hide_backdrop,
time: dialog.close_delay
)
|> JS.hide(
to: "##{dialog.id}-content",
transition: dialog.transitions.hide_content,
time: dialog.close_delay
)
|> JS.set_attribute({"data-state", "closed"}, to: "##{dialog.id}-trigger")
|> JS.set_attribute({"data-state", "closed"}, to: "##{dialog.id}-backdrop")
|> JS.set_attribute({"data-state", "closed"}, to: "##{dialog.id}-content")
Expand Down
12 changes: 6 additions & 6 deletions lib/swish/tag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ defmodule Swish.Tag do
"""
end

attr :id, :string, required: true
attr :target, :string, default: "body"
attr :update, :string, values: ~w(prepend append origin), default: "origin"
attr :close_delay, :integer, default: 0
attr :rest, :global
slot :inner_block, required: true
attr(:id, :string, required: true)
attr(:target, :string, default: "body")
attr(:update, :string, values: ~w(prepend append origin), default: "origin")
attr(:close_delay, :integer, default: 0)
attr(:rest, :global)
slot(:inner_block, required: true)

def portal(assigns) do
~H"""
Expand Down

0 comments on commit 39f0f48

Please sign in to comment.