Skip to content

Commit 6f7fbac

Browse files
pierrotsmnrdpmeier
andauthored
CSS refactor (#312)
Co-authored-by: Philip Meier <github.pmeier@posteo.de>
1 parent b44c66c commit 6f7fbac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+823
-831
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies = [
2727
"httpx",
2828
"importlib_metadata>=4.6; python_version<'3.10'",
2929
"packaging",
30-
"panel==1.3.8",
30+
"panel==1.4.2",
3131
"pydantic>=2",
3232
"pydantic-core",
3333
"pydantic-settings>=2",

ragna/deploy/_ui/app.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,47 @@
2323
pn.config.browser_info = True
2424

2525

26-
HERE = Path(__file__).parent
27-
# CSS = HERE / "css"
28-
IMGS = HERE / "imgs"
29-
RES = HERE / "resources"
30-
31-
3226
class App(param.Parameterized):
3327
def __init__(self, *, hostname, port, api_url, origins, open_browser):
3428
super().__init__()
35-
ui.apply_design_modifiers()
29+
30+
# Apply the design modifiers to the panel components
31+
# It returns all the CSS files of the modifiers
32+
self.css_filepaths = ui.apply_design_modifiers()
3633
self.hostname = hostname
3734
self.port = port
3835
self.api_url = api_url
3936
self.origins = origins
4037
self.open_browser = open_browser
4138

4239
def get_template(self):
40+
# A bit hacky, but works.
41+
# we need to preload the css files to avoid a flash of unstyled content, especially when switching between chats.
42+
# This is achieved by adding <link ref="preload" ...> tags in the head of the document.
43+
# But none of the panel templates allow to add custom link tags in the head.
44+
# the only way I found is to take advantage of the raw_css parameter, which allows to add custom css in the head.
45+
preload_css = "\n".join(
46+
[
47+
f"""<link rel="preload" href="{css_fp}" as="style" />"""
48+
for css_fp in self.css_filepaths
49+
]
50+
)
51+
preload_css = f"""
52+
</style>
53+
{preload_css}
54+
<style type="text/css">
55+
"""
56+
4357
template = pn.template.FastListTemplate(
4458
# We need to set a title to have it appearing on the browser's tab
4559
# but it means we need to hide it from the header bar
4660
title="Ragna",
4761
accent_base_color=ui.MAIN_COLOR,
4862
theme_toggle=False,
4963
collapsed_sidebar=True,
50-
# main_layout=None
51-
raw_css=[ui.APP_RAW],
64+
raw_css=[ui.CSS_VARS, preload_css],
5265
favicon="imgs/ragna_logo.svg",
53-
css_files=["https://rsms.me/inter/inter.css"],
66+
css_files=["https://rsms.me/inter/inter.css", "css/main.css"],
5467
)
5568

5669
template.modal.objects = [
@@ -129,7 +142,10 @@ def serve(self):
129142
autoreload=True,
130143
profiler="pyinstrument",
131144
allow_websocket_origin=[urlsplit(origin).netloc for origin in self.origins],
132-
static_dirs={"imgs": str(IMGS), "resources": str(RES)}, # "css": str(CSS),
145+
static_dirs={
146+
dir: str(Path(__file__).parent / dir)
147+
for dir in ["css", "imgs", "resources"]
148+
},
133149
)
134150

135151

ragna/deploy/_ui/auth_page.py

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
import panel as pn
22
import param
33

4-
from . import styles as ui
5-
6-
# TODO Move this into a CSS file
7-
login_inputs_stylesheets = """
8-
9-
:host {
10-
width:100%;
11-
margin-left:0px;
12-
margin-right:0px;
13-
}
14-
15-
label {
16-
font-weight: 600;
17-
font-size: 16px;
18-
}
19-
20-
input {
21-
background-color: white !important;
22-
}
23-
24-
"""
25-
264

275
class AuthPage(pn.viewable.Viewer, param.Parameterized):
286
feedback_message = param.String(default=None)
@@ -37,11 +15,11 @@ def __init__(self, api_wrapper, **params):
3715

3816
self.login_input = pn.widgets.TextInput(
3917
name="Email",
40-
stylesheets=[login_inputs_stylesheets, ui.BK_INPUT_GRAY_BORDER],
18+
css_classes=["auth_login_input"],
4119
)
4220
self.password_input = pn.widgets.PasswordInput(
4321
name="Password",
44-
stylesheets=[login_inputs_stylesheets, ui.BK_INPUT_GRAY_BORDER],
22+
css_classes=["auth_password_input"],
4523
)
4624

4725
async def perform_login(self, event=None):
@@ -74,23 +52,8 @@ def display_error_message(self):
7452
return None
7553
else:
7654
return pn.pane.HTML(
77-
f"""<div class="error">{self.feedback_message}</div>""",
78-
stylesheets=[
79-
"""
80-
:host {
81-
width:100%;
82-
margin-left:0px;
83-
margin-right:0px;
84-
}
85-
86-
div.error {
87-
width:100%;
88-
color:red;
89-
text-align:center;
90-
font-weight: 600;
91-
font-size: 16px;
92-
} """
93-
],
55+
f"""<div class="auth_error">{self.feedback_message}</div>""",
56+
css_classes=["auth_error"],
9457
)
9558

9659
@pn.depends("custom_js")
@@ -107,67 +70,22 @@ def __panel__(self):
10770
login_button = pn.widgets.Button(
10871
name="Sign In",
10972
button_type="primary",
110-
stylesheets=[
111-
""" :host {
112-
width:100%;
113-
margin-left:0px;
114-
margin-right:0px;
115-
} """
116-
],
73+
css_classes=["auth_login_button"],
11774
)
11875
login_button.on_click(self.perform_login)
11976

12077
self.main_layout = pn.Column(
12178
self.wrapped_custom_js,
12279
pn.pane.HTML(
12380
"<h1>Log In</h1>",
124-
stylesheets=[
125-
""" :host {
126-
width:100%;
127-
margin-left:0px;
128-
margin-right:0px;
129-
text-align:center;
130-
}
131-
h1 {
132-
font-weight: 600;
133-
font-size: 24px;
134-
}
135-
"""
136-
],
81+
css_classes=["auth_title"],
13782
),
13883
self.display_error_message,
13984
self.login_input,
14085
self.password_input,
14186
pn.pane.HTML("<br />"),
14287
login_button,
143-
stylesheets=[
144-
""" :host {
145-
background-color:white;
146-
/*background-color:gold;*/
147-
border-radius: 5px;
148-
box-shadow: lightgray 0px 0px 10px;
149-
padding: 0 25px 0 25px;
150-
151-
width:30%;
152-
min-width:360px;
153-
max-width:430px;
154-
155-
margin-left: auto;
156-
margin-right: auto;
157-
margin-top: 10%;
158-
159-
}
160-
:host > div {
161-
margin-bottom: 10px;
162-
margin-top: 10px;
163-
}
164-
165-
.bk-panel-models-layout-Column {
166-
width:100%;
167-
}
168-
169-
"""
170-
],
88+
css_classes=["auth_page_main_layout"],
17189
)
17290

17391
return self.main_layout

0 commit comments

Comments
 (0)