# Geist Chat

The thread. It stays pinned to the newest message while a reply streams.

Build a Chat in this project that looks and behaves like Geist's. Measured from the running Geist app (vercel.com/geist). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or Base UI primitives if it has none.

Fidelity: Partly measured from the Vercel Agent thread on vercel.com/docs, light and dark. The 32px gap between turns and the scroll button are measured. The panel header (48px, title on the left, ghost icon buttons) and the 12px gray tip under the composer follow the Vercel Agent panel. The attach button stays hidden because neither the Vercel Agent nor v0 composer has one. The typing dots and the empty state are derived from Geist's Loading Dots and Empty State.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--ds-background-100` | `hsl(0 0% 100%)` | `hsl(0 0% 4%)` |
| `--ds-gray-900` | `hsl(0 0% 30%)` | `hsl(0 0% 63%)` |
| `--ds-gray-1000` | `hsl(0 0% 9%)` | `hsl(0 0% 93%)` |
| `--ds-gray-alpha-400` | `#00000014` | `#ffffff24` |
| `--ds-focus-color` | `oklch(57.61% 0.2508 258.23)` | `oklch(71.78% 0.1521 250.77)` |
| `--ds-focus-ring` | `0 0 0 2px var(--ds-background-100), 0 0 0 4px var(--ds-focus-color)` | `0 0 0 2px var(--ds-background-100), 0 0 0 4px var(--ds-focus-color)` |
| `--ds-shadow-border` | `0 0 0 1px #00000014, 0 0 0 1px var(--ds-background-200)` | `0 0 0 1px #ffffff25, 0 0 0 1px #000` |
| `--ds-primary-hover` | `hsl(0 0% 22%)` | `hsl(0 0% 80%)` |
| `--ease-in-out` | `cubic-bezier(0.4, 0, 0.2, 1)` | `cubic-bezier(0.4, 0, 0.2, 1)` |
| `--default-transition-duration` | `0.15s` | `0.15s` |
| `--font-size-micro` | `0.75rem` | `0.75rem` |
| `--font-size-small` | `0.875rem` | `0.875rem` |
| `--font-size-regular` | `1rem` | `1rem` |
| `--font-weight-semibold` | `600` | `600` |
| `--radius-menu` | `12px` | `12px` |
| `--radius-rounded` | `9999px` | `9999px` |

## CSS

