@gradio/button 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,98 +1,103 @@
1
- <script>
2
- import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
3
- import Button from "./Index.svelte";
4
- </script>
1
+ <script module>
2
+ import { defineMeta } from "@storybook/addon-svelte-csf";
3
+ import Button from "./shared/Button.svelte";
5
4
 
6
- <Meta
7
- title="Components/Button"
8
- component={Button}
9
- argTypes={{
10
- label: {
11
- control: "text",
12
- description: "The text to display on the button",
13
- name: "label",
14
- value: "Gradio Button"
15
- },
16
- variant: {
17
- options: ["primary", "secondary", "stop"],
18
- description: "The variant of the button",
19
- control: { type: "select" },
20
- defaultValue: "primary"
21
- },
22
- size: {
23
- options: ["sm", "lg"],
24
- description: "The size of the button",
25
- control: { type: "select" },
26
- defaultValue: "lg"
27
- },
28
- visible: {
29
- options: [true, false],
30
- description: "Sets the visibility of the button",
31
- control: { type: "boolean" },
32
- defaultValue: true
33
- },
34
- interactive: {
35
- options: [true, false],
36
- description: "If false, the button will be in a disabled state",
37
- control: { type: "boolean" },
38
- defaultValue: true
39
- },
40
- disabled: {
41
- options: [true, false],
42
- control: { type: "boolean" },
43
- defaultValue: false
44
- },
45
- scale: {
46
- options: [null, 0.5, 1, 2],
47
- description:
48
- "relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. Only applies in Rows, or top-level Components in Blocks where fill_height=True. ",
49
- control: { type: "select" }
5
+ const { Story } = defineMeta({
6
+ title: "Components/Button",
7
+ component: Button,
8
+ tags: ["autodocs"],
9
+ argTypes: {
10
+ value: {
11
+ control: "text",
12
+ description: "The text to display on the button"
13
+ },
14
+ variant: {
15
+ options: ["primary", "secondary", "stop", "huggingface"],
16
+ description: "The variant of the button",
17
+ control: { type: "select" }
18
+ },
19
+ size: {
20
+ options: ["sm", "md", "lg"],
21
+ description: "The size of the button",
22
+ control: { type: "select" }
23
+ },
24
+ visible: {
25
+ description: "Sets the visibility of the button",
26
+ control: { type: "boolean" }
27
+ },
28
+ disabled: {
29
+ description: "If true, the button will be in a disabled state",
30
+ control: { type: "boolean" }
31
+ },
32
+ scale: {
33
+ options: [null, 0.5, 1, 2],
34
+ description: "Relative size compared to adjacent components",
35
+ control: { type: "select" }
36
+ },
37
+ link: {
38
+ control: "text",
39
+ description: "URL to navigate to when clicked"
40
+ }
50
41
  }
51
- }}
52
- />
42
+ });
43
+ </script>
53
44
 
54
- <Template let:args>
55
- <Button value="Gradio Button" {...args} />
56
- </Template>
45
+ {#snippet template(args)}
46
+ <Button {...args}>{args.value}</Button>
47
+ {/snippet}
57
48
 
58
49
  <Story
59
50
  name="Primary"
60
- args={{ variant: "primary", size: "lg", scale: 1, interactive: true }}
51
+ args={{ variant: "primary", size: "lg", value: "Primary Button" }}
52
+ {template}
61
53
  />
62
54
  <Story
63
55
  name="Secondary"
64
- args={{ variant: "secondary", size: "lg", interactive: true }}
56
+ args={{ variant: "secondary", size: "lg", value: "Secondary Button" }}
57
+ {template}
65
58
  />
66
- <Story name="Stop" args={{ variant: "stop", size: "lg", interactive: true }} />
67
59
  <Story
68
- name="Button with link"
69
- args={{ link: "https://huggingface.co/welcome", interactive: true }}
60
+ name="Stop"
61
+ args={{ variant: "stop", size: "lg", value: "Stop Button" }}
62
+ {template}
70
63
  />
71
64
  <Story
72
- name="Button with external image icon"
73
- args={{
74
- interactive: true,
75
- icon: {
76
- url: "https://huggingface.co/front/assets/huggingface_logo-noborder.svg",
77
- path: "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
78
- }
79
- }}
65
+ name="Small"
66
+ args={{ variant: "primary", size: "sm", value: "Small Button" }}
67
+ {template}
80
68
  />
81
69
  <Story
82
- name="Button with external image icon and no text"
70
+ name="Medium"
71
+ args={{ variant: "primary", size: "md", value: "Medium Button" }}
72
+ {template}
73
+ />
74
+ <Story
75
+ name="Disabled"
83
76
  args={{
84
- interactive: true,
85
- icon: {
86
- url: "https://huggingface.co/front/assets/huggingface_logo-noborder.svg",
87
- path: "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
88
- },
89
- value: ""
77
+ variant: "primary",
78
+ size: "lg",
79
+ disabled: true,
80
+ value: "Disabled Button"
90
81
  }}
82
+ {template}
91
83
  />
92
-
93
84
  <Story
94
- name="Button with visible equal to false"
85
+ name="Button with link"
95
86
  args={{
96
- visible: false
87
+ variant: "primary",
88
+ size: "lg",
89
+ link: "https://huggingface.co",
90
+ value: "Link Button"
97
91
  }}
92
+ {template}
93
+ />
94
+ <Story
95
+ name="Huggingface variant"
96
+ args={{ variant: "huggingface", size: "lg", value: "Huggingface Button" }}
97
+ {template}
98
+ />
99
+ <Story
100
+ name="Hidden"
101
+ args={{ variant: "primary", visible: false, value: "Hidden Button" }}
102
+ {template}
98
103
  />
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @gradio/button
2
2
 
3
+ ## 0.6.3
4
+
5
+ ### Fixes
6
+
7
+ - [#12800](https://github.com/gradio-app/gradio/pull/12800) [`7a1c321`](https://github.com/gradio-app/gradio/commit/7a1c321b6546ba05a353488f5133e8262c4a8a39) - Bump svelte/kit for security reasons. Thanks @freddyaboulton!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/utils@0.11.2
12
+ - @gradio/upload@0.17.4
13
+ - @gradio/client@2.0.3
14
+ - @gradio/image@0.25.1
15
+
16
+ ## 0.6.2
17
+
18
+ ### Fixes
19
+
20
+ - [#12681](https://github.com/gradio-app/gradio/pull/12681) [`ba46c2d`](https://github.com/gradio-app/gradio/commit/ba46c2df1405c11e495304af8f91acfdf69d0b18) - Migrate Button to Svelte 5. Thanks @freddyaboulton!
21
+
22
+ ### Dependency updates
23
+
24
+ - @gradio/utils@0.11.1
25
+ - @gradio/client@2.0.2
26
+
3
27
  ## 0.6.1
4
28
 
5
29
  ### Dependency updates
package/Index.svelte CHANGED
@@ -7,9 +7,21 @@
7
7
  import type { SharedProps } from "@gradio/utils";
8
8
 
9
9
  import Button from "./shared/Button.svelte";
10
+ import type { FileData } from "client/js/src";
11
+ interface ButtonProps {
12
+ value: string | null;
13
+ variant: "primary" | "secondary" | "stop";
14
+ size: "sm" | "md" | "lg";
15
+ scale: number;
16
+ link: string | null;
17
+ icon: FileData | null;
18
+ link_target: "_self" | "_blank";
19
+ elem_id: string | null;
20
+ elem_classes?: string[];
21
+ }
10
22
 
11
- let _props: { shared_props: SharedProps; props: {} } = $props();
12
- const gradio = new Gradio<never, {}>(_props);
23
+ let _props: { shared_props: SharedProps; props: ButtonProps } = $props();
24
+ const gradio = new Gradio<never, ButtonProps>(_props);
13
25
 
14
26
  function handle_click() {
15
27
  gradio.dispatch("click");
@@ -29,7 +41,7 @@
29
41
  visible={gradio.shared.visible}
30
42
  disabled={!gradio.shared.interactive}
31
43
  link_target={gradio.props.link_target}
32
- on:click={handle_click}
44
+ onclick={handle_click}
33
45
  >
34
46
  {gradio.props.value ?? ""}
35
47
  </Button>
package/dist/Index.svelte CHANGED
@@ -7,9 +7,21 @@
7
7
  import type { SharedProps } from "@gradio/utils";
8
8
 
9
9
  import Button from "./shared/Button.svelte";
10
+ import type { FileData } from "client/js/src";
11
+ interface ButtonProps {
12
+ value: string | null;
13
+ variant: "primary" | "secondary" | "stop";
14
+ size: "sm" | "md" | "lg";
15
+ scale: number;
16
+ link: string | null;
17
+ icon: FileData | null;
18
+ link_target: "_self" | "_blank";
19
+ elem_id: string | null;
20
+ elem_classes?: string[];
21
+ }
10
22
 
11
- let _props: { shared_props: SharedProps; props: {} } = $props();
12
- const gradio = new Gradio<never, {}>(_props);
23
+ let _props: { shared_props: SharedProps; props: ButtonProps } = $props();
24
+ const gradio = new Gradio<never, ButtonProps>(_props);
13
25
 
14
26
  function handle_click() {
15
27
  gradio.dispatch("click");
@@ -29,7 +41,7 @@
29
41
  visible={gradio.shared.visible}
30
42
  disabled={!gradio.shared.interactive}
31
43
  link_target={gradio.props.link_target}
32
- on:click={handle_click}
44
+ onclick={handle_click}
33
45
  >
34
46
  {gradio.props.value ?? ""}
35
47
  </Button>
@@ -1,8 +1,20 @@
1
1
  export { default as BaseButton } from "./shared/Button.svelte";
2
2
  import type { SharedProps } from "@gradio/utils";
3
+ import type { FileData } from "client/js/src";
4
+ interface ButtonProps {
5
+ value: string | null;
6
+ variant: "primary" | "secondary" | "stop";
7
+ size: "sm" | "md" | "lg";
8
+ scale: number;
9
+ link: string | null;
10
+ icon: FileData | null;
11
+ link_target: "_self" | "_blank";
12
+ elem_id: string | null;
13
+ elem_classes?: string[];
14
+ }
3
15
  type $$ComponentProps = {
4
16
  shared_props: SharedProps;
5
- props: {};
17
+ props: ButtonProps;
6
18
  };
7
19
  declare const Index: import("svelte").Component<$$ComponentProps, {}, "">;
8
20
  type Index = ReturnType<typeof Index>;
@@ -1,20 +1,39 @@
1
1
  <script lang="ts">
2
2
  import { type FileData } from "@gradio/client";
3
3
  import { Image } from "@gradio/image/shared";
4
-
5
- export let elem_id = "";
6
- export let elem_classes: string[] = [];
7
- export let visible: boolean | "hidden" = true;
8
- export let variant: "primary" | "secondary" | "stop" | "huggingface" =
9
- "secondary";
10
- export let size: "sm" | "md" | "lg" = "lg";
11
- export let value: string | null = null;
12
- export let link: string | null = null;
13
- export let link_target: "_self" | "_blank" | "_parent" | "_top" = "_self";
14
- export let icon: FileData | null = null;
15
- export let disabled = false;
16
- export let scale: number | null = null;
17
- export let min_width: number | undefined = undefined;
4
+ import { type Snippet } from "svelte";
5
+
6
+ let {
7
+ elem_id,
8
+ elem_classes = [],
9
+ visible,
10
+ variant,
11
+ size,
12
+ value,
13
+ link,
14
+ link_target,
15
+ icon,
16
+ disabled,
17
+ scale,
18
+ min_width,
19
+ onclick = () => {},
20
+ children
21
+ }: {
22
+ elem_id: string | null;
23
+ elem_classes: string[] | null;
24
+ visible: boolean | "hidden";
25
+ variant: "primary" | "secondary" | "stop" | "huggingface";
26
+ size: "sm" | "md" | "lg";
27
+ value: string | null;
28
+ link: string | null;
29
+ link_target: "_self" | "_blank" | "_parent" | "_top";
30
+ icon: FileData | null;
31
+ disabled: boolean;
32
+ scale: number | null;
33
+ min_width: number | undefined;
34
+ onclick: () => void;
35
+ children?: Snippet;
36
+ } = $props();
18
37
  </script>
19
38
 
20
39
  {#if link && link.length > 0}
@@ -40,11 +59,13 @@
40
59
  restProps={{ alt: `${value} icon`, class: "button-icon" }}
41
60
  />
42
61
  {/if}
43
- <slot />
62
+ {#if children}
63
+ {@render children()}
64
+ {/if}
44
65
  </a>
45
66
  {:else}
46
67
  <button
47
- on:click
68
+ {onclick}
48
69
  class:hidden={visible === false || visible === "hidden"}
49
70
  class="{size} {variant} {elem_classes.join(' ')}"
50
71
  style:flex-grow={scale}
@@ -62,7 +83,9 @@
62
83
  src={icon.url}
63
84
  />
64
85
  {/if}
65
- <slot />
86
+ {#if children}
87
+ {@render children()}
88
+ {/if}
66
89
  </button>
67
90
  {/if}
68
91
 
@@ -1,43 +1,21 @@
1
1
  import { type FileData } from "@gradio/client";
2
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
- $$bindings?: Bindings;
5
- } & Exports;
6
- (internal: unknown, props: Props & {
7
- $$events?: Events;
8
- $$slots?: Slots;
9
- }): Exports & {
10
- $set?: any;
11
- $on?: any;
12
- };
13
- z_$$bindings?: Bindings;
14
- }
15
- type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
16
- default: any;
17
- } ? Props extends Record<string, never> ? any : {
18
- children?: any;
19
- } : {});
20
- declare const Button: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
21
- elem_id?: string;
22
- elem_classes?: string[];
23
- visible?: boolean | "hidden";
24
- variant?: "primary" | "secondary" | "stop" | "huggingface";
25
- size?: "sm" | "md" | "lg";
26
- value?: string | null;
27
- link?: string | null;
28
- link_target?: "_self" | "_blank" | "_parent" | "_top";
29
- icon?: FileData | null;
30
- disabled?: boolean;
31
- scale?: number | null;
32
- min_width?: number | undefined;
33
- }, {
34
- default: {};
35
- }>, {
36
- click: PointerEvent;
37
- } & {
38
- [evt: string]: CustomEvent<any>;
39
- }, {
40
- default: {};
41
- }, {}, string>;
42
- type Button = InstanceType<typeof Button>;
2
+ import { type Snippet } from "svelte";
3
+ type $$ComponentProps = {
4
+ elem_id: string | null;
5
+ elem_classes: string[] | null;
6
+ visible: boolean | "hidden";
7
+ variant: "primary" | "secondary" | "stop" | "huggingface";
8
+ size: "sm" | "md" | "lg";
9
+ value: string | null;
10
+ link: string | null;
11
+ link_target: "_self" | "_blank" | "_parent" | "_top";
12
+ icon: FileData | null;
13
+ disabled: boolean;
14
+ scale: number | null;
15
+ min_width: number | undefined;
16
+ onclick: () => void;
17
+ children?: Snippet;
18
+ };
19
+ declare const Button: import("svelte").Component<$$ComponentProps, {}, "">;
20
+ type Button = ReturnType<typeof Button>;
43
21
  export default Button;
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@gradio/button",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
7
7
  "license": "ISC",
8
8
  "private": false,
9
9
  "dependencies": {
10
- "@gradio/client": "^2.0.1",
11
- "@gradio/utils": "^0.11.0",
12
- "@gradio/upload": "^0.17.3",
13
- "@gradio/image": "^0.25.0"
10
+ "@gradio/client": "^2.0.3",
11
+ "@gradio/image": "^0.25.1",
12
+ "@gradio/upload": "^0.17.4",
13
+ "@gradio/utils": "^0.11.2"
14
14
  },
15
15
  "devDependencies": {
16
- "@gradio/preview": "^0.15.1"
16
+ "@gradio/preview": "^0.15.2"
17
17
  },
18
18
  "main": "./Index.svelte",
19
19
  "main_changeset": true,
@@ -26,7 +26,7 @@
26
26
  }
27
27
  },
28
28
  "peerDependencies": {
29
- "svelte": "^5.43.4"
29
+ "svelte": "^5.48.0"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
@@ -1,20 +1,39 @@
1
1
  <script lang="ts">
2
2
  import { type FileData } from "@gradio/client";
3
3
  import { Image } from "@gradio/image/shared";
4
-
5
- export let elem_id = "";
6
- export let elem_classes: string[] = [];
7
- export let visible: boolean | "hidden" = true;
8
- export let variant: "primary" | "secondary" | "stop" | "huggingface" =
9
- "secondary";
10
- export let size: "sm" | "md" | "lg" = "lg";
11
- export let value: string | null = null;
12
- export let link: string | null = null;
13
- export let link_target: "_self" | "_blank" | "_parent" | "_top" = "_self";
14
- export let icon: FileData | null = null;
15
- export let disabled = false;
16
- export let scale: number | null = null;
17
- export let min_width: number | undefined = undefined;
4
+ import { type Snippet } from "svelte";
5
+
6
+ let {
7
+ elem_id,
8
+ elem_classes = [],
9
+ visible,
10
+ variant,
11
+ size,
12
+ value,
13
+ link,
14
+ link_target,
15
+ icon,
16
+ disabled,
17
+ scale,
18
+ min_width,
19
+ onclick = () => {},
20
+ children
21
+ }: {
22
+ elem_id: string | null;
23
+ elem_classes: string[] | null;
24
+ visible: boolean | "hidden";
25
+ variant: "primary" | "secondary" | "stop" | "huggingface";
26
+ size: "sm" | "md" | "lg";
27
+ value: string | null;
28
+ link: string | null;
29
+ link_target: "_self" | "_blank" | "_parent" | "_top";
30
+ icon: FileData | null;
31
+ disabled: boolean;
32
+ scale: number | null;
33
+ min_width: number | undefined;
34
+ onclick: () => void;
35
+ children?: Snippet;
36
+ } = $props();
18
37
  </script>
19
38
 
20
39
  {#if link && link.length > 0}
@@ -40,11 +59,13 @@
40
59
  restProps={{ alt: `${value} icon`, class: "button-icon" }}
41
60
  />
42
61
  {/if}
43
- <slot />
62
+ {#if children}
63
+ {@render children()}
64
+ {/if}
44
65
  </a>
45
66
  {:else}
46
67
  <button
47
- on:click
68
+ {onclick}
48
69
  class:hidden={visible === false || visible === "hidden"}
49
70
  class="{size} {variant} {elem_classes.join(' ')}"
50
71
  style:flex-grow={scale}
@@ -62,7 +83,9 @@
62
83
  src={icon.url}
63
84
  />
64
85
  {/if}
65
- <slot />
86
+ {#if children}
87
+ {@render children()}
88
+ {/if}
66
89
  </button>
67
90
  {/if}
68
91