Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to change the color depending on the conditions. #4159

Closed
maki8maki opened this issue Oct 11, 2024 · 1 comment · Fixed by #4175 or #4177
Closed

Want to change the color depending on the conditions. #4159

maki8maki opened this issue Oct 11, 2024 · 1 comment · Fixed by #4175 or #4177
Labels
bug Something isn't working

Comments

@maki8maki
Copy link

maki8maki commented Oct 11, 2024

Describe the bug
I wrote code to change the shade of rx.color used as background of rx.box depending on the conditions, but the background remains white.
When I replaced rx.color("gray", shade=3) with "var(--gray-3)" and rx.color("gray", shade=7) with "var(--gray-7)" it worked fine.

To Reproduce

from typing import List

import reflex as rx


class State(rx.State):
    my_list: List[int] = [i for i in range(90)]


def get_background_color(index: int):
    return rx.cond(index % 2 == 0, rx.color("gray", shade=3), rx.color("gray", shade=7))


def render_box(value: int, index: int):
    return rx.box(
        rx.text(value),
        bg=get_background_color(index),
        width="30px",
        height="30px",
        border=f"1px solid {rx.color('gray', 12)}",
    )


def display():
    return rx.grid(
        rx.foreach(State.my_list, lambda value, index: render_box(value, index)),
        columns="9",
        border=f"1px solid {rx.color('gray', 12)}",
        justify="center",
    )


app = rx.App()


@rx.page()
def index():
    return display()

Screenshots
Current output
screenshot 1

Expected output
screenshot 2

Specifics (please complete the following information):

  • Python Version: 3.12.7
  • Reflex Version: 0.6.1
  • OS: 14.7 (intel)
  • Browser (Optional): Safari 18.0.1

Additional context
This may not be accurate, but I recall that this issue did not occur in previous versions.

@maki8maki maki8maki added the bug Something isn't working label Oct 11, 2024
@adhami3310 adhami3310 linked a pull request Oct 15, 2024 that will close this issue
@adhami3310
Copy link
Member

apparently rx.Color was being treated as an object var instead of being treated as a string, i made some fixes and it should be there for 0.6.4.

the issue that made this appear is that ObjectVar is typically a dict, and as such we don't translate bg to background-color, if you want a workaround, you can do "background-color" in style for now. we should adjust the logic for converting names to only treat object vars with _var_type == dict as style mapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants