From dd3e2bde22616c4e9b88ba3b1544f522b30dc5ca Mon Sep 17 00:00:00 2001 From: Lendemor Date: Tue, 28 Jan 2025 17:48:30 +0100 Subject: [PATCH 1/3] merging two style instance should give a style instance --- reflex/style.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/reflex/style.py b/reflex/style.py index 3916bbc7c1..d6bc28c5a5 100644 --- a/reflex/style.py +++ b/reflex/style.py @@ -292,6 +292,19 @@ def __setitem__(self, key: str, value: Any): ) super().__setitem__(key, value) + def __or__(self, other: Style) -> Style: + """Combine two styles. + + Args: + other: The other style to combine. + + Returns: + The combined style. + """ + if not isinstance(other, Style): + other = Style(other) + return Style(super().__or__(self, other)) + def _format_emotion_style_pseudo_selector(key: str) -> str: """Format a pseudo selector for emotion CSS-in-JS. From bf0634db562dcba7145b33f989965203793265e0 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Tue, 28 Jan 2025 18:59:09 +0100 Subject: [PATCH 2/3] fix ci --- reflex/style.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/reflex/style.py b/reflex/style.py index d6bc28c5a5..97bd151eb4 100644 --- a/reflex/style.py +++ b/reflex/style.py @@ -292,7 +292,7 @@ def __setitem__(self, key: str, value: Any): ) super().__setitem__(key, value) - def __or__(self, other: Style) -> Style: + def __or__(self, other: Style | dict) -> Style: """Combine two styles. Args: @@ -301,9 +301,7 @@ def __or__(self, other: Style) -> Style: Returns: The combined style. """ - if not isinstance(other, Style): - other = Style(other) - return Style(super().__or__(self, other)) + return Style(super().__or__(self, other)) # pyright: ignore [reportGeneralTypeIssues, reportCallIssue] def _format_emotion_style_pseudo_selector(key: str) -> str: From 30005b2dde6698b7836db4377f7de57474124821 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Tue, 28 Jan 2025 20:24:49 +0100 Subject: [PATCH 3/3] carry _var_data --- reflex/style.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reflex/style.py b/reflex/style.py index 97bd151eb4..9c3355137c 100644 --- a/reflex/style.py +++ b/reflex/style.py @@ -301,7 +301,8 @@ def __or__(self, other: Style | dict) -> Style: Returns: The combined style. """ - return Style(super().__or__(self, other)) # pyright: ignore [reportGeneralTypeIssues, reportCallIssue] + _var_data = VarData.merge(self._var_data, getattr(other, "_var_data", None)) + return Style(super().__or__(self, other), _var_data=_var_data) # pyright: ignore [reportGeneralTypeIssues, reportCallIssue] def _format_emotion_style_pseudo_selector(key: str) -> str: