@gradio/tabs 0.1.0 → 0.2.0
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.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/shared/Tabs.svelte +59 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @gradio/tabs
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#7018](https://github.com/gradio-app/gradio/pull/7018) [`ec28b4e`](https://github.com/gradio-app/gradio/commit/ec28b4e7c47a9233d9e3a725cc9fe8f9044dfa94) - Add `visible` and `interactive` params to `gr.Tab()`. Thanks [@hannahblair](https://github.com/hannahblair)!
|
|
8
|
+
|
|
3
9
|
## 0.1.0
|
|
4
10
|
|
|
5
11
|
### Features
|
package/package.json
CHANGED
package/shared/Tabs.svelte
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<script lang="ts">
|
|
6
|
-
import { setContext, createEventDispatcher
|
|
6
|
+
import { setContext, createEventDispatcher } from "svelte";
|
|
7
7
|
import { writable } from "svelte/store";
|
|
8
8
|
import type { SelectData } from "@gradio/utils";
|
|
9
9
|
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
name: string;
|
|
12
12
|
id: object;
|
|
13
13
|
elem_id: string | undefined;
|
|
14
|
+
visible: boolean;
|
|
15
|
+
interactive: boolean;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export let visible = true;
|
|
@@ -29,8 +31,28 @@
|
|
|
29
31
|
|
|
30
32
|
setContext(TABS, {
|
|
31
33
|
register_tab: (tab: Tab) => {
|
|
32
|
-
tabs.
|
|
33
|
-
|
|
34
|
+
let existingTab = tabs.find((t) => t.id === tab.id);
|
|
35
|
+
if (existingTab) {
|
|
36
|
+
// update existing tab with newer values
|
|
37
|
+
let i = tabs.findIndex((t) => t.id === tab.id);
|
|
38
|
+
tabs[i] = { ...tabs[i], ...tab };
|
|
39
|
+
} else {
|
|
40
|
+
tabs.push({
|
|
41
|
+
name: tab.name,
|
|
42
|
+
id: tab.id,
|
|
43
|
+
elem_id: tab.elem_id,
|
|
44
|
+
visible: tab.visible,
|
|
45
|
+
interactive: tab.interactive
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
selected_tab.update((current) => {
|
|
49
|
+
if (current === false && tab.visible && tab.interactive) {
|
|
50
|
+
return tab.id;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let nextTab = tabs.find((t) => t.visible && t.interactive);
|
|
54
|
+
return nextTab ? nextTab.id : current;
|
|
55
|
+
});
|
|
34
56
|
tabs = tabs;
|
|
35
57
|
return tabs.length - 1;
|
|
36
58
|
},
|
|
@@ -56,22 +78,35 @@
|
|
|
56
78
|
</script>
|
|
57
79
|
|
|
58
80
|
<div class="tabs {elem_classes.join(' ')}" class:hide={!visible} id={elem_id}>
|
|
59
|
-
<div class="tab-nav scroll-hide">
|
|
81
|
+
<div class="tab-nav scroll-hide" role="tablist">
|
|
60
82
|
{#each tabs as t, i (t.id)}
|
|
61
|
-
{#if t.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
{#if t.visible}
|
|
84
|
+
{#if t.id === $selected_tab}
|
|
85
|
+
<button
|
|
86
|
+
role="tab"
|
|
87
|
+
class="selected"
|
|
88
|
+
aria-selected={true}
|
|
89
|
+
aria-controls={t.elem_id}
|
|
90
|
+
id={t.elem_id ? t.elem_id + "-button" : null}
|
|
91
|
+
>
|
|
92
|
+
{t.name}
|
|
93
|
+
</button>
|
|
94
|
+
{:else}
|
|
95
|
+
<button
|
|
96
|
+
role="tab"
|
|
97
|
+
aria-selected={false}
|
|
98
|
+
aria-controls={t.elem_id}
|
|
99
|
+
disabled={!t.interactive}
|
|
100
|
+
aria-disabled={!t.interactive}
|
|
101
|
+
id={t.elem_id ? t.elem_id + "-button" : null}
|
|
102
|
+
on:click={() => {
|
|
103
|
+
change_tab(t.id);
|
|
104
|
+
dispatch("select", { value: t.name, index: i });
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
{t.name}
|
|
108
|
+
</button>
|
|
109
|
+
{/if}
|
|
75
110
|
{/if}
|
|
76
111
|
{/each}
|
|
77
112
|
</div>
|
|
@@ -107,6 +142,12 @@
|
|
|
107
142
|
font-size: var(--section-header-text-size);
|
|
108
143
|
}
|
|
109
144
|
|
|
145
|
+
button:disabled {
|
|
146
|
+
color: var(--body-text-color-subdued);
|
|
147
|
+
opacity: 0.5;
|
|
148
|
+
cursor: not-allowed;
|
|
149
|
+
}
|
|
150
|
+
|
|
110
151
|
button:hover {
|
|
111
152
|
color: var(--body-text-color);
|
|
112
153
|
}
|