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

59 lines
1.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
2022-03-08 21:35:42 +08:00
import { Table } from "@gradio/table";
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
import type { LoadingStatus } from "../StatusTracker/types";
import { createEventDispatcher, tick } from "svelte";
import type { Styles } from "@gradio/utils";
type Headers = Array<string>;
type Data = Array<Array<string | number>>;
type Datatype = "str" | "markdown" | "html" | "number" | "bool" | "date";
export let headers: Headers = [];
export let elem_id: string = "";
export let visible: boolean = true;
export let value: Data | { data: Data; headers: Headers } = [["", "", ""]];
export let mode: "static" | "dynamic";
export let col_count: [number, "fixed" | "dynamic"];
export let row_count: [number, "fixed" | "dynamic"];
export let parent: string | null = null;
export let style: Styles = {};
2022-05-19 06:14:12 +08:00
export let label: string | null = null;
export let wrap: boolean;
export let datatype: Datatype | Array<Datatype>;
const dispatch = createEventDispatcher();
export let loading_status: LoadingStatus;
async function handle_change(detail: {
data: Array<Array<string | number>>;
headers: Array<string>;
}) {
value = detail;
await tick();
dispatch("change", detail);
}
</script>
<div
id={elem_id}
class="relative overflow-hidden"
class:flex-1={parent === "row" || !parent}
class:!hidden={!visible}
>
<StatusTracker {...loading_status} />
<Table
2022-05-19 06:14:12 +08:00
{label}
{row_count}
{col_count}
values={value}
{headers}
on:change={({ detail }) => handle_change(detail)}
editable={mode === "dynamic"}
{style}
{wrap}
{datatype}
/>
</div>