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

Help Request: Are nested slots supposed to function? #22

Open
JeremyLWright opened this issue Feb 7, 2025 · 1 comment
Open

Help Request: Are nested slots supposed to function? #22

JeremyLWright opened this issue Feb 7, 2025 · 1 comment

Comments

@JeremyLWright
Copy link

JeremyLWright commented Feb 7, 2025

Thank you for the wonderful library. It's been a delight to componetize elements of my application.

I have a structure in React I am trying to port to view components

<Card>
    <CardHeader>
        <CardTitle>
             My title
        </CardTitle>
    </CardHeader>
</Card>

I am trying to represent this in ViewComponents I and it works nicely, however when I attempt to make a "kind" of card that nests card, I cannot determine how to fill the CardTitle

Card Preview (Works Nicely)

 def card(self, **kwargs):
    template = Template(
      """
    {% component 'ui.Card' extra_css='w-full max-w-md' as card %}
      {% call card.header as ch %}
        {% call ch.title %}Welcome Back{% endcall %}
        {% call ch.description %}Sign in to manage your networks{% endcall %}
      {% endcall %}
      {% call card.body as cc %}
        <span>Form Data</span>
      {% endcall %}
    {% endcomponent %}
      """ 
    )
    
    return template.render(Context({}))

NetworkCard wraps Card (I'm stuck here)

{% component 'ui.Card' as card %} 
    {% call card.header extra_css="flex flex-col sm:flex-row items-start justify-between space-y-2 sm:space-y-0 pb-2" as ch %}
        <div class="space-y-1">
            <div class="flex flex-col sm:flex-row sm:items-center gap-2">
                {% call ch.title extra_css="text-lg sm:text-xl font-bold" as ct %}
                    {% call ct.title as t%}
                    ### WHAT GOES HERE? How do I get the "top level content" <--- this is where I get stuck
                    {% endcall %}
                {% endcall %}
                {% component 'ui.Badge' extra_css='bg-green-100 text-green-800' %}
                    {{ self.status.value }}
                    Badge
                {% endcomponent %}
            </div>
            {% call ch.description %}
                {{card.forwarding_address}}
            {% endcall %}
        </div>
    {% endcall %}
def network_card(self, **kwargs):
    template = Template(
      """
      {% component "NetworkCard" forwarding_address='addr' invited_users='6' destination_address='addr2' as nc %}
        {% call nc.card as card %}
          {% call card.header as ch %}
            {% call ch.title as ct%} Founders {% endcall %} #<---- this text gets lost
            {% call ch.description %} Description {% endcall %}
          {% endcall %} {# header #}
          {% call card.body %}
          {% endcall %} {# body #}
          {% endcall %} {# card #}
        {% call nc.status %}
        In Progress
        {% endcall %}

      {% endcomponent %}
      """ 
    )
    
    return template.render(Context({}))

Am I approaching my component design incorrectly?

@michael-yin
Copy link
Member

@JeremyLWright

Could you please create an example project and paste the link here? So I can help check with more details.

Thx

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

2 participants