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

This commit is contained in:
Elijah Ahianyo 2024-01-29 20:03:36 +00:00 committed by GitHub
parent 11f6d7ccef
commit 3a97a10d92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -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:

View File

@ -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)