gradio-pr-bot commited on
Commit
cd826c9
·
verified ·
1 Parent(s): e3c6723

Upload folder using huggingface_hub

Browse files
6.3.1/textbox/Example.svelte ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+
4
+ export let value: string | null;
5
+ export let type: "gallery" | "table";
6
+ export let selected = false;
7
+
8
+ let size: number;
9
+ let el: HTMLDivElement;
10
+
11
+ function set_styles(element: HTMLElement, el_width: number): void {
12
+ element.style.setProperty(
13
+ "--local-text-width",
14
+ `${el_width && el_width < 150 ? el_width : 200}px`
15
+ );
16
+ element.style.whiteSpace = "unset";
17
+ }
18
+
19
+ function truncate_text(text: string | null, max_length = 60): string {
20
+ if (!text) return "";
21
+ const str = String(text);
22
+ if (str.length <= max_length) return str;
23
+ return str.slice(0, max_length) + "...";
24
+ }
25
+
26
+ onMount(() => {
27
+ set_styles(el, size);
28
+ });
29
+ </script>
30
+
31
+ <div
32
+ bind:clientWidth={size}
33
+ bind:this={el}
34
+ class:table={type === "table"}
35
+ class:gallery={type === "gallery"}
36
+ class:selected
37
+ >
38
+ {truncate_text(value)}
39
+ </div>
40
+
41
+ <style>
42
+ .gallery {
43
+ padding: var(--size-1) var(--size-2);
44
+ }
45
+
46
+ div {
47
+ overflow: hidden;
48
+ white-space: nowrap;
49
+ }
50
+ </style>
6.3.1/textbox/Index.svelte ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script context="module" lang="ts">
4
+ export { default as BaseTextbox } from "./shared/Textbox.svelte";
5
+ export { default as BaseExample } from "./Example.svelte";
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import { tick } from "svelte";
10
+ import TextBox from "./shared/Textbox.svelte";
11
+ import StatusTracker from "@gradio/statustracker";
12
+ import { Block } from "@gradio/atoms";
13
+ import { Gradio } from "@gradio/utils";
14
+ import type { TextboxProps, TextboxEvents } from "./types";
15
+
16
+ let _props = $props();
17
+ const gradio = new Gradio<TextboxEvents, TextboxProps>(_props);
18
+
19
+ let label = $derived(gradio.shared.label || "Textbox");
20
+ // Need to set the value to "" otherwise a change event gets
21
+ // dispatched when the child sets it to ""
22
+ gradio.props.value = gradio.props.value ?? "";
23
+ let old_value = $state(gradio.props.value);
24
+
25
+ async function dispatch_change() {
26
+ if (old_value !== gradio.props.value) {
27
+ old_value = gradio.props.value;
28
+ await tick();
29
+ gradio.dispatch("change", $state.snapshot(gradio.props.value));
30
+ }
31
+ }
32
+
33
+ async function handle_input(value: string): Promise<void> {
34
+ if (!gradio.shared || !gradio.props) return;
35
+ gradio.props.validation_error = null;
36
+ gradio.props.value = value;
37
+ await tick();
38
+ gradio.dispatch("input");
39
+ }
40
+
41
+ $effect(() => {
42
+ dispatch_change();
43
+ });
44
+
45
+ function handle_change(value: string): void {
46
+ if (!gradio.shared || !gradio.props) return;
47
+ gradio.props.validation_error = null;
48
+ gradio.props.value = value;
49
+ }
50
+ </script>
51
+
52
+ <Block
53
+ visible={gradio.shared.visible}
54
+ elem_id={gradio.shared.elem_id}
55
+ elem_classes={gradio.shared.elem_classes}
56
+ scale={gradio.shared.scale}
57
+ min_width={gradio.shared.min_width}
58
+ allow_overflow={false}
59
+ padding={gradio.shared.container}
60
+ rtl={gradio.props.rtl}
61
+ >
62
+ {#if gradio.shared.loading_status}
63
+ <StatusTracker
64
+ autoscroll={gradio.shared.autoscroll}
65
+ i18n={gradio.i18n}
66
+ {...gradio.shared.loading_status}
67
+ show_validation_error={false}
68
+ on_clear_status={() =>
69
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
70
+ />
71
+ {/if}
72
+
73
+ <TextBox
74
+ value={gradio.props.value}
75
+ {label}
76
+ info={gradio.props.info}
77
+ show_label={gradio.shared.show_label}
78
+ lines={gradio.props.lines}
79
+ type={gradio.props.type}
80
+ rtl={gradio.props.rtl}
81
+ text_align={gradio.props.text_align}
82
+ max_lines={gradio.props.max_lines}
83
+ placeholder={gradio.props.placeholder}
84
+ submit_btn={gradio.props.submit_btn}
85
+ stop_btn={gradio.props.stop_btn}
86
+ buttons={gradio.props.buttons}
87
+ autofocus={gradio.props.autofocus}
88
+ container={gradio.shared.container}
89
+ autoscroll={gradio.shared.autoscroll}
90
+ max_length={gradio.props.max_length}
91
+ html_attributes={gradio.props.html_attributes}
92
+ validation_error={gradio.shared?.loading_status?.validation_error ||
93
+ gradio.shared?.validation_error}
94
+ on:change={(e) => handle_change(e.detail)}
95
+ on:input={(e) => handle_input(e.detail)}
96
+ on:submit={() => {
97
+ gradio.shared.validation_error = null;
98
+ gradio.dispatch("submit");
99
+ }}
100
+ on:blur={() => gradio.dispatch("blur")}
101
+ on:select={(e) => gradio.dispatch("select", e.detail)}
102
+ on:focus={() => gradio.dispatch("focus")}
103
+ on:stop={() => gradio.dispatch("stop")}
104
+ on:copy={(e) => gradio.dispatch("copy", e.detail)}
105
+ on_custom_button_click={(id) => {
106
+ gradio.dispatch("custom_button_click", { id });
107
+ }}
108
+ disabled={!gradio.shared.interactive}
109
+ />
110
+ </Block>
111
+
112
+ <!-- bind:value_is_output={gradio.props.value_is_output} -->
6.3.1/textbox/package.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/textbox",
3
+ "version": "0.13.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "Index.svelte",
11
+ "exports": {
12
+ ".": {
13
+ "gradio": "./Index.svelte",
14
+ "svelte": "./dist/Index.svelte",
15
+ "types": "./dist/Index.svelte.d.ts"
16
+ },
17
+ "./example": {
18
+ "gradio": "./Example.svelte",
19
+ "svelte": "./dist/Example.svelte",
20
+ "types": "./dist/Example.svelte.d.ts"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "dependencies": {
25
+ "@gradio/atoms": "workspace:^",
26
+ "@gradio/icons": "workspace:^",
27
+ "@gradio/statustracker": "workspace:^",
28
+ "@gradio/utils": "workspace:^"
29
+ },
30
+ "devDependencies": {
31
+ "@gradio/preview": "workspace:^"
32
+ },
33
+ "peerDependencies": {
34
+ "svelte": "^5.43.4"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/gradio-app/gradio.git",
39
+ "directory": "js/textbox"
40
+ }
41
+ }
6.3.1/textbox/shared/Textbox.svelte ADDED
@@ -0,0 +1,537 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import {
3
+ beforeUpdate,
4
+ afterUpdate,
5
+ createEventDispatcher,
6
+ tick
7
+ } from "svelte";
8
+ import { BlockTitle, IconButton, IconButtonWrapper } from "@gradio/atoms";
9
+ import { Copy, Check, Send, Square } from "@gradio/icons";
10
+ import type {
11
+ SelectData,
12
+ CopyData,
13
+ CustomButton as CustomButtonType
14
+ } from "@gradio/utils";
15
+ import type { InputHTMLAttributes } from "../types";
16
+
17
+ export let value = "";
18
+ export let value_is_output = false;
19
+ export let lines = 1;
20
+ export let placeholder = "";
21
+ export let label: string;
22
+ export let info: string | undefined = undefined;
23
+ export let disabled = false;
24
+ export let show_label = true;
25
+ export let container = true;
26
+ export let max_lines: number | undefined = undefined;
27
+ export let type: "text" | "password" | "email" = "text";
28
+ export let buttons: (string | CustomButtonType)[] | null = null;
29
+ export let on_custom_button_click: ((id: number) => void) | null = null;
30
+ export let submit_btn: string | boolean | null = null;
31
+ export let stop_btn: string | boolean | null = null;
32
+ export let rtl = false;
33
+ export let autofocus = false;
34
+ export let text_align: "left" | "right" | undefined = undefined;
35
+ export let autoscroll = true;
36
+ export let max_length: number | undefined = undefined;
37
+ export let html_attributes: InputHTMLAttributes | null = null;
38
+ export let validation_error: string | null | undefined = undefined;
39
+
40
+ let el: HTMLTextAreaElement | HTMLInputElement;
41
+ let copied = false;
42
+ let timer: NodeJS.Timeout;
43
+ let can_scroll: boolean;
44
+ let previous_scroll_top = 0;
45
+ let user_has_scrolled_up = false;
46
+ let _max_lines: number;
47
+ let ghost_element: HTMLTextAreaElement | null = null;
48
+
49
+ const show_textbox_border = !submit_btn;
50
+
51
+ $: if (max_lines === undefined || max_lines === null) {
52
+ if (type === "text") {
53
+ _max_lines = Math.max(lines, 20);
54
+ } else {
55
+ _max_lines = 1;
56
+ }
57
+ } else {
58
+ _max_lines = Math.max(max_lines, lines);
59
+ }
60
+
61
+ $: (value,
62
+ validation_error,
63
+ el && lines !== _max_lines && lines > 1 && resize({ target: el }));
64
+
65
+ $: if (value === null) value = "";
66
+
67
+ const dispatch = createEventDispatcher<{
68
+ change: string;
69
+ submit: undefined;
70
+ stop: undefined;
71
+ blur: undefined;
72
+ select: SelectData;
73
+ input: string;
74
+ focus: undefined;
75
+ copy: CopyData;
76
+ custom_button_click: { component_id: number };
77
+ }>();
78
+
79
+ beforeUpdate(() => {
80
+ if (
81
+ !user_has_scrolled_up &&
82
+ el &&
83
+ el.offsetHeight + el.scrollTop > el.scrollHeight - 100
84
+ ) {
85
+ can_scroll = true;
86
+ }
87
+ });
88
+
89
+ const scroll = (): void => {
90
+ if (can_scroll && autoscroll && !user_has_scrolled_up) {
91
+ el.scrollTo(0, el.scrollHeight);
92
+ }
93
+ };
94
+
95
+ async function handle_change(): Promise<void> {
96
+ await tick();
97
+ dispatch("change", value);
98
+ }
99
+
100
+ afterUpdate(() => {
101
+ if (autofocus) {
102
+ el.focus();
103
+ }
104
+ if (can_scroll && autoscroll) {
105
+ scroll();
106
+ }
107
+ value_is_output = false;
108
+ });
109
+ $: (value, handle_change());
110
+
111
+ async function handle_copy(): Promise<void> {
112
+ if ("clipboard" in navigator) {
113
+ await navigator.clipboard.writeText(value);
114
+ dispatch("copy", { value: value });
115
+ copy_feedback();
116
+ }
117
+ }
118
+
119
+ function copy_feedback(): void {
120
+ copied = true;
121
+ if (timer) clearTimeout(timer);
122
+ timer = setTimeout(() => {
123
+ copied = false;
124
+ }, 1000);
125
+ }
126
+
127
+ function handle_select(event: Event): void {
128
+ const target: HTMLTextAreaElement | HTMLInputElement = event.target as
129
+ | HTMLTextAreaElement
130
+ | HTMLInputElement;
131
+ const text = target.value;
132
+ const index: [number, number] = [
133
+ target.selectionStart as number,
134
+ target.selectionEnd as number
135
+ ];
136
+ dispatch("select", { value: text.substring(...index), index: index });
137
+ }
138
+
139
+ async function handle_keypress(e: KeyboardEvent): Promise<void> {
140
+ if (e.key === "Enter" && e.shiftKey && lines > 1) {
141
+ e.preventDefault();
142
+ await tick();
143
+ dispatch("submit");
144
+ } else if (
145
+ e.key === "Enter" &&
146
+ !e.shiftKey &&
147
+ lines === 1 &&
148
+ _max_lines >= 1
149
+ ) {
150
+ e.preventDefault();
151
+ await tick();
152
+ dispatch("submit");
153
+ }
154
+ await tick();
155
+ dispatch("input", value);
156
+ }
157
+
158
+ function handle_scroll(event: Event): void {
159
+ const target = event.target as HTMLElement;
160
+ const current_scroll_top = target.scrollTop;
161
+ if (current_scroll_top < previous_scroll_top) {
162
+ user_has_scrolled_up = true;
163
+ }
164
+ previous_scroll_top = current_scroll_top;
165
+
166
+ const max_scroll_top = target.scrollHeight - target.clientHeight;
167
+ const user_has_scrolled_to_bottom = current_scroll_top >= max_scroll_top;
168
+ if (user_has_scrolled_to_bottom) {
169
+ user_has_scrolled_up = false;
170
+ }
171
+ }
172
+
173
+ function handle_stop(): void {
174
+ dispatch("stop");
175
+ }
176
+
177
+ function handle_submit(): void {
178
+ dispatch("submit");
179
+ }
180
+
181
+ async function resize(
182
+ event: Event | { target: HTMLTextAreaElement | HTMLInputElement }
183
+ ): Promise<void> {
184
+ await tick();
185
+ if (lines === _max_lines) return;
186
+
187
+ const target = event.target as HTMLTextAreaElement;
188
+ const computed_styles = window.getComputedStyle(target);
189
+ const padding_top = parseFloat(computed_styles.paddingTop);
190
+ const padding_bottom = parseFloat(computed_styles.paddingBottom);
191
+ const line_height = parseFloat(computed_styles.lineHeight);
192
+
193
+ let max =
194
+ _max_lines === undefined
195
+ ? false
196
+ : padding_top + padding_bottom + line_height * _max_lines;
197
+ let min = padding_top + padding_bottom + lines * line_height;
198
+
199
+ target.style.height = "1px";
200
+
201
+ let scroll_height;
202
+ if (max && target.scrollHeight > max) {
203
+ scroll_height = max;
204
+ } else if (target.scrollHeight < min) {
205
+ scroll_height = min;
206
+ } else {
207
+ scroll_height = target.scrollHeight;
208
+ }
209
+
210
+ target.style.height = `${scroll_height}px`;
211
+
212
+ update_scrollbar_visibility(target);
213
+ }
214
+
215
+ function update_scrollbar_visibility(textarea: HTMLTextAreaElement): void {
216
+ // Using "auto" scroll does not work, as the scrollbar is visible even
217
+ // when the content is about the same height as the textarea height. So
218
+ // here, we add the scrollbar if the content is longer than a threshold
219
+ // of 1 line height beyond the textarea height.
220
+ const content_height = textarea.scrollHeight;
221
+ const visible_height = textarea.clientHeight;
222
+ const line_height = parseFloat(
223
+ window.getComputedStyle(textarea).lineHeight
224
+ );
225
+ if (content_height > visible_height + line_height) {
226
+ textarea.style.overflowY = "scroll";
227
+ } else {
228
+ textarea.style.overflowY = "hidden";
229
+ }
230
+ }
231
+
232
+ function text_area_resize(
233
+ _el: HTMLTextAreaElement,
234
+ _value: string
235
+ ): any | undefined {
236
+ if (lines === _max_lines || (lines === 1 && _max_lines === 1)) return;
237
+
238
+ _el.style.overflowY = "scroll";
239
+ _el.addEventListener("input", resize);
240
+
241
+ if (!_value.trim()) return;
242
+ resize({ target: _el });
243
+
244
+ return {
245
+ destroy: () => _el.removeEventListener("input", resize)
246
+ };
247
+ }
248
+ </script>
249
+
250
+ <!-- svelte-ignore a11y-autofocus -->
251
+ <label class:container class:show_textbox_border>
252
+ {#if show_label && buttons && buttons.length > 0}
253
+ <IconButtonWrapper {buttons} {on_custom_button_click}>
254
+ {#if buttons.some((btn) => typeof btn === "string" && btn === "copy")}
255
+ <IconButton
256
+ Icon={copied ? Check : Copy}
257
+ on:click={handle_copy}
258
+ label={copied ? "Copied" : "Copy"}
259
+ />
260
+ {/if}
261
+ </IconButtonWrapper>
262
+ {/if}
263
+ <BlockTitle show_label={validation_error ? true : show_label} {info}
264
+ >{label}
265
+ {#if validation_error}
266
+ <div class="validation-error">{validation_error}</div>
267
+ {/if}
268
+ </BlockTitle>
269
+
270
+ <div class="input-container">
271
+ {#if lines === 1 && _max_lines === 1}
272
+ {#if type === "text"}
273
+ <input
274
+ data-testid="textbox"
275
+ type="text"
276
+ class="scroll-hide"
277
+ dir={rtl ? "rtl" : "ltr"}
278
+ bind:value
279
+ bind:this={el}
280
+ {placeholder}
281
+ {disabled}
282
+ {autofocus}
283
+ maxlength={max_length}
284
+ on:keypress={handle_keypress}
285
+ on:blur
286
+ on:select={handle_select}
287
+ on:focus
288
+ class:validation-error={validation_error}
289
+ style={text_align ? "text-align: " + text_align : ""}
290
+ autocapitalize={html_attributes?.autocapitalize}
291
+ autocorrect={html_attributes?.autocorrect}
292
+ spellcheck={html_attributes?.spellcheck}
293
+ autocomplete={html_attributes?.autocomplete}
294
+ tabindex={html_attributes?.tabindex}
295
+ enterkeyhint={html_attributes?.enterkeyhint}
296
+ lang={html_attributes?.lang}
297
+ />
298
+ {:else if type === "password"}
299
+ <input
300
+ data-testid="password"
301
+ type="password"
302
+ class="scroll-hide"
303
+ bind:value
304
+ bind:this={el}
305
+ {placeholder}
306
+ {disabled}
307
+ {autofocus}
308
+ maxlength={max_length}
309
+ on:keypress={handle_keypress}
310
+ on:blur
311
+ on:select={handle_select}
312
+ on:focus
313
+ class:validation-error={validation_error}
314
+ autocomplete=""
315
+ autocapitalize={html_attributes?.autocapitalize}
316
+ autocorrect={html_attributes?.autocorrect}
317
+ spellcheck={html_attributes?.spellcheck}
318
+ tabindex={html_attributes?.tabindex}
319
+ enterkeyhint={html_attributes?.enterkeyhint}
320
+ lang={html_attributes?.lang}
321
+ />
322
+ {:else if type === "email"}
323
+ <input
324
+ data-testid="textbox"
325
+ type="email"
326
+ class="scroll-hide"
327
+ bind:value
328
+ bind:this={el}
329
+ {placeholder}
330
+ {disabled}
331
+ {autofocus}
332
+ maxlength={max_length}
333
+ on:keypress={handle_keypress}
334
+ on:blur
335
+ on:select={handle_select}
336
+ on:focus
337
+ class:validation-error={validation_error}
338
+ autocomplete="email"
339
+ autocapitalize={html_attributes?.autocapitalize}
340
+ autocorrect={html_attributes?.autocorrect}
341
+ spellcheck={html_attributes?.spellcheck}
342
+ tabindex={html_attributes?.tabindex}
343
+ enterkeyhint={html_attributes?.enterkeyhint}
344
+ lang={html_attributes?.lang}
345
+ />
346
+ {/if}
347
+ {:else}
348
+ <textarea
349
+ data-testid="textbox"
350
+ use:text_area_resize={value}
351
+ dir={rtl ? "rtl" : "ltr"}
352
+ class:no-label={!show_label && (submit_btn || stop_btn)}
353
+ bind:value
354
+ bind:this={el}
355
+ {placeholder}
356
+ rows={lines}
357
+ {disabled}
358
+ {autofocus}
359
+ maxlength={max_length}
360
+ on:keypress={handle_keypress}
361
+ on:blur
362
+ on:select={handle_select}
363
+ on:focus
364
+ on:scroll={handle_scroll}
365
+ class:validation-error={validation_error}
366
+ style={text_align ? "text-align: " + text_align : ""}
367
+ autocapitalize={html_attributes?.autocapitalize}
368
+ autocorrect={html_attributes?.autocorrect}
369
+ spellcheck={html_attributes?.spellcheck}
370
+ autocomplete={html_attributes?.autocomplete}
371
+ tabindex={html_attributes?.tabindex}
372
+ enterkeyhint={html_attributes?.enterkeyhint}
373
+ lang={html_attributes?.lang}
374
+ />
375
+ {/if}
376
+ {#if submit_btn}
377
+ <button
378
+ class="submit-button"
379
+ class:padded-button={submit_btn !== true}
380
+ on:click={handle_submit}
381
+ >
382
+ {#if submit_btn === true}
383
+ <Send />
384
+ {:else}
385
+ {submit_btn}
386
+ {/if}
387
+ </button>
388
+ {/if}
389
+ {#if stop_btn}
390
+ <button
391
+ class="stop-button"
392
+ class:padded-button={stop_btn !== true}
393
+ on:click={handle_stop}
394
+ >
395
+ {#if stop_btn === true}
396
+ <Square fill="none" stroke_width={2.5} />
397
+ {:else}
398
+ {stop_btn}
399
+ {/if}
400
+ </button>
401
+ {/if}
402
+ </div>
403
+ </label>
404
+
405
+ <style>
406
+ label {
407
+ display: block;
408
+ width: 100%;
409
+ }
410
+
411
+ input[type="text"],
412
+ input[type="password"],
413
+ input[type="email"],
414
+ textarea {
415
+ flex-grow: 1;
416
+ outline: none !important;
417
+ margin-top: 0px;
418
+ margin-bottom: 0px;
419
+ resize: none;
420
+ z-index: 1;
421
+ display: block;
422
+ position: relative;
423
+ outline: none !important;
424
+ background: var(--input-background-fill);
425
+ padding: var(--input-padding);
426
+ width: 100%;
427
+ color: var(--body-text-color);
428
+ font-weight: var(--input-text-weight);
429
+ font-size: var(--input-text-size);
430
+ line-height: var(--line-sm);
431
+ border: none;
432
+ }
433
+
434
+ textarea.no-label {
435
+ padding-top: 5px;
436
+ padding-bottom: 5px;
437
+ }
438
+ label.show_textbox_border input,
439
+ label.show_textbox_border textarea {
440
+ box-shadow: var(--input-shadow);
441
+ }
442
+ label:not(.container),
443
+ label:not(.container) input,
444
+ label:not(.container) textarea {
445
+ height: 100%;
446
+ }
447
+ label.container.show_textbox_border input,
448
+ label.container.show_textbox_border textarea {
449
+ border: var(--input-border-width) solid var(--input-border-color);
450
+ border-radius: var(--input-radius);
451
+ }
452
+ input:disabled,
453
+ textarea:disabled {
454
+ -webkit-opacity: 1;
455
+ opacity: 1;
456
+ }
457
+
458
+ label.container.show_textbox_border input:focus,
459
+ label.container.show_textbox_border textarea:focus {
460
+ box-shadow: var(--input-shadow-focus);
461
+ border-color: var(--input-border-color-focus);
462
+ background: var(--input-background-fill-focus);
463
+ }
464
+
465
+ input::placeholder,
466
+ textarea::placeholder {
467
+ color: var(--input-placeholder-color);
468
+ }
469
+
470
+ /* Same submit button style as MultimodalTextbox for the consistent UI */
471
+ .input-container {
472
+ display: flex;
473
+ position: relative;
474
+ align-items: flex-end;
475
+ }
476
+ .submit-button,
477
+ .stop-button {
478
+ border: none;
479
+ text-align: center;
480
+ text-decoration: none;
481
+ font-size: 14px;
482
+ cursor: pointer;
483
+ border-radius: 15px;
484
+ min-width: 30px;
485
+ height: 30px;
486
+ flex-shrink: 0;
487
+ display: flex;
488
+ justify-content: center;
489
+ align-items: center;
490
+ z-index: var(--layer-1);
491
+ }
492
+ .stop-button,
493
+ .submit-button {
494
+ background: var(--button-secondary-background-fill);
495
+ color: var(--button-secondary-text-color);
496
+ }
497
+ .stop-button:hover,
498
+ .submit-button:hover {
499
+ background: var(--button-secondary-background-fill-hover);
500
+ }
501
+ .stop-button:disabled,
502
+ .submit-button:disabled {
503
+ background: var(--button-secondary-background-fill);
504
+ cursor: pointer;
505
+ }
506
+ .stop-button:active,
507
+ .submit-button:active {
508
+ box-shadow: var(--button-shadow-active);
509
+ }
510
+ .submit-button :global(svg) {
511
+ height: 22px;
512
+ width: 22px;
513
+ }
514
+
515
+ .stop-button :global(svg) {
516
+ height: 16px;
517
+ width: 16px;
518
+ }
519
+ .padded-button {
520
+ padding: 0 10px;
521
+ }
522
+
523
+ div.validation-error {
524
+ color: var(--error-icon-color);
525
+ font-size: var(--font-sans);
526
+ margin-top: var(--spacing-sm);
527
+ font-weight: var(--weight-semibold);
528
+ }
529
+
530
+ label.container input.validation-error,
531
+ label.container textarea.validation-error {
532
+ border-color: transparent !important;
533
+ box-shadow:
534
+ 0 0 3px 1px var(--error-icon-color),
535
+ var(--shadow-inset) !important;
536
+ }
537
+ </style>
6.3.1/textbox/types.ts ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ type SelectData,
3
+ type CopyData,
4
+ type CustomButton
5
+ } from "@gradio/utils";
6
+ import type { LoadingStatus } from "@gradio/statustracker";
7
+
8
+ export interface TextboxEvents {
9
+ change: string;
10
+ submit: never;
11
+ blur: never;
12
+ select: SelectData;
13
+ input: never;
14
+ focus: never;
15
+ stop: never;
16
+ clear_status: LoadingStatus;
17
+ copy: CopyData;
18
+ custom_button_click: { id: number };
19
+ }
20
+
21
+ export interface TextboxProps {
22
+ value: string;
23
+ info: string;
24
+ lines: number;
25
+ type: "text" | "password" | "email" | undefined;
26
+ rtl: boolean;
27
+ text_align: "right" | "left";
28
+ max_lines: number;
29
+ placeholder: string;
30
+ submit_btn: string;
31
+ stop_btn: string;
32
+ buttons: (string | CustomButton)[] | null;
33
+ autofocus: boolean;
34
+ autoscroll: boolean;
35
+ max_length: number;
36
+ html_attributes: InputHTMLAttributes;
37
+ validation_error: string | null;
38
+ }
39
+
40
+ type FullAutoFill =
41
+ | AutoFill
42
+ | "bday"
43
+ | `${OptionalPrefixToken<AutoFillAddressKind>}${"cc-additional-name"}`
44
+ | "nickname"
45
+ | "language"
46
+ | "organization-title"
47
+ | "photo"
48
+ | "sex"
49
+ | "url";
50
+
51
+ export interface InputHTMLAttributes {
52
+ autocapitalize?:
53
+ | "off"
54
+ | "none"
55
+ | "on"
56
+ | "sentences"
57
+ | "words"
58
+ | "characters"
59
+ | null;
60
+ autocorrect?: "on" | "off" | null;
61
+ spellcheck?: boolean | null;
62
+ autocomplete?: FullAutoFill | undefined | null;
63
+ tabindex?: number | null;
64
+ enterkeyhint?:
65
+ | "enter"
66
+ | "done"
67
+ | "go"
68
+ | "next"
69
+ | "previous"
70
+ | "search"
71
+ | "send"
72
+ | null;
73
+ lang?: string | null;
74
+ }