gradio-pr-bot commited on
Commit
eb93143
·
verified ·
1 Parent(s): 4aaa918

Upload folder using huggingface_hub

Browse files
6.2.0/radio/Example.svelte ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string | null;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ export let choices: [string, string | number][];
6
+
7
+ let name_string: string;
8
+
9
+ if (value === null) {
10
+ name_string = "";
11
+ } else {
12
+ let name = choices.find((pair) => pair[1] === value);
13
+ name_string = name ? name[0] : "";
14
+ }
15
+ </script>
16
+
17
+ <div
18
+ class:table={type === "table"}
19
+ class:gallery={type === "gallery"}
20
+ class:selected
21
+ >
22
+ {name_string}
23
+ </div>
24
+
25
+ <style>
26
+ .gallery {
27
+ padding: var(--size-1) var(--size-2);
28
+ }
29
+ </style>
6.2.0/radio/Index.svelte ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseRadio } from "./shared/Radio.svelte";
3
+ export { default as BaseExample } from "./Example.svelte";
4
+ </script>
5
+
6
+ <script lang="ts">
7
+ import { Gradio } from "@gradio/utils";
8
+ import { Block, BlockTitle } from "@gradio/atoms";
9
+ import { StatusTracker } from "@gradio/statustracker";
10
+ import BaseRadio from "./shared/Radio.svelte";
11
+ import type { RadioEvents, RadioProps } from "./types";
12
+
13
+ const props = $props();
14
+
15
+ const gradio = new Gradio<RadioEvents, RadioProps>(props);
16
+
17
+ let disabled = $derived(!gradio.shared.interactive);
18
+
19
+ let old_value = $state(gradio.props.value);
20
+ $effect(() => {
21
+ if (old_value != gradio.props.value) {
22
+ old_value = gradio.props.value;
23
+ gradio.dispatch("change");
24
+ }
25
+ });
26
+ </script>
27
+
28
+ <Block
29
+ visible={gradio.shared.visible}
30
+ type="fieldset"
31
+ elem_id={gradio.shared.elem_id}
32
+ elem_classes={gradio.shared.elem_classes}
33
+ container={gradio.shared.container}
34
+ scale={gradio.shared.scale}
35
+ min_width={gradio.shared.min_width}
36
+ rtl={gradio.props.rtl}
37
+ >
38
+ <StatusTracker
39
+ autoscroll={gradio.shared.autoscroll}
40
+ i18n={gradio.i18n}
41
+ {...gradio.shared.loading_status}
42
+ on_clear_status={() =>
43
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
44
+ />
45
+
46
+ <BlockTitle show_label={gradio.shared.show_label} info={gradio.props.info}
47
+ >{gradio.shared.label || gradio.i18n("radio.radio")}</BlockTitle
48
+ >
49
+
50
+ <div class="wrap">
51
+ {#each gradio.props.choices as [display_value, internal_value], i (i)}
52
+ <BaseRadio
53
+ {display_value}
54
+ {internal_value}
55
+ bind:selected={gradio.props.value}
56
+ {disabled}
57
+ rtl={gradio.props.rtl}
58
+ on_input={() => {
59
+ gradio.dispatch("input");
60
+ gradio.dispatch("select", {
61
+ value: internal_value,
62
+ index: i
63
+ });
64
+ }}
65
+ />
66
+ {/each}
67
+ </div>
68
+ </Block>
69
+
70
+ <style>
71
+ .wrap {
72
+ display: flex;
73
+ flex-wrap: wrap;
74
+ gap: var(--checkbox-label-gap);
75
+ }
76
+ </style>
6.2.0/radio/package.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/radio",
3
+ "version": "0.8.0",
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/statustracker": "workspace:^",
27
+ "@gradio/utils": "workspace:^"
28
+ },
29
+ "devDependencies": {
30
+ "@gradio/preview": "workspace:^"
31
+ },
32
+ "peerDependencies": {
33
+ "svelte": "^5.43.4"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/gradio-app/gradio.git",
38
+ "directory": "js/radio"
39
+ }
40
+ }
6.2.0/radio/shared/Radio.svelte ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module">
2
+ let id = 0;
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import { tick } from "svelte";
7
+ let {
8
+ selected = $bindable(),
9
+ display_value,
10
+ internal_value,
11
+ disabled,
12
+ rtl,
13
+ on_input
14
+ } = $props();
15
+ let is_selected = $derived(selected === internal_value);
16
+
17
+ async function handle_input(
18
+ e: Event & { target: EventTarget & HTMLInputElement }
19
+ ): Promise<void> {
20
+ is_selected = e.target.checked;
21
+ if (is_selected) {
22
+ await tick();
23
+ on_input();
24
+ }
25
+ }
26
+ </script>
27
+
28
+ <label
29
+ class:disabled
30
+ class:selected={is_selected}
31
+ data-testid="{display_value}-radio-label"
32
+ class:rtl
33
+ >
34
+ <input
35
+ {disabled}
36
+ type="radio"
37
+ name="radio-{++id}"
38
+ value={internal_value}
39
+ aria-checked={is_selected}
40
+ bind:group={selected}
41
+ on:input={handle_input}
42
+ />
43
+ <span>{display_value}</span>
44
+ </label>
45
+
46
+ <style>
47
+ label {
48
+ display: flex;
49
+ align-items: center;
50
+ transition: var(--button-transition);
51
+ cursor: pointer;
52
+ box-shadow: var(--checkbox-label-shadow);
53
+ border: var(--checkbox-label-border-width) solid
54
+ var(--checkbox-label-border-color);
55
+ border-radius: var(--checkbox-border-radius);
56
+ background: var(--checkbox-label-background-fill);
57
+ padding: var(--checkbox-label-padding);
58
+ color: var(--checkbox-label-text-color);
59
+ font-weight: var(--checkbox-label-text-weight);
60
+ font-size: var(--checkbox-label-text-size);
61
+ line-height: var(--line-md);
62
+ }
63
+
64
+ label:hover {
65
+ background: var(--checkbox-label-background-fill-hover);
66
+ }
67
+ label:focus {
68
+ background: var(--checkbox-label-background-fill-focus);
69
+ }
70
+
71
+ label.selected {
72
+ background: var(--checkbox-label-background-fill-selected);
73
+ color: var(--checkbox-label-text-color-selected);
74
+ border-color: var(--checkbox-label-border-color-selected);
75
+ }
76
+
77
+ label > * + * {
78
+ margin-left: var(--size-2);
79
+ }
80
+
81
+ label.rtl > * + * {
82
+ margin-left: 0;
83
+ margin-right: var(--size-2);
84
+ }
85
+
86
+ input {
87
+ --ring-color: transparent;
88
+ position: relative;
89
+ box-shadow: var(--checkbox-shadow);
90
+ border: var(--checkbox-border-width) solid var(--checkbox-border-color);
91
+ border-radius: var(--radius-full);
92
+ background-color: var(--checkbox-background-color);
93
+ line-height: var(--line-sm);
94
+ }
95
+
96
+ input:checked,
97
+ input:checked:hover {
98
+ border-color: var(--checkbox-border-color-selected);
99
+ background-image: var(--radio-circle);
100
+ background-color: var(--checkbox-background-color-selected);
101
+ }
102
+
103
+ input:checked::after {
104
+ content: "";
105
+ position: absolute;
106
+ top: 50%;
107
+ left: 50%;
108
+ transform: translate(-50%, -50%);
109
+ border-radius: 50%;
110
+ background-color: white;
111
+ }
112
+
113
+ input:hover:not([disabled]) {
114
+ border-color: var(--checkbox-border-color-hover);
115
+ background-color: var(--checkbox-background-color-hover);
116
+ }
117
+
118
+ input:focus:not([disabled]) {
119
+ border-color: var(--checkbox-border-color-focus);
120
+ background-color: var(--checkbox-background-color-focus);
121
+ }
122
+
123
+ input:checked:focus:not([disabled]) {
124
+ border-color: var(--checkbox-border-color-focus);
125
+ background-image: var(--radio-circle);
126
+ background-color: var(--checkbox-background-color-selected);
127
+ }
128
+
129
+ input[disabled],
130
+ .disabled {
131
+ cursor: not-allowed;
132
+ }
133
+
134
+ input[disabled] {
135
+ opacity: 0.75;
136
+ }
137
+ </style>
6.2.0/radio/types.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { LoadingStatus } from "@gradio/statustracker";
2
+ import type { SelectData } from "@gradio/utils";
3
+
4
+ export interface RadioProps {
5
+ choices: [string, string | number][];
6
+ value: string;
7
+ info: string;
8
+ rtl: boolean;
9
+ }
10
+
11
+ export interface RadioEvents {
12
+ select: SelectData;
13
+ change: any;
14
+ input: any;
15
+ clear_status: LoadingStatus;
16
+ }