gradio-pr-bot commited on
Commit
6739a0f
·
verified ·
1 Parent(s): 7985769

Upload folder using huggingface_hub

Browse files
6.14.0/checkbox/Example.svelte ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: boolean | null;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ </script>
6
+
7
+ <div
8
+ class:table={type === "table"}
9
+ class:gallery={type === "gallery"}
10
+ class:selected
11
+ >
12
+ {value !== null ? value.toLocaleString() : ""}
13
+ </div>
14
+
15
+ <style>
16
+ .gallery {
17
+ padding: var(--size-1) var(--size-2);
18
+ }
19
+ </style>
6.14.0/checkbox/Index.svelte ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseCheckbox } from "./shared/Checkbox.svelte";
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import { Gradio } from "@gradio/utils";
7
+ import { Block, Info, IconButtonWrapper } from "@gradio/atoms";
8
+ import { StatusTracker } from "@gradio/statustracker";
9
+ import type { CheckboxProps, CheckboxEvents } from "./types";
10
+ import BaseCheckbox from "./shared/Checkbox.svelte";
11
+
12
+ let props = $props();
13
+ const gradio = new Gradio<CheckboxEvents, CheckboxProps>(props);
14
+ </script>
15
+
16
+ <Block
17
+ visible={gradio.shared.visible}
18
+ elem_id={gradio.shared.elem_id}
19
+ elem_classes={gradio.shared.elem_classes}
20
+ >
21
+ <StatusTracker
22
+ autoscroll={gradio.shared.autoscroll}
23
+ i18n={gradio.i18n}
24
+ {...gradio.shared.loading_status}
25
+ on_clear_status={() =>
26
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
27
+ />
28
+ {#if gradio.shared.show_label && gradio.props.buttons && gradio.props.buttons.length > 0}
29
+ <IconButtonWrapper
30
+ buttons={gradio.props.buttons}
31
+ on_custom_button_click={(id) => {
32
+ gradio.dispatch("custom_button_click", { id });
33
+ }}
34
+ />
35
+ {/if}
36
+ <BaseCheckbox
37
+ label={gradio.shared.label || gradio.i18n("checkbox.checkbox")}
38
+ bind:value={gradio.props.value}
39
+ interactive={gradio.shared.interactive}
40
+ show_label={gradio.shared.show_label}
41
+ on_change={(val) => gradio.dispatch("change", val)}
42
+ on_input={() => gradio.dispatch("input")}
43
+ on_select={(data) => gradio.dispatch("select", data)}
44
+ />
45
+ {#if gradio.props.info}
46
+ <Info info={gradio.props.info} />
47
+ {/if}
48
+ </Block>
6.14.0/checkbox/package.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/checkbox",
3
+ "version": "0.7.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
+ "./package.json": "./package.json",
13
+ ".": {
14
+ "gradio": "./Index.svelte",
15
+ "svelte": "./dist/Index.svelte",
16
+ "types": "./dist/Index.svelte.d.ts"
17
+ },
18
+ "./example": {
19
+ "gradio": "./Example.svelte",
20
+ "svelte": "./dist/Example.svelte",
21
+ "types": "./dist/Example.svelte.d.ts"
22
+ }
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.48.0"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/gradio-app/gradio.git",
38
+ "directory": "js/checkbox"
39
+ }
40
+ }
6.14.0/checkbox/shared/Checkbox.svelte ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { SelectData } from "@gradio/utils";
3
+
4
+ let {
5
+ label = "Checkbox",
6
+ value = $bindable(),
7
+ indeterminate = false,
8
+ interactive = true,
9
+ show_label = true,
10
+ on_change,
11
+ on_input,
12
+ on_select
13
+ }: {
14
+ label?: string;
15
+ value?: boolean;
16
+ indeterminate?: boolean;
17
+ interactive?: boolean;
18
+ show_label?: boolean;
19
+ on_change?: (value: boolean) => void;
20
+ on_input?: () => void;
21
+ on_select?: (data: SelectData) => void;
22
+ } = $props();
23
+
24
+ let disabled = $derived(!interactive);
25
+
26
+ let old_value = $state(value);
27
+
28
+ $effect(() => {
29
+ if (old_value !== value) {
30
+ old_value = value;
31
+ on_change?.($state.snapshot(value as boolean));
32
+ }
33
+ });
34
+
35
+ async function handle_enter(
36
+ event: KeyboardEvent & { currentTarget: EventTarget & HTMLInputElement }
37
+ ): Promise<void> {
38
+ if (event.key === "Enter") {
39
+ value = !value;
40
+ on_select?.({
41
+ index: 0,
42
+ value: event.currentTarget.checked,
43
+ selected: event.currentTarget.checked
44
+ });
45
+ }
46
+ }
47
+
48
+ async function handle_input(
49
+ event: Event & { currentTarget: EventTarget & HTMLInputElement }
50
+ ): Promise<void> {
51
+ value = event.currentTarget.checked;
52
+ on_select?.({
53
+ index: 0,
54
+ value: event.currentTarget.checked,
55
+ selected: event.currentTarget.checked
56
+ });
57
+ on_input?.();
58
+ }
59
+ </script>
60
+
61
+ <label class="checkbox-container" class:disabled>
62
+ <input
63
+ bind:checked={value}
64
+ bind:indeterminate
65
+ on:keydown={handle_enter}
66
+ on:input={handle_input}
67
+ {disabled}
68
+ type="checkbox"
69
+ name="test"
70
+ data-testid="checkbox"
71
+ />
72
+ {#if show_label}
73
+ <span class="label-text">
74
+ {label}
75
+ </span>
76
+ {/if}
77
+ </label>
78
+
79
+ <style>
80
+ .checkbox-container {
81
+ display: flex;
82
+ align-items: center;
83
+ gap: var(--spacing-lg);
84
+ cursor: pointer;
85
+ }
86
+
87
+ .label-text {
88
+ color: var(--body-text-color);
89
+ font-size: var(--checkbox-label-text-size);
90
+ line-height: var(--line-sm);
91
+ }
92
+
93
+ .info {
94
+ display: block;
95
+ color: var(--body-text-color-subdued);
96
+ font-size: var(--text-xs);
97
+ margin-top: var(--spacing-xs);
98
+ }
99
+
100
+ input {
101
+ --ring-color: transparent;
102
+ position: relative;
103
+ box-shadow: var(--checkbox-shadow);
104
+ border: 1px solid var(--checkbox-border-color);
105
+ border-radius: var(--checkbox-border-radius);
106
+ background-color: var(--checkbox-background-color);
107
+ line-height: var(--line-sm);
108
+ flex-shrink: 0;
109
+ z-index: 0;
110
+ }
111
+
112
+ input:checked,
113
+ input:checked:hover,
114
+ input:checked:focus {
115
+ background-image: var(--checkbox-check);
116
+ background-color: var(--checkbox-background-color-selected);
117
+ border-color: var(--checkbox-border-color-focus);
118
+ }
119
+
120
+ input:checked:focus {
121
+ background-image: var(--checkbox-check);
122
+ background-color: var(--checkbox-background-color-selected);
123
+ border-color: var(--checkbox-border-color-focus);
124
+ }
125
+
126
+ input:hover {
127
+ border-color: var(--checkbox-border-color-hover);
128
+ background-color: var(--checkbox-background-color-hover);
129
+ }
130
+
131
+ input:focus {
132
+ border-color: var(--checkbox-border-color-focus);
133
+ background-color: var(--checkbox-background-color-focus);
134
+ }
135
+
136
+ input:indeterminate {
137
+ background-image: none;
138
+ background-color: var(--checkbox-background-color-selected);
139
+ border-color: var(--checkbox-border-color-focus);
140
+ position: relative;
141
+ }
142
+
143
+ input:indeterminate::before {
144
+ content: "";
145
+ position: absolute;
146
+ top: 50%;
147
+ left: 50%;
148
+ transform: translate(-50%, -50%);
149
+ width: 100%;
150
+ height: 100%;
151
+ z-index: 1;
152
+ border-radius: var(--checkbox-border-radius);
153
+ background-color: var(--checkbox-background-color-selected);
154
+ }
155
+
156
+ input:indeterminate::after {
157
+ content: "";
158
+ position: absolute;
159
+ top: 50%;
160
+ left: 50%;
161
+ transform: translate(-50%, -50%);
162
+ width: 8px;
163
+ height: 2px;
164
+ background-color: white;
165
+ z-index: 2;
166
+ }
167
+
168
+ input:indeterminate:hover {
169
+ background-color: var(--checkbox-background-color-selected);
170
+ border-color: var(--checkbox-border-color-hover);
171
+ }
172
+
173
+ input:indeterminate:focus {
174
+ background-color: var(--checkbox-background-color-selected);
175
+ border-color: var(--checkbox-border-color-focus);
176
+ }
177
+
178
+ input[disabled] {
179
+ cursor: not-allowed;
180
+ opacity: 0.75;
181
+ }
182
+
183
+ label.disabled {
184
+ cursor: not-allowed;
185
+ }
186
+
187
+ input:not([disabled]):hover {
188
+ cursor: pointer;
189
+ }
190
+ </style>
6.14.0/checkbox/types.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { SelectData, CustomButton } from "@gradio/utils";
2
+ import type { LoadingStatus } from "js/statustracker";
3
+
4
+ export interface CheckboxProps {
5
+ value: boolean;
6
+ info: string;
7
+ buttons: (string | CustomButton)[] | null;
8
+ }
9
+
10
+ export interface CheckboxEvents {
11
+ change: boolean;
12
+ input: boolean;
13
+ select: SelectData;
14
+ clear_status: LoadingStatus;
15
+ custom_button_click: { id: number };
16
+ }