Skip to content

Commit 8530b6e

Browse files
hannahblairgradio-pr-bot
andauthoredDec 4, 2024··
Redesign pending bubble in Chatbot (#10099)
* redesign pending bubble in chatbot * add changeset * add minwidth to image frame * add changeset * adjust bubble margin for avatars * ensure iconbuttonwrapper doesnt get cut off --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent ce5680f commit 8530b6e

File tree

4 files changed

+118
-41
lines changed

4 files changed

+118
-41
lines changed
 

‎.changeset/purple-rivers-cry.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@gradio/chatbot": minor
3+
"@gradio/image": minor
4+
"gradio": minor
5+
---
6+
7+
feat:Redesign pending bubble in Chatbot

‎js/chatbot/shared/ChatBot.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
/>
356356
{/each}
357357
{#if pending_message}
358-
<Pending {layout} />
358+
<Pending {layout} {avatar_images} />
359359
{:else}
360360
{@const options = get_last_bot_options()}
361361
{#if options}

‎js/chatbot/shared/Pending.svelte

+109-40
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,129 @@
11
<script lang="ts">
2+
import { Image } from "@gradio/image/shared";
3+
import type { FileData } from "@gradio/client";
4+
25
export let layout = "bubble";
6+
export let avatar_images: [FileData | null, FileData | null] = [null, null];
37
</script>
48

5-
<div
6-
class="message pending"
7-
role="status"
8-
aria-label="Loading response"
9-
aria-live="polite"
10-
style:border-radius={layout === "bubble" ? "var(--radius-xxl)" : "none"}
11-
>
12-
<span class="sr-only">Loading content</span>
13-
<div class="dot-flashing" />
14-
&nbsp;
15-
<div class="dot-flashing" />
16-
&nbsp;
17-
<div class="dot-flashing" />
9+
<div class="container">
10+
{#if avatar_images[1] !== null}
11+
<div class="avatar-container">
12+
<Image class="avatar-image" src={avatar_images[1].url} alt="bot avatar" />
13+
</div>
14+
{/if}
15+
16+
<div
17+
class="message bot pending {layout}"
18+
class:with_avatar={avatar_images[1] !== null}
19+
class:with_opposite_avatar={avatar_images[0] !== null}
20+
role="status"
21+
aria-label="Loading response"
22+
aria-live="polite"
23+
>
24+
<div class="message-content">
25+
<span class="sr-only">Loading content</span>
26+
<div class="dots">
27+
<div class="dot" />
28+
<div class="dot" />
29+
<div class="dot" />
30+
</div>
31+
</div>
32+
</div>
1833
</div>
1934

2035
<style>
21-
.pending {
22-
background: var(--color-accent-soft);
36+
.container {
2337
display: flex;
24-
flex-direction: row;
25-
justify-content: center;
26-
align-items: center;
27-
align-self: center;
28-
gap: 2px;
38+
margin: calc(var(--spacing-xl) * 2);
39+
}
40+
41+
.bubble.pending {
42+
border-width: 1px;
43+
border-radius: var(--radius-lg);
44+
border-bottom-left-radius: 0;
45+
border-color: var(--border-color-primary);
46+
background-color: var(--background-fill-secondary);
47+
box-shadow: var(--shadow-drop);
48+
align-self: flex-start;
49+
width: fit-content;
50+
margin-bottom: var(--spacing-xl);
51+
}
52+
53+
.bubble.with_opposite_avatar {
54+
margin-right: calc(var(--spacing-xxl) + 35px + var(--spacing-xxl));
55+
}
56+
57+
.panel.pending {
58+
margin: 0;
59+
padding: calc(var(--spacing-lg) * 2) calc(var(--spacing-lg) * 2);
2960
width: 100%;
30-
height: var(--size-16);
61+
border: none;
62+
background: none;
63+
box-shadow: none;
64+
border-radius: 0;
3165
}
32-
.dot-flashing {
33-
animation: flash 1s infinite ease-in-out;
34-
border-radius: 5px;
66+
67+
.panel.with_avatar {
68+
padding-left: calc(var(--spacing-xl) * 2) !important;
69+
padding-right: calc(var(--spacing-xl) * 2) !important;
70+
}
71+
72+
.avatar-container {
73+
align-self: flex-start;
74+
position: relative;
75+
display: flex;
76+
justify-content: flex-start;
77+
align-items: flex-start;
78+
width: 35px;
79+
height: 35px;
80+
flex-shrink: 0;
81+
bottom: 0;
82+
border-radius: 50%;
83+
border: 1px solid var(--border-color-primary);
84+
margin-right: var(--spacing-xxl);
85+
}
86+
87+
.message-content {
88+
padding: var(--spacing-sm) var(--spacing-xl);
89+
min-height: var(--size-8);
90+
display: flex;
91+
align-items: center;
92+
}
93+
94+
.dots {
95+
display: flex;
96+
gap: var(--spacing-xs);
97+
align-items: center;
98+
}
99+
100+
.dot {
101+
width: var(--size-1-5);
102+
height: var(--size-1-5);
103+
margin-right: var(--spacing-xs);
104+
border-radius: 50%;
35105
background-color: var(--body-text-color);
36-
width: 7px;
37-
height: 7px;
38-
color: var(--body-text-color);
106+
opacity: 0.5;
107+
animation: pulse 1.5s infinite;
108+
}
109+
110+
.dot:nth-child(2) {
111+
animation-delay: 0.2s;
39112
}
40-
@keyframes flash {
113+
114+
.dot:nth-child(3) {
115+
animation-delay: 0.4s;
116+
}
117+
118+
@keyframes pulse {
41119
0%,
42120
100% {
43-
opacity: 0;
121+
opacity: 0.4;
122+
transform: scale(1);
44123
}
45124
50% {
46125
opacity: 1;
126+
transform: scale(1.1);
47127
}
48128
}
49-
50-
.dot-flashing:nth-child(1) {
51-
animation-delay: 0s;
52-
}
53-
54-
.dot-flashing:nth-child(2) {
55-
animation-delay: 0.33s;
56-
}
57-
.dot-flashing:nth-child(3) {
58-
animation-delay: 0.66s;
59-
}
60129
</style>

‎js/image/shared/ImagePreview.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
.image-container {
117117
height: 100%;
118118
position: relative;
119+
min-width: var(--size-20);
119120
}
120121
121122
.image-container button {

0 commit comments

Comments
 (0)
Please sign in to comment.