mwouts / itables

Pandas DataFrames as Interactive DataTables
https://mwouts.github.io/itables/
MIT License
803 stars 58 forks source link

Changing the color of buttons in searchBuilder #294

Closed mshqn closed 2 months ago

mshqn commented 5 months ago

Hello, currently the color of searchBuilder buttons is dark grey which makes it difficult to read the text inside them. Also adding searchBuilder to the table makes the search box and number of entries per page dark-coloured and the text is completely invisible. I would like to make all buttons and input fields light but I am not sure how to do it. I would be grateful for help.

Here is my example file:

Screenshot 2024-06-21 at 13 10 07
---
title: Test
standalone: true
format:
  html:
    echo: false
    css: styles.css
---

``` {python}
from itables import init_notebook_mode, show
from sklearn.datasets import load_diabetes

init_notebook_mode(all_interactive=True)

diabetes = load_diabetes(as_frame=True)
show(
    diabetes.data,
    layout={"top1": "searchBuilder"},
    searchBuilder={
        "preDefined": {"criteria": [{"data": "age", "condition": ">", "value": [0]}]}
    },
)
```

I started with adding the following styles.css but it didn't work:

html.dark div.dtsb-searchBuilder button.dtsb-button,
html.dark div.dtsb-searchBuilder select.dtsb-dropDown,
html.dark div.dtsb-searchBuilder input.dtsb-input {
    background-color: #F1F1F1 !important;
}

I don't have experience with html/css and not sure how to proceed.

mwouts commented 5 months ago

Hi @mshqn , this looks like the dark mode of DataTables.

The init_notebook_mode cell activates the dark mode using this HTML snippet: https://github.com/mwouts/itables/blob/main/src/itables/html/init_datatables.html

Is by chance your browser configured to use a dark mode?

mshqn commented 4 months ago

Thank you @mwouts! The problem was indeed in dark mode. My solution was to modify the yml:

---
title: Test
embed-resources: true
format:
  html:
    echo: false
include-after-body:
  text: |
    <script>
      document.documentElement.classList.remove('dark');
    </script>
---

I am not sure if this is the best solution but it worked:

Screenshot 2024-06-24 at 10 47 51
MarsPanther commented 4 months ago

@mwouts is there a permanent solution for this, even the exported website buttons and inputs are not clearly vissble anymore.

A temporary/ permanet fix to integrate with jupyter lab dark theme will be highly appreciated.

image

mwouts commented 4 months ago

As I mentioned above (https://github.com/mwouts/itables/issues/294#issuecomment-2183379643), the dark mode activation of ITables is done by the init_notebook_mode.

Can you make sure you do call that function?

If so, can you look into the HTML file https://github.com/mwouts/itables/blob/main/src/itables/html/init_datatables.html and figure out why it's not working for you?

calvma commented 4 months ago

I had to change to light appearance at the OS level in MacOS ito fix this! Perhaps a line that omits checking system theme on macs would be useful!

mwouts commented 4 months ago

Yes as I mentioned above, the current light vs dark mode detection needs improving. The current logic is just below - dark mode is activated if either the browser is in dark mode or Jupyter is in dark mode:

https://github.com/mwouts/itables/blob/dfe261c8ed38d8c46b97f8bc28183c976883c0a6/src/itables/html/init_datatables.html#L1-L11

It would make sense to look at the Jupyter mode, and then at the system settings. PRs that would improve the current implementation are welcome!

mwouts commented 4 months ago

Hi everyone, I have a development version that should be a bit smarter re the dark mode. Would you mind giving it a try and let me know how it works for you? You can install it with:

pip install git+https://github.com/mwouts/itables.git@improve_dark_mode

(that requires nodejs, see more at Developing ITables)