Skip to content

Commit

Permalink
opentierboy-76 Refactor Themes (#78)
Browse files Browse the repository at this point in the history
- Refactor themes to solely use next-themes
  • Loading branch information
infinia-yzl committed Aug 4, 2024
1 parent bbd518c commit e8d740e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}

/* Ocean theme */
.theme-ocean {
.ocean-light {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--card: 0 0% 100%;
Expand Down Expand Up @@ -108,7 +108,7 @@
--tier-gradient-6: linear-gradient(to right, #3C6E8F, #2E8B57); /* Deepest ocean */
}

.dark.theme-ocean {
.ocean-dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--card: 222.2 84% 4.9%;
Expand Down Expand Up @@ -143,7 +143,7 @@
}

/* Forest theme */
.theme-forest {
.forest-light {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--card: 0 0% 100%;
Expand Down Expand Up @@ -178,7 +178,7 @@
--tier-gradient-6: linear-gradient(to right, #fae8cc, #f5c29e);
}

.dark.theme-forest {
.forest-dark {
--background: 20 14.3% 4.1%;
--foreground: 0 0% 95%;
--card: 24 9.8% 10%;
Expand Down
6 changes: 6 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ export default function RootLayout({
<ThemeProvider
attribute="class"
defaultTheme="system"
themes={[
'ocean-light', 'ocean-dark',
'forest-light', 'forest-dark',
'dark', 'light',
'system'
]}
enableSystem
disableTransitionOnChange
>
Expand Down
11 changes: 3 additions & 8 deletions components/ThemeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@ const colorThemes = ['classic', 'ocean', 'forest'];

export function ThemeSelector() {
const [mounted, setMounted] = useState(false);
const {setTheme} = useTheme();
const {theme, setTheme} = useTheme();

useEffect(() => {
setMounted(true);
}, []);

const handleThemeChange = (newTheme: string) => {
const [newColorTheme, newMode] = newTheme.split('-');
document.documentElement.classList.remove('theme-ocean', 'theme-forest');
if (newColorTheme !== 'classic') {
document.documentElement.classList.add(`theme-${newColorTheme}`);
}
setTheme(newMode);
setTheme(newTheme.replace('classic-', ''));
};

if (!mounted) {
Expand All @@ -43,7 +38,7 @@ export function ThemeSelector() {
{colorThemes.map((colorTheme) => (
<DropdownMenuItem key={colorTheme}
className="flex items-center justify-between p-2"
onClick={() => handleThemeChange(colorTheme)}
onClick={() => handleThemeChange(`${colorTheme}-${theme && theme.includes('dark') ? 'dark' : 'light'}`)}
>
<span className="flex-grow pl-2 text-sm">
{colorTheme.charAt(0).toUpperCase() + colorTheme.slice(1)}
Expand Down

0 comments on commit e8d740e

Please sign in to comment.