66
77from reflex import constants
88from reflex .components .core .breakpoints import Breakpoints , breakpoints_values
9- from reflex .event import EventChain , EventHandler
9+ from reflex .event import EventChain , EventHandler , EventSpec , run_script
1010from reflex .utils import format
1111from reflex .utils .exceptions import ReflexError
1212from reflex .utils .imports import ImportVar
@@ -49,9 +49,9 @@ def _color_mode_var(_js_expr: str, _var_type: Type = str) -> Var:
4949
5050
5151def set_color_mode (
52- new_color_mode : LiteralColorMode | Var [LiteralColorMode ] | None = None ,
53- ) -> Var [ EventChain ] :
54- """Create an EventChain Var that sets the color mode to a specific value.
52+ new_color_mode : LiteralColorMode | Var [LiteralColorMode ],
53+ ) -> EventSpec :
54+ """Create an EventSpec Var that sets the color mode to a specific value.
5555
5656 Note: `set_color_mode` is not a real event and cannot be triggered from a
5757 backend event handler.
@@ -60,24 +60,15 @@ def set_color_mode(
6060 new_color_mode: The color mode to set.
6161
6262 Returns:
63- The EventChain Var that can be passed to an event trigger.
63+ The EventSpec Var that can be passed to an event trigger.
6464 """
6565 base_setter = _color_mode_var (
6666 _js_expr = constants .ColorMode .SET ,
67- _var_type = EventChain ,
68- )
69- if new_color_mode is None :
70- return base_setter
71-
72- if not isinstance (new_color_mode , Var ):
73- new_color_mode = LiteralVar .create (new_color_mode )
67+ ).to (FunctionVar )
7468
75- return Var (
76- f"() => { base_setter !s} ({ new_color_mode !s} )" ,
77- _var_data = VarData .merge (
78- base_setter ._get_all_var_data (), new_color_mode ._get_all_var_data ()
79- ),
80- ).to (FunctionVar , EventChain )
69+ return run_script (
70+ base_setter .call (new_color_mode ),
71+ )
8172
8273
8374# Var resolves to the current color mode for the app ("light", "dark" or "system")
0 commit comments