gradio/ui/packages/form/src/DropdownOptions.svelte

74 lines
1.6 KiB
Svelte
Raw Normal View History

Dropdown Component Updates (#3211) * dropdown * more dropdown updates * dropdown styling + option visibility * changelog * notebook * fix test * Allow more image formats (#3225) * add wildcard to image input * simplify mime types * changelog * regen noteboks --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: pngwn <hello@pngwn.io> * fix webcam mirroring (#3245) * fix webcam * changelog * fix changelog * fix changelog * fix changelog --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Add `interactive=False` mode to `gr.Button` (#3266) * add interactive=False to button * add interactive=True by default * changelog * fix frontend * fix backend test * formatting * review changes * LaTeX height fix (#3258) * latex height fix * changelog * formatting * em * em * accidentally added script (#3273) * Adding a script to benchmark the queue (#3272) * added benchmark queue script * changelg * fix instructions * Fix matplotlib image size (#3274) * Fix matplotlib css * CHANGELOG * Undo lockfile * Add timeouts to queue messages (#3196) * Fix + test * Remove print statements + fix import for 3.7 * CHANGELOG * Remove more print statements * Add 60 second timeout for uploading data * Fix test --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * icons * separate options into component * formatting * changelog * changelog * fix ui tests * formatting again... * backend test fix * format * doc fixes --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: fienestar <fienestar@gmail.com> Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2023-02-24 05:32:18 +08:00
<script lang="ts">
import { fly } from "svelte/transition";
import { createEventDispatcher } from "svelte";
export let value: string | Array<string> | undefined = undefined;
export let filtered: Array<string>;
export let showOptions: boolean = false;
export let activeOption: string;
export let disabled: boolean = false;
const dispatch = createEventDispatcher();
</script>
{#if showOptions && !disabled}
<ul
class="options"
aria-expanded={showOptions}
transition:fly={{ duration: 200, y: 5 }}
on:mousedown|preventDefault={(e) => dispatch("change", e)}
>
{#each filtered as choice}
<li
class="item"
role="button"
class:selected={value?.includes(choice)}
class:active={activeOption === choice}
class:bg-gray-100={activeOption === choice}
class:dark:bg-gray-600={activeOption === choice}
data-value={choice}
aria-label={choice}
>
<span class:hide={!value?.includes(choice)} class="inner-item pr-1">
</span>
{choice}
</li>
{/each}
</ul>
{/if}
<style>
.options {
position: absolute;
z-index: var(--layer-5);
margin-left: 0;
box-shadow: var(--shadow-drop-lg);
border-radius: var(--radius-lg);
background: var(--color-background-primary);
width: var(--size-full);
max-height: var(--size-32);
overflow: auto;
color: var(--color-text-body);
list-style: none;
}
.item {
display: flex;
cursor: pointer;
padding: var(--size-2);
}
.item:hover,
.active {
background: var(--color-background-secondary);
}
.inner-item {
padding-right: var(--size-1);
}
.hide {
visibility: hidden;
}
</style>