Skip to content

Add accordion component#2208

Merged
aliabid94 merged 2 commits into
mainfrom
accordion
Sep 8, 2022
Merged

Add accordion component#2208
aliabid94 merged 2 commits into
mainfrom
accordion

Conversation

@aliabid94
Copy link
Copy Markdown
Contributor

@aliabid94 aliabid94 commented Sep 8, 2022

Allows users to wrap elements in an accordion. It's been requested several times and I thought this might be useful for the more complex SD demos being created right now.

Fixes: #938

Use:

with gr.Accordion("open up"):
   # components here

Recording 2022-09-07 at 17 04 33

@abidlabs
Copy link
Copy Markdown
Member

abidlabs commented Sep 8, 2022

Niceee very cool @aliabid94!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Sep 8, 2022

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2208-all-demos

Comment thread gradio/layouts.py Outdated
"""
Parameters:
label: name of accordion section.
open: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix docstring for open

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open is a Python keyword so syntax highlighters annoyingly highlight it. WDYT about naming this closed instead?

@abidlabs
Copy link
Copy Markdown
Member

abidlabs commented Sep 8, 2022

Would it be possible to support gr.Accordion() in gr.Interface()? The reason I ask is because a lot of gr.Interface() users would probably love to have a section of collapsible inputs as well. I can imagine something like the following API:

gr.Interface(
  image_generator,
  [gr.Textbox(),
   gr.Accordion("Advanced Options", [
     gr.Slider(),
     gr.Slider(),
    ]
  ]
  gr.Image()
]

Otherwise, LGTM @aliabid94!

@abidlabs
Copy link
Copy Markdown
Member

abidlabs commented Sep 8, 2022

One other thing: the label of the Accordion is much bigger, darker, and bolder than the label of the other components as you can see here:

image

I think it stands out too much. What about making it the same font style as the title of tabs:

image

@aliabid94 aliabid94 requested a review from abidlabs September 8, 2022 02:05
@aliabid94
Copy link
Copy Markdown
Contributor Author

ok made the label smaller and not bold. Also added mention to guides. Adding to Interface will be a lot of work, let's make a separate issue for that. Let's get this in for 3.3 @abidlabs

See how the first column has two Textboxes arranged vertically. The second column has an Image and Button arranged vertically. Notice how the relative widths of the two columns is set by the `scale` parameter. The column with twice the `scale` value takes up twice the width.

## Tabs
## Tabs amd Accordions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Tabs amd Accordions
## Tabs and Accordions

$code_blocks_flipper
$demo_blocks_flipper

Also note the Accordion that can be opened and closed - another layout element to selectively show content.
Copy link
Copy Markdown
Member

@abidlabs abidlabs Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Also note the Accordion that can be opened and closed - another layout element to selectively show content.
Also note the `gradio.Accordion('label')` in this example. The Accordion is a layout that can be toggled open or closed. Like `Tabs`, it is a layout element that can selectively hide or show content. Any components that are defined inside of a `with gradio.Accordion('label'):` will be hidden or shown when the accordion's toggle icon is clicked.

@abidlabs
Copy link
Copy Markdown
Member

abidlabs commented Sep 8, 2022

Ok sounds good! LGTM

@aliabid94 aliabid94 merged commit f852386 into main Sep 8, 2022
@aliabid94 aliabid94 deleted the accordion branch September 8, 2022 03:32
@aliabid94
Copy link
Copy Markdown
Contributor Author

oh whoops merged before reading comments, will make another pr for them

@pngwn
Copy link
Copy Markdown
Member

pngwn commented Sep 13, 2022

I missed this PR but I don't understand why this component was added instead of just adding some options to gr.Group, those were the conversations we had in the past and wouldn't have significantly increased API surface area like a new component does.

@abidlabs
Copy link
Copy Markdown
Member

Agree with communicating on this more, but from my understanding gr.Group() is designed to change the padding/display of children. gr.Accordion() has a pretty orthogonal functionality (toggling the children), so I think it's clearer to have a separate class for this.

@pngwn
Copy link
Copy Markdown
Member

pngwn commented Sep 13, 2022

I may have meant gr.Box which is mostly visual and could easily have taken some additional arguments.

There are also some issues with the implementation, I'll take a look at them when I get time.

@aliabid94
Copy link
Copy Markdown
Contributor Author

Oh sorry yeah. Makes sense to incorporate into gr.Box

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

Successfully merging this pull request may close these issues.

Implementation of a collapsible accordion (for advanced options for e.g.)

3 participants