gradio-pr-bot commited on
Commit
d314faa
·
verified ·
1 Parent(s): cc62be9

Upload folder using huggingface_hub

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