Replies: 5 comments
|
Hi @cytech — you're right that 4.1.0 has no supported opt-out, so your workaround isn't wrong, but you don't have to fork the bundle for it. What ColorMode actually touches, so it's clear what has to be disabled:
All three go through ESM / Vite: import { ColorMode } from 'admin-lte'
// 1. stop every future write: init, toggle clicks, OS changes
ColorMode.prototype._applyTheme = () => {}
// 2. undo the one write that already happened during the import (see below)
document.documentElement.setAttribute('data-bs-theme', myTheme)That second line is the part that isn't obvious. A Classic <script src="/vendor/adminlte/adminlte.min.js"></script>
<script>
adminlte.ColorMode.prototype._applyTheme = function () {}
</script>Method names are preserved in the minified builds too ( I checked all of this against the published 4.1.0 tarball in headless Chromium: with the snippet above, Simpler alternative if your themes are plain One more thing to check: if your layout started from the demo HTML, there's also a small inline no-flash script in This should be first-class, though, not a prototype patch. I'll add an opt-out in 4.1.1 as an attribute on <html data-lte-color-mode="off">ColorMode would skip its init pass, the toggle click handler, and the matchMedia listener; the no-flash head snippet in the demo layout would honor it too. Does that cover your case, or do you also need to call |
|
thank you very much for the explanation. yes, i think your opt-out option would work for me. I currently set a variable in laravel and pass that to the master.blade template. |
|
follow up.. |
|
Thanks for flagging this, @cytech — you were right that 4.1.0 gives you no way out, so forking the bundle wasn't a misuse of it. We've fixed it properly in #6095 rather than leaving you on a patch. From the next release, applications with their own theming turn ColorMode off with one attribute: <html data-lte-color-mode="off">It never writes Related, in case it suits you better than opting out: a theme you render server-side is now respected as a default. For 4.1.0 today, without forking the file — everything routes through import { ColorMode } from 'admin-lte'
// 1. stop every future write: init, toggle clicks, OS changes
ColorMode.prototype._applyTheme = () => {}
// 2. undo the one write that already happened during the import (see below)
document.documentElement.setAttribute('data-bs-theme', myTheme)That second line is the non-obvious part, and probably what pushed you to fork. A With a classic <script src="/vendor/adminlte/adminlte.min.js"></script>
<script>
adminlte.ColorMode.prototype._applyTheme = function () {}
</script>Method names survive minification, so both work against One thing to check either way: if your layout started from the demo HTML, there's a small inline no-flash script in |
|
awesome |
Uh oh!
There was an error while loading. Please reload this page.
can anyone recommend how to disable the ColorMode in 4.1.0 (from dist, not rebuilding)?
my app has its own "themeing" mechanism and the ColorMode is overwriting the data-bs-theme that I set.
the only way i have gotten around it is to copy the node_modules/admin-lte/dist/js/adminlte.esm.js to my own resources, disable _applyTheme, and then vite the assets...
All reactions