Browse Source
Merge pull request #520 from bkimmel/bkimmel/labels-on-icons
add a label to theme icon
pull/529/head
Dan Ditomaso
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
11 additions and
4 deletions
-
src/components/ThemeSwitcher.tsx
|
|
|
@ -24,18 +24,25 @@ export default function ThemeSwitcher({ |
|
|
|
setPreference(nextPreference); |
|
|
|
}; |
|
|
|
|
|
|
|
const [firstCharOfPreference = "", ...restOfPreference] = preference; |
|
|
|
|
|
|
|
return ( |
|
|
|
<button |
|
|
|
type="button" |
|
|
|
className={cn( |
|
|
|
"transition-all duration-300 scale-100 cursor-pointer m-6 p-2", |
|
|
|
"transition-all duration-300 scale-100 cursor-pointer m-6 p-2 focus:*:data-label:opacity-100", |
|
|
|
className, |
|
|
|
)} |
|
|
|
onClick={toggleTheme} |
|
|
|
aria-label={preference === "system" |
|
|
|
? `System theme (currently ${theme}). Click to change theme.` |
|
|
|
: `Current theme: ${theme}. Click to change theme.`} |
|
|
|
aria-description={"Change current theme"} |
|
|
|
> |
|
|
|
<span |
|
|
|
data-label |
|
|
|
className="transition-all block absolute w-full mb-auto mt-auto ml-0 mr-0 text-xs left-0 -top-5 opacity-0 rounded-lg" |
|
|
|
> |
|
|
|
{firstCharOfPreference.toLocaleUpperCase() + |
|
|
|
(restOfPreference ?? []).join("")} |
|
|
|
</span> |
|
|
|
{themeIcons[preference]} |
|
|
|
</button> |
|
|
|
); |
|
|
|
|