Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Custom bot pictures: say which state the bot is in

erywim156db35c36b0
diff --git a/src/components/Avatar.test.ts b/src/components/Avatar.test.ts
index ff07ce26b2..51f1436c59 100644
--- a/src/components/Avatar.test.ts
+++ b/src/components/Avatar.test.ts
@@ -131,6 +131,15 @@ describe("theme hooks on faces", () => {
expect(render({})).not.toContain("data-avatar");
});
+ it("says which state a bot's custom picture is in, so a theme can show it", () => {
+ const picture = (state?: MausAvatarProps["state"]) => renderToStaticMarkup(createElement(BotAvatar, {
+ bot: { color: "green", avatarUrl: "/api/attachments/a.png", avatarCrop: "circle" }, animated: false, ...(state ? { state } : {}),
+ }));
+ expect(picture("working")).toMatch(/data-avatar="picture"[^>]*data-bot-state="working"/);
+ expect(picture("thinking")).toContain('data-bot-state="thinking"');
+ expect(picture(), "a picture with no state is idle").toContain('data-bot-state="idle"');
+ });
+
it("marks the person's picture and their initials", () => {
expect(renderToStaticMarkup(createElement(InitialsAvatar, { initials: "AL", avatarUrl: "/api/attachments/me.png" }))).toMatch(/<img data-avatar="picture" data-avatar-kind="person"/);
expect(renderToStaticMarkup(createElement(InitialsAvatar, { initials: "AL" }))).toMatch(/<div data-avatar="initials" data-avatar-kind="person"/);
diff --git a/src/components/Avatar.tsx b/src/components/Avatar.tsx
index ecc2988cb1..479b65bba6 100644
--- a/src/components/Avatar.tsx
+++ b/src/components/Avatar.tsx
@@ -286,6 +286,7 @@ export function BotAvatar({ bot, size = 44, label, readable = false, ...mascotPr
return (
<span
{...avatarMarks("bot", "picture")}
+ data-bot-state={mascotProps.state ?? "idle"}
className="relative block shrink-0 overflow-hidden bg-raised"
style={{ width: size, height: size, borderRadius: radius }}
>