Skip to content

[Twig Components] - scoped props ? #1970

Closed
@barberob

Description

@barberob

(i'm using only anonymous components)

Hey, the current behavior is that inner components can acces their parents props. This is useful but this creates some edge cases that can be annoying. For exemple, i'm creating a sort of UI library and some nested components can share attributes with same name like in my case : icon
Here my badge can have an icon sometime but i dont want one in this case, so i have to set it to null

//--------- in both my components

{% props icon = null, ..... %}

{# ... some code  ... #}




//------- in my template

<twig:Nav:Link icon="folder-plus">

    {# ... what i'd like to do  ... #}
    <twig:Badge>.......</twig:Badge>

    {# ... what I have to do ( i guess ? )  ... #}
    <twig:Badge :icon="null">.......</twig:Badge>

</twig:Nav:Link>

I would like to avoid giving different name to same prop on each of my components ( badgeIcon, buttonIcon, ..... ) or that weird null thing
Is there a way to make some specific props "private" or "scoped", as they would be defined in the components, and only accessible in this component ant not it's children.
In my ideal world, i think it would be great to have something like :

{# could be a function or a fiter #}
{% props scoped(icon = null), ..... %}

{# or a second twig tag specific to this behavior #}  
{% scopedProps icon = null, ... %}

Does it make sense ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions