Skip to content

Commit 31e7286

Browse files
committed
fix: sidebar aesthetics
1 parent abbba30 commit 31e7286

File tree

4 files changed

+99
-62
lines changed

4 files changed

+99
-62
lines changed

daras_ai_v2/icons.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
search = '<i class="fa-solid fa-magnifying-glass"></i>'
5555
library = '<i class="fa-solid fa-book"></i>'
5656
sidebar_flip = "<i class='fa-light fa-sidebar-flip'></i>"
57+
arrow_up_right = "<i class='fa-regular fa-arrow-up-right'></i>"
5758

5859
# brands
5960
github = '<i class="fa-brands fa-github"></i>'

daras_ai_v2/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@
308308
]
309309

310310
SIDEBAR_LINKS = [
311-
("/explore/", "Search", "<i class='fa-solid fa-magnifying-glass'></i>"),
311+
# ("/explore/", "Search", "<i class='fa-solid fa-magnifying-glass'></i>"),
312312
(DOCS_URL, "Docs", "<i class='fa-regular fa-book'></i>"),
313313
("/api/", "API", "<i class='fa-regular fa-code'></i>"),
314314
(BLOG_URL, "Blog", "<i class='fa-regular fa-newspaper'></i>"),
315315
("/pricing", "Pricing", "<i class='fa-regular fa-circle-dollar'></i>"),
316316
(CONTACT_URL, "Contact", "<i class='fa-regular fa-envelope'></i>"),
317317
]
318-
SIDEBAR_ICON_SIZE = "40px"
318+
SIDEBAR_ICON_SIZE = "32px"
319319

320320
HEADER_ICONS = {"/explore/": '<i class="fa-solid fa-magnifying-glass"></i>'}
321321

routers/root.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def page_wrapper(
738738
):
739739
with gui.div(
740740
className="d-flex px-md-2 px-3 py-2 align-items-center justify-content-between text-nowrap",
741-
style={"height": "64px"},
741+
style={"height": "54px"},
742742
):
743743
# sidebar header
744744
gui.tag(
@@ -750,7 +750,7 @@ def page_wrapper(
750750
)
751751
open_sidebar_btn = gui.button(
752752
label=icons.sidebar_flip,
753-
className="m-0 d-none hover-btn",
753+
className="m-0 d-none hover-btn gooey-btn",
754754
unsafe_allow_html=True,
755755
type="tertiary",
756756
)
@@ -787,7 +787,7 @@ def page_wrapper(
787787

788788
close_mobile_sidebar = gui.button(
789789
label=icons.cancel,
790-
className="m-0 d-md-none p-2",
790+
className="m-0 d-md-none gooey-btn",
791791
unsafe_allow_html=True,
792792
type="tertiary",
793793
)
@@ -798,7 +798,7 @@ def page_wrapper(
798798
if sidebar_ref.is_open:
799799
close_sidebar = gui.button(
800800
label=icons.sidebar_flip,
801-
className="m-0 d-none d-md-block",
801+
className="m-0 d-none d-md-block gooey-btn",
802802
unsafe_allow_html=True,
803803
type="tertiary",
804804
)

widgets/sidebar.py

Lines changed: 92 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def use_sidebar(key: str, session: dict, default_open: bool = True) -> SidebarRe
4141
return ref
4242

4343

44-
def sidebar_list_item(icon, title, is_sidebar_open, url=None):
44+
def sidebar_list_item(icon, title, is_sidebar_open, url=None, hover_icon=None):
4545
with (
4646
gui.styled(
4747
"""
@@ -50,46 +50,60 @@ def sidebar_list_item(icon, title, is_sidebar_open, url=None):
5050
text-decoration: none;
5151
}
5252
& .sidebar-list-item {
53-
min-height: 24px;
53+
border-radius: 8px;
54+
height: 36px;
55+
width: min-content;
56+
padding: 6px 10px;
5457
}
55-
& .sidebar-list-item-icon {
56-
max-width: 18px;
57-
min-width: 18px;
58+
& .sidebar-list-item-hover-icon {
59+
display: none;
5860
}
59-
& a:hover {
60-
.sidebar-list-item-title {
61-
text-decoration: underline !important;
62-
text-decoration-color: #000 !important;
63-
text-decoration-thickness: 2px !important;
64-
text-underline-offset: 2px !important;
61+
& .sidebar-list-item:hover {
62+
background-color: #f0f0f0;
63+
.sidebar-list-item-hover-icon {
64+
display: block;
6565
}
6666
}
67+
& .sidebar-list-item-title {
68+
font-size: 0.875rem;
69+
}
6770
"""
6871
),
69-
gui.div(className="d-flex align-items-center"),
72+
gui.div(),
7073
):
71-
with gui.div(className="d-flex align-items-center w-100"):
72-
with gui.tag(
73-
"a",
74-
href=url,
75-
className="d-flex align-items-center sidebar-list-item w-100",
76-
):
74+
link_classes = "d-block sidebar-list-item ms-2"
75+
if is_sidebar_open:
76+
link_classes += " d-flex align-items-baseline justify-content-between w-100"
77+
with gui.tag(
78+
"a",
79+
href=url,
80+
className=link_classes,
81+
):
82+
with gui.div(className="d-flex align-items-baseline"):
83+
icon_classes = "d-block sidebar-list-item-icon"
84+
if is_sidebar_open:
85+
icon_classes += " me-2"
86+
7787
if icon:
7888
gui.html(
7989
icon,
80-
className="sidebar-list-item-icon me-2 d-flex justify-content-center",
90+
className=icon_classes,
8191
)
8292
if is_sidebar_open:
8393
gui.html(title, className="sidebar-list-item-title d-block")
8494

95+
if hover_icon:
96+
with gui.div(className="sidebar-list-item-hover-icon"):
97+
gui.html(hover_icon, className="text-secondary")
98+
8599

86100
def sidebar_item_list(is_sidebar_open):
87101
for i, (url, label, icon) in enumerate(settings.SIDEBAR_LINKS):
88-
if not is_sidebar_open and i >= 1:
89-
break
90102
if icon:
91103
with gui.div():
92-
sidebar_list_item(icon, label, is_sidebar_open, url)
104+
sidebar_list_item(
105+
icon, label, is_sidebar_open, url, icons.arrow_up_right
106+
)
93107
else:
94108
with gui.div(
95109
className="d-inline-block me-2 small",
@@ -99,28 +113,34 @@ def sidebar_item_list(is_sidebar_open):
99113

100114

101115
def render_default_sidebar(session: dict):
102-
is_sidebar_open = session.get("main-sidebar", True)
116+
is_sidebar_open = use_sidebar("main-sidebar", session, default_open=True).is_open
103117
with gui.div(
104-
className="d-flex flex-column flex-grow-1 gap-3 px-3 my-3 text-nowrap",
105-
style={"marginLeft": "4px"},
118+
className=f"d-flex flex-column flex-grow-1 {'pe-3' if is_sidebar_open else ''} my-3 text-nowrap",
106119
):
107-
with gui.div(className="pe-2"):
120+
with gui.div(className="mb-4"):
108121
sidebar_list_item(
109122
"<i class='fa-regular fa-floppy-disk'></i>",
110123
"Saved",
111124
is_sidebar_open,
112-
"/saved/",
125+
"/account/saved/",
126+
)
127+
sidebar_list_item(
128+
icons.search,
129+
"Explore",
130+
is_sidebar_open,
131+
"/explore/",
113132
)
114133

115-
sidebar_item_list(is_sidebar_open)
134+
if is_sidebar_open:
135+
sidebar_item_list(is_sidebar_open)
116136

117137

118138
def sidebar_logo_header(session: dict):
119139
with gui.div(
120140
className="d-flex align-items-center justify-content-between d-md-none me-2 w-100 py-2",
121-
style={"height": "64px"},
141+
style={"height": "54px"},
122142
):
123-
sidebar_ref = use_sidebar("main-sidebar", session, default_open=True)
143+
sidebar_ref = use_sidebar("main-sidebar", session)
124144
gui.tag(
125145
"img",
126146
src=settings.GOOEY_LOGO_FACE,
@@ -133,64 +153,80 @@ def sidebar_logo_header(session: dict):
133153
className="m-0",
134154
unsafe_allow_html=True,
135155
type="tertiary",
156+
style={"padding": "6px 10px"},
136157
)
137158
if open_mobile_sidebar:
138159
sidebar_ref.set_mobile_open(True)
139160
raise gui.RerunException()
140161

141162

163+
# Sidebar width variables
164+
sidebar_open_width = "245px"
165+
sidebar_closed_width = "53px"
166+
sidebar_mobile_width = "80vw"
167+
168+
142169
def sidebar_layout(sidebar_ref: SidebarRef):
143170
is_mobile_open = sidebar_ref.is_mobile_open
144171
sidebar_funtion_classes = (
145172
"gooey-sidebar-open" if sidebar_ref.is_open else "gooey-sidebar-closed"
146173
)
174+
147175
side_bar_styles = dedent(
148-
"""
149-
html {
176+
f"""
177+
html {{
150178
/* override margin-left from app.css */
151179
margin-left: 0 !important;
152-
}
180+
}}
181+
& .gooey-btn {{
182+
padding: 6px 10px !important;
183+
}}
184+
& .gooey-btn:hover {{
185+
background-color: #f0f0f0 !important;
186+
}}
153187
154-
& .gooey-sidebar {
188+
& .gooey-sidebar {{
155189
transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.2s cubic-bezier(0.4, 0, 0.2, 1), max-width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
156190
background-color: #f9f9f9;
157191
position: sticky;
158192
top: 0;
159193
left: 0;
160194
bottom: 0;
161195
z-index: 999;
162-
}
163-
& .gooey-sidebar-open {
164-
min-width: 250px;
165-
width: 250px;
166-
max-width: 250px;
167-
}
168-
& .gooey-sidebar-closed {
169-
min-width: 60px;
170-
width: 60px;
171-
max-width: 60px;
172-
}
196+
border-right: 1px solid #e0e0e0;
197+
}}
198+
199+
& .gooey-sidebar-open {{
200+
min-width: {sidebar_open_width};
201+
width: {sidebar_open_width};
202+
max-width: {sidebar_open_width};
203+
}}
204+
& .gooey-sidebar-closed {{
205+
min-width: {sidebar_closed_width};
206+
width: {sidebar_closed_width};
207+
max-width: {sidebar_closed_width};
208+
}}
173209
174-
& .gooey-sidebar-closed:hover {
210+
& .gooey-sidebar-closed:hover {{
175211
cursor: e-resize;
176-
}
212+
}}
177213
178-
@media (max-width: 767px) {
179-
& .gooey-sidebar-open {
214+
@media (max-width: 767px) {{
215+
& .gooey-sidebar-open {{
180216
position: fixed;
181-
min-width: 100vw;
182-
width: 100vw;
183-
max-width: 100vw;
217+
min-width: {sidebar_mobile_width};
218+
width: {sidebar_mobile_width};
219+
max-width: {sidebar_mobile_width};
184220
z-index: 2000;
185-
}
186-
& .gooey-sidebar-closed {
221+
}}
222+
& .gooey-sidebar-closed {{
187223
position: fixed;
188224
min-width: 0px;
189225
width: 0px;
190226
max-width: 0px;
191227
overflow: hidden;
192-
}
193-
}
228+
}}
229+
}}
194230
"""
195231
)
196232
if not is_mobile_open:

0 commit comments

Comments
 (0)