-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add icon and link params to gr.Button
#5080
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
🎉 Chromatic build completed! There are 0 visual changes to review. |
Very cool! cc @Wauplin |
Awesome! Love this work @hannahblair ! |
…gradio-app/gradio into button-add-icon-and-link-params
gr.Button
gr.Button
…gradio-app/gradio into button-add-icon-and-link-params
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-5080-all-demos You can install the changes in this PR by running: pip install https://gradio-builds.s3.amazonaws.com/e00ebfb5de9e25c4a29bcec7a8e11b0d23d2861f/gradio-3.39.0-py3-none-any.whl |
Noticed something interesting while reviewing @hannahblair: If I add a import gradio as gr
with gr.Blocks() as demo:
gr.Button(icon="cheetah.jpg")
demo.launch() produces this: whereas: import gradio as gr
with gr.Blocks() as demo:
gr.Button(icon="cheetah.jpg", link="https://www.google.com")
demo.launch() produces this: |
Nice @hannahblair! Just a few nits above and then should be good to go |
@abidlabs Thanks for catching those! Updates pushed. |
Thanks @hannahblair. Can confirm that those issues are fixed. However, I noticed that there's some subtle inconsistencies when applying other props to
import gradio as gr
with gr.Blocks() as demo:
textbox = gr.Textbox()
with gr.Row():
b1 = gr.Button(link="https://www.google.com", scale=2, min_width=0)
b2 = gr.Button(link="#", scale=1, min_width=0)
b1.click(lambda :"hi", None, textbox)
demo.launch() to import gradio as gr
with gr.Blocks() as demo:
textbox = gr.Textbox()
with gr.Row():
b1 = gr.Button(scale=2, min_width=0)
b2 = gr.Button(scale=1, min_width=0)
b1.click(lambda :"hi", None, textbox)
demo.launch()
import gradio as gr
with gr.Blocks() as demo:
textbox = gr.Textbox()
with gr.Row():
b1 = gr.Button(visible=False, min_width=0, link="#")
b2 = gr.Button(min_width=0, link="https://www.google.com")
b1.click(lambda :"hi", None, textbox)
demo.launch() with import gradio as gr
with gr.Blocks() as demo:
textbox = gr.Textbox()
with gr.Row():
b1 = gr.Button(visible=False, min_width=0)
b2 = gr.Button(min_width=0)
b1.click(lambda :"hi", None, textbox)
demo.launch() |
@abidlabs Sorry for the oversight - The new |
Lgtm @hannahblair! Thanks for addressing the feedback |
I'm sorry but I can't seem to make icon button work locally. What I did so far:
import gradio as gr
with gr.Blocks(css="""button {justify-content: left !important;}""") as demo:
gr.Button(value="Login with HF", icon="https://huggingface.co/front/assets/huggingface_logo-noborder.svg")
demo.launch()
And I only get a simple button with text but without the logo. I guess I'm missing something but I don't know what. I also tried
Any way I could get that working? I'm looking forward to integrate it in the "Sign in with HF" PR to get nice icons 😃 (edit: also did EDIT:
|
That code is working for me @Wauplin. The most likely culprit is that you need to build the frontend first. Can you try running |
Thanks both! I finally made it work 😄 I deleted |
Ah great to hear! Thanks for letting us know 😄 |
Hi @shinetzh! Thanks for pointing this out. This is actually isn't something that we've implemented yet, but I agree that we should! I'll create an issue for this update functionality and get to it as soon as I can. 🙂 |
When clicked on a button with a link, Is it possible to open the link in a new tab? |
@muge-birlik that is already the case by default for any links that are not anchor links in the same page. e.g. try with: import gradio as gr
with gr.Blocks() as demo:
textbox = gr.Textbox()
with gr.Row():
b1 = gr.Button(link="https://www.google.com", scale=2, min_width=0)
b2 = gr.Button(link="#", scale=1, min_width=0)
b1.click(lambda :"hi", None, textbox)
demo.launch() |
Description
This PR allows us to add a link and icon to the
gr.Button
component. The default icon placement is central alongside the text:If a different icon placement is desired, we can use custom css.
Icon Demo
Link Demo
Closes: #5060
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh