Skip to content

Commit 7d4e807

Browse files
[ENG-4127][ENG-4128][ENG-4126][ENG-4125]UI overview section improvements (#1097)
* UI overview improvements * Add next/prev for state overview
1 parent 7683712 commit 7d4e807

File tree

8 files changed

+62
-22
lines changed

8 files changed

+62
-22
lines changed

docs/ui/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ rx.text('Hello World!', color='blue', font_size="1.5em")
3131
Here `"Hello World!"` is the child text to display, while `color` and `font_size` are props that modify the appearance of the text.
3232

3333
```md alert success
34-
Regular Python data types can be passed in as children to components.
35-
This is useful for passing in text, numbers, and other simple data types.
34+
# Regular Python data types can be passed in as children to components. This is useful for passing in text, numbers, and other simple data types.
3635
```
3736

3837
## Another Example
@@ -55,6 +54,7 @@ rx.vstack(
5554
header="Third item",
5655
content="The third accordion item's content",
5756
),
57+
collapsible=True,
5858
width="300px",
5959
)
6060
)

pcweb/components/docpage/sidebar/sidebar.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import reflex as rx
66
import reflex_chakra as rc
77
from pcweb.components.docpage.navbar.state import NavbarState
8-
from .state import SidebarState, SidebarItem
8+
from .state import SidebarState, SideBarItem, SideBarBase
99
import reflex_chakra as rc
1010

1111
from .sidebar_items.learn import learn, frontend, backend, hosting
@@ -17,6 +17,7 @@
1717
from .sidebar_items.recipes import recipes
1818
from pcweb.styles.colors import c_color
1919

