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

Any ideas how to do nested components? #17

Closed
9876691 opened this issue Oct 15, 2021 · 2 comments
Closed

Any ideas how to do nested components? #17

9876691 opened this issue Oct 15, 2021 · 2 comments

Comments

@9876691
Copy link

9876691 commented Oct 15, 2021

I'd like to build a nested tabs component. Something like

Tabs {
  tabs: vec!(Tab {
    title: "Tab 1",
    body: markup::new! {
            div {
              ... more content
            }
        }
  })
}

So a component, with a list of nested sub components.

I tried a few different things, something like

markup::define! {
    Tab<'a>(
        title: &'a str,
        body: Box<dyn markup::Render>
    ) {
        input[type="radio", id="tab2", name="css-tabs"] {}
        div {
            {title}
        }
        div {
            @body
        }
    }
    Tabs<'a>(tabs: &'a [Tab]) {
       ...list all the tabs
    }
}

But that doesn't compile. I guess I could pass around the Tab elements as a string, but ideally I"d like the type safety.

Any ideas?

@ZaneHannanAU
Copy link

Could use Box::new or the https://doc.rust-lang.org/nightly/unstable-book/language-features/box-syntax.html keyword; potentially even use a tab(markup::new! {}) function to return a wrapped Raw type.

@9876691 9876691 closed this as completed Oct 18, 2021
@utkarshkukreti
Copy link
Owner

Hey @ianpurton, did you manage to figure out a solution? Box<dyn Render> will not work as the trait is not object-safe because its render function takes a generic argument (for performance reasons).

I pushed some changes in 694f021 to address this.

You can try it out by adding a dependency on the latest git commit.

I'm still thinking of a better name than DynRender for the struct before making a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants