This repository was archived by the owner on Feb 3, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change @@ -13,23 +13,21 @@ const changeFavicon = (src) => {
1313const { 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.
2019mode . 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
Original file line number Diff line number Diff line change 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.
You canβt perform that action at this time.
0 commit comments