Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/enterprise/drag-and-drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ def state_tracking_example():
Create dynamic draggable lists using `rx.foreach`:

```python demo exec
import dataclasses
import reflex as rx
import reflex_enterprise as rxe

class ListItem(rx.Base):
@dataclasses.dataclass
class ListItem:
id: str
text: str
list_id: str
Expand Down
25 changes: 16 additions & 9 deletions docs/getting_started/dashboard_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ You can see what the finished app and code will look like here:


```python exec
import dataclasses
from collections import Counter

class User(rx.Base):
@dataclasses.dataclass
class User:
"""The user model."""

name: str
Expand Down Expand Up @@ -181,7 +183,8 @@ rx.vstack(
import reflex as rx
from collections import Counter

class User(rx.Base):
@dataclasses.dataclass
class User:
"""The user model."""

name: str
Expand Down Expand Up @@ -616,14 +619,15 @@ So far our data has been defined in a list of lists, where the data is accessed

A better way to structure our data in Reflex is to use a class to represent a user. This way we can access the data using attributes i.e. `user.name`, `user.email`.

In Reflex when we create these classes to showcase our data, the class must inherit from `rx.Base`.

`rx.Base` is also necessary if we want to have a state var that is an iterable with different types. For example if we wanted to have `age` as an `int` we would have to use `rx.base` as we could not do this with a state var defined as `list[list[str]]`.
In Reflex when we create these classes to showcase our data, we can use dataclasses.

The `show_user` render function is also updated to access the data by named attributes, instead of indexing.

```python exec
class User(rx.Base):
import dataclasses

@dataclasses.dataclass
class User:
"""The user model."""

name: str
Expand Down Expand Up @@ -670,7 +674,8 @@ rx.table.root(


```python
class User(rx.Base):
@dataclasses.dataclass
class User:
"""The user model."""

name: str
Expand Down Expand Up @@ -1119,7 +1124,8 @@ rx.vstack(
```

```python
class User(rx.Base):
@dataclasses.dataclass
class User:
"""The user model."""

name: str
Expand Down Expand Up @@ -1663,7 +1669,8 @@ rx.vstack(
import reflex as rx
from collections import Counter

class User(rx.Base):
@dataclasses.dataclass
class User:
"""The user model."""

name: str
Expand Down
8 changes: 5 additions & 3 deletions pcweb/components/docpage/sidebar/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

from __future__ import annotations

from dataclasses import dataclass, field

import reflex as rx
from reflex.base import Base


class SideBarBase(Base):
@dataclass(kw_only=True)
class SideBarBase:
"""Base class for the Side bar."""

# The name to display in the sidebar.
Expand All @@ -18,7 +20,7 @@ class SideBarBase(Base):
link: str = ""

# The children items.
children: list[SideBarItem] = []
children: list[SideBarItem] = field(default_factory=list)

# Whether the item is a category. Occurs if a single item is at the top level of the sidebar for aesthetics.
outer = False
Expand Down
1 change: 0 additions & 1 deletion pcweb/pages/docs/apiref.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

modules = [
rx.App,
rx.Base,
rx.Component,
rx.ComponentState,
(rx.Config, rx.config.BaseConfig),
Expand Down
20 changes: 13 additions & 7 deletions pcweb/pages/docs/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ class PropDocsState(rx.State):

def render_select(prop: PropDocumentation, component: type[Component], prop_dict: dict):
if (
not rx.utils.types._issubclass(
component, (RadixThemesComponent, RadixPrimitiveComponent)
)
not safe_issubclass(component, (RadixThemesComponent, RadixPrimitiveComponent))
or component.__name__ in EXCLUDED_COMPONENTS
):
return rx.fragment()
try:
type_ = rx.utils.types.get_args(prop.type)[0]
type_ = get_args(prop.type)[0]
except Exception:
return rx.fragment()

Expand Down Expand Up @@ -249,6 +247,13 @@ def color_scheme_hovercard(literal_values: list[str]) -> rx.Component:
)


def safe_issubclass(cls, class_or_tuple):
try:
return issubclass(cls, class_or_tuple)
except TypeError:
return False


def prop_docs(
prop: PropDocumentation,
prop_dict: dict,
Expand All @@ -258,9 +263,10 @@ def prop_docs(
"""Generate the docs for a prop."""
# Get the type of the prop.
type_ = prop.type
if rx.utils.types._issubclass(prop.type, rx.Var):
origin = get_origin(type_)
if safe_issubclass(origin, rx.Var):
# For vars, get the type of the var.
type_ = rx.utils.types.get_args(type_)[0]
type_ = get_args(type_)[0]

origin = get_origin(type_)
args = get_args(type_)
Expand Down Expand Up @@ -448,7 +454,7 @@ def generate_props(
prop_dict = {}

is_interactive = True
if not rx.utils.types._issubclass(
if not issubclass(
component, (RadixThemesComponent, RadixPrimitiveComponent)
) or component.__name__ in [
"Theme",
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading