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

Fix single file upload display #7221

Merged
merged 6 commits into from Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/red-squids-drop.md
@@ -0,0 +1,6 @@
---
"@gradio/file": patch
"gradio": patch
---

fix:Fix single file upload display
64 changes: 64 additions & 0 deletions js/file/FileUpload.stories.svelte
@@ -0,0 +1,64 @@
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import { format } from "svelte-i18n";
import FileUpload from "./shared/FileUpload.svelte";
import { get } from "svelte/store";

export const meta = {
title: "Components/FileUpload",
component: FileUpload,
argTypes: {
value: {
control: "text",
description: "The URL or filepath (or list of URLs or filepaths)",
name: "value",
value: []
},
file_count: {
control: "radio",
options: ["single", "multiple"],
description: "Whether to allow single or multiple files to be uploaded",
name: "file_count",
value: "single"
}
}
};
</script>

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

<Story
name="Single File"
args={{
value: [
{
path: "cheetah.jpg",
orig_name: "cheetah.jpg",
url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
size: 10000
}
],
file_count: "single"
}}
/>
<Story
name="Multiple files"
args={{
value: Array(2).fill({
path: "cheetah.jpg",
orig_name: "cheetah.jpg",
url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
size: 10000
}),
file_count: "multiple"
}}
/>
<Story
name="No value"
args={{
value: null,
file_count: "multiple"
}}
/>
2 changes: 1 addition & 1 deletion js/file/shared/FileUpload.svelte
Expand Up @@ -67,7 +67,7 @@
label={label || "File"}
/>

{#if value && (Array.isArray(value) ? value.length > 0 : false)}
{#if value && (Array.isArray(value) ? value.length > 0 : true)}
<ModifyUpload {i18n} on:clear={handle_clear} absolute />
<FilePreview {i18n} on:select {selectable} {value} {height} />
{:else}
Expand Down