Created the react frontend project and added some basic component
This commit is contained in:
1 parent
b3ab69cc22
commit
35835e9187
41 files changed
+9804
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
type Theme = 'dark' | 'light';
|
||||
|
||||
interface ThemeState {
|
||||
theme: Theme;
|
||||
setTheme: (theme: Theme) => void;
|
||||
toggleTheme: () => void;
|
||||
}
|
||||
|
||||
export const useThemeStore = create<ThemeState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
theme: 'dark',
|
||||
setTheme: (theme) => {
|
||||
document.documentElement.classList.remove('dark', 'light');
|
||||
document.documentElement.classList.add(theme);
|
||||
set({ theme });
|
||||
},
|
||||
toggleTheme: () => {
|
||||
const newTheme = get().theme === 'dark' ? 'light' : 'dark';
|
||||
document.documentElement.classList.remove('dark', 'light');
|
||||
document.documentElement.classList.add(newTheme);
|
||||
set({ theme: newTheme });
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'showy-theme',
|
||||
onRehydrateStorage: () => (state) => {
|
||||
if (state) {
|
||||
document.documentElement.classList.add(state.theme);
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in new issue
Block a user