Skip to content

Commit

Permalink
Make modals client-side using Alpine.js
Browse files Browse the repository at this point in the history
  • Loading branch information
starcraft66 committed Jan 22, 2024
1 parent f09afa0 commit 73f29b2
Show file tree
Hide file tree
Showing 14 changed files with 676 additions and 419 deletions.
21 changes: 18 additions & 3 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import {Socket} from "phoenix"
import {LiveSocket} from "phoenix_live_view"
import { Socket } from "phoenix"
import { LiveSocket } from "phoenix_live_view"
import Alpine from "alpinejs"
import focus from "@alpinejs/focus"

window.Alpine = Alpine
Alpine.plugin(focus)
Alpine.start()

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
let liveSocket = new LiveSocket("/live", Socket, {
params: { _csrf_token: csrfToken },
dom: {
onBeforeElUpdated(from, to) {
if (from._x_dataStack) {
window.Alpine.clone(from, to)
}
}
}
})

// Connect if there are any LiveViews on the page
liveSocket.connect()
Expand Down
5 changes: 3 additions & 2 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"author": "",
"license": "ISC",
"dependencies": {
"alpinejs": "^3.12.3"
"@alpinejs/focus": "^3.13.3",
"alpinejs": "^3.13.3"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.9",
"autoprefixer": "^10.4.14",
"daisyui": "^3.1.9",
"daisyui": "^4.6.0",
"postcss": "^8.4.24",
"postcss-import": "^14.1.0",
"tailwindcss": "^3.3.2"
Expand Down
550 changes: 363 additions & 187 deletions assets/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Config
config :esbuild,
path: System.get_env("MIX_ESBUILD_PATH"),
default: [
args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/js --external:/images/*),
args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/js --external:/images/*),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let
mixFodDeps = beamPackages.fetchMixDeps {
pname = "${pname}-deps";
inherit src version;
hash = "sha256-DCKtG/m48Pg3enY7ZU1uUMEH4L/UvgXY9PWf37l1gZ0=";
hash = "sha256-i0Ke1iqNQOnJHTD61Nk8BshwKQvjpmI+Kbac+fk294E=";
};

yarnDeps = mkYarnModules {
Expand Down
66 changes: 42 additions & 24 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
systems = [
# systems for which you want to build the `perSystem` attributes
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
Expand Down
Loading

0 comments on commit 73f29b2

Please sign in to comment.