gradio-pr-bot commited on
Commit
26fbf1c
·
verified ·
1 Parent(s): 7013cf7

Upload folder using huggingface_hub

Browse files
6.1.0/checkbox/Index.svelte CHANGED
@@ -25,7 +25,15 @@
25
  on_clear_status={() =>
26
  gradio.dispatch("clear_status", gradio.shared.loading_status)}
27
  />
28
- <BaseCheckbox {gradio} />
 
 
 
 
 
 
 
 
29
  {#if gradio.props.info}
30
  <Info info={gradio.props.info} />
31
  {/if}
 
25
  on_clear_status={() =>
26
  gradio.dispatch("clear_status", gradio.shared.loading_status)}
27
  />
28
+ <BaseCheckbox
29
+ label={gradio.shared.label || gradio.i18n("checkbox.checkbox")}
30
+ bind:value={gradio.props.value}
31
+ interactive={gradio.shared.interactive}
32
+ show_label={gradio.shared.show_label}
33
+ on_change={(val) => gradio.dispatch("change", val)}
34
+ on_input={() => gradio.dispatch("input")}
35
+ on_select={(data) => gradio.dispatch("select", data)}
36
+ />
37
  {#if gradio.props.info}
38
  <Info info={gradio.props.info} />
39
  {/if}
6.1.0/checkbox/package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "@gradio/checkbox",
3
- "version": "0.5.0",
4
  "description": "Gradio UI packages",
5
  "type": "module",
6
  "author": "",
 
1
  {
2
  "name": "@gradio/checkbox",
3
+ "version": "0.5.1",
4
  "description": "Gradio UI packages",
5
  "type": "module",
6
  "author": "",
6.1.0/checkbox/shared/Checkbox.svelte CHANGED
@@ -1,19 +1,32 @@
1
  <script lang="ts">
2
- import type { Gradio } from "@gradio/utils";
3
- import type { CheckboxProps, CheckboxEvents } from "../types";
4
-
5
- const props = $props();
6
- const gradio: Gradio<CheckboxEvents, CheckboxProps> = props.gradio;
7
-
8
- let disabled = $derived(!gradio.shared.interactive);
9
-
10
- let old_value = $state(gradio.props.value);
11
- let label = $derived(gradio.shared.label || gradio.i18n("checkbox.checkbox"));
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  $effect(() => {
14
- if (old_value !== gradio.props.value) {
15
- old_value = gradio.props.value;
16
- gradio.dispatch("change", $state.snapshot(gradio.props.value));
17
  }
18
  });
19
 
@@ -21,8 +34,8 @@
21
  event: KeyboardEvent & { currentTarget: EventTarget & HTMLInputElement }
22
  ): Promise<void> {
23
  if (event.key === "Enter") {
24
- gradio.props.value = !gradio.props.value;
25
- gradio.dispatch("select", {
26
  index: 0,
27
  value: event.currentTarget.checked,
28
  selected: event.currentTarget.checked
@@ -33,19 +46,19 @@
33
  async function handle_input(
34
  event: Event & { currentTarget: EventTarget & HTMLInputElement }
35
  ): Promise<void> {
36
- gradio.props.value = event.currentTarget.checked;
37
- gradio.dispatch("select", {
38
  index: 0,
39
  value: event.currentTarget.checked,
40
  selected: event.currentTarget.checked
41
  });
42
- gradio.dispatch("input");
43
  }
44
  </script>
45
 
46
  <label class="checkbox-container" class:disabled>
47
  <input
48
- bind:checked={gradio.props.value}
49
  on:keydown={handle_enter}
50
  on:input={handle_input}
51
  {disabled}
@@ -53,7 +66,7 @@
53
  name="test"
54
  data-testid="checkbox"
55
  />
56
- {#if gradio.shared.show_label}
57
  <span class="label-text">
58
  {label}
59
  </span>
 
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
 
 
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
 
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}
 
66
  name="test"
67
  data-testid="checkbox"
68
  />
69
+ {#if show_label}
70
  <span class="label-text">
71
  {label}
72
  </span>