gradio-pr-bot commited on
Commit
8c0f5d6
·
verified ·
1 Parent(s): 7a60fcc

Upload folder using huggingface_hub

Browse files
6.0.0-dev.6/checkboxgroup/Example.svelte ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string[];
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ export let choices: [string, string | number][];
6
+
7
+ let names = value
8
+ .map(
9
+ (val) =>
10
+ (
11
+ choices.find((pair) => pair[1] === val) as
12
+ | [string, string | number]
13
+ | undefined
14
+ )?.[0]
15
+ )
16
+ .filter((name) => name !== undefined);
17
+ let names_string = names.join(", ");
18
+ </script>
19
+
20
+ <div
21
+ class:table={type === "table"}
22
+ class:gallery={type === "gallery"}
23
+ class:selected
24
+ >
25
+ {names_string}
26
+ </div>
27
+
28
+ <style>
29
+ .gallery {
30
+ padding: var(--size-1) var(--size-2);
31
+ }
32
+ </style>
6.0.0-dev.6/checkboxgroup/Index.svelte ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options immutable={true} />
2
+
3
+ <script lang="ts">
4
+ import { Gradio } from "@gradio/utils";
5
+ import { Block, BlockTitle } from "@gradio/atoms";
6
+ import { StatusTracker } from "@gradio/statustracker";
7
+ import { dequal } from "dequal";
8
+ import type { CheckboxGroupProps, CheckboxGroupEvents } from "./types";
9
+
10
+ let props = $props();
11
+
12
+ let gradio = new Gradio<CheckboxGroupEvents, CheckboxGroupProps>(props);
13
+
14
+ function toggle_choice(choice: string | number): void {
15
+ if (gradio.props.value.includes(choice)) {
16
+ gradio.props.value = gradio.props.value.filter((v) => v !== choice);
17
+ } else {
18
+ gradio.props.value = [...gradio.props.value, choice];
19
+ }
20
+ gradio.dispatch("input");
21
+ }
22
+
23
+ function toggle_select_all(): void {
24
+ const all_values = gradio.props.choices.map(
25
+ ([, internal_value]) => internal_value
26
+ );
27
+ if (gradio.props.value.length === all_values.length) {
28
+ gradio.props.value = [];
29
+ } else {
30
+ gradio.props.value = all_values.slice();
31
+ }
32
+ gradio.dispatch("input");
33
+ }
34
+
35
+ let select_all_state = $derived.by(() => {
36
+ const all_values = gradio.props.choices.map(
37
+ ([, internal_value]) => internal_value
38
+ );
39
+ if (gradio.props.value.length === 0) return "unchecked";
40
+ if (gradio.props.value.length === all_values.length) return "checked";
41
+ return "indeterminate";
42
+ });
43
+
44
+ let disabled = $derived(!gradio.shared.interactive);
45
+ let old_value = gradio.props.value;
46
+ $effect(() => {
47
+ gradio.props.value;
48
+ if (dequal(old_value, gradio.props.value)) {
49
+ return;
50
+ }
51
+
52
+ old_value = gradio.props.value;
53
+ gradio.dispatch("change", $state.snapshot(gradio.props.value));
54
+ });
55
+ </script>
56
+
57
+ <Block
58
+ visible={gradio.shared.visible}
59
+ elem_id={gradio.shared.elem_id}
60
+ elem_classes={gradio.shared.elem_classes}
61
+ type="fieldset"
62
+ container={gradio.shared.container}
63
+ scale={gradio.shared.scale}
64
+ min_width={gradio.shared.min_width}
65
+ >
66
+ <StatusTracker
67
+ autoscroll={gradio.shared.autoscroll}
68
+ i18n={gradio.i18n}
69
+ {...gradio.shared.loading_status}
70
+ on:clear_status={() =>
71
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
72
+ />
73
+ <BlockTitle
74
+ show_label={gradio.shared.show_label ||
75
+ (gradio.props.show_select_all && gradio.shared.interactive)}
76
+ info={gradio.props.info}
77
+ >
78
+ {#if gradio.props.show_select_all && gradio.shared.interactive}
79
+ <div class="select-all-container">
80
+ <label class="select-all-label">
81
+ <input
82
+ class="select-all-checkbox"
83
+ on:change={toggle_select_all}
84
+ checked={select_all_state === "checked"}
85
+ indeterminate={select_all_state === "indeterminate"}
86
+ type="checkbox"
87
+ title="Select/Deselect All"
88
+ />
89
+ </label>
90
+ <button type="button" class="label-text" on:click={toggle_select_all}>
91
+ {gradio.shared.show_label ? gradio.shared.label : "Select All"}
92
+ </button>
93
+ </div>
94
+ {:else if gradio.shared.show_label}
95
+ {gradio.shared.label || gradio.i18n("checkbox.checkbox_group")}
96
+ {/if}
97
+ </BlockTitle>
98
+
99
+ <div class="wrap" data-testid="checkbox-group">
100
+ {#each gradio.props.choices as [display_value, internal_value], i}
101
+ <label
102
+ class:disabled
103
+ class:selected={gradio.props.value.includes(internal_value)}
104
+ >
105
+ <input
106
+ {disabled}
107
+ on:change={() => toggle_choice(internal_value)}
108
+ on:input={(evt) =>
109
+ gradio.dispatch("select", {
110
+ index: i,
111
+ value: internal_value,
112
+ selected: evt.currentTarget.checked
113
+ })}
114
+ on:keydown={(event) => {
115
+ if (event.key === "Enter") {
116
+ toggle_choice(internal_value);
117
+ gradio.dispatch("select", {
118
+ index: i,
119
+ value: internal_value,
120
+ selected: !gradio.props.value.includes(internal_value)
121
+ });
122
+ }
123
+ }}
124
+ checked={gradio.props.value.includes(internal_value)}
125
+ type="checkbox"
126
+ name={internal_value?.toString()}
127
+ title={internal_value?.toString()}
128
+ />
129
+ <span class="ml-2">{display_value}</span>
130
+ </label>
131
+ {/each}
132
+ </div>
133
+ </Block>
134
+
135
+ <style>
136
+ .wrap {
137
+ display: flex;
138
+ flex-wrap: wrap;
139
+ gap: var(--checkbox-label-gap);
140
+ }
141
+ label {
142
+ display: flex;
143
+ align-items: center;
144
+ transition: var(--button-transition);
145
+ cursor: pointer;
146
+ box-shadow: var(--checkbox-label-shadow);
147
+ border: var(--checkbox-label-border-width) solid
148
+ var(--checkbox-label-border-color);
149
+ border-radius: var(--checkbox-border-radius);
150
+ background: var(--checkbox-label-background-fill);
151
+ padding: var(--checkbox-label-padding);
152
+ color: var(--checkbox-label-text-color);
153
+ font-weight: var(--checkbox-label-text-weight);
154
+ font-size: var(--checkbox-label-text-size);
155
+ line-height: var(--line-md);
156
+ }
157
+
158
+ label:hover {
159
+ background: var(--checkbox-label-background-fill-hover);
160
+ }
161
+ label:focus {
162
+ background: var(--checkbox-label-background-fill-focus);
163
+ }
164
+ label.selected {
165
+ background: var(--checkbox-label-background-fill-selected);
166
+ color: var(--checkbox-label-text-color-selected);
167
+ border-color: var(--checkbox-label-border-color-selected);
168
+ }
169
+
170
+ label > * + * {
171
+ margin-left: var(--size-2);
172
+ }
173
+
174
+ input {
175
+ --ring-color: transparent;
176
+ position: relative;
177
+ box-shadow: var(--checkbox-shadow);
178
+ border: var(--checkbox-border-width) solid var(--checkbox-border-color);
179
+ border-radius: var(--checkbox-border-radius);
180
+ background-color: var(--checkbox-background-color);
181
+ line-height: var(--line-sm);
182
+ }
183
+
184
+ input:checked,
185
+ input:checked:hover,
186
+ input:checked:focus {
187
+ border-color: var(--checkbox-border-color-selected);
188
+ background-image: var(--checkbox-check);
189
+ background-color: var(--checkbox-background-color-selected);
190
+ }
191
+
192
+ input:checked:focus {
193
+ border-color: var(--checkbox-border-color-focus);
194
+ background-image: var(--checkbox-check);
195
+ background-color: var(--checkbox-background-color-selected);
196
+ }
197
+
198
+ input:hover {
199
+ border-color: var(--checkbox-border-color-hover);
200
+ background-color: var(--checkbox-background-color-hover);
201
+ }
202
+
203
+ input:not(:checked):focus {
204
+ border-color: var(--checkbox-border-color-focus);
205
+ }
206
+
207
+ input[disabled],
208
+ .disabled {
209
+ cursor: not-allowed !important;
210
+ }
211
+
212
+ input[disabled] {
213
+ opacity: 0.75;
214
+ }
215
+
216
+ input:hover {
217
+ cursor: pointer;
218
+ }
219
+
220
+ .select-all-container {
221
+ display: flex;
222
+ align-items: center;
223
+ gap: var(--size-2);
224
+ }
225
+
226
+ .select-all-label {
227
+ display: flex;
228
+ align-items: center;
229
+ cursor: pointer;
230
+ margin: 0;
231
+ padding: 0;
232
+ background: none;
233
+ border: none;
234
+ box-shadow: none;
235
+ }
236
+
237
+ .select-all-checkbox {
238
+ --ring-color: transparent;
239
+ position: relative;
240
+ box-shadow: var(--checkbox-shadow);
241
+ border: var(--checkbox-border-width) solid var(--checkbox-border-color);
242
+ border-radius: var(--checkbox-border-radius);
243
+ background-color: var(--checkbox-background-color);
244
+ line-height: var(--line-sm);
245
+ margin: 0;
246
+ }
247
+
248
+ .select-all-checkbox:checked,
249
+ .select-all-checkbox:checked:hover,
250
+ .select-all-checkbox:checked:focus {
251
+ border-color: var(--checkbox-border-color-selected);
252
+ background-image: var(--checkbox-check);
253
+ background-color: var(--checkbox-background-color-selected);
254
+ }
255
+
256
+ .select-all-checkbox:indeterminate,
257
+ .select-all-checkbox:indeterminate:hover {
258
+ border-color: var(--checkbox-border-color-selected);
259
+ background-color: var(--checkbox-background-color-selected);
260
+ position: relative;
261
+ }
262
+
263
+ .select-all-checkbox:indeterminate::after {
264
+ content: "";
265
+ position: absolute;
266
+ left: 50%;
267
+ top: 50%;
268
+ transform: translate(-50%, -50%);
269
+ width: 60%;
270
+ height: 2px;
271
+ background-color: white;
272
+ }
273
+
274
+ .select-all-checkbox:not(:indeterminate):not(:checked):hover {
275
+ border-color: var(--checkbox-border-color-hover);
276
+ background-color: var(--checkbox-background-color-hover);
277
+ cursor: pointer;
278
+ }
279
+
280
+ .label-text {
281
+ margin: 0;
282
+ cursor: pointer;
283
+ background: none;
284
+ border: none;
285
+ padding: 0;
286
+ font: inherit;
287
+ color: inherit;
288
+ text-align: left;
289
+ }
290
+ </style>
6.0.0-dev.6/checkboxgroup/package.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/checkboxgroup",
3
+ "version": "0.8.0-dev.2",
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
+ "dequal": "^2.0.3"
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/checkboxgroup"
40
+ }
41
+ }
6.0.0-dev.6/checkboxgroup/types.ts ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { SelectData } from "@gradio/utils";
2
+
3
+ export interface CheckboxGroupProps {
4
+ value: (string | number)[];
5
+ choices: [string, string | number][];
6
+ info: string;
7
+ show_select_all: boolean;
8
+ }
9
+
10
+ export interface CheckboxGroupEvents {
11
+ change: (string | number)[];
12
+ input: (string | number)[];
13
+ select: SelectData;
14
+ clear_status: void;
15
+ }