Skip to content

Commit

Permalink
Ensure source selection does not get hidden in overflow (#6279)
Browse files Browse the repository at this point in the history
* add wrapper around content and source selection

* formatting

* remove upload 100% height

* add changeset

* move source selection to atoms

* formatting

* add changeset

* add changeset

* add changeset

* tweak <Upload /> height to accomodate source selection

* add changeset

* calc new height with source selection

* formatting

* tweak

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
hannahblair and gradio-pr-bot authored Nov 7, 2023
1 parent dfdaf10 commit 3cdeabc
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 94 deletions.
9 changes: 9 additions & 0 deletions .changeset/mean-papayas-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@gradio/atoms": patch
"@gradio/audio": patch
"@gradio/upload": patch
"@gradio/video": patch
"gradio": patch
---

fix:Ensure source selection does not get hidden in overflow
74 changes: 74 additions & 0 deletions js/atoms/src/SelectSource.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<script lang="ts">
import { Microphone, Upload, Video } from "@gradio/icons";
export let sources: string[];
export let active_source: string;
export let handle_clear: () => void = () => {};
</script>

{#if sources.length > 1}
<span class="source-selection">
{#if sources.includes("upload")}
<button
class="icon"
aria-label="Upload file"
on:click={() => {
handle_clear();
active_source = "upload";
}}><Upload /></button
>
{/if}

{#if sources.includes("microphone")}
<button
class="icon"
aria-label="Record audio"
on:click={() => {
handle_clear();
active_source = "microphone";
}}><Microphone /></button
>
{/if}

{#if sources.includes("webcam")}
<button
class="icon"
aria-label="Record video"
on:click={() => {
handle_clear();
active_source = "webcam";
}}><Video /></button
>
{/if}
</span>
{/if}

<style>
.source-selection {
display: flex;
align-items: center;
justify-content: center;
border-top: 1px solid var(--border-color-primary);
width: 95%;
bottom: 0;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
align-self: flex-end;
}
.icon {
width: 22px;
height: 22px;
margin: var(--spacing-lg) var(--spacing-xs);
padding: var(--spacing-xs);
color: var(--neutral-400);
border-radius: var(--radius-md);
}
.icon:hover,
.icon:focus {
color: var(--color-accent);
}
</style>
1 change: 1 addition & 0 deletions js/atoms/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export { default as Info } from "./Info.svelte";
export { default as ShareButton } from "./ShareButton.svelte";
export { default as UploadText } from "./UploadText.svelte";
export { default as Toolbar } from "./Toolbar.svelte";
export { default as SelectSource } from "./SelectSource.svelte";

export const BLOCK_KEY = {};
10 changes: 10 additions & 0 deletions js/audio/Audio.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@
label: "Audio Recorder"
}}
/>

<Story
name="Upload Audio"
args={{
value: null,
interactive: true,
sources: ["microphone", "upload"],
label: "Audio Upload"
}}
/>
50 changes: 4 additions & 46 deletions js/audio/interactive/InteractiveAudio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import { Upload, ModifyUpload } from "@gradio/upload";
import { upload, prepare_files, type FileData } from "@gradio/client";
import { BlockLabel } from "@gradio/atoms";
import { Music, Microphone, Upload as UploadIcon } from "@gradio/icons";
import { Music } from "@gradio/icons";
import AudioPlayer from "../player/AudioPlayer.svelte";
import { _ } from "svelte-i18n";
import type { IBlobEvent, IMediaRecorder } from "extendable-media-recorder";
import type { I18nFormatter } from "js/app/src/gradio_helper";
import AudioRecorder from "../recorder/AudioRecorder.svelte";
import StreamAudio from "../streaming/StreamAudio.svelte";
import { SelectSource } from "@gradio/atoms";
export let value: null | FileData = null;
export let label: string;
Expand Down Expand Up @@ -227,6 +228,7 @@
bind:dragging
on:error={({ detail }) => dispatch("error", detail)}
{root}
include_sources={sources.length > 1}
>
<slot />
</Upload>
Expand All @@ -253,48 +255,4 @@
/>
{/if}

{#if sources.length > 1}
<span class="source-selection">
<button
class="icon"
aria-label="Upload audio"
on:click={() => {
clear();
active_source = "upload";
}}><UploadIcon /></button
>
<button
class="icon"
aria-label="Record audio"
on:click={() => {
clear();
active_source = "microphone";
}}><Microphone /></button
>
</span>
{/if}

<style>
.source-selection {
display: flex;
align-items: center;
justify-content: center;
border-top: 1px solid var(--border-color-primary);
width: 95%;
margin: 0 auto;
}
.icon {
width: 22px;
height: 22px;
margin: var(--spacing-lg) var(--spacing-xs);
padding: var(--spacing-xs);
color: var(--neutral-400);
border-radius: var(--radius-md);
}
.icon:hover,
.icon:focus {
color: var(--color-accent);
}
</style>
<SelectSource {sources} bind:active_source handle_clear={clear} />
3 changes: 2 additions & 1 deletion js/upload/src/Upload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
export let disable_click = false;
export let root: string;
export let hidden = false;
export let include_sources = false;
// Needed for wasm support
const upload_fn = getContext<typeof upload_files>("upload_files");
Expand Down Expand Up @@ -94,6 +95,7 @@
class:center
class:boundedheight
class:flex
style:height={include_sources ? "calc(100% - 40px" : "100%"}
on:drag|preventDefault|stopPropagation
on:dragstart|preventDefault|stopPropagation
on:dragend|preventDefault|stopPropagation
Expand Down Expand Up @@ -122,7 +124,6 @@
button {
cursor: pointer;
width: var(--size-full);
height: var(--size-full);
}
.hidden {
Expand Down
23 changes: 20 additions & 3 deletions js/video/Video.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
import Video from "./Index.svelte";
import { format } from "svelte-i18n";
import { get } from "svelte/store";
</script>

<Meta
Expand All @@ -22,9 +24,11 @@
}}
/>

<Template let:args>
<Video {...args} />
</Template>
<div>
<Template let:args>
<Video {...args} i18n={get(format)} />
</Template>
</div>

<Story
name="Record from webcam"
Expand Down Expand Up @@ -55,3 +59,16 @@
width: 400
}}
/>

<Story
name="Upload video"
args={{
label: "world video",
show_label: true,
interactive: true,
sources: ["upload", "webcam"],
width: 400,
height: 400,
value: null
}}
/>
48 changes: 4 additions & 44 deletions js/video/shared/InteractiveVideo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import type { FileData } from "@gradio/client";
import { BlockLabel } from "@gradio/atoms";
import { Webcam } from "@gradio/image";
import { Video, Upload as UploadIcon } from "@gradio/icons";
import { Video } from "@gradio/icons";
import { prettyBytes, playable } from "./utils";
import Player from "./Player.svelte";
import type { I18nFormatter } from "@gradio/utils";
import { SelectSource } from "@gradio/atoms";
export let value: FileData | null = null;
export let subtitle: FileData | null = null;
Expand Down Expand Up @@ -69,6 +70,7 @@
on:load={handle_load}
on:error={({ detail }) => dispatch("error", detail)}
{root}
include_sources={sources.length > 1}
>
<slot />
</Upload>
Expand Down Expand Up @@ -112,26 +114,7 @@
{/if}
{/if}

{#if sources.length > 1}
<span class="source-selection">
<button
class="icon"
aria-label="Upload video"
on:click={() => {
handle_clear();
active_source = "upload";
}}><UploadIcon /></button
>
<button
class="icon"
aria-label="Record video"
on:click={() => {
handle_clear();
active_source = "webcam";
}}><Video /></button
>
</span>
{/if}
<SelectSource {sources} bind:active_source {handle_clear} />

<style>
.file-name {
Expand All @@ -144,27 +127,4 @@
padding: var(--size-2);
font-size: var(--text-xl);
}
.source-selection {
display: flex;
align-items: center;
justify-content: center;
border-top: 1px solid var(--border-color-primary);
width: 95%;
margin: 0 auto;
}
.icon {
width: 22px;
height: 22px;
margin: var(--spacing-lg) var(--spacing-xs);
padding: var(--spacing-xs);
color: var(--neutral-400);
border-radius: var(--radius-md);
}
.icon:hover,
.icon:focus {
color: var(--color-accent);
}
</style>

0 comments on commit 3cdeabc

Please sign in to comment.