From a958b49a7c912f7b2b659f04c3f511b2ea572fcb Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 3 Jul 2025 16:37:54 +0200 Subject: [PATCH] feat: add dasyui for backpex --- assets/css/app.css | 4 ++++ assets/js/app.js | 3 +++ assets/package-lock.json | 20 ++++++++++++++++++++ assets/package.json | 5 +++++ assets/tailwind.config.js | 1 - lib/mv_web/components/layouts/root.html.heex | 4 ++-- lib/mv_web/router.ex | 1 + 7 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 assets/package-lock.json create mode 100644 assets/package.json diff --git a/assets/css/app.css b/assets/css/app.css index 6733f52..7f9662e 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -2,6 +2,10 @@ @import "tailwindcss/components"; @import "tailwindcss/utilities"; +@plugin "daisyui" { + themes: light, dark; +} + @source "../../deps/backpex/**/*.*ex"; @source '../../deps/backpex/assets/js/**/*.*js' diff --git a/assets/js/app.js b/assets/js/app.js index 02d9b5f..0782763 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -23,6 +23,9 @@ import {LiveSocket} from "phoenix_live_view" import { Hooks as BackpexHooks } from 'backpex' import topbar from "../vendor/topbar" +// Set stored theme as soon as possible +BackpexHooks.BackpexThemeSelector.setStoredTheme() + let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") let liveSocket = new LiveSocket("/live", Socket, { longPollFallbackMs: 2500, diff --git a/assets/package-lock.json b/assets/package-lock.json new file mode 100644 index 0000000..5cb181b --- /dev/null +++ b/assets/package-lock.json @@ -0,0 +1,20 @@ +{ + "name": "assets", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "daisyui": "^5.0.43" + } + }, + "node_modules/daisyui": { + "version": "5.0.43", + "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-5.0.43.tgz", + "integrity": "sha512-2pshHJ73vetSpsbAyaOncGnNYL0mwvgseS1EWy1I9Qpw8D11OuBoDNIWrPIME4UFcq2xuff3A9x+eXbuFR9fUQ==", + "funding": { + "url": "https://github.com/saadeghi/daisyui?sponsor=1" + } + } + } +} diff --git a/assets/package.json b/assets/package.json new file mode 100644 index 0000000..db75eb6 --- /dev/null +++ b/assets/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "daisyui": "^5.0.43" + } +} diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js index c16fe48..b3a2cf3 100644 --- a/assets/tailwind.config.js +++ b/assets/tailwind.config.js @@ -19,7 +19,6 @@ module.exports = { }, }, plugins: [ - require("@tailwindcss/forms"), // Allows prefixing tailwind classes with LiveView classes to add rules // only when LiveView classes are applied, for example: // diff --git a/lib/mv_web/components/layouts/root.html.heex b/lib/mv_web/components/layouts/root.html.heex index 9857506..8c00e2d 100644 --- a/lib/mv_web/components/layouts/root.html.heex +++ b/lib/mv_web/components/layouts/root.html.heex @@ -1,5 +1,5 @@ - + {Application.get_env(:live_debugger, :live_debugger_tags)} @@ -13,7 +13,7 @@ - + {@inner_content} diff --git a/lib/mv_web/router.ex b/lib/mv_web/router.ex index 24efd8e..7eb7f38 100644 --- a/lib/mv_web/router.ex +++ b/lib/mv_web/router.ex @@ -8,6 +8,7 @@ defmodule MvWeb.Router do plug :put_root_layout, html: {MvWeb.Layouts, :root} plug :protect_from_forgery plug :put_secure_browser_headers + plug Backpex.ThemeSelectorPlug end pipeline :api do