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

Use var(--something) to color cells #497

Open
tfmark opened this issue Apr 3, 2024 · 2 comments
Open

Use var(--something) to color cells #497

tfmark opened this issue Apr 3, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@tfmark
Copy link
Contributor

tfmark commented Apr 3, 2024

Is your feature request related to a problem? Please describe.

There's currently no built-in way to color rows in a row % 2 fashion (see #379).

Rolling our own is relatively simple:

import ipydatagrid
import pandas as pd

ipydatagrid.DataGrid(
    dataframe=pd.DataFrame({"a":[1, 2, 3]}),
    default_renderer=ipydatagrid.TextRenderer(background_color=ipydatagrid.VegaExpr("cell.row % 2 == 0 ? 'white' : 'red'"))
)

image

.. however when I switch to dark mode, the styled rows does not update (of course they wouldnt), but the rest of the grid does:

image

I thought I might be able to use CSS variables to get around this, but trying to use, e.g. var(--ipydatagrid-layout-color2) results in a black background:

image

which suggests the variables aren't available to the canvas (or whatever is coloring the rows).

Describe the solution you'd like
I'd like to be able to theme my grid with variables so it works in both light and dark mode.

Describe alternatives you've considered

The python widget does not have the attribute _isLightTheme that the javascript side has, otherwise I might be able to manually set different TextRenderers based on whether or not the widget was experiencing dark mode.

Additional context

n/a

@martinRenou martinRenou added the enhancement New feature or request label Apr 4, 2024
@martinRenou
Copy link
Member

This could indeed be a nice addition! I believe it's possible to implement

@tfmark
Copy link
Contributor Author

tfmark commented Apr 9, 2024

Might be a little easier now that jupyter-widgets/ipywidgets#3796 is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants