2023-11-17 14:22:28 +01:00
|
|
|
"""Sidebar component for the app."""
|
|
|
|
|
|
|
|
from blurme import styles
|
|
|
|
from blurme.state import State
|
2023-11-26 13:51:54 +01:00
|
|
|
from reflex.page import get_decorated_pages
|
|
|
|
|
2023-11-17 14:22:28 +01:00
|
|
|
|
|
|
|
import reflex as rx
|
|
|
|
|
|
|
|
|
|
|
|
def sidebar_header() -> rx.Component:
|
2023-11-22 15:54:26 +01:00
|
|
|
"""Returns:
|
2023-11-17 20:25:22 +01:00
|
|
|
The sidebar header component.
|
|
|
|
"""
|
2023-11-17 14:22:28 +01:00
|
|
|
return rx.hstack(
|
|
|
|
# The logo.
|
|
|
|
rx.image(
|
|
|
|
src="/icon.png",
|
|
|
|
height="4.5em",
|
|
|
|
),
|
|
|
|
rx.spacer(),
|
|
|
|
width="100%",
|
|
|
|
border_bottom=styles.border,
|
|
|
|
padding="1em",
|
2023-12-05 13:16:15 +01:00
|
|
|
align = 'center',
|
2023-11-17 14:22:28 +01:00
|
|
|
)
|
|
|
|
|
2023-11-22 15:54:26 +01:00
|
|
|
def sidebar_item(text: str, icon: str, url: str, ) -> rx.Component:
|
2023-11-17 14:22:28 +01:00
|
|
|
"""Sidebar item.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
text: The text of the item.
|
|
|
|
icon: The icon of the item.
|
|
|
|
url: The URL of the item.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
rx.Component: The sidebar item component.
|
|
|
|
"""
|
|
|
|
# Whether the item is active.
|
2023-11-26 13:51:54 +01:00
|
|
|
active = State.router.page.path == url
|
|
|
|
|
|
|
|
#active = (State.router.page.path == f"/{text.lower()}") | (
|
|
|
|
# (State.router.page.path == "/") & text == "Strona główna"
|
|
|
|
#)
|
2023-11-17 14:22:28 +01:00
|
|
|
|
|
|
|
return rx.link(
|
|
|
|
rx.hstack(
|
2023-11-22 15:54:26 +01:00
|
|
|
rx.image(
|
|
|
|
src=icon,
|
|
|
|
height="2.5em",
|
|
|
|
padding="0.5em",
|
|
|
|
),
|
2023-11-17 14:22:28 +01:00
|
|
|
rx.text(
|
|
|
|
text,
|
2023-11-26 13:51:54 +01:00
|
|
|
|
2023-11-17 14:22:28 +01:00
|
|
|
),
|
|
|
|
bg=rx.cond(
|
|
|
|
active,
|
|
|
|
styles.accent_color,
|
|
|
|
"transparent",
|
|
|
|
),
|
2023-12-05 13:16:15 +01:00
|
|
|
#color=rx.cond(
|
|
|
|
# active,
|
|
|
|
# styles.accent_text_color,
|
|
|
|
# styles.text_color,
|
|
|
|
#),
|
2023-11-17 14:22:28 +01:00
|
|
|
border_radius=styles.border_radius,
|
|
|
|
box_shadow=styles.box_shadow,
|
|
|
|
width="100%",
|
2023-11-22 15:54:26 +01:00
|
|
|
padding_x="1.3em",
|
|
|
|
height = "2.5em"
|
2023-11-17 14:22:28 +01:00
|
|
|
),
|
|
|
|
href=url,
|
|
|
|
width="100%",
|
2023-11-22 15:54:26 +01:00
|
|
|
|
2023-11-17 14:22:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def sidebar() -> rx.Component:
|
|
|
|
"""The sidebar.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The sidebar component.
|
|
|
|
"""
|
|
|
|
# Get all the decorated pages and add them to the sidebar.
|
|
|
|
from reflex.page import get_decorated_pages
|
|
|
|
|
|
|
|
return rx.box(
|
|
|
|
rx.vstack(
|
|
|
|
sidebar_header(),
|
|
|
|
rx.vstack(
|
|
|
|
*[
|
|
|
|
sidebar_item(
|
|
|
|
text=page.get("title", page["route"].strip("/").capitalize()),
|
2023-11-22 15:54:26 +01:00
|
|
|
icon=page.get("image",page["route"].strip("/").capitalize()),
|
2023-11-17 14:22:28 +01:00
|
|
|
url=page["route"],
|
|
|
|
)
|
|
|
|
for page in get_decorated_pages()
|
|
|
|
],
|
2023-11-25 14:23:04 +01:00
|
|
|
rx.spacer(),
|
2023-11-17 14:22:28 +01:00
|
|
|
width="100%",
|
|
|
|
overflow_y="auto",
|
|
|
|
align_items="flex-start",
|
|
|
|
padding="1em",
|
|
|
|
),
|
|
|
|
rx.spacer(),
|
2023-11-22 15:54:26 +01:00
|
|
|
height="100em",
|
2023-12-05 13:16:15 +01:00
|
|
|
|
2023-11-17 14:22:28 +01:00
|
|
|
),
|
|
|
|
display=["none", "none", "block"],
|
|
|
|
min_width=styles.sidebar_width,
|
|
|
|
height="100%",
|
|
|
|
position="sticky",
|
|
|
|
top="0px",
|
|
|
|
border_right=styles.border,
|
|
|
|
)
|