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

[Custom Components] Support Named Slots in svelte #8706

Open
1 task done
Col0ring opened this issue Jul 5, 2024 · 6 comments
Open
1 task done

[Custom Components] Support Named Slots in svelte #8706

Col0ring opened this issue Jul 5, 2024 · 6 comments
Assignees
Labels
custom-components Related to custom component cli or workflow enhancement New feature or request

Comments

@Col0ring
Copy link
Contributor

Col0ring commented Jul 5, 2024

  • I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
Custom components can only use Default Slot in svelte currently, therefore it cannot provide more customized layout configurations for users. I'm wondering if gradio can provide a component like gr.Slot to support Named Slot.

Describe the solution you'd like
This is a sample to use gr.Slot:
app.py

with CustomComponent():
    # default slot
    gr.Button()
    # named slot
    with gr.Slot(name="extra"):
        gr.Button()

custom_components/Index.svelte

<div><slot/></div>
<div><slot name="extra"/></div>

Additional context
Add any other context or screenshots about the feature request here.

@abidlabs abidlabs added enhancement New feature or request custom-components Related to custom component cli or workflow labels Jul 5, 2024
@abidlabs
Copy link
Member

abidlabs commented Jul 5, 2024

cc @pngwn

@pngwn
Copy link
Member

pngwn commented Jul 6, 2024

Very interesting. I'll have to think about this a little.

@pngwn pngwn self-assigned this Jul 6, 2024
@pngwn
Copy link
Member

pngwn commented Jul 8, 2024

On reflection, I think it might be better to match the Svelte API for this where the slot name is a parameter on the thing being slotted:

with CustomComponent():
    gr.Button() # default slot
    gr.Button(slot="extra") # named slot

We could potentially use this mechanism ourselves for things like icons etc in the future. Imagine this:

with gr.IconButton() as btn:
    gr.Markdown("**Important button**")
    gr.icons.Warning(slot="icon") 

@pngwn
Copy link
Member

pngwn commented Jul 8, 2024

We could even expose html primitives for quick bits of UI, food for thought.

@Col0ring
Copy link
Contributor Author

Col0ring commented Jul 8, 2024

On reflection, I think it might be better to match the Svelte API for this where the slot name is a parameter on the thing being slotted:

with CustomComponent():
    gr.Button() # default slot
    gr.Button(slot="extra") # named slot

We could potentially use this mechanism ourselves for things like icons etc in the future. Imagine this:

with gr.IconButton() as btn:
    gr.Markdown("**Important button**")
    gr.icons.Warning(slot="icon") 

LGTM. One last question, it looks like we can't add multiple components to a named slot in this way.

with CustomComponent():
    gr.Button() # default slot
    # expected  to be rendered in order in <slot name="extra" />
    gr.Button(slot="extra") # named slot
    gr.Button(slot="extra") # named slot

Similar usage to gr.Slot, I think it might still be useful to provide an additional component gr.Fragment like svelte:fragment in svelte to resolve this.

with CustomComponent():
    gr.Button() # default slot
    # expected  to be rendered in order in <slot name="extra" />
    with gr.Fragment(slot="extra"): # named slot
       # default slot
       gr.Button() 
       gr.Button() 

@pngwn
Copy link
Member

pngwn commented Jul 8, 2024

Yeah maybe, I guess that would reduce the API surface area a little an provide a more explicit API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom-components Related to custom component cli or workflow enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants