Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix recursive UI #4599

Merged
merged 4 commits into from
Jan 7, 2025
Merged

fix recursive UI #4599

merged 4 commits into from
Jan 7, 2025

Conversation

adhami3310
Copy link
Member

@adhami3310 adhami3310 commented Jan 7, 2025

this is now possible

@dataclass
class File:
    name: str
    children: list["File"]


@rx.memo
def folder(file: rx.Var[File]) -> rx.Component:
    return rx.vstack(
        rx.heading(file.name),
        rx.box(
            rx.foreach(file.children, lambda f: folder(file=f)),
            padding_inline_start="1em",
        ),
    )


def index() -> rx.Component:
    return folder(
        file=File(
            "home",
            [
                File(
                    "documents",
                    [],
                ),
                File(
                    "downloads",
                    [
                        File("images", []),
                        File("videos", []),
                        File("music", []),
                    ],
                ),
                File("pictures", []),
            ],
        )
    )

@masenf masenf merged commit 0ad0a84 into main Jan 7, 2025
41 checks passed
@masenf masenf deleted the fix-recursive-UI branch January 7, 2025 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants