Skip to content

Commit acb6163

Browse files
authored
Merge pull request #57 from thanglequoc/AddGitHubPage
Replace theme toggle with pill-shaped slider
2 parents cb0265b + 6b831f3 commit acb6163

3 files changed

Lines changed: 74 additions & 25 deletions

File tree

docs/_includes/navbar.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
</ul>
1818

1919
<div class="navbar__actions">
20-
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode" title="Toggle dark mode">
21-
<span class="icon-sun">&#9728;&#65039;</span>
22-
<span class="icon-moon">&#127769;</span>
20+
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode" title="Toggle dark mode" role="switch" aria-checked="false">
21+
<span class="theme-toggle__track">
22+
<span class="theme-toggle__icon theme-toggle__icon--sun">&#9728;&#65039;</span>
23+
<span class="theme-toggle__icon theme-toggle__icon--moon">&#127769;</span>
24+
<span class="theme-toggle__thumb"></span>
25+
</span>
2326
</button>
2427

2528
<a href="https://github.com/thanglequoc/timer-ninja" target="_blank" rel="noopener" class="navbar__github" aria-label="GitHub">

docs/_sass/_navbar.scss

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,38 +110,81 @@
110110
gap: $space-md;
111111
}
112112

113-
// Theme toggle
113+
// Theme toggle slider
114114
.theme-toggle {
115115
background: none;
116-
border: 2px solid var(--color-border);
117-
border-radius: 50%;
118-
width: 38px;
119-
height: 38px;
116+
border: none;
117+
padding: 0;
118+
cursor: pointer;
119+
line-height: 1;
120120
display: flex;
121121
align-items: center;
122-
justify-content: center;
123-
cursor: pointer;
124-
color: var(--color-text-muted);
125-
transition: all $transition-normal;
126-
font-size: 1.1rem;
122+
}
127123

128-
&:hover {
129-
border-color: var(--color-primary);
130-
color: var(--color-primary);
131-
transform: rotate(20deg);
124+
.theme-toggle__track {
125+
position: relative;
126+
width: 56px;
127+
height: 28px;
128+
background: #d1e9eb;
129+
border-radius: 999px;
130+
display: flex;
131+
align-items: center;
132+
justify-content: space-between;
133+
padding: 0 6px;
134+
transition: background-color 0.3s ease;
135+
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
136+
}
137+
138+
.theme-toggle__icon {
139+
font-size: 0.85rem;
140+
line-height: 1;
141+
z-index: 1;
142+
transition: opacity 0.3s ease;
143+
user-select: none;
144+
}
145+
146+
.theme-toggle__icon--sun {
147+
opacity: 1;
148+
}
149+
150+
.theme-toggle__icon--moon {
151+
opacity: 0.4;
152+
}
153+
154+
.theme-toggle__thumb {
155+
position: absolute;
156+
top: 3px;
157+
left: 3px;
158+
width: 22px;
159+
height: 22px;
160+
background: #fff;
161+
border-radius: 50%;
162+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
163+
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
164+
}
165+
166+
.theme-toggle:hover .theme-toggle__thumb {
167+
box-shadow: 0 2px 8px rgba(70, 191, 198, 0.4);
168+
}
169+
170+
[data-theme="dark"] {
171+
.theme-toggle__track {
172+
background: #2a3a4a;
132173
}
133174

134-
.icon-sun,
135-
.icon-moon {
136-
transition: opacity $transition-fast, transform $transition-normal;
175+
.theme-toggle__icon--sun {
176+
opacity: 0.4;
137177
}
138178

139-
.icon-moon { display: none; }
140-
}
179+
.theme-toggle__icon--moon {
180+
opacity: 1;
181+
}
141182

142-
[data-theme="dark"] .theme-toggle {
143-
.icon-sun { display: none; }
144-
.icon-moon { display: block; }
183+
.theme-toggle__thumb {
184+
transform: translateX(28px);
185+
background: #1a2636;
186+
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(109, 213, 219, 0.3);
187+
}
145188
}
146189

147190
// GitHub link

docs/assets/js/theme-toggle.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
function setTheme(theme) {
2020
html.setAttribute('data-theme', theme);
2121
localStorage.setItem(STORAGE_KEY, theme);
22+
if (toggle) {
23+
toggle.setAttribute('aria-checked', theme === 'dark' ? 'true' : 'false');
24+
}
2225
}
2326

2427
// Initialize

0 commit comments

Comments
 (0)