Skip to content

Commit

Permalink
add functionality to format CSS stylesheets (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeier authored Dec 20, 2023
1 parent a437e7e commit 2056246
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 33 deletions.
62 changes: 29 additions & 33 deletions ragna/deploy/_ui/central_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,39 +293,35 @@ def on_click_chat_info_wrapper(self, event):
dedent=True,
# debug
# pn.pane.Markdown(f"Chat ID: {self.current_chat['id']}"),
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)
)
],
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"}),
),
),
],
)
Expand Down
22 changes: 22 additions & 0 deletions ragna/deploy/_ui/styles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
UI Helpers
"""
from typing import Optional

import panel as pn


Expand All @@ -12,6 +14,26 @@ def divider():
CSS constants
"""


def stylesheets(*class_selectors: tuple[str, dict[str, str]]) -> Optional[list[str]]:
if not class_selectors:
return None

return [
"\n".join(
[
f"{selector} {{",
*[
f" {property}: {value};"
for property, value in declarations.items()
],
"}",
]
)
for selector, declarations in class_selectors
]


MAIN_COLOR = "#DF5538" # "rgba(223, 85, 56, 1)"


Expand Down

0 comments on commit 2056246

Please sign in to comment.