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

Ensure source selection does not get hidden in overflow #6279

Merged
merged 22 commits into from Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
60d788a
add wrapper around content and source selection
hannahblair Nov 3, 2023
bbf1465
formatting
hannahblair Nov 3, 2023
b7c77a7
Merge branch 'main' into fix-source-styling
hannahblair Nov 3, 2023
6955808
remove upload 100% height
hannahblair Nov 6, 2023
2c52068
add changeset
gradio-pr-bot Nov 6, 2023
c8c9d7b
move source selection to atoms
hannahblair Nov 6, 2023
3b83209
Merge branch 'fix-source-styling' of github.com:gradio-app/gradio int…
hannahblair Nov 6, 2023
bdc613a
formatting
hannahblair Nov 6, 2023
f48f9ea
add changeset
gradio-pr-bot Nov 6, 2023
f14fd86
Merge branch 'fix-source-styling' of github.com:gradio-app/gradio int…
hannahblair Nov 6, 2023
5626f71
add changeset
gradio-pr-bot Nov 6, 2023
f42717d
add changeset
gradio-pr-bot Nov 6, 2023
c9b79a0
tweak <Upload /> height to accomodate source selection
hannahblair Nov 6, 2023
7ba3d8e
Merge branch 'fix-source-styling' of github.com:gradio-app/gradio int…
hannahblair Nov 6, 2023
7e1dd9f
add changeset
gradio-pr-bot Nov 6, 2023
1054c41
calc new height with source selection
hannahblair Nov 6, 2023
b35ad20
Merge branch 'fix-source-styling' of github.com:gradio-app/gradio int…
hannahblair Nov 6, 2023
560b0c1
Merge branch 'main' into fix-source-styling
hannahblair Nov 6, 2023
2e259d8
formatting
hannahblair Nov 6, 2023
4486b17
Merge branch 'fix-source-styling' of github.com:gradio-app/gradio int…
hannahblair Nov 6, 2023
8e6513f
tweak
hannahblair Nov 6, 2023
0f76527
Merge branch 'main' into fix-source-styling
hannahblair Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/mean-papayas-try.md
@@ -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
@@ -0,0 +1,74 @@
<script lang="ts">
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

these changes are just moving the source selection over to a reusable component

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
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
Expand Up @@ -30,3 +30,13 @@
label: "Audio Recorder"
}}
/>

<Story
hannahblair marked this conversation as resolved.
Show resolved Hide resolved
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
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}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure if there's a better name for this param

>
<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
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%"}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the actual fix for the issue

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
@@ -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
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>