Explorar o código

Pass down themes for `rx.cond` and `rx.match` (#2432)

Elijah Ahianyo hai 1 ano
pai
achega
3a97a10d92
Modificáronse 2 ficheiros con 26 adicións e 2 borrados
  1. 11 2
      reflex/components/core/cond.py
  2. 15 0
      reflex/components/core/match.py

+ 11 - 2
reflex/components/core/cond.py

@@ -59,10 +59,10 @@ class Cond(MemoizationLeaf):
         )
 
     def _get_props_imports(self):
-        """Get the imports needed for components props.
+        """Get the imports needed for component's props.
 
         Returns:
-            The  imports for the components props of the component.
+            The imports for the component's props of the component.
         """
         return []
 
@@ -100,6 +100,15 @@ class Cond(MemoizationLeaf):
             _IS_TRUE_IMPORT,
         )
 
+    def _apply_theme(self, theme: Component):
+        """Apply the theme to this component.
+
+        Args:
+            theme: The theme to apply.
+        """
+        self.comp1.apply_theme(theme)  # type: ignore
+        self.comp2.apply_theme(theme)  # type: ignore
+
 
 @overload
 def cond(condition: Any, c1: Component, c2: Any) -> Component:

+ 15 - 0
reflex/components/core/match.py

@@ -270,3 +270,18 @@ class Match(MemoizationLeaf):
             super()._get_imports(),
             getattr(self.cond._var_data, "imports", {}),
         )
+
+    def _apply_theme(self, theme: Component):
+        """Apply the theme to this component.
+
+        Args:
+            theme: The theme to apply.
+        """
+        # apply theme to return components.
+        for match_case in self.match_cases:
+            if isinstance(match_case[-1], Component):
+                match_case[-1].apply_theme(theme)
+
+        # apply theme to default component
+        if isinstance(self.default, Component):
+            self.default.apply_theme(theme)