gradio-pr-bot commited on
Commit
63bfc93
·
verified ·
1 Parent(s): 7095327

Upload folder using huggingface_hub

Browse files
6.4.0/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.4.0/checkboxgroup/Index.svelte ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options immutable={true} />
2
+
3
+ <script lang="ts">
4
+ import { Gradio } from "@gradio/utils";
5
+ import { Block, BlockTitle, IconButtonWrapper } 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
+ {#if gradio.shared.show_label && gradio.props.buttons && gradio.props.buttons.length > 0}
74
+ <IconButtonWrapper
75
+ buttons={gradio.props.buttons}
76
+ on_custom_button_click={(id) => {
77
+ gradio.dispatch("custom_button_click", { id });
78
+ }}
79
+ />
80
+ {/if}
81
+ <BlockTitle
82
+ show_label={gradio.shared.show_label ||
83
+ (gradio.props.show_select_all && gradio.shared.interactive)}
84
+ info={gradio.props.info}
85
+ >
86
+ {#if gradio.props.show_select_all && gradio.shared.interactive}
87
+ <div class="select-all-container">
88
+ <label class="select-all-label">
89
+ <input
90
+ class="select-all-checkbox"
91
+ on:change={toggle_select_all}
92
+ checked={select_all_state === "checked"}
93
+ indeterminate={select_all_state === "indeterminate"}
94
+ type="checkbox"
95
+ title="Select/Deselect All"
96
+ />
97
+ </label>
98
+ <button type="button" class="label-text" on:click={toggle_select_all}>
99
+ {gradio.shared.show_label ? gradio.shared.label : "Select All"}
100
+ </button>
101
+ </div>
102
+ {:else if gradio.shared.show_label}
103
+ {gradio.shared.label || gradio.i18n("checkbox.checkbox_group")}
104
+ {/if}
105
+ </BlockTitle>
106
+
107
+ <div class="wrap" data-testid="checkbox-group">
108
+ {#each gradio.props.choices as [display_value, internal_value], i}
109
+ <label
110
+ class:disabled
111
+ class:selected={gradio.props.value.includes(internal_value)}
112
+ >
113
+ <input
114
+ {disabled}
115
+ on:change={() => toggle_choice(internal_value)}
116
+ on:input={(evt) =>
117
+ gradio.dispatch("select", {
118
+ index: i,
119
+ value: internal_value,
120
+ selected: evt.currentTarget.checked
121
+ })}
122
+ on:keydown={(event) => {
123
+ if (event.key === "Enter") {
124
+ toggle_choice(internal_value);
125
+ gradio.dispatch("select", {
126
+ index: i,
127
+ value: internal_value,
128
+ selected: !gradio.props.value.includes(internal_value)
129
+ });
130
+ }
131
+ }}
132
+ checked={gradio.props.value.includes(internal_value)}
133
+ type="checkbox"
134
+ name={internal_value?.toString()}
135
+ title={internal_value?.toString()}
136
+ />
137
+ <span class="ml-2">{display_value}</span>
138
+ </label>
139
+ {/each}
140
+ </div>
141
+ </Block>
142
+
143
+ <style>
144
+ .wrap {
145
+ display: flex;
146
+ flex-wrap: wrap;
147
+ gap: var(--checkbox-label-gap);
148
+ }
149
+ label {
150
+ display: flex;
151
+ align-items: center;
152
+ transition: var(--button-transition);
153
+ cursor: pointer;
154
+ box-shadow: var(--checkbox-label-shadow);
155
+ border: var(--checkbox-label-border-width) solid
156
+ var(--checkbox-label-border-color);
157
+ border-radius: var(--checkbox-border-radius);
158
+ background: var(--checkbox-label-background-fill);
159
+ padding: var(--checkbox-label-padding);
160
+ color: var(--checkbox-label-text-color);
161
+ font-weight: var(--checkbox-label-text-weight);
162
+ font-size: var(--checkbox-label-text-size);
163
+ line-height: var(--line-md);
164
+ }
165
+
166
+ label:hover {
167
+ background: var(--checkbox-label-background-fill-hover);
168
+ }
169
+ label:focus {
170
+ background: var(--checkbox-label-background-fill-focus);
171
+ }
172
+ label.selected {
173
+ background: var(--checkbox-label-background-fill-selected);
174
+ color: var(--checkbox-label-text-color-selected);
175
+ border-color: var(--checkbox-label-border-color-selected);
176
+ }
177
+
178
+ label > * + * {
179
+ margin-left: var(--size-2);
180
+ }
181
+
182
+ input {
183
+ --ring-color: transparent;
184
+ position: relative;
185
+ box-shadow: var(--checkbox-shadow);
186
+ border: var(--checkbox-border-width) solid var(--checkbox-border-color);
187
+ border-radius: var(--checkbox-border-radius);
188
+ background-color: var(--checkbox-background-color);
189
+ line-height: var(--line-sm);
190
+ }
191
+
192
+ input:checked,
193
+ input:checked:hover,
194
+ input:checked:focus {
195
+ border-color: var(--checkbox-border-color-selected);
196
+ background-image: var(--checkbox-check);
197
+ background-color: var(--checkbox-background-color-selected);
198
+ }
199
+
200
+ input:checked:focus {
201
+ border-color: var(--checkbox-border-color-focus);
202
+ background-image: var(--checkbox-check);
203
+ background-color: var(--checkbox-background-color-selected);
204
+ }
205
+
206
+ input:hover {
207
+ border-color: var(--checkbox-border-color-hover);
208
+ background-color: var(--checkbox-background-color-hover);
209
+ }
210
+
211
+ input:not(:checked):focus {
212
+ border-color: var(--checkbox-border-color-focus);
213
+ }
214
+
215
+ input[disabled],
216
+ .disabled {
217
+ cursor: not-allowed !important;
218
+ }
219
+
220
+ input[disabled] {
221
+ opacity: 0.75;
222
+ }
223
+
224
+ input:hover {
225
+ cursor: pointer;
226
+ }
227
+
228
+ .select-all-container {
229
+ display: flex;
230
+ align-items: center;
231
+ gap: var(--size-2);
232
+ }
233
+
234
+ .select-all-label {
235
+ display: flex;
236
+ align-items: center;
237
+ cursor: pointer;
238
+ margin: 0;
239
+ padding: 0;
240
+ background: none;
241
+ border: none;
242
+ box-shadow: none;
243
+ }
244
+
245
+ .select-all-checkbox {
246
+ --ring-color: transparent;
247
+ position: relative;
248
+ box-shadow: var(--checkbox-shadow);
249
+ border: var(--checkbox-border-width) solid var(--checkbox-border-color);
250
+ border-radius: var(--checkbox-border-radius);
251
+ background-color: var(--checkbox-background-color);
252
+ line-height: var(--line-sm);
253
+ margin: 0;
254
+ }
255
+
256
+ .select-all-checkbox:checked,
257
+ .select-all-checkbox:checked:hover,
258
+ .select-all-checkbox:checked:focus {
259
+ border-color: var(--checkbox-border-color-selected);
260
+ background-image: var(--checkbox-check);
261
+ background-color: var(--checkbox-background-color-selected);
262
+ }
263
+
264
+ .select-all-checkbox:indeterminate,
265
+ .select-all-checkbox:indeterminate:hover {
266
+ border-color: var(--checkbox-border-color-selected);
267
+ background-color: var(--checkbox-background-color-selected);
268
+ position: relative;
269
+ }
270
+
271
+ .select-all-checkbox:indeterminate::after {
272
+ content: "";
273
+ position: absolute;
274
+ left: 50%;
275
+ top: 50%;
276
+ transform: translate(-50%, -50%);
277
+ width: 60%;
278
+ height: 2px;
279
+ background-color: white;
280
+ }
281
+
282
+ .select-all-checkbox:not(:indeterminate):not(:checked):hover {
283
+ border-color: var(--checkbox-border-color-hover);
284
+ background-color: var(--checkbox-background-color-hover);
285
+ cursor: pointer;
286
+ }
287
+
288
+ .label-text {
289
+ margin: 0;
290
+ cursor: pointer;
291
+ background: none;
292
+ border: none;
293
+ padding: 0;
294
+ font: inherit;
295
+ color: inherit;
296
+ text-align: left;
297
+ }
298
+ </style>
6.4.0/checkboxgroup/package.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/checkboxgroup",
3
+ "version": "0.9.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
+ "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.4.0/checkboxgroup/types.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { SelectData, CustomButton } 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
+ buttons: (string | CustomButton)[] | null;
9
+ }
10
+
11
+ export interface CheckboxGroupEvents {
12
+ change: (string | number)[];
13
+ input: (string | number)[];
14
+ select: SelectData;
15
+ clear_status: void;
16
+ custom_button_click: { id: number };
17
+ }