Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 3a720e5

Browse files
committed
use a button
1 parent fc74fe0 commit 3a720e5

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

β€Žpackages/docs/index.cssβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ input {
6363
display: none;
6464
}
6565

66-
label, button {
66+
button {
67+
min-width: 120px;
6768
border: 1px solid var(--color);
6869
padding: 0.5rem 1rem;
6970
border-radius: 2px;

β€Žpackages/docs/index.jsβ€Ž

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,21 @@ const changeFavicon = (src) => {
1313
const { mode } = window.__perfect_dark_mode__
1414

1515
// Get some elements we will use.
16-
const labelElement = document.getElementById('label')
17-
const checkboxElement = document.getElementById('checkbox')
16+
const toggleElement = document.getElementById('toggle')
1817

1918
// Listen to the color mode and update the UI.
2019
mode.subscribe((v) => {
21-
checkboxElement.checked = v === 'dark'
22-
labelElement.childNodes[2].textContent = v === 'dark' ? '🌚 Dark' : '🌝 Light'
20+
toggleElement.textContent = v === 'dark' ? '🌚 Dark' : '🌝 Light'
2321
changeFavicon(v === 'dark' ? 'moon.png' : 'sun.png')
2422
})
2523

2624
// At this point our callback will have been called,
2725
// so the checkbox state and text will be correct and we can show them.
28-
labelElement.style.visibility = 'unset'
26+
toggleElement.style.visibility = 'unset'
2927

3028
// When the checkbox is clicked we update the mode.
3129
// Our listener above will do the rest.
32-
checkboxElement.addEventListener('change', (e) =>
30+
toggleElement.addEventListener('click', (e) =>
3331
mode.update((v) => (v === 'light' ? 'dark' : 'light')),
3432
)
3533

β€Žpackages/docs/index.pugβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ html
3232
// For users with JS disabled there will not be a color mode toggle, they can change
3333
// their system color mode.
3434
p You can set the color mode, this will be saved.
35-
label(id="label" style="visibility: hidden;")
36-
input(type="checkbox" id="checkbox")
37-
| 🌝 color mode
35+
button(id="toggle" style="visibility: hidden;") 🌝 color mode
3836
p You can reset the color mode and fallback to system color mode.
3937
button(id="button") Reset
4038
p For debugging and understanding here is the saved color mode and the OS color mode.

0 commit comments

Comments
Β (0)