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

Improve stylessheets formatting in UI code #258

Closed
pmeier opened this issue Dec 20, 2023 · 0 comments · Fixed by #312
Closed

Improve stylessheets formatting in UI code #258

pmeier opened this issue Dec 20, 2023 · 0 comments · Fixed by #312

Comments

@pmeier
Copy link
Member

pmeier commented Dec 20, 2023

We recently merged #257 that introduced a helper function on how to define CSS class selectors in our Python code. We turned

stylesheets=[
""" :host { width: 100%; }
.pills_list {
/*background-color:gold;*/
display: grid;
grid-auto-flow: row;
row-gap: 10px;
grid-template: repeat({{GRID_HEIGHT}}, 1fr) / repeat(3, 1fr);
max-height: 200px;
overflow: scroll;
}
.chat_document_pill {
background-color: rgb(241,241,241);
margin-left: 5px;
margin-right: 5px;
padding: 5px 15px;
border-radius: 10px;
color:var(--accent-color);
width:fit-content;
grid-column: span 1;
}
ul {
list-style-type: none
}
""".replace(
"{{GRID_HEIGHT}}", str(grid_height)
)
],

into

stylesheets=ui.stylesheets(
(":host", {"width": "100%"}),
(
".pills_list",
{
# "background-color": "gold",
"display": "grid",
"grid-auto-flow": "row",
"row-gap": "10px",
"grid-template": f"repeat({grid_height}, 1fr) / repeat(3, 1fr)",
"max-height": "200px",
"overflow": "scroll",
},
),
(
".chat_document_pill",
{
"background-color": "rgb(241,241,241)",
"margin-left": "5px",
"margin-right": "5px",
"padding": "5px 15px",
"border-radius": "10px",
"color": "var(--accent-color)",
"width": "fit-content",
"grid-column": "span 1",
},
),
("ul", {"list-style-type": "none"}),
),

We need to apply this to all occurrences inside our UI code, i.e. https://github.com/Quansight/ragna/tree/main/ragna/deploy/_ui.

To do that replace split the large multiline string into the individual class selectors. For each class selector, define a two-tuple where the first item is the selector and the second item is a dictionary with the declarations. For example:

.pills_list {
/*background-color:gold;*/
display: grid;
grid-auto-flow: row;
row-gap: 10px;
grid-template: repeat({{GRID_HEIGHT}}, 1fr) / repeat(3, 1fr);
max-height: 200px;
overflow: scroll;
}

needs to be transformed into

(
".pills_list",
{
# "background-color": "gold",
"display": "grid",
"grid-auto-flow": "row",
"row-gap": "10px",
"grid-template": f"repeat({grid_height}, 1fr) / repeat(3, 1fr)",
"max-height": "200px",
"overflow": "scroll",
},
),

After you have done this for every class selector, pass all the tuples to the new stylesheets function.

Of course you can do this in a single PR, but doing this incrementally, i.e. one component at a time is also perfectly fine.

@pmeier pmeier linked a pull request Feb 7, 2024 that will close this issue
@pmeier pmeier removed help wanted Extra attention is needed good first issue Good for newcomers labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant