From 3a97a10d928a19dacd573a30d79999335dbff98d Mon Sep 17 00:00:00 2001 From: Elijah Ahianyo Date: Mon, 29 Jan 2024 20:03:36 +0000 Subject: [PATCH] Pass down themes for `rx.cond` and `rx.match` (#2432) --- reflex/components/core/cond.py | 13 +++++++++++-- reflex/components/core/match.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/reflex/components/core/cond.py b/reflex/components/core/cond.py index 1564f3cf0..b17ab5409 100644 --- a/reflex/components/core/cond.py +++ b/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: diff --git a/reflex/components/core/match.py b/reflex/components/core/match.py index 20d55bd04..4cce14b33 100644 --- a/reflex/components/core/match.py +++ b/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)