20+
2021
def sidebar_link(*children, **props):
2122
"""Create a sidebar link that closes the sidebar when clicked."""
2223
return rx.link(
@@ -28,7 +29,7 @@ def sidebar_link(*children, **props):
2829

2930

3031
def sidebar_leaf(
31-
item: SidebarItem,
32+
item: SideBarItem,
3233
url: str,
3334
) -> rx.Component:
3435
"""Get the leaf node of the sidebar."""
@@ -124,7 +125,7 @@ def sidebar_icon(name):
124125

125126

126127
def sidebar_item_comp(
127-
item: SidebarItem,
128+
item: SideBarItem,
128129
index: list[int],
129130
url: str,
130131
):
@@ -221,6 +222,18 @@ def get_prev_next(url):
221222
return None, None
222223

223224

225+
def filter_out_non_sidebar_items(items: list[SideBarBase]) -> list[SideBarItem]:
226+
"""Filter out non-sidebar items making sure only SideBarItems are present.
227+
228+
Args:
229+
items: The items to filter.
230+
231+
Return:
232+
The filtered side bar items.
233+
"""
234+
return [item for item in items if isinstance(item, SideBarItem)]
235+
236+
224237
def sidebar_category(name: str, url: str, icon: str, index: int):
225238
return rx.el.li(
226239
rx.link(
@@ -267,7 +280,13 @@ def sidebar_category(name: str, url: str, icon: str, index: int):
267280
)
268281

269282

270-
def create_sidebar_section(section_title, section_url, items, index, url):
283+
def create_sidebar_section(
284+
section_title: str,
285+
section_url: str,
286+
items: list[SideBarItem],
287+
index: rx.Var[list[str]] | list[str],
288+
url: rx.Var[str] | str,
289+
) -> rx.Component:
271290
# Check if the section has any nested sections (Like the Other Libraries Section)
272291
nested = any(len(child.children) > 0 for item in items for child in item.children)
273292
# Make sure the index is a list
@@ -313,7 +332,6 @@ def sidebar_comp(
313332
tutorials_index: list[int],
314333
width: str = "100%",
315334
):
316-
317335
from pcweb.pages.docs.recipes_overview import overview
318336
from pcweb.pages.docs.library import library
319337
from pcweb.pages.docs.custom_components import custom_components
@@ -351,12 +369,12 @@ def sidebar_comp(
351369
create_sidebar_section(
352370
"User Interface",
353371
ui.overview.path,
354-
frontend,
372+
filter_out_non_sidebar_items(frontend),
355373
frontend_index,
356374
url,
357375
),
358376
create_sidebar_section(
359-
"State", state.overview.path, backend, backend_index, url
377+
"State", state.overview.path, filter_out_non_sidebar_items(backend), backend_index, url
360378
),
361379
create_sidebar_section(
362380
"Hosting",

pcweb/components/docpage/sidebar/sidebar_items/component_lib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import reflex as rx
2-
from ..state import SidebarItem
2+
from ..state import SideBarItem
33
from reflex.utils.format import to_title_case, to_snake_case
44

55

@@ -12,28 +12,28 @@ def get_component_link(category, clist, prefix="") -> str:
1212
def get_category_children(category, category_list, prefix=""):
1313
category = category.replace("-", " ")
1414
if isinstance(category_list, dict):
15-
return SidebarItem(
15+
return SideBarItem(
1616
names=category,
1717
children=[
1818
get_category_children(c, category_list[c]) for c in category_list
1919
],
2020
)
2121
category_item_children = []
2222
category_item_children.append(
23-
SidebarItem(
23+
SideBarItem(
2424
names="Overview",
2525
link=f"/docs/library/{prefix}{category.lower().replace(' ', '-')}/",
2626
)
2727
)
2828
for c in category_list:
2929
component_name = to_snake_case(c[0])
3030
name = to_title_case(component_name, sep=" ")
31-
item = SidebarItem(
31+
item = SideBarItem(
3232
names=name,
3333
link=get_component_link(category, c, prefix=prefix),
3434
)
3535
category_item_children.append(item)
36-
return SidebarItem(names=category, children=category_item_children)
36+
return SideBarItem(names=category, children=category_item_children)
3737

3838

3939
def get_sidebar_items_component_lib():

pcweb/components/docpage/sidebar/sidebar_items/item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pcweb.route import Route
2-
from ..state import SidebarState, SidebarItem
2+
from ..state import SidebarState, SideBarItem
33

44

55
def create_item(route: Route, children=None):
@@ -13,10 +13,10 @@ def create_item(route: Route, children=None):
1313
else:
1414
alt_name_for_next_prev = ""
1515
name = name.replace("Api", "API").replace("Cli", "CLI")
16-
return SidebarItem(
16+
return SideBarItem(
1717
names=name, alt_name_for_next_prev=alt_name_for_next_prev, link=route.path
1818
)
19-
return SidebarItem(
19+
return SideBarItem(
2020
names=route,
2121
children=list(map(create_item, children)),
2222
)

pcweb/components/docpage/sidebar/sidebar_items/learn.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ def get_sidebar_items_frontend():
4242
wrapping_react,
4343
custom_components,
4444
)
45+
from pcweb.components.docpage.sidebar.state import SideBarSection
4546

4647
items = [
48+
SideBarSection(
49+
names="User Interface Overview",
50+
alt_name_for_next_prev="",
51+
link=ui.overview.path
52+
),
4753
create_item(
4854
"Components",
4955
children=[
@@ -115,8 +121,14 @@ def get_sidebar_items_backend():
115121
utility_methods,
116122
vars,
117123
)
124+
from pcweb.components.docpage.sidebar.state import SideBarSection
118125

119126
items = [
127+
SideBarSection(
128+
names="State Overview",
129+
alt_name_for_next_prev="",
130+
link=state.overview.path
131+
),
120132
create_item(
121133
"Vars",
122134
children=[

pcweb/components/docpage/sidebar/sidebar_items/recipes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .item import create_item, SidebarItem
1+
from .item import create_item
22

33

44
def get_sidebar_items_recipes():

pcweb/components/docpage/sidebar/sidebar_items/reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .item import create_item, SidebarItem
1+
from .item import create_item
22

33

44
def get_sidebar_items_api_reference():

pcweb/components/docpage/sidebar/state.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from reflex.base import Base
88

99

10-
class SidebarItem(Base):
11-
"""A single item in the sidebar."""
10+
class SideBarBase(Base):
11+
"""Base class for the Side bar."""
1212

1313
# The name to display in the sidebar.
1414
names: str = ""
@@ -19,12 +19,22 @@ class SidebarItem(Base):
1919
link: str = ""
2020

2121
# The children items.
22-
children: list[SidebarItem] = []
22+
children: list[SideBarItem] = []
2323

2424
# Whether the item is a category. Occurs if a single item is at the top level of the sidebar for asthetics.
2525
outer = False
2626

2727

28+
class SideBarItem(SideBarBase):
29+
"""A single item in the sidebar."""
30+
...
31+
32+
33+
class SideBarSection(SideBarBase):
34+
"""A section in the sidebar."""
35+
...
36+
37+
2838
class SidebarState(rx.State):
2939
_sidebar_index: int = -1
3040

0 commit comments

Comments
 (0)