gradio/js/app/src/components/Label/Label.svelte

52 lines
1.5 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, Empty } 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 elem_classes: Array<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;
2022-03-08 21:35:42 +08:00
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;
export let selectable: boolean = false;
2022-03-17 00:34:30 +08:00
const dispatch = createEventDispatcher<{ change: undefined }>();
$: ({ confidences, label: _label } = value);
$: _label, confidences, dispatch("change");
2022-03-08 21:35:42 +08:00
</script>
<Block
test_id="label"
{visible}
{elem_id}
{elem_classes}
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 on:select {selectable} {value} {show_label} {color} />
{:else}
<Empty><LabelIcon /></Empty>
{/if}
</Block>