File tree Expand file tree Collapse file tree 4 files changed +20
-9
lines changed
Expand file tree Collapse file tree 4 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 1+ import { getContext , setContext } from 'svelte' ;
2+
3+ type ThemeStore = {
4+ currentTheme : string ;
5+ handleThemeChange : ( theme : string ) => void ;
6+ } ;
7+
8+ const themeKey = Symbol ( 'theme' ) ;
9+
10+ export const setThemeContext = ( storeCreator : ( ) => ThemeStore ) =>
11+ setContext ( themeKey , storeCreator ( ) ) ;
12+
13+ export const getThemeContext = ( ) : ThemeStore => getContext ( themeKey ) ;
Original file line number Diff line number Diff line change 11<script lang =" ts" >
2- import { getContext } from ' svelte' ;
3-
42 import { Sun , Moon } from ' @lucide/svelte' ;
53 import * as Dialog from ' @/lib/components/ui/dialog/index.js' ;
64 import { buttonVariants } from ' @/lib/components/ui/button/index.js' ;
75 import * as RadioGroup from ' @/lib/components/ui/radio-group/index' ;
86 import { Label } from ' @/lib/components/ui/label' ;
97 import { themes } from ' @/lib/utils/themes' ;
10- import type { ThemeContext } from ' @/stores/ThemeStove.svelte ' ;
8+ import { getThemeContext } from ' @/contexts/ThemeContext ' ;
119
1210 let isOpen = $state (false );
1311
14- let { currentTheme, handleThemeChange } = $derived (getContext < ThemeContext >( ' theme ' ));
12+ let { currentTheme, handleThemeChange } = $derived (getThemeContext ( ));
1513
1614 const handleThemeSelection = (value : string ) => {
1715 handleThemeChange (value );
Original file line number Diff line number Diff line change 55 import { Sun , Moon } from ' @lucide/svelte' ;
66 import * as RadioGroup from ' @/lib/components/ui/radio-group/index' ;
77 import Label from ' @/lib/components/ui/label/label.svelte' ;
8- import { getContext } from ' svelte' ;
9- import type { ThemeContext } from ' @/stores/ThemeStove.svelte' ;
8+ import { getThemeContext } from ' @/contexts/ThemeContext' ;
109
11- let { currentTheme, handleThemeChange } = $derived (getContext < ThemeContext >( ' theme ' ));
10+ let { currentTheme, handleThemeChange } = $derived (getThemeContext ( ));
1211 </script >
1312
1413<Card .Root >
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import ' ../app.css' ;
3- import { setContext , type Snippet } from ' svelte' ;
3+ import { type Snippet } from ' svelte' ;
44 import { ClerkProvider } from ' svelte-clerk' ;
55 import Footer from ' @/lib/components/Footer.svelte' ;
66 import { Toaster } from ' @/lib/components/ui/sonner/index.js' ;
77 import { PUBLIC_CLERK_PUBLISHABLE_KEY } from ' $env/static/public' ;
88 import { useTheme } from ' @/stores/ThemeStove.svelte' ;
9+ import { setThemeContext } from ' @/contexts/ThemeContext' ;
910
10- setContext ( ' theme ' , useTheme () );
11+ setThemeContext ( useTheme );
1112
1213 const { children }: { children: Snippet } = $props ();
1314 </script >
You can’t perform that action at this time.
0 commit comments