diff --git a/README.md b/README.md index d559511..a272fa8 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,10 @@ export default { ``` -3. Load the script. +3. Load the script before the `body` tag. ```html - + ``` ## Demo diff --git a/tw-theme-toggle.min.js b/tw-theme-toggle.min.js deleted file mode 100644 index a92b53c..0000000 --- a/tw-theme-toggle.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Tailwind CSS Theme Toggle Script - * - * @author Ga Satrya - @gasatrya - * @copyright 2024 Ga Satrya - * @license MIT - */ -(function(){var t=document.createElement("button"),e=document.createElementNS("http://www.w3.org/2000/svg","svg"),n=document.createElementNS("http://www.w3.org/2000/svg","path"),r=document.createElementNS("http://www.w3.org/2000/svg","svg"),o=document.createElementNS("http://www.w3.org/2000/svg","path"),i=document.createTextNode("Light"),s=document.createTextNode("Dark");e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("fill","none"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","1.5"),e.setAttribute("stroke-linecap","round"),e.setAttribute("stroke-linejoin","round"),e.setAttribute("class","size-6"),e.setAttribute("width","24"),e.setAttribute("height","24"),n.setAttribute("d","M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"),e.appendChild(n),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none"),r.setAttribute("stroke","currentColor"),r.setAttribute("stroke-width","1.5"),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),r.setAttribute("class","size-6"),r.setAttribute("width","24"),r.setAttribute("height","24"),o.setAttribute("d","M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"),r.appendChild(o),t.appendChild(e),t.appendChild(i),document.body.appendChild(t),t.addEventListener("click",()=>{document.documentElement.classList.toggle("light"),document.documentElement.classList.toggle("dark"),t.contains(e)?(t.replaceChild(r,e),t.replaceChild(s,i)):(t.replaceChild(e,r),t.replaceChild(i,s))}),document.head.appendChild(document.createElement("style")).textContent=`html.light{background-color:#fff;color:#000}html.dark{background-color:#000;color:#fff}#theme-toggle{position:fixed;bottom:20px;right:20px;display:flex;align-items:center;border-radius:9999px;padding:10px 15px;cursor:pointer;font-size:14px}.light #theme-toggle{border:1px solid rgba(0,0,0,.2)}.dark #theme-toggle{border:1px solid rgba(255,255,255,.2)}`,document.documentElement.classList.add("light")})();