Skip to content

Commit

Permalink
Apply styler
Browse files Browse the repository at this point in the history
  • Loading branch information
srcrip committed May 16, 2024
1 parent a11b119 commit cda3d9d
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
plugins: [Phoenix.LiveView.HTMLFormatter],
plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["demo"],
import_deps: [:phoenix_live_view],
Expand Down
5 changes: 1 addition & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ if Mix.env() == :dev do
version: "0.12.15",
module: esbuild.(~w(--format=esm --sourcemap --outfile=../priv/static/live_toast.esm.js)),
main: esbuild.(~w(--format=cjs --sourcemap --outfile=../priv/static/live_toast.cjs.js)),
cdn:
esbuild.(
~w(--format=iife --target=es2016 --global-name=LiveMotion --outfile=../priv/static/live_toast.js)
),
cdn: esbuild.(~w(--format=iife --target=es2016 --global-name=LiveMotion --outfile=../priv/static/live_toast.js)),
cdn_min:
esbuild.(
~w(--format=iife --target=es2016 --global-name=LiveMotion --minify --outfile=../priv/static/live_toast.min.js)
Expand Down
2 changes: 1 addition & 1 deletion demo/.formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
plugins: [Phoenix.LiveView.HTMLFormatter],
plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
import_deps: [:phoenix_live_view],
locals_without_parens: [
Expand Down
3 changes: 1 addition & 2 deletions demo/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import Config
config :esbuild,
version: "0.17.11",
demo: [
args:
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]
Expand Down
4 changes: 2 additions & 2 deletions demo/lib/demo_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ defmodule DemoWeb do
quote do
use Phoenix.Router, helpers: false

import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
import Plug.Conn
end
end

Expand Down Expand Up @@ -49,8 +49,8 @@ defmodule DemoWeb do

defp html_helpers do
quote do
import Phoenix.HTML
import DemoWeb.CoreComponents
import Phoenix.HTML

alias Phoenix.LiveView.JS

Expand Down
1 change: 1 addition & 0 deletions demo/lib/demo_web/components/layouts.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule DemoWeb.Layouts do
@moduledoc false
use DemoWeb, :html

embed_templates("layouts/*")
Expand Down
3 changes: 1 addition & 2 deletions demo/lib/demo_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ defmodule DemoWeb.PageController do
conn

["info"] ->
conn
|> put_flash(:info, "This is an info flash.")
put_flash(conn, :info, "This is an info flash.")

["info", "error"] ->
conn
Expand Down
53 changes: 19 additions & 34 deletions demo/lib/demo_web/live/home_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule DemoWeb.HomeLive do
@moduledoc false
use DemoWeb, :live_view

alias Phoenix.LiveView.JS
Expand Down Expand Up @@ -26,25 +27,18 @@ defmodule DemoWeb.HomeLive do

def handle_event("change_settings", payload, socket) do
socket =
socket
|> assign(:settings, Map.merge(socket.assigns.settings, payload))
assign(socket, :settings, Map.merge(socket.assigns.settings, payload))

{:noreply, socket}
end

def handle_event("update_toast", _payload, socket) do
body =
[
"This is a toast event.",
"Different toast event.",
"This is another toast event.",
"Hello, world!"
]
|> Enum.random()
Enum.random(["This is a toast event.", "Different toast event.", "This is another toast event.", "Hello, world!"])

uuid = "this-is-a-uuid"

%LiveToast{
LiveToast.send_toast(%LiveToast{
kind: :info,
msg: body,
title: nil,
Expand All @@ -54,16 +48,15 @@ defmodule DemoWeb.HomeLive do
component: nil,
container_id: "toast-group",
uuid: uuid
}
|> LiveToast.send_toast()
})

{:noreply, socket}
end

def handle_event("show_progress", _payload, socket) do
uuid = "show-progress"

%LiveToast{
LiveToast.send_toast(%LiveToast{
kind: :info,
msg: "Uploading...",
title: "Show Progress",
Expand All @@ -73,8 +66,7 @@ defmodule DemoWeb.HomeLive do
component: nil,
container_id: "toast-group",
uuid: uuid
}
|> LiveToast.send_toast()
})

Process.send_after(self(), :progress, 3000)

Expand Down Expand Up @@ -113,7 +105,7 @@ defmodule DemoWeb.HomeLive do
_ -> nil
end

%LiveToast{
LiveToast.send_toast(%LiveToast{
kind:
case kind do
"info" -> :info
Expand All @@ -126,16 +118,15 @@ defmodule DemoWeb.HomeLive do
duration: duration,
component: component,
container_id: "toast-group"
}
|> LiveToast.send_toast()
})

{:noreply, socket}
end

def handle_event("flash", %{"kind" => kind}, socket) do
socket =
socket
|> put_flash(
put_flash(
socket,
case kind do
"info" -> :info
"error" -> :error
Expand All @@ -154,7 +145,7 @@ defmodule DemoWeb.HomeLive do
def handle_info(:progress, socket) do
uuid = "show-progress"

%LiveToast{
LiveToast.send_toast(%LiveToast{
kind: :info,
msg: "Still going, please wait a little longer...",
title: "Show Progress",
Expand All @@ -164,8 +155,7 @@ defmodule DemoWeb.HomeLive do
component: nil,
container_id: "toast-group",
uuid: uuid
}
|> LiveToast.send_toast()
})

Process.send_after(self(), :done, 2000)

Expand All @@ -175,7 +165,7 @@ defmodule DemoWeb.HomeLive do
def handle_info(:done, socket) do
uuid = "show-progress"

%LiveToast{
LiveToast.send_toast(%LiveToast{
kind: :info,
msg: "Upload complete!",
title: "Show Progress",
Expand All @@ -185,8 +175,7 @@ defmodule DemoWeb.HomeLive do
component: nil,
container_id: "toast-group",
uuid: uuid
}
|> LiveToast.send_toast()
})

{:noreply, socket}
end
Expand Down Expand Up @@ -389,22 +378,18 @@ defmodule DemoWeb.HomeLive do
def tab(assigns), do: demo(assigns)

def apply_action(socket, :why) do
socket
|> assign(:page_title, "Live Toast — Why Live Toast?")
assign(socket, :page_title, "Live Toast — Why Live Toast?")
end

def apply_action(socket, :recipes) do
socket
|> assign(:page_title, "Live Toast — Recipes")
assign(socket, :page_title, "Live Toast — Recipes")
end

def apply_action(socket, :customization) do
socket
|> assign(:page_title, "Live Toast — Customization")
assign(socket, :page_title, "Live Toast — Customization")
end

def apply_action(socket, _) do
socket
|> assign(:page_title, "Live Toast — Demo")
assign(socket, :page_title, "Live Toast — Demo")
end
end
5 changes: 3 additions & 2 deletions demo/mix.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Demo.MixProject do
use Mix.Project

@moduledoc false

use Mix.Project

def project do
[
app: :demo,
Expand Down Expand Up @@ -39,6 +39,7 @@ defmodule Demo.MixProject do
{:doctor, ">= 0.0.0", only: [:dev], runtime: false},
{:ex_doc, ">= 0.0.0", only: [:dev], runtime: false},
{:mix_audit, ">= 0.0.0", only: [:dev], runtime: false},
{:styler, "~> 0.11.9", only: [:dev], runtime: false},
{:phoenix_html, "~> 4.0"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:floki, ">= 0.30.0", only: :test},
Expand Down
1 change: 1 addition & 0 deletions demo/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"plug_cowboy": {:hex, :plug_cowboy, "2.7.1", "87677ffe3b765bc96a89be7960f81703223fe2e21efa42c125fcd0127dd9d6b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "02dbd5f9ab571b864ae39418db7811618506256f6d13b4a45037e5fe78dc5de3"},
"plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"styler": {:hex, :styler, "0.11.9", "2595393b94e660cd6e8b582876337cc50ff047d184ccbed42fdad2bfd5d78af5", [:mix], [], "hexpm", "8b7806ba1fdc94d0a75127c56875f91db89b75117fcc67572661010c13e1f259"},
"tailwind": {:hex, :tailwind, "0.2.2", "9e27288b568ede1d88517e8c61259bc214a12d7eed271e102db4c93fcca9b2cd", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "ccfb5025179ea307f7f899d1bb3905cd0ac9f687ed77feebc8f67bdca78565c4"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"},
Expand Down
4 changes: 2 additions & 2 deletions demo/test/demo_web/live/home_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule DemoWeb.HomeLiveTest do
use DemoWeb.ConnCase

@moduledoc false

use DemoWeb.ConnCase

import Phoenix.LiveViewTest

describe "Demo Page" do
Expand Down
8 changes: 4 additions & 4 deletions demo/test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ defmodule DemoWeb.ConnCase do

using do
quote do
@endpoint DemoWeb.Endpoint

use DemoWeb, :verified_routes

import Plug.Conn
import Phoenix.ConnTest
import DemoWeb.ConnCase
import Phoenix.ConnTest
import Plug.Conn

@endpoint DemoWeb.Endpoint
end
end

Expand Down
26 changes: 11 additions & 15 deletions lib/live_toast.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
defmodule LiveToast do
@moduledoc """
LiveComponent for displaying toast messages.
"""

use Phoenix.LiveComponent

alias Phoenix.LiveView.JS
alias Phoenix.LiveView.Socket

@enforce_keys [:kind, :msg]
defstruct [
:kind,
Expand All @@ -27,13 +34,6 @@ defmodule LiveToast do
uuid: Ecto.UUID.t() | nil
}

alias Phoenix.LiveView.JS
alias Phoenix.LiveView.Socket

@moduledoc """
LiveComponent for displaying toast messages.
"""

@impl Phoenix.LiveComponent
def mount(socket) do
socket =
Expand Down Expand Up @@ -90,8 +90,7 @@ defmodule LiveToast do
uuid = toast.uuid || Ecto.UUID.generate()

toast =
toast
|> struct!(container_id: container_id, uuid: uuid)
struct!(toast, container_id: container_id, uuid: uuid)

Phoenix.LiveView.send_update(__MODULE__, id: container_id, toasts: [toast])

Expand Down Expand Up @@ -323,8 +322,7 @@ defmodule LiveToast do

defp toast(assigns) do
assigns =
assigns
|> assign_new(:id, fn -> "flash-#{assigns.kind}" end)
assign_new(assigns, :id, fn -> "flash-#{assigns.kind}" end)

~H"""
<div
Expand Down Expand Up @@ -510,8 +508,7 @@ defmodule LiveToast do
to: selector,
display: "flex",
transition:
{"transition-all transform ease-out duration-300",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
{"transition-all transform ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
"opacity-100 translate-y-0 sm:scale-100"}
)
end
Expand All @@ -521,8 +518,7 @@ defmodule LiveToast do
to: selector,
time: 200,
transition:
{"transition-all transform ease-in duration-200",
"opacity-100 translate-y-0 sm:scale-100",
{"transition-all transform ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"}
)
end
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ defmodule LiveToast.MixProject do
{:doctor, ">= 0.0.0", only: [:dev], runtime: false},
{:ex_doc, "~> 0.32.2", only: [:dev], runtime: false},
{:mix_audit, ">= 0.0.0", only: [:dev], runtime: false},
{:styler, "~> 0.11.9", only: [:dev], runtime: false},
{:makeup, "1.1.2", only: [:dev], runtime: false},
{:makeup_elixir, "0.16.2", only: [:dev], runtime: false},
{:makeup_js, "~> 0.1.0", only: [:dev], runtime: false},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
"plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"},
"plug_crypto": {:hex, :plug_crypto, "2.1.0", "f44309c2b06d249c27c8d3f65cfe08158ade08418cf540fd4f72d4d6863abb7b", [:mix], [], "hexpm", "131216a4b030b8f8ce0f26038bc4421ae60e4bb95c5cf5395e1421437824c4fa"},
"styler": {:hex, :styler, "0.11.9", "2595393b94e660cd6e8b582876337cc50ff047d184ccbed42fdad2bfd5d78af5", [:mix], [], "hexpm", "8b7806ba1fdc94d0a75127c56875f91db89b75117fcc67572661010c13e1f259"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"},
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
Expand Down

0 comments on commit cda3d9d

Please sign in to comment.