# Sidebar (/docs/agent-ui/components/sidebar)

Use a sidebar for what sits beside the page, like a list of chats at the start or an assistant docked at the end. It's built on UI SDK Resizable beside the page and UI SDK Drawer on narrow screens.

Here's a whole chat app in one sidebar: [Thread Search](./thread-search.mdx) and a [Thread List](./thread-list.mdx) in the panel, and in the page a [Conversation](./conversation.mdx) of [Messages](./message.mdx) between [Day Separators](./day-separator.mdx), with [Conversation Search](./conversation-search.mdx) over it, a [Connection Status](./connection-status.mdx) that shows while the browser is offline, and the [Composer](./composer.mdx#controls-and-narrow-screens) with every control.

<Example caption="Open a chat from the list, or press Search chats to find one. Press the search button in the header to find text in this chat, and type a prompt to add it. Under 768px wide, the chats move into a drawer that the button beside the title opens.">
  <ChatShellExample />

  ```tsx tab="React"
  "use client";
  import type { MessageAuthor, Thread } from "@kind-ui/agent-ui";
  import { createConversationController, dayKey, isContinuation } from "@kind-ui/agent-ui/core";
  import { memo, useMemo, useState, useSyncExternalStore } from "react";
  import { ConnectionStatus } from "@/components/ui/connection-status";
  import {
    Conversation,
    ConversationContent,
    ConversationEmpty,
    ConversationEmptyDescription,
    ConversationEmptyTitle,
    ConversationJump,
    ConversationMarks,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/conversation";
  import { ConversationSearch } from "@/components/ui/conversation-search";
  import { DaySeparator } from "@/components/ui/day-separator";
  import { Markdown } from "@/components/ui/markdown";
  import {
    Message,
    MessageAuthor as MessageAuthorName,
    MessageAvatar,
    MessageContent,
    MessageHeader,
    MessageTime,
  } from "@/components/ui/message";
  import { Sidebar, SidebarHandle, SidebarInset, SidebarPanel, SidebarTrigger } from "@/components/ui/sidebar";
  import { ThreadList } from "@/components/ui/thread-list";
  import { ThreadSearch } from "@/components/ui/thread-search";
  import FullComposer from "../composer/full";

  const now = "2026-11-18T12:00:00Z";
  const timeZone = "UTC";

  type Line = {
    id: string;
    role: "user" | "assistant";
    text: string;
    createdAt: string;
    author?: MessageAuthor;
  };

  const assistant: MessageAuthor = { id: "assistant", name: "Assistant" };

  const initialThreads: Thread[] = (
    [
      { id: "release", title: "Release checklist", updatedAt: "2026-11-10T09:00:00Z", pinned: true },
      { id: "export", title: "Nightly export timeouts", updatedAt: "2026-11-18T10:30:00Z" },
      { id: "launch", title: "Draft the launch post", updatedAt: "2026-11-18T08:00:00Z", status: "running" },
      { id: "build", title: "Why the build is slow", updatedAt: "2026-11-17T16:00:00Z", unread: true },
      { id: "tests", title: "Flaky checkout tests", updatedAt: "2026-11-14T09:20:00Z" },
      { id: "pricing", title: "Compare pricing tiers", updatedAt: "2026-11-02T18:40:00Z" },
      { id: "schema", title: "Migrate the user schema", updatedAt: "2026-09-21T14:00:00Z" },
    ] satisfies Thread[]
  ).map((thread) => ({ ...thread, href: `#${thread.id}` }));

  const initialLines: Record<string, Line[]> = {
    export: [
      {
        id: "m1",
        role: "user",
        createdAt: "2026-11-17T17:40:00Z",
        text: "The nightly **billing** export failed again. Can you take a look?",
      },
      {
        id: "m2",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-17T17:41:00Z",
        text: "Since Wednesday, every run has stopped after 30 seconds waiting on the reports service:\n\n- its median response time went from 4 to 41 seconds\n- it was slow, not down",
      },
      {
        id: "m3",
        role: "user",
        createdAt: "2026-11-18T10:28:00Z",
        text: "Did last night's run go through?",
      },
      {
        id: "m4",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-18T10:29:00Z",
        text: "Yes. It retried two pages with backoff and finished in 48 minutes.",
      },
      {
        id: "m5",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-18T10:30:00Z",
        text: "I also opened a pull request that alerts when a **billing** run takes longer than an hour.",
      },
    ],
  };

  type Row = { id: string; date: string } | { id: string; line: Line; continued: boolean };

  // A day separator goes before the first message of each day, so it takes a row of its own.
  const toRows = (lines: Line[]): Row[] =>
    lines.flatMap((line, index): Row[] => {
      const previous = lines[index - 1];
      const row = {
        id: line.id,
        line,
        continued: isContinuation(previous, line),
      };
      return previous && dayKey(previous.createdAt, timeZone) === dayKey(line.createdAt, timeZone)
        ? [row]
        : [{ id: `day-${dayKey(line.createdAt, timeZone)}`, date: line.createdAt }, row];
    });

  const ChatRow = memo(function ChatRow({ row, index }: { row: Row; index: number }) {
    return (
      <ConversationRow value={row.id} index={index}>
        {"line" in row ? (
          <Message
            aria-label={row.line.role === "user" ? "Your message" : "Assistant message"}
            messageRole={row.line.role}
            text={row.line.text}
            author={row.line.author}
            continued={row.continued}
            createdAt={row.line.createdAt}
            now={now}
            timeZone={timeZone}
          >
            {row.line.author && (
              <>
                <MessageAvatar />
                <MessageHeader>
                  <MessageAuthorName />
                  <MessageTime />
                </MessageHeader>
              </>
            )}
            <MessageContent>
              <Markdown source={row.line.text} />
            </MessageContent>
          </Message>
        ) : (
          <DaySeparator date={row.date} timeZone={timeZone} relative={false} />
        )}
      </ConversationRow>
    );
  });

  const subscribe = (change: () => void) => {
    window.addEventListener("online", change);
    window.addEventListener("offline", change);
    return () => {
      window.removeEventListener("online", change);
      window.removeEventListener("offline", change);
    };
  };

  export default function ChatShellExample() {
    const [threads, setThreads] = useState(initialThreads);
    const [current, setCurrent] = useState("export");
    const [lines, setLines] = useState(initialLines);
    const [controller] = useState(createConversationController);
    const [searching, setSearching] = useState(false);
    const [marks, setMarks] = useState<readonly number[]>([]);
    const online = useSyncExternalStore(
      subscribe,
      () => navigator.onLine,
      () => true,
    );

    const thread = threads.find((item) => item.id === current);
    const rows = useMemo(() => toRows(lines[current] ?? []), [lines, current]);
    const searchable = useMemo(
      () => rows.map((row) => ({ id: row.id, text: "line" in row ? row.line.text : "" })),
      [rows],
    );
    const update = (id: string, change: Partial<Thread>) =>
      setThreads((items) => items.map((item) => (item.id === id ? { ...item, ...change } : item)));
    const open = (id: string) => {
      setCurrent(id);
      setSearching(false);
      update(id, { unread: false });
    };
    const create = (title: string) => {
      const id = crypto.randomUUID();
      setThreads((items) => [
        { id, title: title.trim() || "New chat", updatedAt: new Date().toISOString(), href: `#${id}` },
        ...items,
      ]);
      open(id);
    };
    const send = (text: string) => {
      const line: Line = {
        id: crypto.randomUUID(),
        role: "user",
        text,
        createdAt: new Date().toISOString(),
      };
      setLines((all) => ({ ...all, [current]: [...(all[current] ?? []), line] }));
      update(current, { updatedAt: line.createdAt });
    };

    return (
      <Sidebar label="Chats" defaultSize="200px" minSize="180px" className="h-[640px] w-full overflow-hidden">
        <SidebarPanel>
          <div className="flex h-12 shrink-0 items-center px-2">
            <ThreadSearch threads={threads} now={now} timeZone={timeZone} onSelect={open} onNew={create} />
          </div>
          <div className="flex min-h-0 flex-1 flex-col px-2 pb-2">
            <div className="min-h-0 flex-1">
              <ThreadList
                threads={threads}
                value={current}
                now={now}
                timeZone={timeZone}
                onSelect={(id, details) => {
                  details.cancel();
                  open(id);
                }}
                onNew={() => create("")}
                onRename={(id, { title }) => update(id, { title })}
                onPinChange={(id, { pinned }) => update(id, { pinned })}
                onDelete={(id) => {
                  const rest = threads.filter((item) => item.id !== id);
                  setThreads(rest);
                  if (id !== current) return;
                  if (rest[0]) open(rest[0].id);
                  else create("");
                }}
              />
            </div>
          </div>
        </SidebarPanel>
        <SidebarHandle />
        <SidebarInset className="bg-[var(--kind-color-raised)]">
          <header className="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
            <SidebarTrigger />
            <h2 className="m-0 min-w-0 flex-1 truncate text-sm font-medium">{thread?.title ?? "New chat"}</h2>
            <button
              type="button"
              data-kind-icon-button=""
              aria-label="Find in chat"
              title="Find in chat"
              onClick={() => setSearching(true)}
            >
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" aria-hidden="true">
                <circle cx="11" cy="11" r="8" />
                <path d="m21 21-4.3-4.3" />
              </svg>
            </button>
          </header>
          <div className="relative min-h-0 flex-1">
            <ConversationSearch
              messages={searchable}
              conversation={controller}
              open={searching}
              onOpenChange={setSearching}
              onMarksChange={setMarks}
            />
            <Conversation
              key={current}
              aria-label="Conversation"
              messageCount={rows.length}
              controller={controller}
              marks={marks}
              className="h-full"
            >
              <ConversationViewport>
                <ConversationContent>
                  {rows.map((row, index) => (
                    <ChatRow key={row.id} row={row} index={index} />
                  ))}
                  <ConversationEmpty>
                    <ConversationEmptyTitle>What can I help with?</ConversationEmptyTitle>
                    <ConversationEmptyDescription>
                      Ask anything to start this chat.
                    </ConversationEmptyDescription>
                  </ConversationEmpty>
                </ConversationContent>
              </ConversationViewport>
              <ConversationJump />
              <ConversationMarks />
              <ConnectionStatus state={online ? "online" : "offline"} />
            </Conversation>
          </div>
          <div className="mx-auto w-full max-w-[var(--kind-chat-max-width)] p-3">
            <FullComposer
              disabled={!online}
              placeholder={online ? "Ask anything…" : "Offline"}
              onSubmit={(draft) => send(draft.text)}
            />
          </div>
        </SidebarInset>
      </Sidebar>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import type { MessageAuthor, Thread } from "@kind-ui/agent-ui";
  import { createConversationController, dayKey, isContinuation } from "@kind-ui/agent-ui/core";
  import {
    computed,
    defineComponent,
    h,
    onBeforeUnmount,
    onMounted,
    type PropType,
    ref,
    shallowRef,
  } from "vue";
  import { ConnectionStatus } from "@/components/ui/vue/connection-status";
  import {
    Conversation,
    ConversationContent,
    ConversationEmpty,
    ConversationEmptyDescription,
    ConversationEmptyTitle,
    ConversationJump,
    ConversationMarks,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/vue/conversation";
  import { ConversationSearch } from "@/components/ui/vue/conversation-search";
  import { DaySeparator } from "@/components/ui/vue/day-separator";
  import { Markdown } from "@/components/ui/vue/markdown";
  import {
    Message,
    MessageAuthor as MessageAuthorName,
    MessageAvatar,
    MessageContent,
    MessageHeader,
    MessageTime,
  } from "@/components/ui/vue/message";
  import {
    Sidebar,
    SidebarHandle,
    SidebarInset,
    SidebarPanel,
    SidebarTrigger,
  } from "@/components/ui/vue/sidebar";
  import { ThreadList } from "@/components/ui/vue/thread-list";
  import { ThreadSearch } from "@/components/ui/vue/thread-search";
  import FullComposer from "../composer/full.vue";

  const now = "2026-11-18T12:00:00Z";
  const timeZone = "UTC";

  type Line = {
    id: string;
    role: "user" | "assistant";
    text: string;
    createdAt: string;
    author?: MessageAuthor;
  };

  const assistant: MessageAuthor = { id: "assistant", name: "Assistant" };

  const initialThreads: Thread[] = (
    [
      { id: "release", title: "Release checklist", updatedAt: "2026-11-10T09:00:00Z", pinned: true },
      { id: "export", title: "Nightly export timeouts", updatedAt: "2026-11-18T10:30:00Z" },
      { id: "launch", title: "Draft the launch post", updatedAt: "2026-11-18T08:00:00Z", status: "running" },
      { id: "build", title: "Why the build is slow", updatedAt: "2026-11-17T16:00:00Z", unread: true },
      { id: "tests", title: "Flaky checkout tests", updatedAt: "2026-11-14T09:20:00Z" },
      { id: "pricing", title: "Compare pricing tiers", updatedAt: "2026-11-02T18:40:00Z" },
      { id: "schema", title: "Migrate the user schema", updatedAt: "2026-09-21T14:00:00Z" },
    ] satisfies Thread[]
  ).map((thread) => ({ ...thread, href: `#${thread.id}` }));

  const initialLines: Record<string, Line[]> = {
    export: [
      {
        id: "m1",
        role: "user",
        createdAt: "2026-11-17T17:40:00Z",
        text: "The nightly **billing** export failed again. Can you take a look?",
      },
      {
        id: "m2",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-17T17:41:00Z",
        text: "Since Wednesday, every run has stopped after 30 seconds waiting on the reports service:\n\n- its median response time went from 4 to 41 seconds\n- it was slow, not down",
      },
      {
        id: "m3",
        role: "user",
        createdAt: "2026-11-18T10:28:00Z",
        text: "Did last night's run go through?",
      },
      {
        id: "m4",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-18T10:29:00Z",
        text: "Yes. It retried two pages with backoff and finished in 48 minutes.",
      },
      {
        id: "m5",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-18T10:30:00Z",
        text: "I also opened a pull request that alerts when a **billing** run takes longer than an hour.",
      },
    ],
  };

  type Row = { id: string; date: string } | { id: string; line: Line; continued: boolean };

  // A day separator goes before the first message of each day, so it takes a row of its own.
  const toRows = (lines: Line[]): Row[] =>
    lines.flatMap((line, index): Row[] => {
      const previous = lines[index - 1];
      const row = { id: line.id, line, continued: isContinuation(previous, line) };
      return previous && dayKey(previous.createdAt, timeZone) === dayKey(line.createdAt, timeZone)
        ? [row]
        : [{ id: `day-${dayKey(line.createdAt, timeZone)}`, date: line.createdAt }, row];
    });

  // Its own component, so a new row or search renders no row whose props stayed the same.
  const ChatRow = defineComponent({
    props: {
      row: { type: Object as PropType<Row>, required: true },
      index: { type: Number, required: true },
    },
    setup(props) {
      return () => {
        const { row } = props;
        return h(ConversationRow, { value: row.id, index: props.index }, () =>
          "line" in row
            ? h(
                Message,
                {
                  "aria-label": row.line.role === "user" ? "Your message" : "Assistant message",
                  messageRole: row.line.role,
                  text: row.line.text,
                  author: row.line.author,
                  continued: row.continued,
                  createdAt: row.line.createdAt,
                  now,
                  timeZone,
                },
                () => [
                  ...(row.line.author
                    ? [h(MessageAvatar), h(MessageHeader, null, () => [h(MessageAuthorName), h(MessageTime)])]
                    : []),
                  h(MessageContent, null, () => h(Markdown, { source: row.line.text })),
                ],
              )
            : h(DaySeparator, { date: row.date, timeZone, relative: false }),
        );
      };
    },
  });

  const threads = shallowRef(initialThreads);
  const current = ref("export");
  const lines = shallowRef(initialLines);
  const controller = createConversationController();
  const searching = ref(false);
  const marks = shallowRef<readonly number[]>([]);
  const online = ref(true);

  const readOnline = () => {
    online.value = navigator.onLine;
  };
  onMounted(() => {
    readOnline();
    window.addEventListener("online", readOnline);
    window.addEventListener("offline", readOnline);
  });
  onBeforeUnmount(() => {
    window.removeEventListener("online", readOnline);
    window.removeEventListener("offline", readOnline);
  });

  const thread = computed(() => threads.value.find((item) => item.id === current.value));
  const rows = computed(() => toRows(lines.value[current.value] ?? []));
  const searchable = computed(() =>
    rows.value.map((row) => ({ id: row.id, text: "line" in row ? row.line.text : "" })),
  );

  const update = (id: string, change: Partial<Thread>) => {
    threads.value = threads.value.map((item) => (item.id === id ? { ...item, ...change } : item));
  };
  const open = (id: string) => {
    current.value = id;
    searching.value = false;
    update(id, { unread: false });
  };
  const create = (title: string) => {
    const id = crypto.randomUUID();
    threads.value = [
      { id, title: title.trim() || "New chat", updatedAt: new Date().toISOString(), href: `#${id}` },
      ...threads.value,
    ];
    open(id);
  };
  const send = (draft: { text: string }) => {
    const line: Line = {
      id: crypto.randomUUID(),
      role: "user",
      text: draft.text,
      createdAt: new Date().toISOString(),
    };
    lines.value = { ...lines.value, [current.value]: [...(lines.value[current.value] ?? []), line] };
    update(current.value, { updatedAt: line.createdAt });
  };

  function onSelect(id: string, details: { cancel(): void }) {
    details.cancel();
    open(id);
  }
  const onRename = (id: string, { title }: { title: string }) => update(id, { title });
  const onPinChange = (id: string, { pinned }: { pinned: boolean }) => update(id, { pinned });
  const onDelete = (id: string) => {
    const rest = threads.value.filter((item) => item.id !== id);
    threads.value = rest;
    if (id !== current.value) return;
    if (rest[0]) open(rest[0].id);
    else create("");
  };
  </script>

  <template>
    <Sidebar label="Chats" default-size="200px" min-size="180px" class="h-[640px] w-full overflow-hidden">
      <SidebarPanel>
        <div class="flex h-12 shrink-0 items-center px-2">
          <ThreadSearch :threads="threads" :now="now" :time-zone="timeZone" @select="open" @new="create" />
        </div>
        <div class="flex min-h-0 flex-1 flex-col px-2 pb-2">
          <div class="min-h-0 flex-1">
            <ThreadList
              :threads="threads"
              :value="current"
              :now="now"
              :time-zone="timeZone"
              :on-rename="onRename"
              :on-delete="onDelete"
              @select="onSelect"
              @new="create('')"
              @pin-change="onPinChange"
            />
          </div>
        </div>
      </SidebarPanel>
      <SidebarHandle />
      <SidebarInset class="bg-[var(--kind-color-raised)]">
        <header class="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
          <SidebarTrigger />
          <h2 class="m-0 min-w-0 flex-1 truncate text-sm font-medium">{{ thread?.title ?? "New chat" }}</h2>
          <button
            type="button"
            data-kind-icon-button=""
            aria-label="Find in chat"
            title="Find in chat"
            @click="searching = true"
          >
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
              <circle cx="11" cy="11" r="8" />
              <path d="m21 21-4.3-4.3" />
            </svg>
          </button>
        </header>
        <div class="relative min-h-0 flex-1">
          <ConversationSearch
            v-model:open="searching"
            :messages="searchable"
            :conversation="controller"
            @marks-change="(next: readonly number[]) => (marks = next)"
          />
          <Conversation
            :key="current"
            aria-label="Conversation"
            :message-count="rows.length"
            :controller="controller"
            :marks="marks"
            class="h-full"
          >
            <ConversationViewport>
              <ConversationContent>
                <ChatRow v-for="(row, index) in rows" :key="row.id" :row="row" :index="index" />
                <ConversationEmpty>
                  <ConversationEmptyTitle>What can I help with?</ConversationEmptyTitle>
                  <ConversationEmptyDescription>Ask anything to start this chat.</ConversationEmptyDescription>
                </ConversationEmpty>
              </ConversationContent>
            </ConversationViewport>
            <ConversationJump />
            <ConversationMarks />
            <ConnectionStatus :state="online ? 'online' : 'offline'" />
          </Conversation>
        </div>
        <div class="mx-auto w-full max-w-[var(--kind-chat-max-width)] p-3">
          <FullComposer
            :disabled="!online"
            :placeholder="online ? 'Ask anything…' : 'Offline'"
            :on-submit="send"
          />
        </div>
      </SidebarInset>
    </Sidebar>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import type { MessageAuthor, Thread } from "@kind-ui/agent-ui";
    import { createConversationController, dayKey, isContinuation } from "@kind-ui/agent-ui/core";
    import { ConnectionStatus } from "@/components/ui/svelte/connection-status/index.js";
    import {
      Conversation,
      ConversationContent,
      ConversationEmpty,
      ConversationEmptyDescription,
      ConversationEmptyTitle,
      ConversationJump,
      ConversationMarks,
      ConversationRow,
      ConversationViewport,
    } from "@/components/ui/svelte/conversation/index.js";
    import { ConversationSearch } from "@/components/ui/svelte/conversation-search/index.js";
    import { DaySeparator } from "@/components/ui/svelte/day-separator/index.js";
    import { Markdown } from "@/components/ui/svelte/markdown/index.js";
    import {
      Message,
      MessageAuthor as MessageAuthorName,
      MessageAvatar,
      MessageContent,
      MessageHeader,
      MessageTime,
    } from "@/components/ui/svelte/message/index.js";
    import {
      Sidebar,
      SidebarHandle,
      SidebarInset,
      SidebarPanel,
      SidebarTrigger,
    } from "@/components/ui/svelte/sidebar/index.js";
    import { ThreadList } from "@/components/ui/svelte/thread-list/index.js";
    import { ThreadSearch } from "@/components/ui/svelte/thread-search/index.js";
    import FullComposer from "../composer/full.svelte";

    const now = "2026-11-18T12:00:00Z";
    const timeZone = "UTC";

    type Line = {
      id: string;
      role: "user" | "assistant";
      text: string;
      createdAt: string;
      author?: MessageAuthor;
    };

    const assistant: MessageAuthor = { id: "assistant", name: "Assistant" };

    const initialThreads: Thread[] = (
      [
        { id: "release", title: "Release checklist", updatedAt: "2026-11-10T09:00:00Z", pinned: true },
        { id: "export", title: "Nightly export timeouts", updatedAt: "2026-11-18T10:30:00Z" },
        { id: "launch", title: "Draft the launch post", updatedAt: "2026-11-18T08:00:00Z", status: "running" },
        { id: "build", title: "Why the build is slow", updatedAt: "2026-11-17T16:00:00Z", unread: true },
        { id: "tests", title: "Flaky checkout tests", updatedAt: "2026-11-14T09:20:00Z" },
        { id: "pricing", title: "Compare pricing tiers", updatedAt: "2026-11-02T18:40:00Z" },
        { id: "schema", title: "Migrate the user schema", updatedAt: "2026-09-21T14:00:00Z" },
      ] satisfies Thread[]
    ).map((thread) => ({ ...thread, href: `#${thread.id}` }));

    const initialLines: Record<string, Line[]> = {
      export: [
        {
          id: "m1",
          role: "user",
          createdAt: "2026-11-17T17:40:00Z",
          text: "The nightly **billing** export failed again. Can you take a look?",
        },
        {
          id: "m2",
          role: "assistant",
          author: assistant,
          createdAt: "2026-11-17T17:41:00Z",
          text: "Since Wednesday, every run has stopped after 30 seconds waiting on the reports service:\n\n- its median response time went from 4 to 41 seconds\n- it was slow, not down",
        },
        {
          id: "m3",
          role: "user",
          createdAt: "2026-11-18T10:28:00Z",
          text: "Did last night's run go through?",
        },
        {
          id: "m4",
          role: "assistant",
          author: assistant,
          createdAt: "2026-11-18T10:29:00Z",
          text: "Yes. It retried two pages with backoff and finished in 48 minutes.",
        },
        {
          id: "m5",
          role: "assistant",
          author: assistant,
          createdAt: "2026-11-18T10:30:00Z",
          text: "I also opened a pull request that alerts when a **billing** run takes longer than an hour.",
        },
      ],
    };

    type Row = { id: string; date: string } | { id: string; line: Line; continued: boolean };

    // A day separator goes before the first message of each day, so it takes a row of its own.
    const toRows = (lines: Line[]): Row[] =>
      lines.flatMap((line, index): Row[] => {
        const previous = lines[index - 1];
        const row = { id: line.id, line, continued: isContinuation(previous, line) };
        return previous && dayKey(previous.createdAt, timeZone) === dayKey(line.createdAt, timeZone)
          ? [row]
          : [{ id: `day-${dayKey(line.createdAt, timeZone)}`, date: line.createdAt }, row];
      });

    let threads = $state.raw(initialThreads);
    let current = $state("export");
    let lines = $state.raw(initialLines);
    const controller = createConversationController();
    let searching = $state(false);
    let marks: readonly number[] = $state.raw([]);
    let online = $state(true);

    $effect(() => {
      const change = () => (online = navigator.onLine);
      change();
      window.addEventListener("online", change);
      window.addEventListener("offline", change);
      return () => {
        window.removeEventListener("online", change);
        window.removeEventListener("offline", change);
      };
    });

    const thread = $derived(threads.find((item) => item.id === current));
    const rows = $derived(toRows(lines[current] ?? []));
    const searchable = $derived(rows.map((row) => ({ id: row.id, text: "line" in row ? row.line.text : "" })));

    const update = (id: string, change: Partial<Thread>) =>
      (threads = threads.map((item) => (item.id === id ? { ...item, ...change } : item)));
    const open = (id: string) => {
      current = id;
      searching = false;
      update(id, { unread: false });
    };
    const create = (title: string) => {
      const id = crypto.randomUUID();
      threads = [
        { id, title: title.trim() || "New chat", updatedAt: new Date().toISOString(), href: `#${id}` },
        ...threads,
      ];
      open(id);
    };
    const send = (text: string) => {
      const line: Line = { id: crypto.randomUUID(), role: "user", text, createdAt: new Date().toISOString() };
      lines = { ...lines, [current]: [...(lines[current] ?? []), line] };
      update(current, { updatedAt: line.createdAt });
    };
  </script>

  <Sidebar label="Chats" defaultSize="200px" minSize="180px" class="h-[640px] w-full overflow-hidden">
    <SidebarPanel>
      <div class="flex h-12 shrink-0 items-center px-2">
        <ThreadSearch {threads} {now} {timeZone} onSelect={open} onNew={create} />
      </div>
      <div class="flex min-h-0 flex-1 flex-col px-2 pb-2">
        <div class="min-h-0 flex-1">
          <ThreadList
            {threads}
            value={current}
            {now}
            {timeZone}
            onSelect={(id: string, details: { cancel(): void }) => {
              details.cancel();
              open(id);
            }}
            onNew={() => create("")}
            onRename={(id: string, { title }: { title: string }) => update(id, { title })}
            onPinChange={(id: string, { pinned }: { pinned: boolean }) => update(id, { pinned })}
            onDelete={(id: string) => {
              const rest = threads.filter((item) => item.id !== id);
              threads = rest;
              if (id !== current) return;
              if (rest[0]) open(rest[0].id);
              else create("");
            }}
          />
        </div>
      </div>
    </SidebarPanel>
    <SidebarHandle />
    <SidebarInset class="bg-[var(--kind-color-raised)]">
      <header class="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
        <SidebarTrigger />
        <h2 class="m-0 min-w-0 flex-1 truncate text-sm font-medium">{thread?.title ?? "New chat"}</h2>
        <button
          type="button"
          data-kind-icon-button=""
          aria-label="Find in chat"
          title="Find in chat"
          onclick={() => (searching = true)}
        >
          <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
            <circle cx="11" cy="11" r="8" />
            <path d="m21 21-4.3-4.3" />
          </svg>
        </button>
      </header>
      <div class="relative min-h-0 flex-1">
        <ConversationSearch
          messages={searchable}
          conversation={controller}
          bind:open={searching}
          onMarksChange={(value: readonly number[]) => (marks = value)}
        />
        {#key current}
          <Conversation aria-label="Conversation" messageCount={rows.length} {controller} {marks} class="h-full">
            <ConversationViewport>
              <ConversationContent>
                {#each rows as row, index (row.id)}
                  <ConversationRow value={row.id} {index}>
                    {#if "line" in row}
                      <Message
                        aria-label={row.line.role === "user" ? "Your message" : "Assistant message"}
                        messageRole={row.line.role}
                        text={row.line.text}
                        author={row.line.author}
                        continued={row.continued}
                        createdAt={row.line.createdAt}
                        {now}
                        {timeZone}
                      >
                        {#if row.line.author}
                          <MessageAvatar />
                          <MessageHeader>
                            <MessageAuthorName />
                            <MessageTime />
                          </MessageHeader>
                        {/if}
                        <MessageContent>
                          <Markdown source={row.line.text} />
                        </MessageContent>
                      </Message>
                    {:else}
                      <DaySeparator date={row.date} {timeZone} relative={false} />
                    {/if}
                  </ConversationRow>
                {/each}
                <ConversationEmpty>
                  <ConversationEmptyTitle>What can I help with?</ConversationEmptyTitle>
                  <ConversationEmptyDescription>Ask anything to start this chat.</ConversationEmptyDescription>
                </ConversationEmpty>
              </ConversationContent>
            </ConversationViewport>
            <ConversationJump />
            <ConversationMarks />
            <ConnectionStatus state={online ? "online" : "offline"} />
          </Conversation>
        {/key}
      </div>
      <div class="mx-auto w-full max-w-[var(--kind-chat-max-width)] p-3">
        <FullComposer
          disabled={!online}
          placeholder={online ? "Ask anything…" : "Offline"}
          onSubmit={(draft) => send(draft.text)}
        />
      </div>
    </SidebarInset>
  </Sidebar>
  ```

  ```tsx tab="Solid"
  import type { MessageAuthor, Thread } from "@kind-ui/agent-ui";
  import { createConversationController, dayKey, isContinuation } from "@kind-ui/agent-ui/core";
  import { createMemo, createSignal, For, onSettled, Show } from "solid-js";
  import { ConnectionStatus } from "@/components/ui/solid/connection-status";
  import {
    Conversation,
    ConversationContent,
    ConversationEmpty,
    ConversationEmptyDescription,
    ConversationEmptyTitle,
    ConversationJump,
    ConversationMarks,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/solid/conversation";
  import { ConversationSearch } from "@/components/ui/solid/conversation-search";
  import { DaySeparator } from "@/components/ui/solid/day-separator";
  import { Markdown } from "@/components/ui/solid/markdown";
  import {
    Message,
    MessageAuthor as MessageAuthorName,
    MessageAvatar,
    MessageContent,
    MessageHeader,
    MessageTime,
  } from "@/components/ui/solid/message";
  import {
    Sidebar,
    SidebarHandle,
    SidebarInset,
    SidebarPanel,
    SidebarTrigger,
  } from "@/components/ui/solid/sidebar";
  import { ThreadList } from "@/components/ui/solid/thread-list";
  import { ThreadSearch } from "@/components/ui/solid/thread-search";
  import FullComposer from "../composer/full.solid";

  const now = "2026-11-18T12:00:00Z";
  const timeZone = "UTC";

  type Line = {
    id: string;
    role: "user" | "assistant";
    text: string;
    createdAt: string;
    author?: MessageAuthor;
  };

  const assistant: MessageAuthor = { id: "assistant", name: "Assistant" };

  const initialThreads: Thread[] = (
    [
      { id: "release", title: "Release checklist", updatedAt: "2026-11-10T09:00:00Z", pinned: true },
      { id: "export", title: "Nightly export timeouts", updatedAt: "2026-11-18T10:30:00Z" },
      { id: "launch", title: "Draft the launch post", updatedAt: "2026-11-18T08:00:00Z", status: "running" },
      { id: "build", title: "Why the build is slow", updatedAt: "2026-11-17T16:00:00Z", unread: true },
      { id: "tests", title: "Flaky checkout tests", updatedAt: "2026-11-14T09:20:00Z" },
      { id: "pricing", title: "Compare pricing tiers", updatedAt: "2026-11-02T18:40:00Z" },
      { id: "schema", title: "Migrate the user schema", updatedAt: "2026-09-21T14:00:00Z" },
    ] satisfies Thread[]
  ).map((thread) => ({ ...thread, href: `#${thread.id}` }));

  const initialLines: Record<string, Line[]> = {
    export: [
      {
        id: "m1",
        role: "user",
        createdAt: "2026-11-17T17:40:00Z",
        text: "The nightly **billing** export failed again. Can you take a look?",
      },
      {
        id: "m2",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-17T17:41:00Z",
        text: "Since Wednesday, every run has stopped after 30 seconds waiting on the reports service:\n\n- its median response time went from 4 to 41 seconds\n- it was slow, not down",
      },
      {
        id: "m3",
        role: "user",
        createdAt: "2026-11-18T10:28:00Z",
        text: "Did last night's run go through?",
      },
      {
        id: "m4",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-18T10:29:00Z",
        text: "Yes. It retried two pages with backoff and finished in 48 minutes.",
      },
      {
        id: "m5",
        role: "assistant",
        author: assistant,
        createdAt: "2026-11-18T10:30:00Z",
        text: "I also opened a pull request that alerts when a **billing** run takes longer than an hour.",
      },
    ],
  };

  type Row = { id: string; date: string } | { id: string; line: Line; continued: boolean };

  // A day separator goes before the first message of each day, so it takes a row of its own.
  const toRows = (lines: Line[]): Row[] =>
    lines.flatMap((line, index): Row[] => {
      const previous = lines[index - 1];
      const row = {
        id: line.id,
        line,
        continued: isContinuation(previous, line),
      };
      return previous && dayKey(previous.createdAt, timeZone) === dayKey(line.createdAt, timeZone)
        ? [row]
        : [{ id: `day-${dayKey(line.createdAt, timeZone)}`, date: line.createdAt }, row];
    });

  function ChatRow(props: { row: Row; index: number }) {
    const line = () => ("line" in props.row ? props.row : undefined);
    return (
      <ConversationRow value={props.row.id} index={props.index}>
        <Show
          when={line()}
          fallback={
            <DaySeparator date={(props.row as { date: string }).date} timeZone={timeZone} relative={false} />
          }
        >
          {(row) => (
            <Message
              aria-label={row().line.role === "user" ? "Your message" : "Assistant message"}
              messageRole={row().line.role}
              text={row().line.text}
              author={row().line.author}
              continued={row().continued}
              createdAt={row().line.createdAt}
              now={now}
              timeZone={timeZone}
            >
              <Show when={row().line.author}>
                <MessageAvatar />
                <MessageHeader>
                  <MessageAuthorName />
                  <MessageTime />
                </MessageHeader>
              </Show>
              <MessageContent>
                <Markdown source={row().line.text} />
              </MessageContent>
            </Message>
          )}
        </Show>
      </ConversationRow>
    );
  }

  export default function ChatShellExample() {
    const [threads, setThreads] = createSignal(initialThreads);
    const [current, setCurrent] = createSignal("export");
    const [lines, setLines] = createSignal(initialLines);
    const controller = createConversationController();
    const [searching, setSearching] = createSignal(false);
    const [marks, setMarks] = createSignal<readonly number[]>([]);
    const [online, setOnline] = createSignal(true);
    onSettled(() => {
      const change = () => setOnline(navigator.onLine);
      change();
      window.addEventListener("online", change);
      window.addEventListener("offline", change);
      return () => {
        window.removeEventListener("online", change);
        window.removeEventListener("offline", change);
      };
    });

    const thread = () => threads().find((item) => item.id === current());
    const rows = createMemo(() => toRows(lines()[current()] ?? []));
    const searchable = createMemo(() =>
      rows().map((row) => ({ id: row.id, text: "line" in row ? row.line.text : "" })),
    );
    const update = (id: string, change: Partial<Thread>) =>
      setThreads((items) => items.map((item) => (item.id === id ? { ...item, ...change } : item)));
    const open = (id: string) => {
      setCurrent(id);
      setSearching(false);
      update(id, { unread: false });
    };
    const create = (title: string) => {
      const id = crypto.randomUUID();
      setThreads((items) => [
        { id, title: title.trim() || "New chat", updatedAt: new Date().toISOString(), href: `#${id}` },
        ...items,
      ]);
      open(id);
    };
    const send = (text: string) => {
      const line: Line = {
        id: crypto.randomUUID(),
        role: "user",
        text,
        createdAt: new Date().toISOString(),
      };
      setLines((all) => ({ ...all, [current()]: [...(all[current()] ?? []), line] }));
      update(current(), { updatedAt: line.createdAt });
    };

    return (
      <Sidebar label="Chats" defaultSize="200px" minSize="180px" class="h-[640px] w-full overflow-hidden">
        <SidebarPanel>
          <div class="flex h-12 shrink-0 items-center px-2">
            <ThreadSearch threads={threads()} now={now} timeZone={timeZone} onSelect={open} onNew={create} />
          </div>
          <div class="flex min-h-0 flex-1 flex-col px-2 pb-2">
            <div class="min-h-0 flex-1">
              <ThreadList
                threads={threads()}
                value={current()}
                now={now}
                timeZone={timeZone}
                onSelect={(id, details) => {
                  details.cancel();
                  open(id);
                }}
                onNew={() => create("")}
                onRename={(id, { title }) => update(id, { title })}
                onPinChange={(id, { pinned }) => update(id, { pinned })}
                onDelete={(id) => {
                  const rest = threads().filter((item) => item.id !== id);
                  setThreads(rest);
                  if (id !== current()) return;
                  if (rest[0]) open(rest[0].id);
                  else create("");
                }}
              />
            </div>
          </div>
        </SidebarPanel>
        <SidebarHandle />
        <SidebarInset class="bg-[var(--kind-color-raised)]">
          <header class="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
            <SidebarTrigger />
            <h2 class="m-0 min-w-0 flex-1 truncate text-sm font-medium">{thread()?.title ?? "New chat"}</h2>
            <button
              type="button"
              data-kind-icon-button=""
              aria-label="Find in chat"
              title="Find in chat"
              onClick={() => setSearching(true)}
            >
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                <circle cx="11" cy="11" r="8" />
                <path d="m21 21-4.3-4.3" />
              </svg>
            </button>
          </header>
          <div class="relative min-h-0 flex-1">
            <ConversationSearch
              messages={searchable()}
              conversation={controller}
              open={searching()}
              onOpenChange={setSearching}
              onMarksChange={setMarks}
            />
            {/* Keyed by the chat, so each chat gets a conversation of its own. */}
            <Show when={current()} keyed>
              <Conversation
                aria-label="Conversation"
                messageCount={rows().length}
                controller={controller}
                marks={marks()}
                class="h-full"
              >
                <ConversationViewport>
                  <ConversationContent>
                    <For each={rows()} keyed={(row) => row.id}>
                      {(row, index) => <ChatRow row={row()} index={index()} />}
                    </For>
                    <ConversationEmpty>
                      <ConversationEmptyTitle>What can I help with?</ConversationEmptyTitle>
                      <ConversationEmptyDescription>
                        Ask anything to start this chat.
                      </ConversationEmptyDescription>
                    </ConversationEmpty>
                  </ConversationContent>
                </ConversationViewport>
                <ConversationJump />
                <ConversationMarks />
                <ConnectionStatus state={online() ? "online" : "offline"} />
              </Conversation>
            </Show>
          </div>
          <div class="mx-auto w-full max-w-[var(--kind-chat-max-width)] p-3">
            <FullComposer
              disabled={!online()}
              placeholder={online() ? "Ask anything…" : "Offline"}
              onSubmit={(draft) => send(draft.text)}
            />
          </div>
        </SidebarInset>
      </Sidebar>
    );
  }
  ```
</Example>

<Example caption="Drag the handle, or focus it and press the arrow keys, to resize the chats. Press the button beside the title, or press Enter on the handle, to hide them.">
  <SidebarExample />

  ```tsx tab="React"
  import { Sidebar, SidebarHandle, SidebarInset, SidebarPanel, SidebarTrigger } from "@/components/ui/sidebar";

  const chats = [
    "Nightly export timeouts",
    "Retry with backoff",
    "Reports service latency",
    "Alert on long runs",
    "Release notes for 2.4",
  ];

  export default function SidebarExample() {
    return (
      <Sidebar label="Chats" className="h-[420px] w-full overflow-hidden">
        <SidebarPanel>
          <div className="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
            <h2 className="m-0 text-sm font-medium">Chats</h2>
          </div>
          <nav aria-label="Recent chats" className="p-2">
            <ul className="flex flex-col gap-0.5">
              {chats.map((chat) => (
                <li key={chat}>
                  <a
                    href="#chat"
                    className="flex h-9 items-center truncate rounded-[var(--kind-radius-md)] px-2.5 text-sm hover:bg-[var(--kind-color-hover)]"
                  >
                    {chat}
                  </a>
                </li>
              ))}
            </ul>
          </nav>
        </SidebarPanel>
        <SidebarHandle />
        <SidebarInset>
          <header className="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
            <SidebarTrigger />
            <h2 className="m-0 truncate text-sm font-medium">Nightly export timeouts</h2>
          </header>
          <p className="m-0 p-4 text-sm text-[var(--kind-color-muted)]">
            Drag the handle to resize the chats, or press the button beside the title to hide them.
          </p>
        </SidebarInset>
      </Sidebar>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import {
    Sidebar,
    SidebarHandle,
    SidebarInset,
    SidebarPanel,
    SidebarTrigger,
  } from "@/components/ui/vue/sidebar";

  const chats = [
    "Nightly export timeouts",
    "Retry with backoff",
    "Reports service latency",
    "Alert on long runs",
    "Release notes for 2.4",
  ];
  </script>

  <template>
    <Sidebar label="Chats" class="h-[420px] w-full overflow-hidden">
      <SidebarPanel>
        <div class="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
          <h2 class="m-0 text-sm font-medium">Chats</h2>
        </div>
        <nav aria-label="Recent chats" class="p-2">
          <ul class="flex flex-col gap-0.5">
            <li v-for="chat in chats" :key="chat">
              <a
                href="#chat"
                class="flex h-9 items-center truncate rounded-[var(--kind-radius-md)] px-2.5 text-sm hover:bg-[var(--kind-color-hover)]"
              >
                {{ chat }}
              </a>
            </li>
          </ul>
        </nav>
      </SidebarPanel>
      <SidebarHandle />
      <SidebarInset>
        <header class="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
          <SidebarTrigger />
          <h2 class="m-0 truncate text-sm font-medium">Nightly export timeouts</h2>
        </header>
        <p class="m-0 p-4 text-sm text-[var(--kind-color-muted)]">
          Drag the handle to resize the chats, or press the button beside the title to hide them.
        </p>
      </SidebarInset>
    </Sidebar>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import {
      Sidebar,
      SidebarHandle,
      SidebarInset,
      SidebarPanel,
      SidebarTrigger,
    } from "@/components/ui/svelte/sidebar/index.js";

    const chats = [
      "Nightly export timeouts",
      "Retry with backoff",
      "Reports service latency",
      "Alert on long runs",
      "Release notes for 2.4",
    ];
  </script>

  <Sidebar label="Chats" class="h-[420px] w-full overflow-hidden">
    <SidebarPanel>
      <div class="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
        <h2 class="m-0 text-sm font-medium">Chats</h2>
      </div>
      <nav aria-label="Recent chats" class="p-2">
        <ul class="flex flex-col gap-0.5">
          {#each chats as chat (chat)}
            <li>
              <a
                href="#chat"
                class="flex h-9 items-center truncate rounded-[var(--kind-radius-md)] px-2.5 text-sm hover:bg-[var(--kind-color-hover)]"
              >
                {chat}
              </a>
            </li>
          {/each}
        </ul>
      </nav>
    </SidebarPanel>
    <SidebarHandle />
    <SidebarInset>
      <header class="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
        <SidebarTrigger />
        <h2 class="m-0 truncate text-sm font-medium">Nightly export timeouts</h2>
      </header>
      <p class="m-0 p-4 text-sm text-[var(--kind-color-muted)]">
        Drag the handle to resize the chats, or press the button beside the title to hide them.
      </p>
    </SidebarInset>
  </Sidebar>
  ```

  ```tsx tab="Solid"
  import { For } from "solid-js";
  import {
    Sidebar,
    SidebarHandle,
    SidebarInset,
    SidebarPanel,
    SidebarTrigger,
  } from "@/components/ui/solid/sidebar";

  const chats = [
    "Nightly export timeouts",
    "Retry with backoff",
    "Reports service latency",
    "Alert on long runs",
    "Release notes for 2.4",
  ];

  export default function SidebarExample() {
    return (
      <Sidebar label="Chats" class="h-[420px] w-full overflow-hidden">
        <SidebarPanel>
          <div class="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
            <h2 class="m-0 text-sm font-medium">Chats</h2>
          </div>
          <nav aria-label="Recent chats" class="p-2">
            <ul class="flex flex-col gap-0.5">
              <For each={chats}>
                {(chat) => (
                  <li>
                    <a
                      href="#chat"
                      class="flex h-9 items-center truncate rounded-[var(--kind-radius-md)] px-2.5 text-sm hover:bg-[var(--kind-color-hover)]"
                    >
                      {chat}
                    </a>
                  </li>
                )}
              </For>
            </ul>
          </nav>
        </SidebarPanel>
        <SidebarHandle />
        <SidebarInset>
          <header class="flex h-12 shrink-0 items-center gap-2 border-b border-[var(--kind-color-border)] px-3">
            <SidebarTrigger />
            <h2 class="m-0 truncate text-sm font-medium">Nightly export timeouts</h2>
          </header>
          <p class="m-0 p-4 text-sm text-[var(--kind-color-muted)]">
            Drag the handle to resize the chats, or press the button beside the title to hide them.
          </p>
        </SidebarInset>
      </Sidebar>
    );
  }
  ```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/sidebar
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/sidebar-web
```

```bash tab="Vue"
npx shadcn@latest add @kind-ui/sidebar-vue
```

```bash tab="Svelte"
npx shadcn@latest add @kind-ui/sidebar-svelte
```

```bash tab="Solid"
npx shadcn@latest add @kind-ui/sidebar-solid
```

## Composition [#composition]

```text
Sidebar
├── SidebarPanel
├── SidebarHandle
├── SidebarInset
└── SidebarTrigger
```

`SidebarPanel` is the panel, an `aside` named by the sidebar's `label`, like "Chats". `SidebarHandle` is the resize handle between the panel and the page, named "Resize Chats", and `SidebarInset` is the page. `SidebarTrigger` is a button that shows and hides the panel, named "Hide Chats" or "Show Chats", with a panel icon when you give it no children.

## Usage [#usage]

### Parts in Reading Order [#parts-in-reading-order]

Write `SidebarPanel`, `SidebarHandle` and `SidebarInset` in reading order. With `side="start"`, the default, the panel comes first. With `side="end"`, the inset comes first and the panel last. Both follow the writing direction, so a start panel sits on the right in a right-to-left page. Put the `SidebarTrigger` in the page's header, at the edge the panel sits on: the start of the header for a start panel, the end for an end panel. There it stays in place whether the panel is open, closed or a drawer.

<Example caption="Press the button in the header to hide the assistant, or drag its handle to resize it. Type a prompt and press Enter to add it to the conversation.">
  <SidebarAssistantExample />

  ```tsx tab="React"
  "use client";
  import { useState } from "react";
  import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/composer";
  import {
    Conversation,
    ConversationContent,
    ConversationJump,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/conversation";
  import { Sidebar, SidebarHandle, SidebarInset, SidebarPanel, SidebarTrigger } from "@/components/ui/sidebar";

  type Line = { id: string; role: "user" | "assistant"; text: string };

  const first: Line[] = [
    { id: "m1", role: "user", text: "Why did the nightly export fail?" },
    {
      id: "m2",
      role: "assistant",
      text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
    },
  ];

  export default function SidebarAssistantExample() {
    const [lines, setLines] = useState(first);

    return (
      <Sidebar side="end" label="Assistant" defaultSize="320px" className="h-[420px] w-full overflow-hidden">
        <SidebarInset>
          <header className="flex h-12 shrink-0 items-center justify-between gap-2 border-b border-[var(--kind-color-border)] px-3">
            <h2 className="m-0 truncate text-sm font-medium">billing-export.ts</h2>
            <SidebarTrigger />
          </header>
          <pre className="m-0 flex-1 overflow-auto p-4 text-xs">
            {
              "export async function run() {\n  const pages = await reports.list({ timeout: 30_000 });\n  await upload(pages);\n}"
            }
          </pre>
        </SidebarInset>
        <SidebarHandle />
        <SidebarPanel>
          <div className="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
            <h2 className="m-0 text-sm font-medium">Assistant</h2>
          </div>
          <Conversation
            aria-label="Assistant conversation"
            messageCount={lines.length}
            className="min-h-0 flex-1"
          >
            <ConversationViewport>
              <ConversationContent>
                {lines.map((line, index) => (
                  <ConversationRow key={line.id} value={line.id} index={index}>
                    <p
                      className={
                        line.role === "user"
                          ? "ms-auto w-fit max-w-[85%] rounded-[var(--kind-bubble-radius)] bg-[var(--kind-color-bubble)] px-3.5 py-2 text-sm"
                          : "text-sm"
                      }
                    >
                      {line.text}
                    </p>
                  </ConversationRow>
                ))}
              </ConversationContent>
            </ConversationViewport>
            <ConversationJump />
          </Conversation>
          <div className="p-2">
            <Composer
              aria-label="Message"
              onSubmit={(draft) =>
                setLines((current) => [
                  ...current,
                  { id: `m${current.length + 1}`, role: "user", text: draft.text },
                ])
              }
            >
              <ComposerInput aria-label="Prompt" placeholder="Ask about this file" />
              <ComposerSubmit />
            </Composer>
          </div>
        </SidebarPanel>
      </Sidebar>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import { ref } from "vue";
  import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/vue/composer";
  import {
    Conversation,
    ConversationContent,
    ConversationJump,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/vue/conversation";
  import {
    Sidebar,
    SidebarHandle,
    SidebarInset,
    SidebarPanel,
    SidebarTrigger,
  } from "@/components/ui/vue/sidebar";

  type Line = { id: string; role: "user" | "assistant"; text: string };

  const lines = ref<Line[]>([
    { id: "m1", role: "user", text: "Why did the nightly export fail?" },
    {
      id: "m2",
      role: "assistant",
      text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
    },
  ]);

  const code =
    "export async function run() {\n  const pages = await reports.list({ timeout: 30_000 });\n  await upload(pages);\n}";

  const send = (draft: { text: string }) => {
    lines.value = [...lines.value, { id: `m${lines.value.length + 1}`, role: "user", text: draft.text }];
  };
  </script>

  <template>
    <Sidebar side="end" label="Assistant" default-size="320px" class="h-[420px] w-full overflow-hidden">
      <SidebarInset>
        <header
          class="flex h-12 shrink-0 items-center justify-between gap-2 border-b border-[var(--kind-color-border)] px-3"
        >
          <h2 class="m-0 truncate text-sm font-medium">billing-export.ts</h2>
          <SidebarTrigger />
        </header>
        <pre class="m-0 flex-1 overflow-auto p-4 text-xs">{{ code }}</pre>
      </SidebarInset>
      <SidebarHandle />
      <SidebarPanel>
        <div class="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
          <h2 class="m-0 text-sm font-medium">Assistant</h2>
        </div>
        <Conversation aria-label="Assistant conversation" :message-count="lines.length" class="min-h-0 flex-1">
          <ConversationViewport>
            <ConversationContent>
              <ConversationRow v-for="(line, index) in lines" :key="line.id" :value="line.id" :index="index">
                <p
                  :class="
                    line.role === 'user'
                      ? 'ms-auto w-fit max-w-[85%] rounded-[var(--kind-bubble-radius)] bg-[var(--kind-color-bubble)] px-3.5 py-2 text-sm'
                      : 'text-sm'
                  "
                >
                  {{ line.text }}
                </p>
              </ConversationRow>
            </ConversationContent>
          </ConversationViewport>
          <ConversationJump />
        </Conversation>
        <div class="p-2">
          <Composer aria-label="Message" :on-submit="send">
            <ComposerInput aria-label="Prompt" placeholder="Ask about this file" />
            <ComposerSubmit />
          </Composer>
        </div>
      </SidebarPanel>
    </Sidebar>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/svelte/composer/index.js";
    import {
      Conversation,
      ConversationContent,
      ConversationJump,
      ConversationRow,
      ConversationViewport,
    } from "@/components/ui/svelte/conversation/index.js";
    import {
      Sidebar,
      SidebarHandle,
      SidebarInset,
      SidebarPanel,
      SidebarTrigger,
    } from "@/components/ui/svelte/sidebar/index.js";

    type Line = { id: string; role: "user" | "assistant"; text: string };

    let lines: Line[] = $state.raw([
      { id: "m1", role: "user", text: "Why did the nightly export fail?" },
      {
        id: "m2",
        role: "assistant",
        text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
      },
    ]);
  </script>

  <Sidebar side="end" label="Assistant" defaultSize="320px" class="h-[420px] w-full overflow-hidden">
    <SidebarInset>
      <header
        class="flex h-12 shrink-0 items-center justify-between gap-2 border-b border-[var(--kind-color-border)] px-3"
      >
        <h2 class="m-0 truncate text-sm font-medium">billing-export.ts</h2>
        <SidebarTrigger />
      </header>
      <pre class="m-0 flex-1 overflow-auto p-4 text-xs">{"export async function run() {\n  const pages = await reports.list({ timeout: 30_000 });\n  await upload(pages);\n}"}</pre>
    </SidebarInset>
    <SidebarHandle />
    <SidebarPanel>
      <div class="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
        <h2 class="m-0 text-sm font-medium">Assistant</h2>
      </div>
      <Conversation aria-label="Assistant conversation" messageCount={lines.length} class="min-h-0 flex-1">
        <ConversationViewport>
          <ConversationContent>
            {#each lines as line, index (line.id)}
              <ConversationRow value={line.id} {index}>
                <p
                  class={line.role === "user"
                    ? "ms-auto w-fit max-w-[85%] rounded-[var(--kind-bubble-radius)] bg-[var(--kind-color-bubble)] px-3.5 py-2 text-sm"
                    : "text-sm"}
                >
                  {line.text}
                </p>
              </ConversationRow>
            {/each}
          </ConversationContent>
        </ConversationViewport>
        <ConversationJump />
      </Conversation>
      <div class="p-2">
        <Composer
          aria-label="Message"
          onSubmit={(draft: { text: string }) => {
            lines = [...lines, { id: `m${lines.length + 1}`, role: "user", text: draft.text }];
          }}
        >
          <ComposerInput aria-label="Prompt" placeholder="Ask about this file" />
          <ComposerSubmit />
        </Composer>
      </div>
    </SidebarPanel>
  </Sidebar>
  ```

  ```tsx tab="Solid"
  import { createSignal, For } from "solid-js";
  import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/solid/composer";
  import {
    Conversation,
    ConversationContent,
    ConversationJump,
    ConversationRow,
    ConversationViewport,
  } from "@/components/ui/solid/conversation";
  import {
    Sidebar,
    SidebarHandle,
    SidebarInset,
    SidebarPanel,
    SidebarTrigger,
  } from "@/components/ui/solid/sidebar";

  type Line = { id: string; role: "user" | "assistant"; text: string };

  const first: Line[] = [
    { id: "m1", role: "user", text: "Why did the nightly export fail?" },
    {
      id: "m2",
      role: "assistant",
      text: "Every run since last week stopped after 30 seconds waiting on the reports service.",
    },
  ];

  export default function SidebarAssistantExample() {
    const [lines, setLines] = createSignal(first);

    return (
      <Sidebar side="end" label="Assistant" defaultSize="320px" class="h-[420px] w-full overflow-hidden">
        <SidebarInset>
          <header class="flex h-12 shrink-0 items-center justify-between gap-2 border-b border-[var(--kind-color-border)] px-3">
            <h2 class="m-0 truncate text-sm font-medium">billing-export.ts</h2>
            <SidebarTrigger />
          </header>
          <pre class="m-0 flex-1 overflow-auto p-4 text-xs">
            {
              "export async function run() {\n  const pages = await reports.list({ timeout: 30_000 });\n  await upload(pages);\n}"
            }
          </pre>
        </SidebarInset>
        <SidebarHandle />
        <SidebarPanel>
          <div class="flex h-12 shrink-0 items-center border-b border-[var(--kind-color-border)] px-4">
            <h2 class="m-0 text-sm font-medium">Assistant</h2>
          </div>
          <Conversation
            aria-label="Assistant conversation"
            messageCount={lines().length}
            class="min-h-0 flex-1"
          >
            <ConversationViewport>
              <ConversationContent>
                <For each={lines()} keyed={(line) => line.id}>
                  {(line, index) => (
                    <ConversationRow value={line().id} index={index()}>
                      <p
                        class={
                          line().role === "user"
                            ? "ms-auto w-fit max-w-[85%] rounded-[var(--kind-bubble-radius)] bg-[var(--kind-color-bubble)] px-3.5 py-2 text-sm"
                            : "text-sm"
                        }
                      >
                        {line().text}
                      </p>
                    </ConversationRow>
                  )}
                </For>
              </ConversationContent>
            </ConversationViewport>
            <ConversationJump />
          </Conversation>
          <div class="p-2">
            <Composer
              aria-label="Message"
              onSubmit={(draft) =>
                setLines((current) => [
                  ...current,
                  { id: `m${current.length + 1}`, role: "user", text: draft.text },
                ])
              }
            >
              <ComposerInput aria-label="Prompt" placeholder="Ask about this file" />
              <ComposerSubmit />
            </Composer>
          </div>
        </SidebarPanel>
      </Sidebar>
    );
  }
  ```
</Example>

### Opening and Closing [#opening-and-closing]

The panel starts open. Pass `defaultOpen={false}` to start it closed, or `open` and `onOpenChange` to control it. The trigger toggles it, and so do Enter on the handle and a double-click on it. Dragging the handle past the panel's midpoint closes it too. `onOpenChange` gets why: `trigger-press`, `handle`, `drag`, `shortcut`, `outside-press` or `escape-key` from the drawer, `breakpoint` when the window crosses `overlayBelow`, or `imperative` from the api, like an agent's `open`.

```tsx
const [open, setOpen] = useState(true);

<Sidebar label="Chats" open={open} onOpenChange={(next) => setOpen(next)}>
  …
</Sidebar>
```

When the trigger, the shortcut or the api opens or closes it, the panel slides in or out from its edge, and the page changes width once, as the panel starts to open or once it has closed, so its text doesn't wrap again on every frame. With a `collapsedSize` above 0, the width slides instead, so the rail stays in view. Under `prefers-reduced-motion`, or with `motion="reduced"` or `"none"`, it changes at once. It never slides while someone drags the handle.

### Sizes [#sizes]

The panel starts at `defaultSize`, 280px, and resizes between `minSize`, 220px, and `maxSize`, 420px. Each takes pixels, rem or a percentage of the sidebar, and pixel and rem sizes hold as the window resizes. Closed, it's `collapsedSize` wide, 0px by default. Pass a rail width, like `"48px"`, to keep the panel's icons in view while it's closed:

```tsx
<Sidebar label="Chats" defaultSize="260px" minSize="200px" maxSize="360px" collapsedSize="48px">
```

### Narrow Screens [#narrow-screens]

Under `overlayBelow`, `"(max-width: 767px)"` by default, the panel is a modal drawer that slides in from its side over the page, and the handle is gone. The drawer always starts closed, the trigger opens it, and Escape, a press outside it or a swipe closes it. Crossing `overlayBelow` reports `breakpoint`: getting narrower closes the drawer, and getting wider gives the panel back whether it was open before. The panel's content mounts again as it moves between the page and the drawer, so keep state you need in the host. Pass an empty string to keep the panel beside the page at every width. The query is read in the browser, so server markup under the default query already hides the panel; with another `overlayBelow`, give `[data-sidebar-frame="panel"]` no width under it yourself until the root has `data-bound`.

### Saving the Layout [#saving-the-layout]

Pass a `storageKey` to save the panel's width and whether it's open when someone resizes or collapses it, and restore them on the next visit. An uncontrolled sidebar takes the saved state over `defaultOpen`. It saves to `localStorage` unless you pass `storage`, anything with `getItem` and `setItem`.

A server can't read `localStorage`, so the page renders `defaultSize` first and the saved width arrives as it hydrates. Save to a cookie instead, and the server can render the saved width on the first paint:

```tsx title="app/chats.tsx"
"use client";
import type { ResizableStorage } from "@ui-sdk/core/resizable";

const cookieStorage: ResizableStorage = {
  getItem: (key) => {
    const value = document.cookie.match(new RegExp(`(?:^|; )${key}=([^;]*)`))?.[1];
    return value === undefined ? null : decodeURIComponent(value);
  },
  setItem: (key, value) => {
    document.cookie = `${key}=${encodeURIComponent(value)}; path=/; max-age=31536000`;
  },
};

export function Chats({ size }: { size: string }) {
  return (
    <Sidebar label="Chats" storageKey="chats" storage={cookieStorage} defaultSize={size}>
      <SidebarPanel>…</SidebarPanel>
      <SidebarHandle />
      <SidebarInset>…</SidebarInset>
    </Sidebar>
  );
}
```

The cookie is named by `resizableStorageKey(storageKey)` from `@ui-sdk/core/resizable`, which a server component can import, and holds the layout under the panels' ids, `${storageKey}-sidebar,${storageKey}-inset`, as percentages. Read the panel's and pass it back as `defaultSize`:

```tsx title="app/page.tsx"
import { resizableStorageKey } from "@ui-sdk/core/resizable";
import { cookies } from "next/headers";
import { Chats } from "./chats";

export default async function Page() {
  const saved = JSON.parse((await cookies()).get(resizableStorageKey("chats"))?.value ?? "{}");
  const [percent] = saved["chats-sidebar,chats-inset"] ?? [];
  return <Chats size={percent === undefined ? "280px" : `${percent}%`} />;
}
```

### Shortcut [#shortcut]

The sidebar has no shortcut by default. Pass one, like `shortcut="mod+b"`, to open and close the panel from anywhere on the page; `mod` is Command on Apple platforms and Ctrl elsewhere. The trigger lists it in `aria-keyshortcuts`, and its render function gets the keys as the platform writes them, like "⌘B", as `shortcutLabel`.

## API Reference [#api-reference]

### SidebarOptions

| Prop             | Type                                                                                      | Description                                                                                                                                                                                                                                                                                            |
| ---------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `side?`          | `"end" \| "start"`                                                                        | The edge the panel sits on, which the drawer comes from on narrow screens. `"start"` and `"end"` follow the writing direction. Write the parts in reading order: the panel first for `"start"`, the inset first for `"end"`. Default: `"start"`                                                        |
| `label?`         | `string \| undefined`                                                                     | Names the panel, its resize handle ("Resize Chats") and its trigger ("Hide Chats"). Default: `"Sidebar"`                                                                                                                                                                                               |
| `open?`          | `boolean \| undefined`                                                                    | Whether the panel is open. Passing it controls it: change it in `onOpenChange`.                                                                                                                                                                                                                        |
| `defaultOpen?`   | `boolean \| undefined`                                                                    | Whether the panel starts open, when `open` isn't passed. The drawer on a narrow screen always starts closed. Default: `true`                                                                                                                                                                           |
| `onOpenChange?`  | `((open: boolean, details: ChangeDetails<SidebarOpenChangeReason>) => void) \| undefined` | Called when a person, the shortcut, the window or an `api` call opens or closes the panel, with why.                                                                                                                                                                                                   |
| `defaultSize?`   | `ResizableSize \| undefined`                                                              | The panel's width at first: pixels, rem or a percentage of the sidebar. Default: `"280px"`                                                                                                                                                                                                             |
| `minSize?`       | `ResizableSize \| undefined`                                                              | The narrowest the open panel gets. Pixel and rem sizes hold as the window resizes. Default: `"220px"`                                                                                                                                                                                                  |
| `maxSize?`       | `ResizableSize \| undefined`                                                              | The widest the panel gets. Default: `"420px"`                                                                                                                                                                                                                                                          |
| `collapsedSize?` | `ResizableSize \| undefined`                                                              | The panel's width while closed: 0 hides it, a rail width like `"48px"` keeps its icons in view. Default: `"0px"`                                                                                                                                                                                       |
| `storageKey?`    | `string \| undefined`                                                                     | Saves the panel's width and whether it's open when a person resizes or collapses it, and restores them on the next visit, under this key. An uncontrolled sidebar takes the saved state over `defaultOpen`. Read once, when the sidebar is created.                                                    |
| `storage?`       | `ResizableStorage \| undefined`                                                           | Where `storageKey` saves: anything with `getItem` and `setItem`, like a cookie a server can read.                                                                                                                                                                                                      |
| `overlayBelow?`  | `string \| undefined`                                                                     | The media query under which the panel turns into a modal drawer, read in the browser. An empty string keeps the panel beside the page at every width. Default: `"(max-width: 767px)"`                                                                                                                  |
| `shortcut?`      | `string \| undefined`                                                                     | A shortcut that opens and closes the panel, like `"mod+b"`. `mod` is Command on Apple platforms.                                                                                                                                                                                                       |
| `motion?`        | `"auto" \| "none" \| "reduced"`                                                           | How the panel moves when its trigger, the shortcut or an `api` call opens or closes it: it slides at full motion, while the page beside it changes width once, and snaps under reduced motion, and never while a person drags the handle. `"auto"` follows `prefers-reduced-motion`. Default: `"auto"` |

Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:

| React                  | Vue                            | Svelte                      | Solid                  |
| ---------------------- | ------------------------------ | --------------------------- | ---------------------- |
| `open`, `onOpenChange` | `v-model:open`, `@open-change` | `bind:open`, `onOpenChange` | `open`, `onOpenChange` |

### Agent [#agent]

An agent connected with `createAgent` finds the sidebar by its `label` and reads `open` and `overlay`, whether the panel is a drawer. `open` is offered while the panel is closed, and `close` while it's open; the reason is `imperative`. Neither needs a person to confirm.

### SidebarAgentActions

| Prop    | Type                        | Description                                 |
| ------- | --------------------------- | ------------------------------------------- |
| `open`  | `(() => void) \| undefined` | Opens the panel, offered while it's closed. |
| `close` | `(() => void) \| undefined` | Closes the panel, offered while it's open.  |

<Caption>
  Runs in React, Vue, Svelte, Solid and Web Components. Call `defineSidebar()`, then write a `<kind-sidebar>` holding a `kind-sidebar-panel` and a `kind-sidebar-inset` in reading order, with a `kind-sidebar-trigger` around a `button` anywhere inside. Each prop is a kebab-case attribute, so `defaultSize` is `default-size` and `overlayBelow` is `overlay-below`; set `storage` as a property, and `open` is a property too. Opening and closing fires `openchange`.
</Caption>
