|
@@ -16,6 +16,7 @@ from reflex.components.component import (
|
|
|
)
|
|
|
from reflex.config import get_config
|
|
|
from reflex.state import BaseState
|
|
|
+from reflex.style import LIGHT_COLOR_MODE
|
|
|
from reflex.utils.imports import ImportVar
|
|
|
|
|
|
|
|
@@ -67,11 +68,12 @@ def _is_dev_mode() -> bool:
|
|
|
return os.environ.get("REFLEX_ENV_MODE", "dev") == "dev"
|
|
|
|
|
|
|
|
|
-def _compile_contexts(state: Optional[Type[BaseState]]) -> str:
|
|
|
+def _compile_contexts(state: Optional[Type[BaseState]], theme: Component) -> str:
|
|
|
"""Compile the initial state and contexts.
|
|
|
|
|
|
Args:
|
|
|
state: The app state.
|
|
|
+ theme: The top-level app theme.
|
|
|
|
|
|
Returns:
|
|
|
The compiled context file.
|
|
@@ -82,9 +84,13 @@ def _compile_contexts(state: Optional[Type[BaseState]]) -> str:
|
|
|
state_name=state.get_name(),
|
|
|
client_storage=utils.compile_client_storage(state),
|
|
|
is_dev_mode=_is_dev_mode(),
|
|
|
+ default_color_mode=getattr(theme, "appearance", LIGHT_COLOR_MODE),
|
|
|
)
|
|
|
if state
|
|
|
- else templates.CONTEXT.render(is_dev_mode=_is_dev_mode())
|
|
|
+ else templates.CONTEXT.render(
|
|
|
+ is_dev_mode=_is_dev_mode(),
|
|
|
+ default_color_mode=getattr(theme, "appearance", LIGHT_COLOR_MODE),
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
|
|
@@ -345,11 +351,15 @@ def compile_theme(style: ComponentStyle) -> tuple[str, str]:
|
|
|
return output_path, code
|
|
|
|
|
|
|
|
|
-def compile_contexts(state: Optional[Type[BaseState]]) -> tuple[str, str]:
|
|
|
+def compile_contexts(
|
|
|
+ state: Optional[Type[BaseState]],
|
|
|
+ theme: Component,
|
|
|
+) -> tuple[str, str]:
|
|
|
"""Compile the initial state / context.
|
|
|
|
|
|
Args:
|
|
|
state: The app state.
|
|
|
+ theme: The top-level app theme.
|
|
|
|
|
|
Returns:
|
|
|
The path and code of the compiled context.
|
|
@@ -357,7 +367,7 @@ def compile_contexts(state: Optional[Type[BaseState]]) -> tuple[str, str]:
|
|
|
# Get the path for the output file.
|
|
|
output_path = utils.get_context_path()
|
|
|
|
|
|
- return output_path, _compile_contexts(state)
|
|
|
+ return output_path, _compile_contexts(state, theme)
|
|
|
|
|
|
|
|
|
def compile_page(
|