Created
May 28, 2025 08:04
-
-
Save dirkk0/459ae9de58d1ceb5a82a4b02a94a2f82 to your computer and use it in GitHub Desktop.
Pico.css plus zero-md with dark/light mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>pico + zero-md</title> | |
<link | |
rel="stylesheet" | |
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" | |
/> | |
<script | |
type="module" | |
src="https://cdn.jsdelivr.net/npm/zero-md@3?register" | |
></script> | |
</head> | |
<body> | |
<header> | |
<dark-mode-toggle></dark-mode-toggle> | |
</header> | |
<main class="container"> | |
<zero-md no-shadow> | |
<template> | |
<link | |
rel="stylesheet" | |
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" | |
/> | |
</template> | |
<script type="text/markdown"> | |
# Header | |
This is a link: [markdown](https://example.com) | |
some test text. | |
</script> | |
</zero-md> | |
</main> | |
<script> | |
// comment this out to initialize to light mode | |
document.querySelector("html").setAttribute("data-theme", "light") | |
class DarkModeToggle extends HTMLElement { | |
constructor() { | |
super() | |
this.innerHTML = ` | |
<div id="theme-switch"> | |
<span id="icon-moon" style="display: none">🌙</span> | |
<span id="icon-sun">☀️</span> | |
</div> | |
` | |
this.toggle = this.querySelector("#theme-switch") | |
this.toggle.addEventListener("click", () => { | |
const html = document.querySelector("html") | |
const theme = html.getAttribute("data-theme") | |
// const theme = "dark" | |
html.setAttribute( | |
"data-theme", | |
theme === "light" ? "dark" : "light" | |
) | |
const isLight = html.getAttribute("data-theme") === "light" | |
document.querySelector("#icon-sun").style.display = isLight | |
? "none" | |
: "block" | |
document.querySelector("#icon-moon").style.display = isLight | |
? "block" | |
: "none" | |
}) | |
} | |
} | |
customElements.define("dark-mode-toggle", DarkModeToggle) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment