Skip to content

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

Pill switcher: stays centred and clear of the controls, one plus, a softer edge before it

milind-sonib9713b6c28e0
diff --git a/DESIGN.md b/DESIGN.md
index d1221dfd23..7ad9acf907 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -47,7 +47,8 @@ where they belong instead of adding new places.
to show. One exception: **New thread** (a plus, also ⌘T) sits at the end of the
header in both modes, because starting a thread is an everyday action people
look for at the top. With Thread tabs on, the bot's threads take the pill's
- place in the header as tabs, with the plus at their end.
+ place in the header as tabs, with the plus at their end. With it off, Simple
+ mode's pill opens a bot's threads once it has two, and the plus sits at their end.
- **No count badges and no "needs you" summaries** above the sidebar list or
in the header. A status mark on the row it belongs to is fine.
- **Settings for one bot live in its bot panel.** App-wide settings live in
diff --git a/src/components/HeaderThreadTabs.tsx b/src/components/HeaderThreadTabs.tsx
index a0b06489eb..e6be6e0dd7 100644
--- a/src/components/HeaderThreadTabs.tsx
+++ b/src/components/HeaderThreadTabs.tsx
@@ -21,8 +21,12 @@ const FADE = 24;
* for them. */
export function useThreadTabsShown(botId: string): boolean {
const on = useFeature("threadTabs");
- const shown = useStoreSelector((state) => botShowsTabs(state.bots.find((bot) => bot.id === botId), state.newChat));
- return on && shown;
+ return useBotHasThreads(botId) && on;
+}
+
+/** Whether this bot has two threads or more to switch between, its blank New thread chat counted. */
+export function useBotHasThreads(botId: string): boolean {
+ return useStoreSelector((state) => botShowsTabs(state.bots.find((bot) => bot.id === botId), state.newChat));
}
/** A bot's threads as tabs in the chat header, once Thread tabs is on and the bot has two threads or more. */
@@ -34,13 +38,13 @@ export function HeaderThreadTabs({ bot }: { bot: Bot }) {
}
/** The mask that fades a sideways-scrolling row's edges where more of it is hidden, none when it all fits. */
-export function edgeFade(element: HTMLElement): string | undefined {
+export function edgeFade(element: HTMLElement, fade = FADE): string | undefined {
const room = element.scrollWidth - element.clientWidth;
if (room <= 1) return undefined;
const rtl = getComputedStyle(element).direction === "rtl";
const hiddenLeft = rtl ? room + element.scrollLeft : element.scrollLeft;
- const left = hiddenLeft > 1 ? "transparent 0, black " + FADE + "px" : "black 0";
- const right = room - hiddenLeft > 1 ? "black calc(100% - " + FADE + "px), transparent 100%" : "black 100%";
+ const left = hiddenLeft > 1 ? "transparent 0, black " + fade + "px" : "black 0";
+ const right = room - hiddenLeft > 1 ? "black calc(100% - " + fade + "px), transparent 100%" : "black 100%";
return `linear-gradient(to right, ${left}, ${right})`;
}
diff --git a/src/components/NewThreadHeaderButton.tsx b/src/components/NewThreadHeaderButton.tsx
index 5fede89f35..102aa6ca34 100644
--- a/src/components/NewThreadHeaderButton.tsx
+++ b/src/components/NewThreadHeaderButton.tsx
@@ -2,11 +2,15 @@ import { Plus } from "lucide-react";
import { t } from "@/lib/i18n";
import { cn } from "@/lib/cn";
import { useStoreDispatch } from "@/state/store-select";
-import { useThreadTabsShown } from "./HeaderThreadTabs";
+import { useAdvancedMode } from "@/lib/interface-mode";
+import { useBotHasThreads, useThreadTabsShown } from "./HeaderThreadTabs";
export function NewThreadHeaderButton({ botId }: { botId: string }) {
const dispatch = useStoreDispatch();
- const givesWay = useThreadTabsShown(botId);
+ const tabs = useThreadTabsShown(botId);
+ const simplePill = !useAdvancedMode() && window.ogb?.remoteClient?.active !== true;
+ const pillHasIt = useBotHasThreads(botId) && simplePill;
+ if (pillHasIt) return null;
return (
<button
type="button"
@@ -15,7 +19,7 @@ export function NewThreadHeaderButton({ botId }: { botId: string }) {
aria-label={t("task.newShort")}
aria-keyshortcuts="Meta+T Control+T"
title={t("task.newShort")}
- className={cn(givesWay && "md:hidden", "flex size-9 shrink-0 items-center justify-center rounded-full text-ink-secondary transition-colors duration-[120ms] hover:bg-ink/[0.06] hover:text-ink active:bg-ink/[0.08] motion-reduce:transition-none")}
+ className={cn(tabs && "md:hidden", "flex size-9 shrink-0 items-center justify-center rounded-full text-ink-secondary transition-colors duration-[120ms] hover:bg-ink/[0.06] hover:text-ink active:bg-ink/[0.08] motion-reduce:transition-none")}
>
<Plus size={16} aria-hidden="true" />
</button>
diff --git a/src/components/ThreadSwitcherPill.tsx b/src/components/ThreadSwitcherPill.tsx
index 964fa69a17..de2b0dcc58 100644
--- a/src/components/ThreadSwitcherPill.tsx
+++ b/src/components/ThreadSwitcherPill.tsx
@@ -12,10 +12,26 @@ import { reducedMotion } from "./MenuMotion";
import { openTabId, type ThreadTab } from "./thread-tabs";
const RESIZE_MS = 240;
+const LIST_FADE = 40;
+const CLEAR_OF_CONTROLS = 24;
+const WIDEST = 720;
const EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
const PART = "flex h-full min-w-0 items-center rounded-full outline-none transition-colors duration-[120ms] hover:bg-ink/[0.06] active:bg-ink/[0.08] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus motion-reduce:transition-none";
const CHIP = "flex h-7 max-w-42 shrink-0 items-center gap-1.5 rounded-full px-3 text-[13px] leading-[18px] outline-none transition-colors duration-[120ms] focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus motion-reduce:transition-none";
+/** The widest the open pill may be while staying centred in the header and clear of the controls on either side. */
+function centredRoom(pill: HTMLElement): number {
+ const row = pill.closest("[data-chathead-row]");
+ const centre = row ? row.getBoundingClientRect().left + row.getBoundingClientRect().width / 2 : 0;
+ let half = row ? row.getBoundingClientRect().width / 2 : WIDEST / 2;
+ for (const side of row?.querySelectorAll<HTMLElement>("[data-chathead-controls]") ?? []) {
+ const box = side.getBoundingClientRect();
+ if (box.width === 0) continue;
+ half = Math.min(half, box.left >= centre ? box.left - centre : centre - box.right);
+ }
+ return Math.max(0, Math.min(WIDEST, 2 * (half - CLEAR_OF_CONTROLS)));
+}
+
export const tabTitle = (tab: ThreadTab): string => (tab.draft ? t("task.newShort") : !tab.title || tab.title === "New thread" ? t("task.untitledChat") : localizedTaskTitle(tab.title));
/** The pill's width glides from what it was to what its new content needs, then lets go. */
@@ -51,6 +67,7 @@ export function ThreadSwitcherPill({ bot, tabs, head, label, panelOpen, onToggle
}) {
const dispatch = useStoreDispatch();
const [open, setOpen] = useState(false);
+ const [room, setRoom] = useState(WIDEST);
const box = useGlidingWidth(open);
const list = useRef<HTMLDivElement>(null);
const toggle = useRef<HTMLButtonElement>(null);
@@ -66,8 +83,10 @@ export function ThreadSwitcherPill({ bot, tabs, head, label, panelOpen, onToggle
useEffect(() => {
if (!open) return;
const away = (event: PointerEvent) => { if (!box.current?.contains(event.target as Node)) setOpen(false); };
+ const resize = () => { if (box.current) setRoom(centredRoom(box.current)); };
document.addEventListener("pointerdown", away);
- return () => document.removeEventListener("pointerdown", away);
+ window.addEventListener("resize", resize);
+ return () => { document.removeEventListener("pointerdown", away); window.removeEventListener("resize", resize); };
}, [open]);
useLayoutEffect(() => {
if (!open || !list.current) return;
@@ -77,7 +96,7 @@ export function ThreadSwitcherPill({ bot, tabs, head, label, panelOpen, onToggle
chip?.focus({ preventScroll: true });
const settle = window.setTimeout(() => {
chip?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
- setFade(edgeFade(row));
+ setFade(edgeFade(row, LIST_FADE));
}, reducedMotion() ? 0 : RESIZE_MS);
return () => window.clearTimeout(settle);
}, [open]);
@@ -101,7 +120,7 @@ export function ThreadSwitcherPill({ bot, tabs, head, label, panelOpen, onToggle
return (
<div ref={box} data-chathead-switch={open ? "open" : "closed"} onKeyDown={open ? onKey : undefined}
- className={cn("flex h-[39px] min-w-0 max-w-full items-center overflow-hidden rounded-full p-[5.5px] text-ink", ELEVATED_FLOAT, open && "max-w-[min(720px,100cqw_-_34rem)]")}>
+ className={cn("flex h-[39px] min-w-0 items-center overflow-hidden rounded-full p-[5.5px] text-ink", ELEVATED_FLOAT, !open && "max-w-full")} style={open ? { maxWidth: room } : undefined}>
{open ? (
<div key="open" className="flex min-w-0 animate-fade-in items-center gap-1 motion-reduce:animate-none">
<button type="button" data-chathead-pill data-tour="bot-pill" onClick={onToggle} title={t("chat.openBotPanel")} aria-label={label}
@@ -109,7 +128,7 @@ export function ThreadSwitcherPill({ bot, tabs, head, label, panelOpen, onToggle
{head}
</button>
<div ref={list} role="listbox" aria-label={t("task.namedList", { name: bot.name })} aria-orientation="horizontal"
- onScroll={(event) => setFade(edgeFade(event.currentTarget))} style={{ maskImage: fade, WebkitMaskImage: fade }}
+ onScroll={(event) => setFade(edgeFade(event.currentTarget, LIST_FADE))} style={{ maskImage: fade, WebkitMaskImage: fade }}
className="flex min-w-0 items-center gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
{tabs.map((tab) => {
const selected = tab.threadId === active;
@@ -140,7 +159,7 @@ export function ThreadSwitcherPill({ bot, tabs, head, label, panelOpen, onToggle
{head}
</button>
<button ref={toggle} type="button" data-chathead-threads aria-haspopup="listbox" aria-expanded={false}
- aria-label={t("task.namedList", { name: bot.name })} onClick={() => setOpen(true)}
+ aria-label={t("task.namedList", { name: bot.name })} onClick={() => { if (box.current) setRoom(centredRoom(box.current)); setOpen(true); }}
className={cn(PART, "gap-1.5 pe-2.5 ps-1.5 text-[14px] font-medium leading-5 text-ink-secondary hover:text-ink")}>
<span aria-hidden="true" className="text-ink-tertiary">·</span>
<span data-chathead-conversation dir="auto" className="min-w-0 max-w-[180px] truncate">{current ? tabTitle(current) : ""}</span>