diff --git a/assets/js/app.js b/assets/js/app.js index 335837e..152b6f5 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -25,11 +25,29 @@ import {LiveSocket} from "phoenix_live_view" import {hooks as colocatedHooks} from "phoenix-colocated/simpleshop_theme" import topbar from "../vendor/topbar" +// Hook to sync color picker and text input +const ColorSync = { + mounted() { + const picker = this.el.querySelector('input[type="color"]') + const text = this.el.querySelector('input[type="text"]') + + if (picker && text) { + picker.addEventListener('input', (e) => { + text.value = e.target.value + }) + + text.addEventListener('input', (e) => { + picker.value = e.target.value + }) + } + } +} + const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") const liveSocket = new LiveSocket("/live", Socket, { longPollFallbackMs: 2500, params: {_csrf_token: csrfToken}, - hooks: {...colocatedHooks}, + hooks: {...colocatedHooks, ColorSync}, }) // Show progress bar on live navigation and form submits diff --git a/lib/simpleshop_theme_web/live/theme_live/index.html.heex b/lib/simpleshop_theme_web/live/theme_live/index.html.heex index 00f57f2..a592860 100644 --- a/lib/simpleshop_theme_web/live/theme_live/index.html.heex +++ b/lib/simpleshop_theme_web/live/theme_live/index.html.heex @@ -130,22 +130,22 @@

Accent Color

-
+