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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 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";
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 container: boolean = false;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
export let show_label: boolean = true;
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}
{container}
{scale}
{min_width}
padding={false}
>
<StatusTracker {...loading_status} />
{#if show_label}
<BlockLabel Icon={LabelIcon} {label} disable={container === false} />
{/if}
{#if _label !== undefined && _label !== null}
<Label on:select {selectable} {value} {color} />
{:else}
<Empty unpadded_box={true}><LabelIcon /></Empty>
{/if}
</Block>