File size: 2,532 Bytes
86dc9ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<script context="module" lang="ts">
	export { default as BaseExample } from "./Example.svelte";
</script>

<script lang="ts">
	import type { Gradio } from "@gradio/utils";
	import { Block, BlockTitle } from "@gradio/atoms";
	import DateTime from "@gradio/datetime";

	export let gradio: Gradio<{
		change: undefined;
	}>;
	export let label = "Time";
	export let show_label = true;
	export let info: string | undefined = undefined;
	export let elem_id = "";
	export let elem_classes: string[] = [];
	export let visible = true;
	export let value: [string, string] = ["", ""];
	let old_value = value;
	export let scale: number | null = null;
	export let min_width: number | undefined = undefined;
	export let include_time = true;
	export let quick_ranges: string[] = [];
	let range_history: [string, string][] = [value];

	$: if (value[0] !== old_value[0] || value[1] !== old_value[1]) {
		old_value = value;
		range_history = [...range_history, value];
	}

	const back_in_history = (): void => {
		range_history.pop();
		const last_range = range_history.pop();
		if (last_range === undefined) {
			value = ["", ""];
			range_history = [];
		} else {
			value = last_range;
			gradio.dispatch("change");
			range_history = [...range_history];
		}
	};
</script>

<Block
	{visible}
	{elem_id}
	{elem_classes}
	{scale}
	{min_width}
	allow_overflow={false}
	padding={true}
>
	<div class="label-content">
		<BlockTitle {show_label} {info}>{label}</BlockTitle>
		{#if show_label}
			<div class="quick-ranges">
				<button
					class="quick-range"
					style:display={range_history.length <= 1 ? "none" : "block"}
					on:click={back_in_history}>Back</button
				>

				{#each quick_ranges as quick_range}
					<button
						class="quick-range"
						on:click={() => {
							value = ["now - " + quick_range, "now"];
						}}>Last {quick_range}</button
					>
				{/each}
			</div>
		{/if}	</div>
	<div class="times">
		<DateTime show_label={false} bind:value={value[0]} {include_time} {gradio} on:gradio></DateTime>
		<DateTime show_label={false} bind:value={value[1]} {include_time} {gradio} on:gradio></DateTime>
	</div>
</Block>

<style>
	.times {
		display: flex;
		gap: 10px;
	}
	.times > :global(.block) {
		margin: 0;
		padding: 0;
	}
	.label-content {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
	}
	.quick-ranges {
		display: inline-flex;
		gap: var(--size-3);
	}
	button {
		color: var(--body-text-color-subdued);
		cursor: pointer;
	}
	button:hover {
		color: var(--body-text-color);
	}
</style>