add test for var alpha

This commit is contained in:
Khaleel Al-Adhami 2024-10-15 10:58:54 -07:00
parent de5702cacf
commit fbb238998d
2 changed files with 9 additions and 1 deletions

View File

@ -1699,7 +1699,7 @@ class LiteralColorVar(CachedVarOperation, LiteralVar, ColorVar):
ternary_operation(
alpha,
LiteralStringVar.create("a"),
LiteralStringVar.create("False"),
LiteralStringVar.create(""),
)
if isinstance(alpha, Var)
else LiteralStringVar.create("a" if alpha else "")

View File

@ -14,6 +14,7 @@ class ColorState(rx.State):
color: str = "mint"
color_part: str = "tom"
shade: int = 4
alpha: bool = False
color_state_name = ColorState.get_full_name().replace(".", "__")
@ -34,6 +35,13 @@ def create_color_var(color):
f'("var(--"+{str(color_state_name)}.color+"-"+(((__to_string) => __to_string.toString())({str(color_state_name)}.shade))+")")',
Color,
),
(
create_color_var(
rx.color(ColorState.color, ColorState.shade, ColorState.alpha)
), # type: ignore
f'("var(--"+{str(color_state_name)}.color+"-"+({str(color_state_name)}.alpha ? "a" : "")+(((__to_string) => __to_string.toString())({str(color_state_name)}.shade))+")")',
Color,
),
(
create_color_var(rx.color(f"{ColorState.color}", f"{ColorState.shade}")), # type: ignore
f'("var(--"+{str(color_state_name)}.color+"-"+{str(color_state_name)}.shade+")")',