Skip to content

Commit 0b27226

Browse files
45 - Sidebar Toggle Button and Color Mode Condition
1 parent 48449b2 commit 0b27226

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

full_stack_python/ui/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def base_layout_component(child, *args, **kwargs) -> rx.Component:
2020
)
2121

2222
def base_page(child: rx.Component, *args, **kwargs) -> rx.Component:
23-
is_logged_in = False
23+
is_logged_in = True
2424
if not isinstance(child,rx. Component):
2525
child = rx.heading("this is not a valid child element")
2626
return rx.cond(

full_stack_python/ui/sidebar.py

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
import reflex as rx
2+
from reflex.style import toggle_color_mode
23

34
from .. import navigation
45

6+
def sidebar_dark_mode_toggle_item() -> rx.Component:
7+
return rx.box(
8+
rx.hstack(
9+
rx.color_mode_cond(
10+
light=rx.icon("moon"),
11+
dark=rx.icon("sun"),
12+
),
13+
rx.text(rx.color_mode_cond(
14+
light="Turn dark mode on",
15+
dark="Turn light mode on",
16+
), size="4"),
17+
width="100%",
18+
padding_x="0.5rem",
19+
padding_y="0.75rem",
20+
align="center",
21+
style={
22+
"_hover": {
23+
"cursor": "pointer", # css
24+
"bg": rx.color("accent", 4),
25+
"color": rx.color("accent", 11),
26+
},
27+
"color": rx.color("accent", 11),
28+
"border-radius": "0.5em",
29+
},
30+
),
31+
on_click=toggle_color_mode,
32+
as_='button',
33+
underline="none",
34+
weight="medium",
35+
width="100%",
36+
)
37+
38+
539
def sidebar_item(
640
text: str, icon: str, href: str
741
) -> rx.Component:
@@ -61,9 +95,7 @@ def sidebar() -> rx.Component:
6195
rx.spacer(),
6296
rx.vstack(
6397
rx.vstack(
64-
sidebar_item(
65-
"Settings", "settings", "/#"
66-
),
98+
sidebar_dark_mode_toggle_item(),
6799
sidebar_item(
68100
"Log out", "log-out", "/#"
69101
),

0 commit comments

Comments
 (0)