Scoped under `[data-style="geist"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="geist"] {
  .ui-chat {
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border-radius: var(--radius-menu);
    background-color: var(--ds-background-100);
    box-shadow: var(--ds-shadow-border);
    color: var(--ds-gray-1000);
    font-family: inherit;
    font-size: var(--font-size-small);
    line-height: 20px;
  }

  .ui-chat-header {
    box-sizing: border-box;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
    min-height: 48px;
    padding: 0 10px 0 16px;

    & .ui-button[data-variant="ghost"] {
      color: var(--ds-gray-900);
    }
  }

  .ui-chat-title {
    flex: 1;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--ds-gray-1000);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-semibold);
    line-height: 20px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ui-chat-viewport {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--ds-gray-alpha-400) transparent;
    outline: none;

    &:focus-visible {
      box-shadow: inset 0 0 0 2px var(--ds-focus-color);
    }
  }

  .ui-chat-content {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 8px 16px 24px;
  }

  .ui-chat-typing {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    gap: 4px;
    height: 20px;
    margin-top: -16px;
  }

  .ui-chat-typing-dot {
    width: 5px;
    height: 5px;
    border-radius: var(--radius-rounded);
    background-color: var(--ds-gray-900);
    animation: geist-chat-typing 1.4s var(--ease-in-out) infinite both;

    &:nth-child(2) {
      animation-delay: 0.2s;
    }

    &:nth-child(3) {
      animation-delay: 0.4s;
    }
  }

  .ui-chat-footer {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    gap: 8px;
    padding: 0 16px 12px;
  }

  .ui-chat-disclaimer {
    margin: 0;
    color: var(--ds-gray-900);
    font-size: var(--font-size-micro);
    line-height: 16px;
  }

  .ui-chat-scroll-button {
    position: relative;
    z-index: 1;
    align-self: center;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: -44px 0 12px;
    padding: 0;
    border: none;
    border-radius: var(--radius-rounded);
    background-color: var(--ds-gray-1000);
    color: var(--ds-background-100);
    cursor: pointer;
    transition: background-color var(--default-transition-duration) var(--ease-in-out);

    & svg {
      width: 16px;
      height: 16px;
    }

    &:focus-visible {
      outline: none;
      box-shadow: var(--ds-focus-ring);
    }

    @media (hover: hover) {
      &:hover {
        background-color: var(--ds-primary-hover);
      }
    }
  }

  .ui-chat-empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 48px 24px;
    text-align: center;
  }

  .ui-chat-empty-title {
    margin: 0;
    color: var(--ds-gray-1000);
    font-size: var(--font-size-regular);
    font-weight: var(--font-weight-semibold);
    line-height: 24px;
  }

  .ui-chat-empty-description {
    margin: 0;
    color: var(--ds-gray-900);
    font-size: var(--font-size-small);
    line-height: 20px;
  }

  @media (prefers-reduced-motion: reduce) {
    .ui-chat-scroll-button {
      transition: none;
    }

    .ui-chat-typing-dot {
      animation: none;
    }
  }
}

@keyframes geist-chat-typing {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }

  40% {
    opacity: 1;
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Button as BaseButton } from "@base-ui/react/button";
import {
  type ComponentProps,
  createContext,
  type RefObject,
  useContext,
  useEffect,
  useMemo,
  useRef,
  useState,
} from "react";
import { join } from "./utils";

type ChatState = {
  viewport: RefObject<HTMLDivElement | null>;
  atBottom: boolean;
  setAtBottom: (atBottom: boolean) => void;
};

const ChatContext = createContext<ChatState | null>(null);

function useChat() {
  const chat = useContext(ChatContext);
  if (!chat) throw new Error("Chat parts must be inside Chat.Root.");
  return chat;
}

function Root({ className, ...props }: ComponentProps<"div">) {
  const viewport = useRef<HTMLDivElement>(null);
  const [atBottom, setAtBottom] = useState(true);
  const value = useMemo(() => ({ viewport, atBottom, setAtBottom }), [atBottom]);
  return (
    <ChatContext value={value}>
      <div className={join("ui-chat", className)} {...props} />
    </ChatContext>
  );
}

function Viewport({ className, children, onScroll, ...props }: ComponentProps<"div">) {
  const { viewport, setAtBottom } = useChat();
  const content = useRef<HTMLDivElement>(null);
  const stuck = useRef(true);

  useEffect(() => {
    const element = viewport.current;
    if (!element || !content.current) return;
    element.scrollTop = element.scrollHeight;
    const observer = new ResizeObserver(() => {
      if (stuck.current) element.scrollTop = element.scrollHeight;
    });
    observer.observe(content.current);
    return () => observer.disconnect();
  }, [viewport]);

  return (
    <div
      ref={viewport}
      className={join("ui-chat-viewport", className)}
      onScroll={(event) => {
        const element = event.currentTarget;
        const bottom = element.scrollHeight - element.scrollTop - element.clientHeight < 8;
        stuck.current = bottom;
        setAtBottom(bottom);
        onScroll?.(event);
      }}
      {...props}
    >
      <div ref={content} className="ui-chat-content">
        {children}
      </div>
    </div>
  );
}

function ScrollButton({ className, children, ...props }: Omit<BaseButton.Props, "className"> & { className?: string }) {
  const { viewport, atBottom } = useChat();
  if (atBottom) return null;
  return (
    <BaseButton
      className={join("ui-chat-scroll-button", className)}
      aria-label="Scroll to latest message"
      onClick={() => viewport.current?.scrollTo({ top: viewport.current.scrollHeight, behavior: "smooth" })}
      {...props}
    >
      {children ?? (
        <svg viewBox="0 0 16 16" fill="none" aria-hidden>
          <path d="M8 3v10M4 9l4 4 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      )}
    </BaseButton>
  );
}

function Header({ className, ...props }: ComponentProps<"div">) {
  return <div className={join("ui-chat-header", className)} {...props} />;
}

function Title({ className, ...props }: ComponentProps<"h2">) {
  return <h2 className={join("ui-chat-title", className)} {...props} />;
}

function Footer({ className, ...props }: ComponentProps<"div">) {
  return <div className={join("ui-chat-footer", className)} {...props} />;
}

function Disclaimer({ className, ...props }: ComponentProps<"p">) {
  return <p className={join("ui-chat-disclaimer", className)} {...props} />;
}

function Typing({ className, ...props }: Omit<ComponentProps<"span">, "children">) {
  return (
    <span role="status" aria-label="Thinking" className={join("ui-chat-typing", className)} {...props}>
      <span className="ui-chat-typing-dot" />
      <span className="ui-chat-typing-dot" />
      <span className="ui-chat-typing-dot" />
    </span>
  );
}

function Empty({ className, ...props }: ComponentProps<"div">) {
  return <div className={join("ui-chat-empty", className)} {...props} />;
}

function EmptyTitle({ className, ...props }: ComponentProps<"h3">) {
  return <h3 className={join("ui-chat-empty-title", className)} {...props} />;
}

function EmptyDescription({ className, ...props }: ComponentProps<"p">) {
  return <p className={join("ui-chat-empty-description", className)} {...props} />;
}

export const Chat = {
  Root,
  Header,
  Title,
  Viewport,
  ScrollButton,
  Typing,
  Footer,
  Disclaimer,
  Empty,
  EmptyTitle,
  EmptyDescription,
};
```

