Skip to content

Commit 15c6f8b

Browse files
fix: dark mode toggle logic (#1155)
* fix: dark mode toggle * Updated code based on review suggestions * Update code --------- Co-authored-by: Arkadii Yakovets <[email protected]> Co-authored-by: Arkadii Yakovets <[email protected]>
1 parent 64abd88 commit 15c6f8b

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

frontend/src/components/ModeToggle.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,27 @@ function ModeToggle({ className }: { className?: string }) {
2525
}
2626

2727
return (
28-
<div className={cn('flex items-center space-x-2', className)}>
29-
<span className="text-sm font-medium text-gray-900 dark:text-gray-100">
30-
<FontAwesomeIcon icon={dark ? faMoon : faSun} className="h-4 w-4" fixedWidth />
31-
</span>
28+
<div className={cn('flex items-center', className)}>
3229
<Tooltip
3330
showArrow
3431
content={dark ? 'Enable light mode' : 'Enable dark mode'}
3532
positioning={{ placement: 'bottom-start' }}
3633
openDelay={100}
3734
closeDelay={100}
3835
>
39-
<label className="relative inline-flex cursor-pointer items-center">
40-
<input
41-
type="checkbox"
42-
className="peer sr-only"
43-
checked={!dark}
44-
onChange={darkModeHandler}
45-
aria-label={dark ? 'Enable light mode' : 'Enable dark mode'}
46-
/>
47-
48-
<div className="peer h-6 w-11 rounded-full bg-gray-200 after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:border after:border-gray-300 after:bg-white after:transition-all after:content-[''] peer-checked:after:translate-x-full peer-checked:after:border-white dark:border-gray-600 dark:bg-gray-700"></div>
49-
</label>
36+
<button
37+
onClick={darkModeHandler}
38+
className="relative h-10 w-10 transform rounded-full bg-[#87a1bc] transition-all duration-200 active:scale-95 hover:ring-1 hover:ring-[#b0c7de] hover:ring-offset-0 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 dark:bg-slate-900 dark:text-white dark:hover:bg-slate-900/90 dark:hover:ring-[#46576b] "
39+
aria-label={dark ? 'Enable light mode' : 'Enable dark mode'}
40+
>
41+
<div className="absolute inset-0 flex items-center justify-center">
42+
<FontAwesomeIcon
43+
icon={dark ? faSun : faMoon}
44+
className="h-5 w-5 transform text-gray-900 transition-all duration-300 hover:rotate-12 dark:text-gray-100"
45+
fixedWidth
46+
/>
47+
</div>
48+
</button>
5049
</Tooltip>
5150
</div>
5251
)

0 commit comments

Comments
 (0)