MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / ThemeProvider

Function ThemeProvider

apps/start/src/components/theme-provider.tsx:109–149  ·  view source on GitHub ↗
({ children }: ThemeProviderProps)

Source from the content-addressed store, hash-verified

107 children: ReactNode;
108};
109export function ThemeProvider({ children }: ThemeProviderProps) {
110 const [userTheme, setUserTheme] = useCookieStore<UserTheme>(
111 'ui-theme',
112 'system',
113 );
114
115 useEffect(() => {
116 if (userTheme !== 'system') return;
117 return setupPreferredListener();
118 }, [userTheme]);
119
120 const appTheme = userTheme === 'system' ? getSystemTheme() : userTheme;
121
122 const setTheme = (newUserTheme: UserTheme) => {
123 const validatedTheme = UserThemeSchema.parse(newUserTheme);
124 setUserTheme(validatedTheme);
125 handleThemeChange(validatedTheme);
126 };
127
128 const getNextTheme = () => {
129 const themes = Object.keys(themeConfig) as UserTheme[];
130 const currentIndex = themes.indexOf(userTheme);
131 const nextIndex = (currentIndex + 1) % themes.length;
132 return themes[nextIndex];
133 };
134
135 return (
136 <ThemeContext
137 value={{
138 userTheme,
139 appTheme,
140 theme: appTheme,
141 setTheme,
142 getNextTheme,
143 themes,
144 }}
145 >
146 {children}
147 </ThemeContext>
148 );
149}
150
151export const useTheme = () => {
152 const context = use(ThemeContext);

Callers

nothing calls this directly

Calls 1

useCookieStoreFunction · 0.90

Tested by

no test coverage detected