## Example

```tsx
import { Button, Chat, Message, PromptInput, Reasoning } from "@replicas/ui";
import { type FormEvent, useEffect, useState } from "react";

type Turn = { id: number; from: "user" | "assistant"; text: string };

const opening: Turn[] = [
  { id: 1, from: "user", text: "Why does the deploy take seven minutes?" },
  {
    id: 2,
    from: "assistant",
    text: "Image optimisation takes almost four of them. It reruns on every deploy because the cache key includes the commit hash, so nothing is reused between builds.",
  },
  { id: 3, from: "user", text: "Can we key it on the image contents instead?" },
  {
    id: 4,
    from: "assistant",
    text: "Yes. Hash each source file and use that as the key. Unchanged images then come straight from the cache, which should bring the step down to a few seconds.",
  },
];

export default function ChatDemo() {
  const [turns, setTurns] = useState(opening);
  const [text, setText] = useState("");
  const [typing, setTyping] = useState(false);

  useEffect(() => {
    if (!typing) return;
    const timer = setTimeout(() => {
      setTurns((current) => [...current, { id: current.length + 1, from: "assistant", text: "I'll look into that next." }]);
      setTyping(false);
    }, 1500);
    return () => clearTimeout(timer);
  }, [typing]);

  const send = (event: FormEvent) => {
    event.preventDefault();
    if (!text.trim() || typing) return;
    setTurns((current) => [...current, { id: current.length + 1, from: "user", text }]);
    setText("");
    setTyping(true);
  };

  return (
    <Chat.Root style={{ width: "100%", maxWidth: 520, height: 480 }}>
      <Chat.Header>
        <Chat.Title>Assistant</Chat.Title>
        <Button variant="ghost" size="small" iconOnly aria-label="New chat">
          <svg viewBox="0 0 16 16" fill="none" aria-hidden>
            <path d="M8 3.5v9M3.5 8h9" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
          </svg>
        </Button>
        <Button variant="ghost" size="small" iconOnly aria-label="Close">
          <svg viewBox="0 0 16 16" fill="none" aria-hidden>
            <path d="M4.5 4.5l7 7M11.5 4.5l-7 7" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
          </svg>
        </Button>
      </Chat.Header>
      <Chat.Viewport>
        {turns.map((turn) =>
          turn.from === "user" ? (
            <Message.Root key={turn.id} from="user">
              <Message.Content>{turn.text}</Message.Content>
            </Message.Root>
          ) : (
            <Message.Root key={turn.id}>
              <Message.Content>
                {turn.id === 2 ? (
                  <Reasoning.Root>
                    <Reasoning.Trigger description="4s">Thought</Reasoning.Trigger>
                    <Reasoning.Content>The build log shows where the time goes.</Reasoning.Content>
                  </Reasoning.Root>
                ) : null}
                <p>{turn.text}</p>
              </Message.Content>
            </Message.Root>
          ),
        )}
        {typing ? <Chat.Typing /> : null}
      </Chat.Viewport>
      <Chat.ScrollButton />
      <Chat.Footer>
        <PromptInput.Root onSubmit={send}>
          <PromptInput.Textarea
            aria-label="Message"
            placeholder="Reply…"
            value={text}
            onChange={(event) => setText(event.target.value)}
          />
          <PromptInput.Footer>
            <PromptInput.Tools>
              <PromptInput.Button iconOnly aria-label="Add files">
                <svg viewBox="0 0 16 16" fill="none" aria-hidden>
                  <path d="M8 3.5v9M3.5 8h9" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
                </svg>
              </PromptInput.Button>
            </PromptInput.Tools>
            <PromptInput.Actions>
              <PromptInput.Button iconOnly aria-label="Dictate">
                <svg viewBox="0 0 16 16" fill="none" aria-hidden>
                  <rect x="6" y="2" width="4" height="7.5" rx="2" stroke="currentColor" strokeWidth="1.25" />
                  <path d="M3.75 7.5a4.25 4.25 0 0 0 8.5 0M8 11.75V14" stroke="currentColor" strokeWidth="1.25" strokeLinecap="round" />
                </svg>
              </PromptInput.Button>
            </PromptInput.Actions>
            <PromptInput.Submit empty={!text.trim()} disabled={!text.trim()} />
          </PromptInput.Footer>
        </PromptInput.Root>
        <Chat.Disclaimer>Answers can be wrong. Check anything important.</Chat.Disclaimer>
      </Chat.Footer>
    </Chat.Root>
  );
}
```

## Foundations

The rest of the Geist style, as a skill: https://replicas.raphaelsalaja.com/skills/geist/SKILL.md