16
16
)
17
17
from reflex .config import get_config
18
18
from reflex .state import BaseState
19
+ from reflex .style import LIGHT_COLOR_MODE
19
20
from reflex .utils .imports import ImportVar
20
21
21
22
@@ -67,11 +68,12 @@ def _is_dev_mode() -> bool:
67
68
return os .environ .get ("REFLEX_ENV_MODE" , "dev" ) == "dev"
68
69
69
70
70
- def _compile_contexts (state : Optional [Type [BaseState ]]) -> str :
71
+ def _compile_contexts (state : Optional [Type [BaseState ]], theme : Component ) -> str :
71
72
"""Compile the initial state and contexts.
72
73
73
74
Args:
74
75
state: The app state.
76
+ theme: The top-level app theme.
75
77
76
78
Returns:
77
79
The compiled context file.
@@ -82,9 +84,13 @@ def _compile_contexts(state: Optional[Type[BaseState]]) -> str:
82
84
state_name = state .get_name (),
83
85
client_storage = utils .compile_client_storage (state ),
84
86
is_dev_mode = _is_dev_mode (),
87
+ default_color_mode = getattr (theme , "appearance" , LIGHT_COLOR_MODE ),
85
88
)
86
89
if state
87
- else templates .CONTEXT .render (is_dev_mode = _is_dev_mode ())
90
+ else templates .CONTEXT .render (
91
+ is_dev_mode = _is_dev_mode (),
92
+ default_color_mode = getattr (theme , "appearance" , LIGHT_COLOR_MODE ),
93
+ )
88
94
)
89
95
90
96
@@ -345,19 +351,23 @@ def compile_theme(style: ComponentStyle) -> tuple[str, str]:
345
351
return output_path , code
346
352
347
353
348
- def compile_contexts (state : Optional [Type [BaseState ]]) -> tuple [str , str ]:
354
+ def compile_contexts (
355
+ state : Optional [Type [BaseState ]],
356
+ theme : Component ,
357
+ ) -> tuple [str , str ]:
349
358
"""Compile the initial state / context.
350
359
351
360
Args:
352
361
state: The app state.
362
+ theme: The top-level app theme.
353
363
354
364
Returns:
355
365
The path and code of the compiled context.
356
366
"""
357
367
# Get the path for the output file.
358
368
output_path = utils .get_context_path ()
359
369
360
- return output_path , _compile_contexts (state )
370
+ return output_path , _compile_contexts (state , theme )
361
371
362
372
363
373
def compile_page (
0 commit comments