Skip to content

Commit 2d4e18b

Browse files
committed
styled dark mode slider
1 parent ca8ed40 commit 2d4e18b

File tree

4 files changed

+91
-43
lines changed

4 files changed

+91
-43
lines changed

src/app/ThemeProvider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export const ThemeProvider = ({ children }) => {
2424
}, [isDark]);
2525

2626
const toggleTheme = () => {
27-
setIsDark((prev) => !prev);
27+
setIsDark((prev) => {
28+
const newTheme = !prev;
29+
console.log(`Theme switched to: ${newTheme ? 'dark' : 'light'} mode`);
30+
return newTheme;
31+
});
2832
};
2933

3034
return <ThemeContext.Provider value={{ isDark, toggleTheme }}>{children}</ThemeContext.Provider>;

src/app/components/Actions/RecordButton.tsx

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,36 @@ import ThemeToggle from './ThemeToggle';
55
const RecordButton = ({ isRecording, onToggle }) => {
66
return (
77
<div className='record-button-container'>
8-
<div className='record-label'>
9-
<div
10-
className={`record-icon ${isRecording ? 'recording' : ''}`}
11-
style={{
12-
backgroundColor: isRecording ? '#ef4444' : '#9ca3af',
13-
transition: 'background-color 0.3s ease',
8+
<div className='record-controls'>
9+
<div className='record-label'>
10+
<div
11+
className={`record-icon ${isRecording ? 'recording' : ''}`}
12+
style={{
13+
backgroundColor: isRecording ? '#ef4444' : '#9ca3af',
14+
transition: 'background-color 0.3s ease',
15+
}}
16+
/>
17+
<span>Record</span>
18+
</div>
19+
<Switch
20+
checked={isRecording}
21+
onChange={onToggle}
22+
sx={{
23+
'& .MuiSwitch-switchBase': {
24+
color: '#9ca3af',
25+
},
26+
'& .MuiSwitch-track': {
27+
backgroundColor: '#e5e7eb',
28+
},
29+
'& .MuiSwitch-switchBase.Mui-checked': {
30+
color: '#374151',
31+
},
32+
'& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track': {
33+
backgroundColor: '#0284c7',
34+
},
1435
}}
1536
/>
16-
<span>Record</span>
1737
</div>
18-
<Switch
19-
checked={isRecording}
20-
onChange={onToggle}
21-
sx={{
22-
'& .MuiSwitch-switchBase': {
23-
color: '#9ca3af',
24-
},
25-
'& .MuiSwitch-track': {
26-
backgroundColor: '#e5e7eb',
27-
},
28-
'& .MuiSwitch-switchBase.Mui-checked': {
29-
color: '#374151',
30-
},
31-
'& .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track': {
32-
backgroundColor: '#0284c7',
33-
},
34-
}}
35-
/>
3638
<ThemeToggle />
3739
</div>
3840
);

src/app/components/Actions/ThemeToggle.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ const ThemeToggle = () => {
1111
onClick={toggleTheme}
1212
aria-label={`Switch to ${isDark ? 'light' : 'dark'} mode`}
1313
>
14-
{isDark ? <Sun className='theme-toggle-icon' /> : <Moon className='theme-toggle-icon' />}
14+
<div className='theme-toggle-icons'>
15+
<Moon className='theme-toggle-icon moon' />
16+
<Sun className='theme-toggle-icon sun' />
17+
</div>
18+
<div className='theme-toggle-slider' />
1519
</button>
1620
);
1721
};

src/app/styles/components/_buttons.scss

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@
6161
align-items: center;
6262
padding: 4px 16px;
6363
background: transparent;
64-
gap: 8px;
64+
justify-content: space-between;
65+
}
66+
67+
.record-controls {
68+
display: flex;
69+
align-items: center;
6570
}
6671

6772
.record-label {
@@ -113,33 +118,66 @@
113118
background-color: #e5e7eb !important;
114119
}
115120

121+
/* Theme toggle button styling */
116122
.theme-toggle {
123+
position: relative;
124+
width: 64px;
125+
height: 32px;
126+
border-radius: 16px;
127+
border: 2px solid #e5e7eb;
128+
background-color: #f3f4f6;
129+
cursor: pointer;
130+
transition: all 300ms ease;
131+
padding: 2px;
132+
}
133+
134+
.theme-toggle.dark {
135+
background-color: #1f2937;
136+
border-color: #374151;
137+
}
138+
139+
.theme-toggle-slider {
140+
position: relative;
141+
width: 24px;
142+
height: 24px;
143+
border-radius: 50%;
144+
background-color: white;
145+
transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
117146
display: flex;
118147
align-items: center;
119148
justify-content: center;
120-
width: 32px;
121-
height: 32px;
122-
border: none;
123-
border-radius: 6px;
124-
background-color: transparent;
125-
color: #374151;
126-
cursor: pointer;
127-
transition: all 200ms ease;
149+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
128150
}
129151

130-
.theme-toggle:hover {
131-
background-color: #f3f4f6;
152+
.theme-toggle.dark .theme-toggle-slider {
153+
transform: translateX(32px);
154+
background-color: #14b8a6;
155+
}
156+
157+
.theme-toggle-icons {
158+
position: absolute;
159+
top: 0;
160+
left: 0;
161+
right: 0;
162+
bottom: 0;
163+
display: flex;
164+
align-items: center;
165+
justify-content: space-between;
166+
padding: 4px 8px;
167+
pointer-events: none;
132168
}
133169

134170
.theme-toggle-icon {
135-
width: 18px;
136-
height: 18px;
171+
width: 16px;
172+
height: 16px;
173+
color: #6b7280;
174+
transition: color 300ms ease;
137175
}
138176

139-
.theme-toggle.dark {
177+
.theme-toggle.dark .theme-toggle-icon.moon {
140178
color: #14b8a6;
141179
}
142180

143-
.theme-toggle.dark:hover {
144-
background-color: rgba(20, 184, 166, 0.1);
181+
.theme-toggle.dark .theme-toggle-icon.sun {
182+
color: #6b7280;
145183
}

0 commit comments

Comments
 (0)