Skip to content

Commit f33e27f

Browse files
adhami3310tartansandal
authored andcommitted
call to_string on colors coming into style (#5836)
* call to_string on colors coming into style * fix unit tests
1 parent 26c3be7 commit f33e27f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

reflex/style.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
from reflex import constants
99
from reflex.components.core.breakpoints import Breakpoints, breakpoints_values
10+
from reflex.constants.colors import Color
1011
from reflex.event import EventChain, EventHandler, EventSpec, run_script
1112
from reflex.utils import format
1213
from reflex.utils.exceptions import ReflexError
1314
from reflex.utils.imports import ImportVar
1415
from reflex.utils.types import typehint_issubclass
1516
from reflex.vars import VarData
1617
from reflex.vars.base import LiteralVar, Var
18+
from reflex.vars.color import LiteralColorVar
1719
from reflex.vars.function import FunctionVar
1820
from reflex.vars.object import ObjectVar
1921

@@ -132,6 +134,9 @@ def convert_item(
132134
if isinstance(style_item, Var):
133135
return style_item, style_item._get_all_var_data()
134136

137+
if isinstance(style_item, Color):
138+
return LiteralColorVar.create(style_item).to_string(use_json=False), None
139+
135140
# Otherwise, convert to Var to collapse VarData encoded in f-string.
136141
new_var = LiteralVar.create(style_item)
137142
var_data = new_var._get_all_var_data() if new_var is not None else None

tests/units/components/test_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ def add_style(self): # pyright: ignore [reportIncompatibleMethodOverride]
21462146
str_page = str(page)
21472147
assert (
21482148
str_page.count(
2149-
f'css:({{ ["fakeParent"] : "parent", ["color"] : Object.assign(new String("var(--plum-10)"), ({{ ["color"] : "plum", ["alpha"] : false, ["shade"] : 10 }})), ["fake"] : "text", ["margin"] : ({test_state.get_name()}.num{FIELD_MARKER}+"%") }})'
2149+
f'css:({{ ["fakeParent"] : "parent", ["color"] : (((__to_string) => __to_string.toString())(Object.assign(new String("var(--plum-10)"), ({{ ["color"] : "plum", ["alpha"] : false, ["shade"] : 10 }})))), ["fake"] : "text", ["margin"] : ({test_state.get_name()}.num{FIELD_MARKER}+"%") }})'
21502150
)
21512151
== 1
21522152
)

0 commit comments

Comments
 (0)