gradio/ui/packages/app/src/components/Label/Label.svelte

50 lines
1.4 KiB
Svelte
Raw Normal View History

2022-03-08 21:35:42 +08:00
<script lang="ts">
2022-03-17 00:34:30 +08:00
import { createEventDispatcher } from "svelte";
2022-03-08 21:35:42 +08:00
import { Label } from "@gradio/label";
import { LineChart as LabelIcon } from "@gradio/icons";
import { Block, BlockLabel } from "@gradio/atoms";
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
import type { LoadingStatus } from "../StatusTracker/types";
import type { Styles } from "@gradio/utils";
2022-03-08 21:35:42 +08:00
export let elem_id: string = "";
export let visible: boolean = true;
export let color: undefined | string = undefined;
2022-03-08 21:35:42 +08:00
export let value: {
label: string;
confidences?: Array<{ label: string; confidence: number }>;
};
2022-05-13 08:23:45 +08:00
export let label: string = "Label";
export let style: Styles = {};
2022-03-29 21:10:35 +08:00
export let loading_status: LoadingStatus;
export let show_label: boolean;
2022-03-17 00:34:30 +08:00
const dispatch = createEventDispatcher<{ change: undefined }>();
$: value, dispatch("change");
2022-03-08 21:35:42 +08:00
</script>
<Block
test_id="label"
{visible}
{elem_id}
disable={typeof style.container === "boolean" && !style.container}
>
<StatusTracker {...loading_status} />
{#if show_label}
<BlockLabel
Icon={LabelIcon}
{label}
disable={typeof style.container === "boolean" && !style.container}
/>
{/if}
{#if typeof value === "object" && value !== undefined && value !== null}
<Label {value} {show_label} {color} />
{:else}
<div class="h-full min-h-[6rem] flex justify-center items-center">
<div class="h-5 dark:text-white opacity-50"><LabelIcon /></div>
</div>
{/if}
</Block>